SVN r361
SVN-Revision: r361
This commit is contained in:
@@ -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);
|
||||
|
||||
+1
@@ -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);
|
||||
|
||||
@@ -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<DataRow>().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();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -732,11 +779,30 @@ namespace Lskj.PubBomImport
|
||||
}
|
||||
//将excel表每一行的数据添加到datatable的行中
|
||||
DataRow dataRow = data.NewRow();
|
||||
int dataRowIndex = 0;
|
||||
for (int j = firstRow.FirstCellNum; j < cellCount; j++)
|
||||
{
|
||||
ICell cell = row.GetCell(j);
|
||||
if (cell.IsMergedCell)
|
||||
{
|
||||
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[j - firstRow.FirstCellNum] = GetCellValue(row.GetCell(j));
|
||||
dataRow[dataRowIndex] = GetCellValue(row.GetCell(j));
|
||||
dataRowIndex += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
data.Rows.Add(dataRow);
|
||||
|
||||
Reference in New Issue
Block a user