diff --git a/插件库/Lskj.PubBomImport/FrmMain.cs b/插件库/Lskj.PubBomImport/FrmMain.cs index 6cca252..f6bcc46 100644 --- a/插件库/Lskj.PubBomImport/FrmMain.cs +++ b/插件库/Lskj.PubBomImport/FrmMain.cs @@ -259,6 +259,36 @@ namespace Lskj.PubBomImport this.Close(); } } + if (Model.ShowType.Equals("000"))//单选文件并返回到表中 + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Multiselect = false; + dialog.InitialDirectory = Properties.Settings.Default.LastSelectFolder; + dialog.Title = "选择导入文件"; + //dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls"; + DialogResult dialogResult = dialog.ShowDialog(); + if (dialogResult == DialogResult.OK) + { + Properties.Settings.Default.LastSelectFolder = Path.GetDirectoryName(dialog.FileName); + BomImpRtnModel bomImpRtnModel = new BomImpRtnModel() + { + ShowType = Model.ShowType, + AfterBomFieldName = Model.AfterBomFieldName, + FileNames = dialog.FileNames + }; + FormDialogModel dialogModel = new FormDialogModel() + { + DialogDllName = "Lskj.PubBomImport.dll", + PubDialogType = DialogType.PubAddRecord, + ReturnTag = bomImpRtnModel + }; + this.Tag = dialogModel; + } + else + { + this.Close(); + } + } else if (Model.ShowType.Equals("1"))//新增多个其它文件 { BomImpRtnModel bomImpRtnModel = new BomImpRtnModel() @@ -623,6 +653,66 @@ namespace Lskj.PubBomImport this.Close(); } } + else if (Model.ShowType.Equals("7"))//修改单个其它文件 + { + 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"] + ""; + FileInfo parentInfo = null; + if (string.IsNullOrEmpty(dirPath)) + { + continue; + } + parentInfo = new FileInfo(dirPath); + 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.StartUpdateInOtherFile(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 cf2ed02..1c8a24a 100644 --- a/插件库/Lskj.PubBomImport/FrmProgress.cs +++ b/插件库/Lskj.PubBomImport/FrmProgress.cs @@ -553,7 +553,7 @@ namespace Lskj.PubBomImport } } /// - /// Bom结构补充,新增其它文件,无版本控制 + /// 批量修改多个其它文件{版次变化直接上传} /// /// public void StartUpdateInOtherFiles(List selectRows) @@ -736,6 +736,193 @@ namespace Lskj.PubBomImport } } /// + /// 单个修改其它文件,有可能存在无规则的文件,直接按照版本变化上传 + /// + /// + public void StartUpdateInOtherFile(List selectRows) + { + try + { + int execOrder = 1; + FrmBillInfo frmBillInfo = new FrmBillInfo(); + string speciesno = selectRows[0]["BomAddSpeciesNo"] + ""; + if (string.IsNullOrEmpty(speciesno)) + { + throw new Exception("未选择文件分类"); + } + if (selectRows.Count > 1) + { + throw new Exception("仅支持单个附件变更"); + } + Dictionary maxfileRowDic = new Dictionary(); + foreach (DataRow selectRow in selectRows) + { + string fileName = selectRow[Model.AfterBomFieldName] + ""; + string dirPath = selectRow["BomFieldNameDir"] + ""; + FileInfo fileInfo = new FileInfo(dirPath); + if (fileInfo != null) + { + string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name).Trim(); + bool isMatch = GetOtherFileCodeInfo(fileInfo.Name, out string code, out string spec, out string name, out string extension, out string bb, out int bc); + if (!isMatch) + { + throw new Exception($"{fileInfo.Name}\r\n文件名不符合规则"); + } + if (string.IsNullOrEmpty(code)) + { + throw new Exception($"编码解析为空"); + } + if (string.IsNullOrEmpty(spec)) + { + throw new Exception($"规格解析为空"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception($"名称解析为空"); + } + if (!fileNameWithoutExtension.StartsWith("LX")) + { + throw new Exception($"文件{fileNameWithoutExtension}名称不符合规则\r\n不以LX开头"); + } + else + { + if (bc <= 0) + { + throw new Exception($"{fileInfo.Name}\r\n为0的版次不允许进行版次修改"); + } + DataRow productRow = BaseImpl.GetDataRowResult($"select ProductId from p_productTab where ProductId = '{code}'"); + if (productRow == null) + { + throw new Exception($"物料编码{code}不存在,无法修改"); + } + DataRow maxRow = BaseImpl.GetDataRowResult($"exec dbo.p_CheckLxFileRevision N'{fileInfo.Name}','{speciesno}';"); + maxfileRowDic[fileInfo.Name] = maxRow; + if (maxRow != null)//如果存在则不允许上传 + { + int.TryParse(maxRow["版本号"] + "", out int oldbb); + int.TryParse(maxRow["新文件版本号"] + "", out int newbb); + if (newbb <= oldbb) + { + throw new Exception($"{fileInfo.Name}\r\n版本号小于等于最大版本号{oldbb},无法修改"); + } + } + else + { + throw new Exception($"{fileInfo.Name}\r\n不存在可以修改的附件"); + } + } + } + else + { + throw new Exception($"{fileName}的文件不存在"); + } + } + frmBillInfo.OnControlSourceBind += (s, args) => + { + Task task = new Task(() => + { + try + { + int.TryParse(Model.FirstRowIndex, out int index); + frmMain.FirstRowIndex = index; + foreach (DataRow selectRow in selectRows) + { + string productId = selectRow["BomMxMainProduct"] + ""; + int childIndex = selectRows.IndexOf(selectRow); + int nowCount = 1 + childIndex; + int allCount = (int)((decimal)(1 + childIndex) / (selectRows.Count + 1) * 100); + int finishCount = (int)((decimal)(1 + nowCount) / (selectRows.Count + 1) * 100); + string fileName = selectRow[Model.AfterBomFieldName] + ""; + string dirPath = selectRow["BomFieldNameDir"] + ""; + FileInfo fileInfo = new FileInfo(dirPath); + if (fileInfo != null) + { + DataRow maxRow = maxfileRowDic.ContainsKey(fileInfo.Name) ? maxfileRowDic[fileInfo.Name] : null; + string uploadFileId = ""; + if (maxRow != null)//如果存在则修改 + { + int.TryParse(maxRow["fileid"] + "", out int fileId); + int.TryParse(maxRow["版本号"] + "", out int oldbb); + int.TryParse(maxRow["新文件版本号"] + "", out int newbb); + if (newbb <= oldbb) + { + throw new Exception($"{fileInfo.Name}\r\n版本号小于等于最大版本号{oldbb},无法修改"); + } + string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name).Trim(); + GetOtherFileCodeInfo(fileInfo.Name, out string code, out string spec, out string name, out string extension, out string bb, out int bc); + SetProcessBar(0, allCount); + bool isUpload = UploadFileToAudit(fileInfo.FullName, code, speciesno, out string msg, out uploadFileId); + if (!isUpload) + { + throw new Exception($"{fileNameWithoutExtension}附件上传失败\r\n{msg}"); + } + StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() => + { + if (selectRow.Table.Columns.Contains("qms_laddf_uniofileid")) + { + selectRow["qms_laddf_uniofileid"] = fileId; + } + if (selectRow.Table.Columns.Contains("qms_laddf_uploadtag")) + { + selectRow["qms_laddf_uploadtag"] = 1; + } + })); + SetProcessBar(100, finishCount); + SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{selectRows.Count + 1}"); + } + else + { + throw new Exception($"{fileInfo.Name}\r\n不存在可以修改的附件"); + } + StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() => + { + if (selectRow.Table.Columns.Contains("qms_laddf_FileId")) + { + int.TryParse(uploadFileId, out int qms_laddf_FileId); + selectRow["qms_laddf_FileId"] = qms_laddf_FileId; + } + })); + } + else + { + throw new Exception($"{fileName}的文件不存在"); + } + } + 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; + } + catch (Exception ex) + { + MessageUtil.Show(ex.Message); + this.Invoke(new Action(() => + { + this.DialogResult = DialogResult.Cancel; + Close(); + ImportTimer?.Dispose(); + })); + } + } + /// /// 修改单个文件 /// ///