From d4d010370830d2e0373e235c8366a763184fbe18 Mon Sep 17 00:00:00 2001 From: wyf Date: Thu, 20 Mar 2025 12:21:13 +0000 Subject: [PATCH] SVN r361 SVN-Revision: r361 --- 插件库/Lskj.PubBomImport/FrmBillInfo.cs | 6 +- 插件库/Lskj.PubBomImport/FrmMain.Designer.cs | 1 + 插件库/Lskj.PubBomImport/FrmMain.cs | 80 ++++++++++++++++++-- 3 files changed, 77 insertions(+), 10 deletions(-) diff --git a/插件库/Lskj.PubBomImport/FrmBillInfo.cs b/插件库/Lskj.PubBomImport/FrmBillInfo.cs index 4032e9b..85ea75e 100644 --- a/插件库/Lskj.PubBomImport/FrmBillInfo.cs +++ b/插件库/Lskj.PubBomImport/FrmBillInfo.cs @@ -104,12 +104,12 @@ namespace Lskj.PubBomImport { } - public void InitializeHeader(DataRow parentRow) + public void InitializeHeader(DataRow parentRow, string controlSql) { // 新增 - if (!string.IsNullOrEmpty(SysModel.BillMasterSql)) + if (!string.IsNullOrEmpty(controlSql)) { - string billMasterSql = SysModel.BillMasterSql; + string billMasterSql = controlSql; billMasterSql = ReplaceHelper.ReplaceRowParam(parentRow, billMasterSql); // 处理单据表头数据 DataRow row = BillImpl.GetDataRowResult(billMasterSql); diff --git a/插件库/Lskj.PubBomImport/FrmMain.Designer.cs b/插件库/Lskj.PubBomImport/FrmMain.Designer.cs index d001375..36c4dfd 100644 --- a/插件库/Lskj.PubBomImport/FrmMain.Designer.cs +++ b/插件库/Lskj.PubBomImport/FrmMain.Designer.cs @@ -274,6 +274,7 @@ namespace Lskj.PubBomImport this.Controls.Add(this.pl_cond); this.Controls.Add(this.pl_bottom); this.Name = "FrmMain"; + this.Opacity = 0D; this.Text = "表格导入"; ((System.ComponentModel.ISupportInitialize)(this.pl_bottom)).EndInit(); this.pl_bottom.ResumeLayout(false); diff --git a/插件库/Lskj.PubBomImport/FrmMain.cs b/插件库/Lskj.PubBomImport/FrmMain.cs index 816ad48..e1ca284 100644 --- a/插件库/Lskj.PubBomImport/FrmMain.cs +++ b/插件库/Lskj.PubBomImport/FrmMain.cs @@ -70,6 +70,10 @@ namespace Lskj.PubBomImport { Opacity = 0; } + else + { + Opacity = 1; + } InitlizeSpiltLocation(); InitEvents(); InitGridColumns(); @@ -82,6 +86,7 @@ namespace Lskj.PubBomImport } catch (Exception ex) { + WaitForm.HideForm(); MessageUtil.Show(ex.Message); this.Close(); } @@ -124,12 +129,14 @@ namespace Lskj.PubBomImport DialogResult dialogResult = dialog.ShowDialog(); if (dialogResult == DialogResult.OK) { + WaitForm.ShowForm("数据导入中"); string dirPath = dialog.SelectedPath; DirectoryInfo directoryInfo = new DirectoryInfo(dirPath); FileInfo[] fileInfos = directoryInfo.GetFiles(); FileInfo parentInfo = fileInfos.Where(n => n.Name.StartsWith("MX") && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (parentInfo != null) { + WaitForm.ShowForm("数据导入中"); DataTable parentTable = ExcelToDatatable(parentInfo.FullName, "", 5); parentTable = parentTable.Rows.Cast().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable(); StringBuilder stringBuilder = new StringBuilder(); @@ -151,16 +158,48 @@ namespace Lskj.PubBomImport { try { + WaitForm.ShowForm("数据导入中"); + DataTable childTable = new DataTable(); + foreach (GridColumn gridColumn in ParentView.Columns) + { + if (!childTable.Columns.Contains(gridColumn.FieldName)) + { + childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType); + } + } + foreach (DataRow parentRow in parentTable.Rows) + { + DataRow childRow = childTable.NewRow(); + childRow["ProductId"] = parentRow["图号"] + ""; + childRow["appellation"] = parentRow["名称"] + ""; + childRow["bak"] = parentRow["备注"] + ""; + childRow["tamount"] = parentRow["套数"] + ""; + childRow["amount"] = parentRow["套数"] + ""; + childTable.Rows.Add(childRow); + } + ParentView.GridControl.DataSource = childTable; + string controlSql = "select '' as billdocument_id,'0' affirmer,'0' rtagid,'{材料代码}' as productid"; + frmBillInfo.InitializeHeader(Model.MaintabFocusedRow, controlSql); + frmBillInfo.BillSave(); + frmBillInfo.OnBillAdd(); int.TryParse(Model.FirstRowIndex, out int index); FirstRowIndex = index; foreach (DataRow dataRow in parentTable.Rows) { + int.TryParse(dataRow["套数"] + "", out int tamount); string code = dataRow["图号"] + ""; FileInfo childInfo = fileInfos.Where(n => n.Name.Contains(code) && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (childInfo != null) { - ParentView.GridControl.DataSource = this.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true); - frmBillInfo.InitializeHeader(dataRow); + DataTable detailTable = this.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true); + foreach (DataRow detailRow in detailTable.Rows) + { + int.TryParse(detailRow["amount"] + "", out int lastAmount); + detailRow["tamount"] = tamount; + detailRow["amount"] = tamount > 0 ? (lastAmount * tamount) + "" : lastAmount + ""; + } + ParentView.GridControl.DataSource = detailTable; + frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql); frmBillInfo.BillSave(); frmBillInfo.OnBillAdd(); } @@ -172,6 +211,7 @@ namespace Lskj.PubBomImport } finally { + WaitForm.HideForm(); this.Close(); } })); @@ -179,15 +219,22 @@ namespace Lskj.PubBomImport } else { - MessageBox.Show("未包含结构文件"); + WaitForm.HideForm(); + MessageUtil.Show("未包含结构文件"); + this.Close(); } } + else + { + WaitForm.HideForm(); + this.Close(); + } } catch (Exception ex) { WaitForm.HideForm(); - this.Show(); - MessageUtil.Show(string.Format("导入失败,原因:{0}", ex.Message)); + MessageUtil.Show(ex.Message); + this.Close(); } } /// @@ -732,11 +779,30 @@ namespace Lskj.PubBomImport } //将excel表每一行的数据添加到datatable的行中 DataRow dataRow = data.NewRow(); + int dataRowIndex = 0; for (int j = firstRow.FirstCellNum; j < cellCount; j++) { - if (row.GetCell(j) != null) //同理,没有数据的单元格都默认是null + ICell cell = row.GetCell(j); + if (cell.IsMergedCell) { - dataRow[j - firstRow.FirstCellNum] = GetCellValue(row.GetCell(j)); + CellRangeAddress mergrRange = FindMergedRegion(sheet, i, j); + if (j == mergrRange.FirstColumn) + { + dataRow[dataRowIndex] = GetCellValue(row.GetCell(j)); + dataRowIndex += 1; + } + else + { + continue; + } + } + else + { + if (row.GetCell(j) != null) //同理,没有数据的单元格都默认是null + { + dataRow[dataRowIndex] = GetCellValue(row.GetCell(j)); + dataRowIndex += 1; + } } } data.Rows.Add(dataRow);