SVN-Revision: r735
This commit is contained in:
wyf
2025-06-14 15:19:44 +00:00
parent 57887a4fec
commit c9b69fb6dc
11 changed files with 1151 additions and 640 deletions
+205 -206
View File
@@ -51,211 +51,210 @@ namespace Lskj.PubBomImportNew
/// <param name="dirPaths"></param>
public void StartImportInFileByZB(List<DataRow> selectRows)
{
try
{
if (Directory.Exists("BomImportTemp"))
{
Directory.Delete("BomImportTemp", true);
}
Directory.CreateDirectory("BomImportTemp");
int execOrder = 1;
if (selectRows.Count > 1)
{
throw new Exception($"不允许选择多个文件");
}
DataRow mxRow = selectRows[0];
if (mxRow != null)
{
string mxDirPath = mxRow["BomFieldNameDir"] + "";
string productId = mxRow["BomMxMainProduct"] + "";
string addState = mxRow["BomMxAddState"] + "";
if (string.IsNullOrEmpty(Model.MainFieldDic))
{
throw new Exception($"字段对应关系配置异常");
}
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') = '0'");
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禁止修改操作");
}
}
FileInfo mxInfo = null;
if (!string.IsNullOrEmpty(mxDirPath))
{
mxInfo = new FileInfo(mxDirPath);
}
if (mxInfo != null)
{
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 = '{mxInfo.Name}'");
if (mxfiletable.Rows.Count > 0)
{
throw new Exception($"该文件已存在,请确认后再创建BOM");
}
FrmBillInfo frmBillInfo = new FrmBillInfo();
int.TryParse(Model.FirstRowIndex + "", out int firstRowIndex);
DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, Model.SheetName, firstRowIndex);
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !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();
var mxCodeRows = parentTable.AsEnumerable();
string[] fieldDic = Model.MainFieldDic.Split(',');
foreach (DataRow parentRow in parentTable.Rows)
{
string code = (parentRow["物料编码"] + "").Trim();
int codeCount = mxCodeRows.Where(n => (n["物料编码"] + "").Trim().StartsWith(code)).Count();
if (codeCount > 1)//只允许存在一个
{
throw new Exception($"文件中的物料编码{code}重复,请修改");
}
DataRow childRow = childTable.NewRow();
foreach (string item in fieldDic)
{
string[] fieldArray = item.Split('^');
string key0 = fieldArray[0];
string key1 = fieldArray[1];
childRow[key0] = parentRow[key1] + "";
}
//childRow["ProductId"] = parentRow["物料编码"] + "";
//childRow["appellation"] = parentRow["名称"] + "";
//childRow["bak"] = parentRow["备注"] + "";
//childRow["tamount"] = parentRow["数量"] + "";
//childRow["amount"] = parentRow["数量"] + "";
childTable.Rows.Add(childRow);
}
SetProcessBar(20, 0);
if (childTable.Rows.Count == 0)
{
throw new Exception($"明细数据不能空");
}
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,'' as bak,'' as bombb,'' as bombc";
// 处理单据表头数据
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
SetProcessBar(60, 0);
frmBillInfo.AddOrUpdateBill(masterRow, childTable);
string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid);
SetProcessBar(80, 0);
//上传文件
string uploadMxFileId = "";
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}");
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("文件不存在");
}
}
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.Cancel;
Close();
ImportTimer?.Dispose();
}));
}
//try
//{
// if (Directory.Exists("BomImportTemp"))
// {
// Directory.Delete("BomImportTemp", true);
// }
// Directory.CreateDirectory("BomImportTemp");
// int execOrder = 1;
// if (selectRows.Count > 1)
// {
// throw new Exception($"不允许选择多个文件");
// }
// DataRow mxRow = selectRows[0];
// if (mxRow != null)
// {
// string mxDirPath = mxRow["BomFieldNameDir"] + "";
// string productId = mxRow["BomMxMainProduct"] + "";
// string addState = mxRow["BomMxAddState"] + "";
// if (string.IsNullOrEmpty(Model.MainFieldDic))
// {
// throw new Exception($"字段对应关系配置异常");
// }
// 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') = '0'");
// 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禁止修改操作");
// }
// }
// FileInfo mxInfo = null;
// if (!string.IsNullOrEmpty(mxDirPath))
// {
// mxInfo = new FileInfo(mxDirPath);
// }
// if (mxInfo != null)
// {
// 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 = '{mxInfo.Name}'");
// if (mxfiletable.Rows.Count > 0)
// {
// throw new Exception($"该文件已存在,请确认后再创建BOM");
// }
// int.TryParse(Model.FirstRowIndex + "", out int firstRowIndex);
// DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, Model.SheetName, firstRowIndex);
// parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !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();
// var mxCodeRows = parentTable.AsEnumerable();
// string[] fieldDic = Model.MainFieldDic.Split(',');
// foreach (DataRow parentRow in parentTable.Rows)
// {
// string code = (parentRow["物料编码"] + "").Trim();
// int codeCount = mxCodeRows.Where(n => (n["物料编码"] + "").Trim().StartsWith(code)).Count();
// if (codeCount > 1)//只允许存在一个
// {
// throw new Exception($"文件中的物料编码{code}重复,请修改");
// }
// DataRow childRow = childTable.NewRow();
// foreach (string item in fieldDic)
// {
// string[] fieldArray = item.Split('^');
// string key0 = fieldArray[0];
// string key1 = fieldArray[1];
// childRow[key0] = parentRow[key1] + "";
// }
// //childRow["ProductId"] = parentRow["物料编码"] + "";
// //childRow["appellation"] = parentRow["名称"] + "";
// //childRow["bak"] = parentRow["备注"] + "";
// //childRow["tamount"] = parentRow["数量"] + "";
// //childRow["amount"] = parentRow["数量"] + "";
// childTable.Rows.Add(childRow);
// }
// SetProcessBar(20, 0);
// if (childTable.Rows.Count == 0)
// {
// throw new Exception($"明细数据不能空");
// }
// 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,'' as bak,'' as bombb,'' as bombc";
// // 处理单据表头数据
// DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
// SetProcessBar(60, 0);
// frmBillInfo.AddOrUpdateBill(masterRow, childTable);
// string guid = Guid.NewGuid() + "";
// frmBillInfo.BillSaveSql(guid);
// SetProcessBar(80, 0);
// //上传文件
// string uploadMxFileId = "";
// 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}");
// 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("文件不存在");
// }
// }
//}
//catch (Exception ex)
//{
// MessageUtil.Show(ex.Message);
// this.Invoke(new Action(() =>
// {
// this.DialogResult = DialogResult.Cancel;
// Close();
// ImportTimer?.Dispose();
// }));
//}
}
public int ProductSaveUnique(string spec, string appellation, string bak, string billSeq, out string productId, out string tipMsg)
{
@@ -417,7 +416,7 @@ namespace Lskj.PubBomImportNew
startRow = mergrRange.LastRow + 1;
if (mergrRange != null)
{
if (mergrRange.FirstColumn < mergrRange.LastColumn && !Model.CustomerServiceApp)
if (mergrRange.FirstColumn < mergrRange.LastColumn)//&& !Model.CustomerServiceApp
{
isBandTitle = true;
bandRow = sheet.GetRow(mergrRange.LastRow + 1);