This commit is contained in:
2026-08-21 17:03:02 +08:00
commit f065129b20
2292 changed files with 666241 additions and 0 deletions
+473
View File
@@ -0,0 +1,473 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using GThinking.N_MISPRO;
using GThinking.N_MISPRO.Data;
using GThinking.N_MODEL.Page;
using GThinking.N_WORKFLOW;
using GThinking.N_MODEL.Dialog;
using GThinking.N_PUBLIC;
using GThinking.N_PUBLIC2;
using GThinking.N_MISPRO.Utility;
using GThinking.N_CONTROL;
using System.IO;
using System.Data.OleDb;
using System.Data.Common;
using GThinking.N_MISPRO.Caching;
using GThinking.N_MISPRO.TableCache;
using GThinking.N_MISPROAS;
namespace GThinking.N_XLXSBJ
{
public partial class XHJDDZB_DR : SingleCardBase
{
XHJDDZB_DREntity entity = new XHJDDZB_DREntity();
protected void Page_Load(object sender, EventArgs e)
{
this.UMID = 100860038;
this.UMName = "报价单型号加点对照表";
base.CurMaster = Master;
this.CurEntity = entity;
this.PageHeight = 180;
this.PageWidth = 420;
this.Master.EnableAttachBtn = false;
this.Master.EnableCancelBtn = false;
this.Master.EnableCopyBtn = false;
this.Master.EnableDeleteBtn = false;
this.Master.EnableEditBtn = false;
this.Master.EnableInsertBtn = false;
this.Master.EnablePrintBtn = false;
this.Master.EnableRefreshBtn = false;
this.Master.EnableSaveBtn = false;
Server.ScriptTimeout = 3600;
fupdPost.FileSaveType = gtAsyncFileUpload.DFileSaveType.SaveToPath;
if (AppRuntime.BitType == AppBitType.Bit32)
fupdPost.Filter = "XLS";
else // AppBitType.Bit64
fupdPost.Filter = "XLS,XLSX";
base.InitPage();
Server.ScriptTimeout = 3600;
btnUn.Style["display"] = "none";
}
#region 控件事件
protected void btnQX_Click(object sender, EventArgs e)
{
CloseWindowNoQuery();
}
protected void btnUnDis_Click(object sender, EventArgs e)
{
TDatabase dberp = TContextDatabases.GetDatabase("DBERP");
TSQL sSQL = new TSQL(dberp);
try
{
lblTitle.Text = "正在导入数据,请稍后...";
dberp.BeginTrans();
string sDRXXMessage = string.Empty;
DataSet aDataExcel = new DataSet();
if (AppRuntime.BitType == AppBitType.Bit32)
{
aDataExcel = XLBJDUtils.ReadFromExcelFile(fupdPost.FilePath, 0, "");
}
else // AppBitType.Bit64
{
ReadWJ(fupdPost.FilePath, ref aDataExcel);
}
string sJDfields = string.Empty;
bool hasZHJD = false;
int JSFSIndex = -1;
ExcelColumnValid(aDataExcel, ref sJDfields, ref hasZHJD, ref JSFSIndex);
InsertDRJL(dberp, sSQL, aDataExcel, sJDfields, ref sDRXXMessage, hasZHJD, JSFSIndex);
dberp.CommitTrans();
if (!sDRXXMessage.ToString().Trim().Equals(""))
{
ShowMessage("导入完成!\r\n存在如下数据未成功导入:\r\n" + sDRXXMessage.ToString());
}
else
{
ShowMessage("导入成功!");
}
DialogOperationScript dos = new DialogOperationScript(this);
dos.ClickOwnerButton(PageParam.GetRTrimString("btnRefreshCID"));
dos.CloseSelf();
dos.Execute();
}
catch (Exception ex)
{
lblTitle.Text = "";
dberp.RollbackTrans();
ShowMessage(ex.Message);
}
finally
{
System.IO.File.Delete(fupdPost.FilePath.Trim());
}
CloseWindowNoQuery();
}
#endregion
#region 自定义函数
private void InsertDRJL(TDatabase dberp, TSQL SQL, DataSet ds, string sJDfields, ref string sDRXXMessage, bool hasZHJD, int JSFSIndex)
{
int columCountbeforeJDYZ = 7;
string sJSFS = string.Empty;
string[] sJDfieldsNum = sJDfields.TrimStart(',').Split(',');
string sJDfieldsV = sJDfields.Replace(",", ",:");
//已经删除过的型号对照组
Dictionary<string, List<string>> DeletedXHDZ = new Dictionary<string, List<string>>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (JSFSIndex > -1)
sJSFS = GetJSFS(ds.Tables[0].Rows[i][JSFSIndex].ToString().Trim());
if (string.IsNullOrEmpty(sJSFS.Trim()))
sJSFS = GetJSFS();
string sJGBXLXHID = ds.Tables[0].Rows[i][0].ToString().Trim();
string sBJDXLXHID = ds.Tables[0].Rows[i][1].ToString().Trim();
string sDYDJID = ds.Tables[0].Rows[i][2].ToString().Trim() == "" ? " " : ds.Tables[0].Rows[i][2].ToString().Trim();
string sXXJGID = ds.Tables[0].Rows[i][3].ToString().Trim() == "" ? " " : ds.Tables[0].Rows[i][3].ToString().Trim();
double dZXJMXX = CMISproConvert.StrToFloat(ds.Tables[0].Rows[i][4].ToString().Trim(), 0);
double dZXJMSX = CMISproConvert.StrToFloat(ds.Tables[0].Rows[i][5].ToString().Trim(), 0);
string sDZHDYDJID = ds.Tables[0].Rows[i][6].ToString().Trim() == "" ? " " : ds.Tables[0].Rows[i][6].ToString().Trim();
double dYZZ = 0;
//如果excel表格导入时有综合加点列,则以导入的数值为准
if (hasZHJD)
{
dYZZ = CMISproConvert.StrToFloat(ds.Tables[0].Rows[i][7].ToString().Trim(), 0);
columCountbeforeJDYZ = 8;
}
//综合加点值为0则计算综合加点
if (dYZZ == 0)
{
dYZZ = 1;
if (sJSFS == "JD")
{
for (int j = columCountbeforeJDYZ; j < ds.Tables[0].Columns.Count; j++)
{
dYZZ = dYZZ * (1 + CMISproConvert.StrToFloat(ds.Tables[0].Rows[i][j].ToString().Trim(), 0) / 100);
}
}
else if (sJSFS == "KD")
{
for (int j = columCountbeforeJDYZ; j < ds.Tables[0].Columns.Count; j++)
{
dYZZ = dYZZ / (1 - CMISproConvert.StrToFloat(ds.Tables[0].Rows[i][j].ToString().Trim(), 0) / 100);
}
}
else if (sJSFS == "01")
{
double dYZZSum = 0;
for (int j = columCountbeforeJDYZ; j < ds.Tables[0].Columns.Count; j++)
{
dYZZSum += CMISproConvert.StrToFloat(ds.Tables[0].Rows[i][j].ToString().Trim(), 0);
}
dYZZ = dYZZ * (1 + dYZZSum / 100);
}
else if (sJSFS == "KH")
{
double dSumKD = 0;
for (int j = columCountbeforeJDYZ; j < ds.Tables[0].Columns.Count; j++)
{
dSumKD += CMISproConvert.StrToFloat(ds.Tables[0].Rows[i][j].ToString().Trim(), 0) / 100;
}
if(dSumKD != 1)
{
dYZZ = dYZZ/(dYZZ-dSumKD);
}
}
}
#region 校验数据
if (string.IsNullOrEmpty(sJGBXLXHID))
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:价格表线缆型号不允许为空!。\r\n";
continue;
}
if (!ExistedXHID(sJGBXLXHID))
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:价格表线缆型号【" + sJGBXLXHID + "】不存在或已停用!。\r\n";
continue;
}
if (string.IsNullOrEmpty(sBJDXLXHID))
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:报价单线缆型号不允许为空!。\r\n";
continue;
}
if (!ExistedXHID(sBJDXLXHID))
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:报价单线缆型号【" + sBJDXLXHID + "】不存在或已停用!。\r\n";
continue;
}
if (dZXJMXX < 0)
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:主芯截面下限--不允许为负数!。\r\n";
continue;
}
if (dZXJMSX < 0)
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:主芯截面上限--不允许为负数!。\r\n";
continue;
}
if (dZXJMSX > 0 && dZXJMXX > dZXJMSX)
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:主芯截面下限不允许超过主芯截面上限!。\r\n";
continue;
}
if (string.IsNullOrEmpty(sDYDJID.Trim()) && (!string.IsNullOrEmpty(sDZHDYDJID.Trim())))
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:电压等级为空时,对照后电压等级必须为空!。\r\n";
continue;
}
if ((!string.IsNullOrEmpty(sDYDJID.Trim())) && (!ExistedDYDJID(sDYDJID)))
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:电压等级【" + sDYDJID + "】不存在或已停用!。\r\n";
continue;
}
if ((!string.IsNullOrEmpty(sDZHDYDJID.Trim())) && (!ExistedDYDJID(sDZHDYDJID)))
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:对照后电压等级【" + sDZHDYDJID + "】不存在或已停用!。\r\n";
continue;
}
if (string.IsNullOrEmpty(sDZHDYDJID.Trim()) || sDZHDYDJID.Trim().Equals(sDYDJID.Trim()))
{
if (sJGBXLXHID.Equals(sBJDXLXHID))
{
sDRXXMessage += "第" + (i + 1) + "行数据未成功导入,原因:价格表线缆型号与报价单线缆型号不允许一致!。\r\n";
continue;
}
}
#endregion
#region 插入语句
SQL.Clear();
SQL.Add("insert into XLXSJGBXHDZB(XLXSJGBXHDZB_JGBXLXHID,XLXSJGBXHDZB_BJDXLXHID,XLXSJGBXHDZB_ZXJMXX,XLXSJGBXHDZB_ZXJMSX,XLXSJGBXHDZB_DYDJID,XLXSJGBXHDZB_DZHDYDJID,XLXSJGBXHDZB_XXJGID,XLXSJGBXHDZB_YZZ,XLXSJGBXHDZB_YZZJSFS ");
SQL.Add(sJDfields);
SQL.Add(",XLXSJGBXHDZB_WHR,XLXSJGBXHDZB_WHRID,XLXSJGBXHDZB_WHSJ) ");
SQL.Add(" values(:XLXSJGBXHDZB_JGBXLXHID,:XLXSJGBXHDZB_BJDXLXHID,:XLXSJGBXHDZB_ZXJMXX,:XLXSJGBXHDZB_ZXJMSX,:XLXSJGBXHDZB_DYDJID,:XLXSJGBXHDZB_DZHDYDJID,:XLXSJGBXHDZB_XXJGID,:XLXSJGBXHDZB_YZZ,:XLXSJGBXHDZB_YZZJSFS");
SQL.Add(sJDfieldsV);
SQL.Add(",:XLXSJGBXHDZB_WHR,:XLXSJGBXHDZB_WHRID,:XLXSJGBXHDZB_WHSJ) ");
SQL.ParamByName("XLXSJGBXHDZB_JGBXLXHID").Value = sJGBXLXHID;
SQL.ParamByName("XLXSJGBXHDZB_BJDXLXHID").Value = sBJDXLXHID;
SQL.ParamByName("XLXSJGBXHDZB_ZXJMXX").Value = dZXJMXX;
SQL.ParamByName("XLXSJGBXHDZB_ZXJMSX").Value = dZXJMSX;
SQL.ParamByName("XLXSJGBXHDZB_DYDJID").Value = sDYDJID;
SQL.ParamByName("XLXSJGBXHDZB_DZHDYDJID").Value = sDZHDYDJID;
SQL.ParamByName("XLXSJGBXHDZB_XXJGID").Value = sXXJGID;
SQL.ParamByName("XLXSJGBXHDZB_YZZ").Value = dYZZ;
SQL.ParamByName("XLXSJGBXHDZB_YZZJSFS").Value = sJSFS;
for (int j = 0; j < sJDfieldsNum.Length; j++)
{
SQL.ParamByName(sJDfieldsNum[j]).Value = CMISproConvert.StrToFloat(ds.Tables[0].Rows[i][columCountbeforeJDYZ + j].ToString().Trim(), 0);
}
SQL.ParamByName("XLXSJGBXHDZB_WHR").Value = tSession.UserName;
SQL.ParamByName("XLXSJGBXHDZB_WHRID").Value = tSession.UserId;
SQL.ParamByName("XLXSJGBXHDZB_WHSJ").Value = DateTime.Now;
dberp.ExecSQL(SQL);
#endregion
}
SQL.Clear();
SQL.Add(@" SELECT TOP 1 XLXSJGBXHDZB_JGBXLXHID,XLXSJGBXHDZB_BJDXLXHID,XLXSJGBXHDZB_XXJGID,XLXSJGBXHDZB_DYDJID,XLXSJGBXHDZB_ZXJMXX,XLXSJGBXHDZB_ZXJMSX
FROM XLXSJGBXHDZB A
WHERE EXISTS (
SELECT 1
FROM XLXSJGBXHDZB B
WHERE
A.XLXSJGBXHDZB_JGBXLXHID =B.XLXSJGBXHDZB_JGBXLXHID
AND A.XLXSJGBXHDZB_BJDXLXHID = B.XLXSJGBXHDZB_BJDXLXHID
AND A.XLXSJGBXHDZB_XXJGID = B.XLXSJGBXHDZB_XXJGID
AND A.XLXSJGBXHDZB_DYDJID=B.XLXSJGBXHDZB_DYDJID
AND A.XLXSJGBXHDZB_DZHDYDJID=B.XLXSJGBXHDZB_DZHDYDJID
AND (
(A.XLXSJGBXHDZB_ZXJMXX BETWEEN B.XLXSJGBXHDZB_ZXJMXX AND B.XLXSJGBXHDZB_ZXJMSX)
OR (B.XLXSJGBXHDZB_ZXJMXX BETWEEN A.XLXSJGBXHDZB_ZXJMXX AND A.XLXSJGBXHDZB_ZXJMSX)
OR (A.XLXSJGBXHDZB_ZXJMSX = 0 AND B.XLXSJGBXHDZB_ZXJMXX >= A.XLXSJGBXHDZB_ZXJMXX)
OR (B.XLXSJGBXHDZB_ZXJMSX = 0 AND A.XLXSJGBXHDZB_ZXJMXX >= B.XLXSJGBXHDZB_ZXJMXX)
)
AND (A.XLXSJGBXHDZB_ZXJMXX <> B.XLXSJGBXHDZB_ZXJMXX or A.XLXSJGBXHDZB_ZXJMSX <> B.XLXSJGBXHDZB_ZXJMSX)
) ");
DataSet dsCF = dberp.OpenDataSet(SQL);
if (dsCF.Tables[0].Rows.Count > 0)
{
string sJGBXLXHID = dsCF.Tables[0].Rows[0]["XLXSJGBXHDZB_JGBXLXHID"].ToString().Trim();
string sBJDXLXHID = dsCF.Tables[0].Rows[0]["XLXSJGBXHDZB_BJDXLXHID"].ToString().Trim();
string sXXJGID = dsCF.Tables[0].Rows[0]["XLXSJGBXHDZB_XXJGID"].ToString().Trim();
string sDYDJID = dsCF.Tables[0].Rows[0]["XLXSJGBXHDZB_DYDJID"].ToString().Trim();
string sZXJMXX = dsCF.Tables[0].Rows[0]["XLXSJGBXHDZB_ZXJMXX"].ToString().Trim();
string sZXJMSX = dsCF.Tables[0].Rows[0]["XLXSJGBXHDZB_ZXJMSX"].ToString().Trim();
string sMSg=string.Format("导入后存在重叠数据{0} {1} {2} {3} {4},请检查!",sJGBXLXHID,sBJDXLXHID,sXXJGID,sDYDJID,"【"+sZXJMXX+"-"+sZXJMSX+"】");
throw new Exception(sMSg);
}
}
private void ExcelColumnValid(DataSet ds, ref string sJDfields, ref bool hasZHJD, ref int JSFSIndex)
{
int columCountbeforeJDYZ = 8;
Dictionary<string, string> ColumnNames = new Dictionary<string, string>();
ColumnNames.Clear();
ColumnNames.Add("0", "价格表线缆型号");
ColumnNames.Add("1", "报价单线缆型号");
ColumnNames.Add("2", "电压等级");
ColumnNames.Add("3", "芯线结构");
ColumnNames.Add("4", "主芯截面 >= ");
ColumnNames.Add("5", "主芯截面 <=");
ColumnNames.Add("6", "对照后电压等级");
if (ds.Tables[0].Columns[7].ColumnName.Trim().Equals("综合加点"))
{
ColumnNames.Add("7", "综合加点");
hasZHJD = true;
}
else
{
hasZHJD = false;
columCountbeforeJDYZ = 7;
}
Dictionary<string, string> fields = new Dictionary<string, string>();
fields.Clear();
fields.Add("型号(%)", "XLXSJGBXHDZB_XLXHJD");
fields.Add("阻燃A级(%)", "XLXSJGBXHDZB_ZA");
fields.Add("阻燃B级(%)", "XLXSJGBXHDZB_ZB");
fields.Add("阻燃C级(%)", "XLXSJGBXHDZB_ZC");
fields.Add("软导体(%)", "XLXSJGBXHDZB_R");
fields.Add("绞型(%)", "XLXSJGBXHDZB_S");
fields.Add("低烟无卤(%)", "XLXSJGBXHDZB_WDZ");
fields.Add("低毒(%)", "XLXSJGBXHDZB_U");
fields.Add("防蚁(%)", "XLXSJGBXHDZB_FY");
fields.Add("防鼠(%)", "XLXSJGBXHDZB_FS");
fields.Add("防水(%)", "XLXSJGBXHDZB_FSJD");
fields.Add("七芯(%)", "XLXSJGBXHDZB_QX");
fields.Add("耐温90℃(%)", "XLXSJGBXHDZB_90");
fields.Add("耐温105(%)", "XLXSJGBXHDZB_105");
fields.Add("B1/B2(%)", "XLXSJGBXHDZB_B1B2");
fields.Add("阻水(%)", "XLXSJGBXHDZB_ZS");
fields.Add("耐火(%)", "XLXSJGBXHDZB_NH");
fields.Add("22铠装(%)", "XLXSJGBXHDZB_22KZ");
fields.Add("屏蔽(%)", "XLXSJGBXHDZB_P");
fields.Add("辐照(%)", "XLXSJGBXHDZB_F");
fields.Add("本安(%)", "XLXSJGBXHDZB_IA");
fields.Add("62铠装(%)", "XLXSJGBXHDZB_62KZ");
fields.Add("材料成本加点", "XLXSJGBXHDZB_CLCBYSJDZ");
foreach (KeyValuePair<string, string> kpv in ColumnNames)
{
if (!ds.Tables[0].Columns[CMISproConvert.StrToInt(kpv.Key.Trim())].ColumnName.Trim().Equals(kpv.Value.Trim()))
{
throw new Exception(string.Format("({0})列标题错误,该列为({1})", ds.Tables[0].Columns[CMISproConvert.StrToInt(kpv.Key.Trim())].ColumnName.Trim(), kpv.Value.Trim()));
}
}
if (ds.Tables[0].Columns.Count > columCountbeforeJDYZ)
{
for (int i = columCountbeforeJDYZ; i < ds.Tables[0].Columns.Count; i++)
{
if (!fields.ContainsKey(ds.Tables[0].Columns[i].ColumnName.Trim()))
{
if (ds.Tables[0].Columns[i].ColumnName.Trim() == "计算方式")
{
JSFSIndex = i;
break;
}
else if (ds.Tables[0].Columns[i].ColumnName.Trim() == "维护人" || ds.Tables[0].Columns[i].ColumnName.Trim() == "维护时间")
{
break;
}
throw new Exception(string.Format("({0})列标题错误)", ds.Tables[0].Columns[i].ColumnName.Trim()));
}
sJDfields += "," + fields[ds.Tables[0].Columns[i].ColumnName.Trim()];
}
}
}
private void ReadWJ(string sPath, ref DataSet aDataExcel)
{
string sMessage = "";
aDataExcel = TExcelData.ReadExcel(sPath.Trim(), "", "", false, ref sMessage);
if (!sMessage.Trim().Equals(""))
{
throw new Exception("文件读取失败!");
}
}
private string GetJSFS()
{
string sJSFS = "JD";
XLXSBJPZXX pzxx = XLBJDUtils.GetXLXSBJPZXX(100860038);
if (!string.IsNullOrEmpty(pzxx.XLXSBJPZ_MRJSFS))
sJSFS = pzxx.XLXSBJPZ_MRJSFS;
return sJSFS;
}
private string GetJSFS(string sJSFS)
{
if (sJSFS.Contains("01"))
return "01";
if (sJSFS.Contains("JD"))
return "JD";
if (sJSFS.Contains("KD"))
return "KD";
if (sJSFS.Contains("KH"))
return "KH";
return "";
}
private bool ExistedXHID(string sXHID)
{
string sSQL = string.Format("select top 1 XLXHB_XLXHID from XLXHB where isnull(XLXHB_TYBZ,'N')<>'Y' and XLXHB_XLXHID ='{0}'", sXHID);
return CMISproDataBase.ExistsRecord("DBERP", sSQL);
}
private bool ExistedDYDJID(string sDYDJID)
{
string sSQL = string.Format("select top 1 XLDYDJB_DYDJID from XLDYDJB where isnull(XLDYDJB_TYBZ,'N')<>'Y' and XLDYDJB_DYDJID ='{0}'", sDYDJID);
return CMISproDataBase.ExistsRecord("DBERP", sSQL);
}
#endregion
}
}