From 3a0cb687097dd4e63fa365e74523cace75afb8e9 Mon Sep 17 00:00:00 2001 From: wyf Date: Mon, 9 Jun 2025 09:39:02 +0000 Subject: [PATCH] SVN r696 SVN-Revision: r696 --- 插件库/Lskj.PubBomImport/FrmMain.cs | 54 +++++++ 插件库/Lskj.PubBomImport/FrmProgress.cs | 201 ++++++++++++++++++++++++ 2 files changed, 255 insertions(+) diff --git a/插件库/Lskj.PubBomImport/FrmMain.cs b/插件库/Lskj.PubBomImport/FrmMain.cs index 927b98f..a92a1c6 100644 --- a/插件库/Lskj.PubBomImport/FrmMain.cs +++ b/插件库/Lskj.PubBomImport/FrmMain.cs @@ -773,6 +773,60 @@ namespace Lskj.PubBomImport this.Close(); } } + else if (Model.ShowType.Equals("9"))//总部,新增一个主文件 + { + BomImpRtnModel bomImpRtnModel = new BomImpRtnModel() + { + ShowType = Model.ShowType, + AfterBomFieldName = Model.AfterBomFieldName, + CanSave = true + }; + FormDialogModel dialogModel = new FormDialogModel() + { + DialogDllName = "Lskj.PubBomImport.dll", + PubDialogType = DialogType.PubAddRecord, + ReturnTag = bomImpRtnModel + }; + this.Tag = dialogModel; + DataTable sourceTable = StaticControl.RightMenuGridView.GridControl.DataSourceTable(); + if (sourceTable.Columns.Contains("BomFieldNameDir")) + { + List selectRows = new List(); + foreach (DataRow sourceRow in sourceTable.Rows) + { + if (sourceRow.RowState == DataRowState.Deleted) + { + continue; + } + 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.StartImportInFileByZB(selectRows); + }; + frmProgress.ImportTimer.Enabled = true; + DialogResult dialogResult = frmProgress.ShowDialog(); + bomImpRtnModel.CanSave = dialogResult == DialogResult.OK; + frmProgress.Dispose(); + } + else + { + this.Close(); + } + } + else + { + this.Close(); + } + } } catch (Exception ex) { diff --git a/插件库/Lskj.PubBomImport/FrmProgress.cs b/插件库/Lskj.PubBomImport/FrmProgress.cs index 55e0d0c..662dadb 100644 --- a/插件库/Lskj.PubBomImport/FrmProgress.cs +++ b/插件库/Lskj.PubBomImport/FrmProgress.cs @@ -2329,6 +2329,207 @@ namespace Lskj.PubBomImport } } /// + /// bom结构上传(总部) + /// + /// + public void StartImportInFileByZB(List 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 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') = '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(); + DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, "", 1); + parentTable = parentTable.Rows.Cast().Where(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 maxBcFileDic = new Dictionary(); + Dictionary fileTableDic = new Dictionary(); + #region 新增或修改MX + frmBillInfo.OnBillAdd(); + SetProcessBar(0, 0); + SetProcessMsg($"正在导入:{Path.GetFileName(mxInfo.FullName)}"); + DataTable childTable = frmBillInfo.GcMainView.GridControl.DataSourceTable().Clone(); + 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($"文件中的物料编码{code}重复,请修改"); + } + DataRow childRow = childTable.NewRow(); + 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"; + // 处理单据表头数据 + 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(); + })); + } + } + /// /// 一级bom结构上传 /// ///