diff --git a/插件库/Lskj.PubBomImport/FrmMain.cs b/插件库/Lskj.PubBomImport/FrmMain.cs
index 18f0c52..d6e4b5a 100644
--- a/插件库/Lskj.PubBomImport/FrmMain.cs
+++ b/插件库/Lskj.PubBomImport/FrmMain.cs
@@ -101,26 +101,54 @@ namespace Lskj.PubBomImport
{
try
{
- FolderBrowserDialog dialog = new FolderBrowserDialog();
- dialog.Description = "选择导入文件夹";
- DialogResult dialogResult = dialog.ShowDialog();
- if (dialogResult == DialogResult.OK)
+ if (Model.ShowType.Equals("1"))
{
- string dirPath = dialog.SelectedPath;
- FrmProgress frmProgress = new FrmProgress();
- frmProgress.frmMain = this;
- frmProgress.ImportTimer.Tick += (ts, te) =>
+ FolderBrowserDialog dialog = new FolderBrowserDialog();
+ dialog.Description = "选择导入文件夹";
+ DialogResult dialogResult = dialog.ShowDialog();
+ if (dialogResult == DialogResult.OK)
{
- frmProgress.ImportTimer.Enabled = false;
- frmProgress.StartImport(dirPath);
- };
- frmProgress.ImportTimer.Enabled = true;
- frmProgress.ShowDialog();
- frmProgress.Dispose();
+ string dirPath = dialog.SelectedPath;
+ FrmProgress frmProgress = new FrmProgress();
+ frmProgress.frmMain = this;
+ frmProgress.ImportTimer.Tick += (ts, te) =>
+ {
+ frmProgress.ImportTimer.Enabled = false;
+ frmProgress.StartImportInDir(dirPath);
+ };
+ frmProgress.ImportTimer.Enabled = true;
+ frmProgress.ShowDialog();
+ frmProgress.Dispose();
+ }
+ else
+ {
+ this.Close();
+ }
}
- else
+ else if (Model.ShowType.Equals("2"))
{
- this.Close();
+ OpenFileDialog dialog = new OpenFileDialog();
+ dialog.Title = "选择导入文件";
+ dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
+ DialogResult dialogResult = dialog.ShowDialog();
+ if (dialogResult == DialogResult.OK)
+ {
+ string dirPath = dialog.FileName;
+ FrmProgress frmProgress = new FrmProgress();
+ frmProgress.frmMain = this;
+ frmProgress.ImportTimer.Tick += (ts, te) =>
+ {
+ frmProgress.ImportTimer.Enabled = false;
+ frmProgress.StartImportInMxFile(dirPath);
+ };
+ frmProgress.ImportTimer.Enabled = true;
+ frmProgress.ShowDialog();
+ frmProgress.Dispose();
+ }
+ else
+ {
+ this.Close();
+ }
}
}
catch (Exception ex)
diff --git a/插件库/Lskj.PubBomImport/FrmProgress.cs b/插件库/Lskj.PubBomImport/FrmProgress.cs
index f98dfcd..b495adc 100644
--- a/插件库/Lskj.PubBomImport/FrmProgress.cs
+++ b/插件库/Lskj.PubBomImport/FrmProgress.cs
@@ -54,7 +54,7 @@ namespace Lskj.PubBomImport
/// 开始导入
///
///
- public void StartImport(string dirPath)
+ public void StartImportInDir(string dirPath)
{
try
{
@@ -64,13 +64,212 @@ namespace Lskj.PubBomImport
FileInfo parentInfo = fileInfos.Where(n => n.Name.StartsWith("MX") && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (parentInfo != null)
{
+ FrmBillInfo frmBillInfo = new FrmBillInfo();
DataTable parentTable = ExcelToDatatable(parentInfo.FullName, Model, "", 5);
parentTable = parentTable.Rows.Cast().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable();
+ DataTable childTable = new DataTable();
+ foreach (GridColumn gridColumn in frmBillInfo.GcMainView.Columns)
+ {
+ if (!childTable.Columns.Contains(gridColumn.FieldName))
+ {
+ childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType);
+ }
+ }
+ foreach (DataRow parentRow in parentTable.Rows)
+ {
+ string code = parentRow["图号"] + "";
+ FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
+ if (childInfo != null && (childInfo.Name.StartsWith("QD") || childInfo.Name.StartsWith("ZZQD")))
+ {
+ DataRow childRow = childTable.NewRow();
+ childRow["ProductId"] = parentRow["图号"] + "";
+ childRow["appellation"] = parentRow["名称"] + "";
+ childRow["bak"] = parentRow["备注"] + "";
+ childRow["tamount"] = parentRow["套数"] + "";
+ childRow["amount"] = parentRow["套数"] + "";
+ childTable.Rows.Add(childRow);
+ }
+ }
StringBuilder stringBuilder = new StringBuilder();
foreach (DataRow dataRow in parentTable.Rows)
{
- stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{dataRow["图号"] + ""}')");
- stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak) values ('{(dataRow["图号"] + "").Replace("'", "''")}','{(dataRow["名称"] + "").Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}') end;");
+ string code = (dataRow["图号"] + "").Trim();
+ if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
+ {
+ stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{dataRow["图号"] + ""}')");
+ stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak) values ('{(dataRow["图号"] + "").Replace("'", "''")}','{(dataRow["名称"] + "").Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}') end;");
+ }
+ }
+ if (!string.IsNullOrEmpty(stringBuilder.ToString()))
+ {
+ SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
+ }
+ frmBillInfo.OnControlSourceBind += (s, args) =>
+ {
+ Task task = new Task(() =>
+ {
+ try
+ {
+ SetProcessBar(0, 0);
+ SetProcessMsg($"正在导入:{Path.GetFileName(parentInfo.FullName)}");
+ SetProcessBar(20, 0);
+ frmBillInfo.GcMainView.GridControl.DataSource = childTable;
+ SetProcessBar(40, 0);
+ string controlSql = "select '' as billdocument_id,'0' affirmer,'0' rtagid,'{材料代码}' as productid";
+ frmBillInfo.InitializeHeader(Model.MaintabFocusedRow, controlSql);
+ SetProcessBar(60, 0);
+ frmBillInfo.BillSave();
+ SetProcessBar(80, 0);
+ frmBillInfo.OnBillAdd();
+ string productId = Model.MaintabFocusedRow["材料代码"] + "";
+ string billdocumentId = Model.MaintabFocusedRow["单据编号"] + "";
+ string idValue = BaseImpl.GetResult($"select top 1 billdocument_id from bom_billListTab where ParentProduct = '{productId}'") + "";
+ string updateParentVerSql = @"update bom_BillListTab set Ver = '{0}' where Billdocument_Id='{1}' and ProductId='{0}'";
+ SqlHelper.ExecuteNonQuery(string.Format(updateParentVerSql, idValue, billdocumentId));
+ //上传文件
+ bool isUpload = UploadFile(parentInfo.FullName, idValue, out string msg);
+ SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
+ SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
+ int.TryParse(Model.FirstRowIndex, out int index);
+ frmMain.FirstRowIndex = index;
+ foreach (DataRow dataRow in parentTable.Rows)
+ {
+
+ int childIndex = parentTable.Rows.IndexOf(dataRow);
+ int nowCount = 1 + childIndex;
+ int allCount = (int)((decimal)(1 + childIndex) / (parentTable.Rows.Count + 1) * 100);
+ int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100);
+ int.TryParse(dataRow["套数"] + "", out int tamount);
+ string code = (dataRow["图号"] + "").Trim();
+ FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
+ if (childInfo != null && (code.StartsWith("QD") || code.StartsWith("ZZQD")))
+ {
+ SetProcessBar(0, allCount);
+ SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}");
+ DataTable detailTable = new DataTable();
+ frmMain.Invoke(new Action(() =>
+ {
+ detailTable = frmMain.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 + "";
+ }
+ frmBillInfo.GcMainView.GridControl.DataSource = detailTable;
+ SetProcessBar(20, allCount);
+ frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql);
+ SetProcessBar(40, allCount);
+ frmBillInfo.BillSave();
+ SetProcessBar(60, allCount);
+ frmBillInfo.OnBillAdd();
+ string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'";
+ SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
+ SetProcessBar(80, allCount);
+ isUpload = UploadFile(childInfo.FullName, idValue, out msg);
+ SetProcessBar(100, finishCount);
+ SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
+ }
+ else
+ {
+ isUpload = UploadFile(childInfo.FullName, idValue, out msg);
+ SetProcessBar(100, finishCount);
+ SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+ }
+ finally
+ {
+ this.DialogResult = DialogResult.OK;
+ this.Close();
+ ImportTimer?.Dispose();
+ }
+ });
+ task.Start();
+ };
+ frmBillInfo.OnLoad(Model);
+ frmMain.ParentView = frmBillInfo.GcMainView;
+ }
+ else
+ {
+ throw new Exception("未包含结构文件");
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageUtil.Show(ex.Message);
+ this.DialogResult = DialogResult.OK;
+ Close();
+ ImportTimer?.Dispose();
+ }
+ }
+ ///
+ /// 开始导入
+ ///
+ ///
+ public void StartImportInMxFile(string dirPath)
+ {
+ try
+ {
+ Model = frmMain.Model;
+ FileInfo parentInfo = new FileInfo(dirPath);
+ if (parentInfo != null && parentInfo.Name.Trim().StartsWith("MX"))
+ {
+ if (Directory.Exists("BomImportTemp"))
+ {
+ Directory.Delete("BomImportTemp", true);
+ }
+ Directory.CreateDirectory("BomImportTemp");
+ DataTable parentTable = ExcelToDatatable(parentInfo.FullName, Model, "", 5);
+ parentTable = parentTable.Rows.Cast().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable();
+ Dictionary childFileDic = new Dictionary();
+ foreach (DataRow parentRow in parentTable.Rows)
+ {
+ string fileName = (parentRow["图号"] + "").Trim();
+ if (fileName.StartsWith("QD") || fileName.StartsWith("ZZQD"))
+ {
+ string fileSql = $"select webpath,sName from P_fm_FileTab where sName like '{fileName}%'";
+ DataRow fileRow = BaseImpl.GetDataRowResult(fileSql);
+ string webpath = fileRow != null ? fileRow["webpath"] + "" : "";
+ string sName = fileRow != null ? fileRow["sName"] + "" : "";
+ if (string.IsNullOrEmpty(webpath))
+ {
+ throw new Exception($"Bom明细附件{fileName}不存在\r\nBom导入失败");
+ }
+ else
+ {
+ using (WebClient webClient = new WebClient())
+ {
+ try
+ {
+ webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
+ string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
+ string tempFileName = $"BomImportTemp/{sName}";
+ webClient.DownloadFile(url, tempFileName);
+ childFileDic.Add(fileName, tempFileName);
+ }
+ catch (Exception)
+ {
+ throw new Exception($"Bom明细附件{fileName}获取失败\r\nBom导入失败");
+ }
+ }
+ }
+ }
+ }
+ StringBuilder stringBuilder = new StringBuilder();
+ foreach (DataRow dataRow in parentTable.Rows)
+ {
+ string code = (dataRow["图号"] + "").Trim();
+ if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
+ {
+ stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{dataRow["图号"] + ""}')");
+ stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak) values ('{(dataRow["图号"] + "").Replace("'", "''")}','{(dataRow["名称"] + "").Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}') end;");
+ }
}
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
{
@@ -93,29 +292,28 @@ namespace Lskj.PubBomImport
childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType);
}
}
- List deleteRows = new List();
foreach (DataRow parentRow in parentTable.Rows)
{
- string code = parentRow["图号"] + "";
- FileInfo childInfo = fileInfos.Where(n => n.Name.Contains(code) && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
- if (childInfo != null)
+ string code = (parentRow["图号"] + "").Trim();
+ if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
{
- DataRow childRow = childTable.NewRow();
- childRow["ProductId"] = parentRow["图号"] + "";
- childRow["appellation"] = parentRow["名称"] + "";
- childRow["bak"] = parentRow["备注"] + "";
- childRow["tamount"] = parentRow["套数"] + "";
- childRow["amount"] = parentRow["套数"] + "";
- childTable.Rows.Add(childRow);
+ string tempFileName = childFileDic[code];
+ FileInfo childInfo = new FileInfo(tempFileName);
+ if (childInfo != null)
+ {
+ DataRow childRow = childTable.NewRow();
+ childRow["ProductId"] = parentRow["图号"] + "";
+ childRow["appellation"] = parentRow["名称"] + "";
+ childRow["bak"] = parentRow["备注"] + "";
+ childRow["tamount"] = parentRow["套数"] + "";
+ childRow["amount"] = parentRow["套数"] + "";
+ childTable.Rows.Add(childRow);
+ }
+ else
+ {
+ throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
+ }
}
- else
- {
- deleteRows.Add(parentRow);
- }
- }
- foreach (DataRow item in deleteRows)
- {
- parentTable.Rows.Remove(item);
}
SetProcessBar(20, 0);
frmBillInfo.GcMainView.GridControl.DataSource = childTable;
@@ -144,45 +342,50 @@ namespace Lskj.PubBomImport
int allCount = (int)((decimal)(1 + childIndex) / (parentTable.Rows.Count + 1) * 100);
int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100);
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)
+ string code = (dataRow["图号"] + "").Trim();
+ if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
{
- SetProcessBar(0, allCount);
- SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}");
- DataTable detailTable = new DataTable();
- frmMain.Invoke(new Action(() =>
+ string tempFileName = childFileDic[code];
+ FileInfo childInfo = new FileInfo(tempFileName);
+ if (childInfo != null)
{
- detailTable = frmMain.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 + "";
+ SetProcessBar(0, allCount);
+ SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}");
+ DataTable detailTable = new DataTable();
+ frmMain.Invoke(new Action(() =>
+ {
+ detailTable = frmMain.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 + "";
+ }
+ frmBillInfo.GcMainView.GridControl.DataSource = detailTable;
+ SetProcessBar(20, allCount);
+ frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql);
+ SetProcessBar(40, allCount);
+ frmBillInfo.BillSave();
+ SetProcessBar(60, allCount);
+ frmBillInfo.OnBillAdd();
+ string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'";
+ SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
+ SetProcessBar(80, allCount);
+ //上传文件
+ //if (Model.ShowType.Equals("1"))
+ //{
+ // isUpload = UploadFile(childInfo.FullName, idValue, out msg);
+ //}
+ SetProcessBar(100, finishCount);
+ SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
}
- frmBillInfo.GcMainView.GridControl.DataSource = detailTable;
- SetProcessBar(20, allCount);
- frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql);
- SetProcessBar(40, allCount);
- frmBillInfo.BillSave();
- SetProcessBar(60, allCount);
- frmBillInfo.OnBillAdd();
- string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'";
- SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
- SetProcessBar(80, allCount);
- //上传文件
- if (Model.ShowType.Equals("1"))
+ else
{
- isUpload = UploadFile(childInfo.FullName, idValue, out msg);
+ throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
+ SetProcessBar(100, finishCount);
+ SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
}
- SetProcessBar(100, finishCount);
- SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
- }
- else
- {
- SetProcessBar(100, finishCount);
- SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
}
}
}
@@ -204,7 +407,8 @@ namespace Lskj.PubBomImport
}
else
{
- MessageUtil.Show("未包含结构文件");
+ MessageUtil.Show("主文件不符合规则");
+ this.DialogResult = DialogResult.Cancel;
Close();
ImportTimer?.Dispose();
}
@@ -212,6 +416,7 @@ namespace Lskj.PubBomImport
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
+ this.DialogResult = DialogResult.Cancel;
Close();
ImportTimer?.Dispose();
}