SVN-Revision: r643
This commit is contained in:
wyf
2025-05-28 10:02:20 +00:00
parent 3954b1f87c
commit c2f02a271b
2 changed files with 609 additions and 56 deletions
+55 -28
View File
@@ -80,7 +80,7 @@ namespace Lskj.PubBomImport
InitGridColumns(); InitGridColumns();
InitMulitControl(); InitMulitControl();
InitDataSource(); InitDataSource();
if (showTypeValue == 0 || showTypeValue == 3 || showTypeValue == 33 || showTypeValue == 4 || showTypeValue == 44 || showTypeValue == 5 || showTypeValue == 55 || (showTypeValue > 0 && showType)) if (showTypeValue == 0 || showTypeValue == 2 || showTypeValue == 3 || showTypeValue == 33 || showTypeValue == 4 || showTypeValue == 44 || showTypeValue == 5 || showTypeValue == 55 || (showTypeValue > 0 && showType))
{ {
OnBtnImportClick(null, null); OnBtnImportClick(null, null);
} }
@@ -286,33 +286,60 @@ namespace Lskj.PubBomImport
// this.Close(); // this.Close();
// } // }
//} //}
//else if (Model.ShowType.Equals("2")) else if (Model.ShowType.Equals("2"))//一级BOM上传
//{ {
// OpenFileDialog dialog = new OpenFileDialog(); BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
// dialog.InitialDirectory = Properties.Settings.Default.LastSelectFolder; {
// dialog.Title = "选择导入文件"; ShowType = Model.ShowType,
// dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls"; AfterBomFieldName = Model.AfterBomFieldName,
// DialogResult dialogResult = dialog.ShowDialog(); CanSave = true
// if (dialogResult == DialogResult.OK) };
// { FormDialogModel dialogModel = new FormDialogModel()
// Properties.Settings.Default.LastSelectFolder = Path.GetDirectoryName(dialog.FileName); {
// string dirPath = dialog.FileName; DialogDllName = "Lskj.PubBomImport.dll",
// FrmProgress frmProgress = new FrmProgress(); PubDialogType = DialogType.PubAddRecord,
// frmProgress.frmMain = this; ReturnTag = bomImpRtnModel
// frmProgress.ImportTimer.Tick += (ts, te) => };
// { this.Tag = dialogModel;
// frmProgress.ImportTimer.Enabled = false; DataTable sourceTable = StaticControl.RightMenuGridView.GridControl.DataSourceTable();
// frmProgress.StartImportInMxFile(dirPath); if (sourceTable.Columns.Contains("BomFieldNameDir"))
// }; {
// frmProgress.ImportTimer.Enabled = true; List<DataRow> selectRows = new List<DataRow>();
// frmProgress.ShowDialog(); foreach (DataRow sourceRow in sourceTable.Rows)
// frmProgress.Dispose(); {
// } if (sourceRow.RowState == DataRowState.Deleted)
// else {
// { continue;
// this.Close(); }
// } string fileName = sourceRow[Model.AfterBomFieldName] + "";
//} string dirPath = sourceRow["BomFieldNameDir"] + "";
selectRows.Add(sourceRow);
}
if (selectRows.Count > 0)
{
FrmProgress frmProgress = new FrmProgress();
frmProgress.frmMain = this;
frmProgress.Model = Model;
frmProgress.ImportTimer.Tick += (ts, te) =>
{
frmProgress.ImportTimer.Enabled = false;
frmProgress.StartImportInFirstFiles(selectRows);
};
frmProgress.ImportTimer.Enabled = true;
DialogResult dialogResult = frmProgress.ShowDialog();
bomImpRtnModel.CanSave = dialogResult == DialogResult.OK;
frmProgress.Dispose();
}
else
{
this.Close();
}
}
else
{
this.Close();
}
}
else if (Model.ShowType.Equals("3"))//新增多个QD文件或图纸文件 else if (Model.ShowType.Equals("3"))//新增多个QD文件或图纸文件
{ {
BomImpRtnModel bomImpRtnModel = new BomImpRtnModel() BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
+554 -28
View File
@@ -55,7 +55,6 @@ namespace Lskj.PubBomImport
{ {
int execOrder = 1; int execOrder = 1;
FrmBillInfo frmBillInfo = new FrmBillInfo(); FrmBillInfo frmBillInfo = new FrmBillInfo();
StringBuilder stringBuilder = new StringBuilder();
foreach (DataRow selectRow in selectRows) foreach (DataRow selectRow in selectRows)
{ {
string fileName = selectRow[Model.AfterBomFieldName] + ""; string fileName = selectRow[Model.AfterBomFieldName] + "";
@@ -84,8 +83,11 @@ namespace Lskj.PubBomImport
} }
if (sourceCode.StartsWith("QD")) if (sourceCode.StartsWith("QD"))
{ {
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{sourceCode}')"); int createCode = ProductSaveUnique(sourceCode.Replace("'", "''"), sourceName.Replace("'", "''"), "", "1000202_1", out string pid, out string msg);
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,spec,model,bak,SpeciesNo) values ('{sourceCode.Replace("'", "''")}','{sourceName.Replace("'", "''")}','{sourceCode.Replace("'", "''")}','{sourceCode.Replace("QD-", "").Replace("'", "''")}','','0199') end;"); if ((createCode + "").Equals("-1"))
{
throw new Exception($"虚拟物料创建失败\r\n{msg}");
}
} }
} }
else else
@@ -99,10 +101,6 @@ namespace Lskj.PubBomImport
throw new Exception($"{fileName}的文件不存在"); throw new Exception($"{fileName}的文件不存在");
} }
} }
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
{
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
}
frmBillInfo.OnControlSourceBind += (s, args) => frmBillInfo.OnControlSourceBind += (s, args) =>
{ {
Task task = new Task(() => Task task = new Task(() =>
@@ -126,7 +124,7 @@ namespace Lskj.PubBomImport
GetFileCodeInfo(fileNameWithoutExtension, out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC); GetFileCodeInfo(fileNameWithoutExtension, out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
if (sourceCode.StartsWith("QD")) if (sourceCode.StartsWith("QD"))
{ {
DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{sourceCode}'"); DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid = (select top 1 productid from p_ProductTab where spec = '{sourceCode}')");
if (productRow == null)//如果不存在bom建立单 if (productRow == null)//如果不存在bom建立单
{ {
string childGuid = Guid.NewGuid() + ""; string childGuid = Guid.NewGuid() + "";
@@ -150,7 +148,7 @@ namespace Lskj.PubBomImport
throw new Exception($"{sourceCode}明细数据为空"); throw new Exception($"{sourceCode}明细数据为空");
} }
SetProcessBar(40, allCount); SetProcessBar(40, allCount);
string childBillMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{sourceCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{sourceCode}' as productid,'{sourceCode}' as bak,'{sourceBB}' as bombb,'{sourceBC}' as bombc"; string childBillMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid = (select top 1 productid from p_ProductTab where spec = '{sourceCode}')) as billdocument_id,'0' affirmer,'0' rtagid,(select top 1 productid from p_ProductTab where spec = '{sourceCode}') as productid,'{sourceCode}' as bak,'{sourceBB}' as bombb,'{sourceBC}' as bombc";
// 处理单据表头数据 // 处理单据表头数据
DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql); DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql);
SetProcessBar(60, allCount); SetProcessBar(60, allCount);
@@ -351,15 +349,13 @@ namespace Lskj.PubBomImport
{ {
throw new Exception($"变更版本{sourceBB}已存在,请进行版次变更"); throw new Exception($"变更版本{sourceBB}已存在,请进行版次变更");
} }
StringBuilder stringBuilder = new StringBuilder();
if (sourceCode.StartsWith("QD")) if (sourceCode.StartsWith("QD"))
{ {
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{sourceCode}')"); int createCode = ProductSaveUnique(sourceCode.Replace("'", "''"), sourceName.Replace("'", "''"), "", "1000202_1", out string pid, out string msg);
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,spec,model,bak,SpeciesNo) values ('{sourceCode.Replace("'", "''")}','{sourceName.Replace("'", "''")}','{sourceCode.Replace("'", "''")}','{sourceCode.Replace("QD-", "").Replace("'", "''")}','','0199') end;"); if ((createCode + "").Equals("-1"))
} {
if (!string.IsNullOrEmpty(stringBuilder.ToString())) throw new Exception($"虚拟物料创建失败\r\n{msg}");
{ }
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
} }
//StringBuilder insertbulider = new StringBuilder(); //StringBuilder insertbulider = new StringBuilder();
@@ -398,7 +394,7 @@ namespace Lskj.PubBomImport
detailRow["bombc"] = sourceBC; detailRow["bombc"] = sourceBC;
} }
SetProcessBar(20, allCount); SetProcessBar(20, allCount);
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{sourceCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{sourceCode}' as productid,'{sourceCode}' as bak,'{sourceBB}' as bombb,'{sourceBC}' as bombc"; string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid = (select top 1 productid from p_ProductTab where spec = '{sourceCode}')) as billdocument_id,'0' affirmer,'0' rtagid,(select top 1 productid from p_ProductTab where spec = '{sourceCode}') as productid,'{sourceCode}' as bak,'{sourceBB}' as bombb,'{sourceBC}' as bombc";
// 处理单据表头数据 // 处理单据表头数据
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql); DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
SetProcessBar(40, allCount); SetProcessBar(40, allCount);
@@ -490,7 +486,7 @@ namespace Lskj.PubBomImport
detailRow["bombc"] = sourceBC; detailRow["bombc"] = sourceBC;
} }
SetProcessBar(20, allCount); SetProcessBar(20, allCount);
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{productCode}' as productid"; string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid = '{productCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{productCode}' as productid";
// 处理单据表头数据 // 处理单据表头数据
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql); DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
if (masterRow == null) if (masterRow == null)
@@ -607,8 +603,11 @@ namespace Lskj.PubBomImport
string childCode = (dataRow["图号"] + "").Trim(); string childCode = (dataRow["图号"] + "").Trim();
if (childCode.StartsWith("QD")) if (childCode.StartsWith("QD"))
{ {
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{childCode}')"); int createCode = ProductSaveUnique(childCode.Replace("'", "''"), (dataRow["名称"] + "").Replace("'", "''"), (dataRow["备注"] + "").Replace("'", "''"), "1000202_1", out string pid, out string msg);
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,spec,model,bak,SpeciesNo) values ('{childCode.Replace("'", "''")}','{(dataRow[""] + "").Replace("'", "''")}','{childCode.Replace("'", "''")}','{childCode.Replace("QD-", "").Replace("'", "''")}','{(dataRow[""] + "").Replace("'", "''")}','0199') end;"); if ((createCode + "").Equals("-1"))
{
throw new Exception($"虚拟物料创建失败\r\n{msg}");
}
} }
} }
if (!string.IsNullOrEmpty(stringBuilder.ToString())) if (!string.IsNullOrEmpty(stringBuilder.ToString()))
@@ -642,7 +641,7 @@ namespace Lskj.PubBomImport
if (childCode.StartsWith("QD")) if (childCode.StartsWith("QD"))
{ {
DataRow childRow = childTable.NewRow(); DataRow childRow = childTable.NewRow();
childRow["ProductId"] = childCode; childRow["ProductId"] = BaseImpl.GetResult($"(select top 1 productid from p_ProductTab where spec = '{childCode}')");
childRow["appellation"] = parentRow["名称"] + ""; childRow["appellation"] = parentRow["名称"] + "";
childRow["bak"] = childCode; childRow["bak"] = childCode;
childRow["bombb"] = childsourceBB; childRow["bombb"] = childsourceBB;
@@ -651,6 +650,10 @@ namespace Lskj.PubBomImport
childRow["amount"] = parentRow["套数"] + ""; childRow["amount"] = parentRow["套数"] + "";
childTable.Rows.Add(childRow); childTable.Rows.Add(childRow);
} }
else if (childCode.StartsWith("ZZQD"))
{
throw new Exception($"MX{sourceCode}未获取到ZZQD附件");
}
} }
if (childInfo != null) if (childInfo != null)
{ {
@@ -691,7 +694,7 @@ namespace Lskj.PubBomImport
else if (childCode.StartsWith("QD")) else if (childCode.StartsWith("QD"))
{ {
DataRow childRow = childTable.NewRow(); DataRow childRow = childTable.NewRow();
childRow["ProductId"] = childCode; childRow["ProductId"] = BaseImpl.GetResult($"(select top 1 productid from p_ProductTab where spec = '{childCode}')");
childRow["appellation"] = parentRow["名称"] + ""; childRow["appellation"] = parentRow["名称"] + "";
childRow["bak"] = childsourceCode; childRow["bak"] = childsourceCode;
childRow["bombb"] = childsourceBB; childRow["bombb"] = childsourceBB;
@@ -939,8 +942,11 @@ namespace Lskj.PubBomImport
string code = (dataRow["图号"] + "").Trim(); string code = (dataRow["图号"] + "").Trim();
if (code.StartsWith("QD")) if (code.StartsWith("QD"))
{ {
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{code}')"); int createCode = ProductSaveUnique(code.Replace("'", "''"), (dataRow["名称"] + "").Replace("'", "''"), (dataRow["备注"] + "").Replace("'", "''"), "1000202_1", out string pid, out string msg);
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,spec,model,bak,SpeciesNo) values ('{code.Replace("'", "''")}','{(dataRow[""] + "").Replace("'", "''")}','{code.Replace("'", "''")}','{code.Replace("QD-", "").Replace("'", "''")}','{(dataRow[""] + "").Replace("'", "''")}','0199') end;"); if ((createCode + "").Equals("-1"))
{
throw new Exception($"虚拟物料创建失败\r\n{msg}");
}
} }
} }
if (!string.IsNullOrEmpty(stringBuilder.ToString())) if (!string.IsNullOrEmpty(stringBuilder.ToString()))
@@ -1082,7 +1088,7 @@ namespace Lskj.PubBomImport
else if (code.StartsWith("QD")) else if (code.StartsWith("QD"))
{ {
DataRow childRow = childTable.NewRow(); DataRow childRow = childTable.NewRow();
childRow["ProductId"] = code; childRow["ProductId"] = BaseImpl.GetResult($"(select top 1 productid from p_ProductTab where spec = '{code}')");
childRow["appellation"] = parentRow["名称"] + ""; childRow["appellation"] = parentRow["名称"] + "";
childRow["bak"] = childsourceCode; childRow["bak"] = childsourceCode;
childRow["bombb"] = childsourceBB; childRow["bombb"] = childsourceBB;
@@ -1198,7 +1204,7 @@ namespace Lskj.PubBomImport
if (childInfo != null) if (childInfo != null)
{ {
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string qdsourceCode, out string qdname, out string qdsourceBB, out int qdsourceBC); GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string qdsourceCode, out string qdname, out string qdsourceBB, out int qdsourceBC);
DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{code}'"); DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid = (select top 1 productid from p_ProductTab where spec = '{code}')");
if (productRow == null) if (productRow == null)
{ {
string childGuid = childInfoRow != null && !string.IsNullOrEmpty(childInfoRow["qms_laddf_Exec"] + "") ? childInfoRow["qms_laddf_Exec"] + "" : Guid.NewGuid() + ""; string childGuid = childInfoRow != null && !string.IsNullOrEmpty(childInfoRow["qms_laddf_Exec"] + "") ? childInfoRow["qms_laddf_Exec"] + "" : Guid.NewGuid() + "";
@@ -1225,7 +1231,7 @@ namespace Lskj.PubBomImport
throw new Exception($"{code}明细数据为空"); throw new Exception($"{code}明细数据为空");
} }
SetProcessBar(40, allCount); SetProcessBar(40, allCount);
string childBillMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{code}') as billdocument_id,'0' affirmer,'0' rtagid,'{code}' as productid,'{qdsourceCode}' as bak,'{qdsourceBB}' as bombb,'{qdsourceBC}' as bombc"; string childBillMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid = (select top 1 productid from p_ProductTab where spec = '{code}')) as billdocument_id,'0' affirmer,'0' rtagid,(select top 1 productid from p_ProductTab where spec = '{code}') as productid,'{qdsourceCode}' as bak,'{qdsourceBB}' as bombb,'{qdsourceBC}' as bombc";
// 处理单据表头数据 // 处理单据表头数据
DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql); DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql);
SetProcessBar(60, allCount); SetProcessBar(60, allCount);
@@ -1420,6 +1426,447 @@ namespace Lskj.PubBomImport
} }
} }
/// <summary> /// <summary>
/// 一级bom结构上传
/// </summary>
/// <param name="dirPaths"></param>
public void StartImportInFirstFiles(List<DataRow> selectRows)
{
try
{
if (Directory.Exists("BomImportTemp"))
{
Directory.Delete("BomImportTemp", true);
}
Directory.CreateDirectory("BomImportTemp");
int execOrder = 1;
var mxRows = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith("MX"));
if (mxRows.Count() > 1)
{
throw new Exception($"不允许出现多个MX文件");
}
DataRow mxRow = mxRows.FirstOrDefault();
if (mxRow != null)
{
string mxFileName = mxRow[Model.AfterBomFieldName] + "";
string mxDirPath = mxRow["BomFieldNameDir"] + "";
string productId = mxRow["BomMxMainProduct"] + "";
string addState = mxRow["BomMxAddState"] + "";
if (string.IsNullOrEmpty(productId))
{
throw new Exception($"保存失败\r\n请重新进行BOM上传后保存");
}
if (addState.Equals("新增"))
{
DataRow billRow = BaseImpl.GetDataRowResult($"select qms_maddf_billdocument_id from qms_BillFileAddMaintab where qms_maddf_productid = '{productId}' and isnull(qms_maddf_addMode,'0') = '2'");
if (billRow != null)
{
throw new Exception($"物料编码{productId}的BOM新增单已存在审批流\r\n请进行审批");
}
//DataRow billbomRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'");
//if (billRow != null)
//{
// throw new Exception($"物料编码{productId}的BOM建立单已存在\r\n请进行修改操作");
//}
}
else
{
//DataRow billbomRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}' and stepover = '1'");
//if (billbomRow != null)
//{
// throw new Exception($"物料编码{productId}的BOM建立单已终审\r\n禁止修改操作");
//}
}
GetFileCodeInfo(mxFileName.Trim(), out string mxsourceCode, out string mxname, out string mxsourceBB, out int mxsourceBC);
DataTable mxfiletable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{productId}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{mxsourceCode}%'");
FileInfo mxInfo = null;
if (!string.IsNullOrEmpty(mxDirPath))
{
mxInfo = new FileInfo(mxDirPath);
}
if (mxInfo != null || mxfiletable.Rows.Count > 0)
{
if (mxfiletable.Rows.Count > 1)
{
throw new Exception($"{mxsourceCode}存在多个版次,请进行MX修改");
}
if (mxfiletable.Rows.Count > 0)
{
using (WebClient webClient = new WebClient())
{
try
{
string webpath = mxfiletable.Rows[0]["webpath"] + "";
string sName = mxfiletable.Rows[0]["sName"] + "";
webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
string tempFileName = $"BomImportTemp/{sName}";
if (!File.Exists(tempFileName))
{
webClient.DownloadFile(url, tempFileName);
}
mxInfo = new FileInfo(tempFileName);
}
catch (Exception)
{
throw new Exception($"Bom明细附件{mxsourceCode}获取失败\r\nBom导入失败");
}
}
}
if (mxInfo != null)
{
int mxMaxBc = 0;
string mxMaxBcFileId = "-1";
foreach (DataRow mxfileRow in mxfiletable.Rows)
{
string fileName = mxfileRow["sname"] + "";
string fileId = mxfileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= mxMaxBc)
{
mxMaxBc = fileBC;
mxMaxBcFileId = fileId;
}
}
if (mxsourceBC > mxMaxBc && mxfiletable.Rows.Count > 0)
{
throw new Exception($"{mxsourceCode}的版次为{mxsourceBC},大于最大版次{mxMaxBc}\r\n请进行变更");
}
mxsourceBC = mxsourceBC >= mxMaxBc ? mxsourceBC : mxMaxBc;
FrmBillInfo frmBillInfo = new FrmBillInfo();
DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, "", 5);
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "") && !string.IsNullOrEmpty(n["名称"] + "")).ToList().CopyToDataTable();
StringBuilder stringBuilder = new StringBuilder();
foreach (DataRow dataRow in parentTable.Rows)
{
string code = (dataRow["图号"] + "").Trim();
if (code.StartsWith("QD"))
{
int createCode = ProductSaveUnique(code.Replace("'", "''"), (dataRow["名称"] + "").Replace("'", "''"), (dataRow["备注"] + "").Replace("'", "''"), "1000202_1", out string pid, out string msg);
if ((createCode + "").Equals("-1"))
{
throw new Exception($"虚拟物料创建失败\r\n{msg}");
}
}
}
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
{
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
}
frmBillInfo.OnControlSourceBind += (s, args) =>
{
Task task = new Task(() =>
{
try
{
int.TryParse(Model.FirstRowIndex, out int index);
frmMain.FirstRowIndex = index;
bool isUpload = false;
string msg = "";
Dictionary<string, DataRow> maxBcFileDic = new Dictionary<string, DataRow>();
Dictionary<string, DataTable> fileTableDic = new Dictionary<string, DataTable>();
#region MX
frmBillInfo.OnBillAdd();
SetProcessBar(0, 0);
SetProcessMsg($"正在导入:{Path.GetFileName(mxInfo.FullName)}");
DataTable childTable = frmBillInfo.GcMainView.GridControl.DataSourceTable().Clone();
StringBuilder insertbulider = new StringBuilder();
insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{productId}';");
//insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productId}','{mxsourceCode }','{mxsourceCode}','{ERPInfo.Instance.UserName}','新增');");
var mxCodeRows = parentTable.AsEnumerable();
foreach (DataRow parentRow in parentTable.Rows)
{
int.TryParse(parentRow["套数"] + "", out int tamount);
string code = (parentRow["图号"] + "").Trim();
int codeCount = mxCodeRows.Where(n => (n["图号"] + "").Trim().StartsWith(code)).Count();
if (codeCount > 1)//只允许存在一个
{
throw new Exception($"MX中的{code}重复,请修改");
}
insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{productId}','{mxsourceCode }','{code}','{ERPInfo.Instance.UserName}','新增');");
DataTable filetable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{code}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{code}%'");
fileTableDic[code] = filetable;
int childMaxBc = -1;
foreach (DataRow fileRow in filetable.Rows)
{
string fileName = fileRow["sname"] + "";
string fileId = fileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= childMaxBc)
{
childMaxBc = fileBC;
maxBcFileDic[code] = fileRow;
}
}
//判断code是否已经上传,如果已经上传则不再上传,
//如果附件不存在文件夹中,则直接使用最新的
//如果附件不存在则提示
FileInfo childInfo = null;
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
if (childInfoRow != null)
{
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
if (!string.IsNullOrEmpty(childDirPath))
{
childInfo = new FileInfo(childDirPath);
}
}
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
using (WebClient webClient = new WebClient())
{
try
{
string webpath = maxBcFileDic[code]["webpath"] + "";
string sName = maxBcFileDic[code]["sName"] + "";
webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
string tempFileName = $"BomImportTemp/{sName}";
if (!File.Exists(tempFileName))
{
webClient.DownloadFile(url, tempFileName);
}
childInfo = new FileInfo(tempFileName);
}
catch (Exception)
{
throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
}
}
}
if (childInfo != null)
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string childsourceCode, out string childname, out string childsourceBB, out int childsourceBC);
//如果文件夹中有附件,则比较版次,如果大于最大版次,则提示
if (childsourceBC > childMaxBc && filetable.Rows.Count > 0)
{
throw new Exception($"{childsourceCode}的版次为{childsourceBC},大于最大版次{childMaxBc}\r\n请进行变更");
}
childsourceBC = childsourceBC >= childMaxBc ? childsourceBC : childMaxBc;
if (code.StartsWith("ZZQD"))
{
DataTable qdTable = ExcelToDatatable(childInfo.FullName, Model, "", index);
DataView filterDataView = new DataView(qdTable);
try
{
if (!string.IsNullOrEmpty(Model.ReadTableCond))
{
filterDataView.RowFilter = Model.ReadTableCond;
}
}
catch (Exception)
{
}
qdTable = filterDataView.ToTable();
var qdCodeRows = qdTable.AsEnumerable();
foreach (DataRow qdItem in qdTable.Rows)
{
string qdCode = (qdItem["物料编码"] + "").Trim();
int qdCount = qdCodeRows.Where(n => (n["物料编码"] + "").Trim().StartsWith(qdCode)).Count();
if (qdCount > 1)//只允许存在一个
{
throw new Exception($"{childsourceCode}中的{qdCode}重复,请修改");
}
}
if (code.StartsWith("ZZQD"))
{
foreach (DataRow zzqdItem in qdTable.Rows)
{
DataRow childRow = childTable.NewRow();
childRow["ProductId"] = (zzqdItem["物料编码"] + "").Trim();
childRow["appellation"] = zzqdItem["名称"] + "";
childRow["bak"] = childsourceCode;
childRow["bombb"] = childsourceBB;
childRow["bombc"] = childsourceBC;
childRow["tamount"] = parentRow["套数"] + "";
int.TryParse(zzqdItem["数量"] + "", out int amount);
childRow["amount"] = amount * tamount;
childTable.Rows.Add(childRow);
}
}
}
}
else
{
if (filetable.Rows.Count == 0)
{
throw new Exception($"{code}的附件不存在,请检查文件");
}
}
}
SetProcessBar(20, 0);
if (childTable.Rows.Count == 0)
{
throw new Exception($"MX明细数据不能空");
}
SetProcessBar(40, 0);
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productId}') as billdocument_id,'0' affirmer,'0' rtagid,'{productId}' as productid,'{mxsourceCode}' as bak,'{mxsourceBB}' as bombb,'{mxsourceBC}' as bombc";
// 处理单据表头数据
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
SetProcessBar(60, 0);
frmBillInfo.AddOrUpdateBill(masterRow, childTable);
string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider.ToString().Replace("'", "''")}' where guid = '{guid}'");
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set userid = '1' where guid = '{guid}'");
SetProcessBar(80, 0);
//上传文件
string uploadMxFileId = mxMaxBcFileId;
if (mxfiletable.Rows.Count == 0)
{
isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out uploadMxFileId);
if (!isUpload)
{
throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}");
}
}
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
{
int.TryParse(uploadMxFileId, out int qms_laddf_FileId);
mxRow["qms_laddf_FileId"] = qms_laddf_FileId;
}
if (mxRow.Table.Columns.Contains("qms_laddf_Exec"))
{
mxRow["qms_laddf_Exec"] = guid;
}
if (mxRow.Table.Columns.Contains("qms_laddf_ExecOrder"))
{
mxRow["qms_laddf_ExecOrder"] = execOrder;
}
}));
execOrder += 1;
#endregion
SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
foreach (DataRow dataRow in parentTable.Rows)
{
int childIndex = parentTable.Rows.IndexOf(dataRow);
int nowCount = 1 + childIndex;
int allCount = (int)((decimal)(1 + childIndex) / (parentTable.Rows.Count + 1) * 100);
int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100);
int.TryParse(dataRow["套数"] + "", out int tamount);
string code = (dataRow["图号"] + "").Trim();
DataTable filetable = fileTableDic.ContainsKey(code) ? fileTableDic[code] : null;
FileInfo childInfo = null;
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
if (childInfoRow != null)
{
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
if (!string.IsNullOrEmpty(childDirPath))
{
childInfo = new FileInfo(childDirPath);
}
}
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
{
using (WebClient webClient = new WebClient())
{
try
{
string webpath = maxBcFileDic[code]["webpath"] + "";
string sName = maxBcFileDic[code]["sName"] + "";
webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
string tempFileName = $"BomImportTemp/{sName}";
if (!File.Exists(tempFileName))
{
webClient.DownloadFile(url, tempFileName);
}
childInfo = new FileInfo(tempFileName);
}
catch (Exception)
{
throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
}
}
}
if (childInfo == null)
{
throw new Exception($"目录中不包含文件{code}");
}
if (childInfo != null)
{
SetProcessBar(0, allCount);
string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
if (filetable.Rows.Count == 0)
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string qdsourceCode, out string qdname, out string qdsourceBB, out int qdsourceBC);
if (filetable.Rows.Count == 0)
{
isUpload = UploadFileToAudit(childInfo.FullName, qdsourceCode, "010106", out msg, out uploadFileId);
if (!isUpload)
{
throw new Exception($"{code}附件上传失败\r\n{msg}");
}
}
}
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
{
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
{
int.TryParse(uploadFileId, out int qms_laddf_FileId);
childInfoRow["qms_laddf_FileId"] = qms_laddf_FileId;
}
}));
SetProcessBar(100, finishCount);
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
}
else
{
throw new Exception($"目录中不包含文件{code}");
}
}
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.OK;
Close();
ImportTimer?.Dispose();
}));
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.Cancel;
Close();
ImportTimer?.Dispose();
}));
}
});
task.Start();
};
frmBillInfo.OnLoad(Model);
frmMain.ParentView = frmBillInfo.GcMainView;
}
else
{
throw new Exception("未找到MX文件");
}
}
else
{
throw new Exception("未包含MX文件");
}
}
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.Cancel;
Close();
ImportTimer?.Dispose();
}));
}
}
/// <summary>
/// 修改终审同步 /// 修改终审同步
/// </summary> /// </summary>
/// <param name="selectRows"></param> /// <param name="selectRows"></param>
@@ -1562,7 +2009,7 @@ namespace Lskj.PubBomImport
{ {
throw new Exception($"物料编码不能为空"); throw new Exception($"物料编码不能为空");
} }
string billdocumentId = BaseImpl.GetResult($"select qms_maddf_billdocument_id from qms_BillFileAddMaintab where qms_maddf_productid = '{parentProductId}' and isnull(qms_maddf_addMode,'0') = '0'") + ""; string billdocumentId = BaseImpl.GetResult($"select qms_maddf_billdocument_id from qms_BillFileAddMaintab where qms_maddf_productid = '{parentProductId}' and (isnull(qms_maddf_addMode,'0') = '0' or isnull(qms_maddf_addMode,'0') = '2')") + "";
if (string.IsNullOrEmpty(billdocumentId)) if (string.IsNullOrEmpty(billdocumentId))
{ {
throw new Exception($"未查询到物料编码{parentProductId}的Bom单据号"); throw new Exception($"未查询到物料编码{parentProductId}的Bom单据号");
@@ -1769,6 +2216,85 @@ namespace Lskj.PubBomImport
})); }));
} }
} }
public int ProductSaveUnique(string spec, string appellation, string bak, string billSeq, out string productId, out string tipMsg)
{
productId = string.Empty;
tipMsg = string.Empty;
try
{
/*----------------------------------------------------
* 1) 组装存储过程参数
*--------------------------------------------------*/
// ProductId OUTPUT
SqlParameter pProductId = new SqlParameter("@ProductId", SqlDbType.VarChar, 100)
{
Direction = ParameterDirection.Output
};
// 存储过程 RETURN 值
SqlParameter pReturn = new SqlParameter("@return", SqlDbType.Int)
{
Direction = ParameterDirection.ReturnValue
};
// 中文字段可根据服务器排序规则切换参数类型
bool useNVar = ERPInfo.Instance.ChangeParameterType;
SqlParameter[] param =
{
new SqlParameter("@Spec", SqlDbType.VarChar, 50),
useNVar
? new SqlParameter("@Appellation", SqlDbType.NVarChar, 200)
: new SqlParameter("@Appellation", SqlDbType.VarChar, 200),
useNVar
? new SqlParameter("@Bak", SqlDbType.NVarChar, 200)
: new SqlParameter("@Bak", SqlDbType.VarChar, 200),
new SqlParameter("@BillSeq", SqlDbType.VarChar, 40),
pProductId,
pReturn
};
param[0].Value = spec;
param[1].Value = appellation ?? string.Empty;
param[2].Value = bak ?? string.Empty;
param[3].Value = string.IsNullOrWhiteSpace(billSeq) ? (object)DBNull.Value : billSeq;
SqlHelper.ExecuteNonQuery(
CommandType.StoredProcedure,
"sp_InsertProductUnique",
param);
/*----------------------------------------------------
* 3) 处理返回值与提示信息
*--------------------------------------------------*/
productId = pProductId.Value == DBNull.Value ? string.Empty
: pProductId.Value.ToString();
int retCode = (pReturn.Value == DBNull.Value) ? -1
: Convert.ToInt32(pReturn.Value);
// 根据返回值给出业务提示
switch (retCode)
{
case 0:
tipMsg = "保存成功!";
break;
case 1:
tipMsg = "规格已存在,直接返回现有编码。";
break;
default:
tipMsg = "发生异常,请查看日志!";
break;
}
return retCode;
}
catch (Exception ex)
{
tipMsg = ex.Message;
throw; // 继续向外抛,让调用层捕获日志
}
}
/// <summary> /// <summary>
/// 显示当前文件 /// 显示当前文件
/// </summary> /// </summary>