SVN r618
SVN-Revision: r618
This commit is contained in:
@@ -242,7 +242,7 @@ namespace Lskj.PubBomImport
|
||||
//param[6].Value = "";
|
||||
//param[7].Value = auditFlag;
|
||||
//param[8].Value = comfirm;
|
||||
|
||||
SqlHelper.ExecuteNonQuery($"delete p_bomImportExecTab where guid = '{guid}'");
|
||||
SqlHelper.ExecuteNonQuery($"insert into p_bomImportExecTab (guid,detailTable,masterSql,detailSql,billNo,detailGuid,UserId,billWay,billSeq,auditFlag,comfirm,newVer) " +
|
||||
$"values ('{guid}','{billModel.DetailTable}','{masterSql.Replace("'", "''")}','{detailSql.Replace("'", "''")}','{billNo}','{detailGuid.Replace("'", "''")}','{ERPInfo.Instance.UserId}','{(billModel.SaveState ? 2 : 1)}','{billModel.BillSeq}','0','{comfirm}','{billModel.NewVer}')");
|
||||
//int result = BillImpl.BillSave(masterSql, detailSql, billModel.DetailTable, ref billNo, detailGuid, billModel.BillSeq, billModel.SaveState ? 2 : 1, comfirm, out tipMsg, 0, billModel.NewVer);
|
||||
|
||||
@@ -460,12 +460,6 @@ namespace Lskj.PubBomImport
|
||||
}
|
||||
string fileName = sourceRow[Model.AfterBomFieldName] + "";
|
||||
string dirPath = sourceRow["BomFieldNameDir"] + "";
|
||||
FileInfo parentInfo = null;
|
||||
if (string.IsNullOrEmpty(dirPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
parentInfo = new FileInfo(dirPath);
|
||||
selectRows.Add(sourceRow);
|
||||
}
|
||||
if (selectRows.Count > 0)
|
||||
|
||||
@@ -817,7 +817,12 @@ namespace Lskj.PubBomImport
|
||||
}
|
||||
Directory.CreateDirectory("BomImportTemp");
|
||||
int execOrder = 1;
|
||||
DataRow mxRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith("MX")).FirstOrDefault();
|
||||
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] + "";
|
||||
@@ -841,66 +846,101 @@ namespace Lskj.PubBomImport
|
||||
throw new Exception($"物料编码{productId}的BOM建立单已存在\r\n请进行修改操作");
|
||||
}
|
||||
}
|
||||
FileInfo mxInfo = new FileInfo(mxDirPath);
|
||||
if (mxInfo != null)
|
||||
else
|
||||
{
|
||||
GetFileCodeInfo(Path.GetFileNameWithoutExtension(mxInfo.Name).Trim(), out string mxsourceCode, out string mxname, out string mxsourceBB, out int mxsourceBC);
|
||||
DataTable mxfiletable = BaseImpl.GetDataTableResult($"select sname,fileId 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}%'");
|
||||
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)
|
||||
{
|
||||
throw new Exception($"{mxsourceCode}的附件已存在");
|
||||
}
|
||||
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") || code.StartsWith("ZZQD"))
|
||||
{
|
||||
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{code}')");
|
||||
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{code.Replace("'", "''")}','{(dataRow["名称"] + "").Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}','0199') end;");
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||
}
|
||||
frmBillInfo.OnControlSourceBind += (s, args) =>
|
||||
{
|
||||
Task task = new Task(() =>
|
||||
using (WebClient webClient = new WebClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(Model.FirstRowIndex, out int index);
|
||||
frmMain.FirstRowIndex = index;
|
||||
bool isUpload = false;
|
||||
string msg = "";
|
||||
DataRow parentProductRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'");
|
||||
Dictionary<string, DataRow> maxBcFileDic = new Dictionary<string, DataRow>();
|
||||
Dictionary<string, DataTable> fileTableDic = new Dictionary<string, DataTable>();
|
||||
if (parentProductRow == null)
|
||||
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") || code.StartsWith("ZZQD"))
|
||||
{
|
||||
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{code}')");
|
||||
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{code.Replace("'", "''")}','{(dataRow["名称"] + "").Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}','0199') end;");
|
||||
}
|
||||
}
|
||||
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)}");
|
||||
@@ -936,7 +976,10 @@ namespace Lskj.PubBomImport
|
||||
{
|
||||
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
|
||||
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
|
||||
childInfo = new FileInfo(childDirPath);
|
||||
if (!string.IsNullOrEmpty(childDirPath))
|
||||
{
|
||||
childInfo = new FileInfo(childDirPath);
|
||||
}
|
||||
}
|
||||
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
|
||||
{
|
||||
@@ -1036,10 +1079,10 @@ namespace Lskj.PubBomImport
|
||||
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider.ToString().Replace("'", "''")}' where guid = '{guid}'");
|
||||
SetProcessBar(80, 0);
|
||||
//上传文件
|
||||
string uploadFileId = mxMaxBcFileId;
|
||||
string uploadMxFileId = mxMaxBcFileId;
|
||||
if (mxfiletable.Rows.Count == 0)
|
||||
{
|
||||
isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out uploadFileId);
|
||||
isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out uploadMxFileId);
|
||||
if (!isUpload)
|
||||
{
|
||||
throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}");
|
||||
@@ -1049,7 +1092,7 @@ namespace Lskj.PubBomImport
|
||||
{
|
||||
if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
|
||||
{
|
||||
int.TryParse(uploadFileId, out int 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"))
|
||||
@@ -1062,123 +1105,211 @@ namespace Lskj.PubBomImport
|
||||
}
|
||||
}));
|
||||
execOrder += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
string uploadFileId = mxMaxBcFileId;
|
||||
if (mxfiletable.Rows.Count == 0)
|
||||
#endregion
|
||||
SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
|
||||
SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
|
||||
foreach (DataRow dataRow in parentTable.Rows)
|
||||
{
|
||||
isUpload = UploadFileToAudit(mxInfo.FullName, mxsourceCode, "010106", out msg, out uploadFileId);
|
||||
if (!isUpload)
|
||||
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;
|
||||
if (code.StartsWith("QD"))
|
||||
{
|
||||
throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}");
|
||||
}
|
||||
}
|
||||
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||
{
|
||||
if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
|
||||
{
|
||||
int.TryParse(uploadFileId, out int qms_laddf_FileId);
|
||||
mxRow["qms_laddf_FileId"] = qms_laddf_FileId;
|
||||
}
|
||||
}));
|
||||
}
|
||||
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;
|
||||
if (code.StartsWith("QD"))
|
||||
{
|
||||
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"] + "";
|
||||
childInfo = new FileInfo(childDirPath);
|
||||
}
|
||||
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
|
||||
{
|
||||
using (WebClient webClient = new WebClient())
|
||||
FileInfo childInfo = null;
|
||||
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
|
||||
if (childInfoRow != null)
|
||||
{
|
||||
try
|
||||
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
|
||||
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
|
||||
if (!string.IsNullOrEmpty(childDirPath))
|
||||
{
|
||||
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导入失败");
|
||||
childInfo = new FileInfo(childDirPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (childInfo == null)
|
||||
{
|
||||
throw new Exception($"MX明细中的{code}文件不存在");
|
||||
}
|
||||
if (childInfo != null)
|
||||
{
|
||||
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}'");
|
||||
if (productRow == null)
|
||||
if ((childInfo == null || filetable.Rows.Count > 0) && maxBcFileDic.ContainsKey(code) && maxBcFileDic[code] != null)
|
||||
{
|
||||
string childGuid = Guid.NewGuid() + "";
|
||||
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($"MX明细中的{code}文件不存在");
|
||||
}
|
||||
if (childInfo != null)
|
||||
{
|
||||
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}'");
|
||||
if (productRow == null)
|
||||
{
|
||||
string childGuid = childInfoRow != null && !string.IsNullOrEmpty(childInfoRow["qms_laddf_Exec"] + "") ? childInfoRow["qms_laddf_Exec"] + "" : Guid.NewGuid() + "";
|
||||
string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
|
||||
if (filetable.Rows.Count == 0)
|
||||
{
|
||||
frmBillInfo.OnBillAdd();
|
||||
SetProcessBar(0, allCount);
|
||||
SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}");
|
||||
DataTable detailTable = new DataTable();
|
||||
frmMain.Invoke(new Action(() =>
|
||||
{
|
||||
detailTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
|
||||
}));
|
||||
foreach (DataRow detailRow in detailTable.Rows)
|
||||
{
|
||||
int.TryParse(detailRow["amount"] + "", out int amount);
|
||||
//数量暂定为自身数量
|
||||
detailRow["tamount"] = amount;
|
||||
detailRow["amount"] = amount;
|
||||
}
|
||||
if (detailTable.Rows.Count == 0)
|
||||
{
|
||||
throw new Exception($"{code}明细数据为空");
|
||||
}
|
||||
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";
|
||||
// 处理单据表头数据
|
||||
DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql);
|
||||
SetProcessBar(60, allCount);
|
||||
frmBillInfo.AddOrUpdateBill(childMasterRow, detailTable);
|
||||
frmBillInfo.BillSaveSql(childGuid);
|
||||
SetProcessBar(80, allCount);
|
||||
//记录历史版本号
|
||||
//string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
|
||||
//SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, childBillNo));
|
||||
//备份Bom清单明细
|
||||
//string bakBomListSql = @"delete bom_BillListlogTab where parentProduct = '{0}' and historyVer = (select top 1 historyVer from bom_BillListTab where parentProduct = '{0}');insert into bom_BillListlogTab select * from bom_BillListTab where parentProduct = '{0}';";
|
||||
//SqlHelper.ExecuteNonQuery(string.Format(bakBomListSql, code));
|
||||
//确认不关联
|
||||
//更新明细关联版本号
|
||||
//string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'";
|
||||
//SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
|
||||
SetProcessBar(80, allCount);
|
||||
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;
|
||||
}
|
||||
if (childInfoRow.Table.Columns.Contains("qms_laddf_Exec"))
|
||||
{
|
||||
childInfoRow["qms_laddf_Exec"] = childGuid;
|
||||
}
|
||||
if (childInfoRow.Table.Columns.Contains("qms_laddf_ExecOrder"))
|
||||
{
|
||||
childInfoRow["qms_laddf_ExecOrder"] = execOrder;
|
||||
}
|
||||
}));
|
||||
execOrder += 1;
|
||||
SetProcessBar(100, finishCount);
|
||||
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetProcessBar(0, allCount);
|
||||
string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
|
||||
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}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
frmBillInfo.OnBillAdd();
|
||||
SetProcessBar(0, allCount);
|
||||
SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}");
|
||||
DataTable detailTable = new DataTable();
|
||||
frmMain.Invoke(new Action(() =>
|
||||
{
|
||||
detailTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
|
||||
}));
|
||||
foreach (DataRow detailRow in detailTable.Rows)
|
||||
{
|
||||
int.TryParse(detailRow["amount"] + "", out int amount);
|
||||
//数量暂定为自身数量
|
||||
detailRow["tamount"] = amount;
|
||||
detailRow["amount"] = amount;
|
||||
}
|
||||
if (detailTable.Rows.Count == 0)
|
||||
{
|
||||
throw new Exception($"{code}明细数据为空");
|
||||
}
|
||||
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";
|
||||
// 处理单据表头数据
|
||||
DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql);
|
||||
SetProcessBar(60, allCount);
|
||||
frmBillInfo.AddOrUpdateBill(childMasterRow, detailTable);
|
||||
frmBillInfo.BillSaveSql(childGuid);
|
||||
SetProcessBar(80, allCount);
|
||||
//记录历史版本号
|
||||
//string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
|
||||
//SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, childBillNo));
|
||||
//备份Bom清单明细
|
||||
//string bakBomListSql = @"delete bom_BillListlogTab where parentProduct = '{0}' and historyVer = (select top 1 historyVer from bom_BillListTab where parentProduct = '{0}');insert into bom_BillListlogTab select * from bom_BillListTab where parentProduct = '{0}';";
|
||||
//SqlHelper.ExecuteNonQuery(string.Format(bakBomListSql, code));
|
||||
//确认不关联
|
||||
//更新明细关联版本号
|
||||
//string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'";
|
||||
//SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
|
||||
SetProcessBar(80, allCount);
|
||||
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);
|
||||
@@ -1195,140 +1326,43 @@ namespace Lskj.PubBomImport
|
||||
int.TryParse(uploadFileId, out int qms_laddf_FileId);
|
||||
childInfoRow["qms_laddf_FileId"] = qms_laddf_FileId;
|
||||
}
|
||||
if (childInfoRow.Table.Columns.Contains("qms_laddf_Exec"))
|
||||
{
|
||||
childInfoRow["qms_laddf_Exec"] = childGuid;
|
||||
}
|
||||
if (childInfoRow.Table.Columns.Contains("qms_laddf_ExecOrder"))
|
||||
{
|
||||
childInfoRow["qms_laddf_ExecOrder"] = execOrder;
|
||||
}
|
||||
}));
|
||||
execOrder += 1;
|
||||
SetProcessBar(100, finishCount);
|
||||
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetProcessBar(0, allCount);
|
||||
string uploadFileId = maxBcFileDic.ContainsKey(code) ? maxBcFileDic[code]["fileId"] + "" : "-1";
|
||||
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}");
|
||||
throw new Exception($"目录中不包含文件{code}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"目录中不包含文件{code}");
|
||||
}
|
||||
}
|
||||
else
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
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"] + "";
|
||||
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.DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
ImportTimer?.Dispose();
|
||||
}));
|
||||
}
|
||||
this.Invoke(new Action(() =>
|
||||
catch (Exception ex)
|
||||
{
|
||||
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;
|
||||
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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user