diff --git a/插件库/Lskj.PubBomImport/FrmBillInfo.cs b/插件库/Lskj.PubBomImport/FrmBillInfo.cs
index f972569..d72e71d 100644
--- a/插件库/Lskj.PubBomImport/FrmBillInfo.cs
+++ b/插件库/Lskj.PubBomImport/FrmBillInfo.cs
@@ -31,6 +31,10 @@ namespace Lskj.PubBomImport
///
private DataTable _detailColumns;
private string guidField = "xxxxx_guid";
+ ///
+ /// 保存或修改时报错信息
+ ///
+ public string SaveErrorMessage = string.Empty;
public GridView GcMainView
{
get { return gcMain.GridView; }
@@ -127,7 +131,15 @@ namespace Lskj.PubBomImport
}
}
}
- public bool BillSave(int comfirm = 0, bool canTipMsg = true)
+ public void InitializeHeader(DataRow rowItem)
+ {
+ // 新增
+ if (rowItem != null)
+ {
+ ControlObj.SetAllControlValue(rowItem, true);
+ }
+ }
+ public bool BillSave(ref string billNo, int comfirm = 0, bool canTipMsg = true)
{
bool saveResult = false;
if (ControlObj.VerifyNull())
@@ -151,9 +163,9 @@ namespace Lskj.PubBomImport
//MessageUtil.Show("表格中数据内容重复,保存失败!");
return saveResult;
}
- string billNo = this.lblOrderNo.Text.Trim();
+ billNo = this.lblOrderNo.Text.Trim();
string detailGuid = Guid.NewGuid().ToString();
- string masterSql = GetAddRecord(ref billNo);
+ string masterSql = billModel.SaveState ? GetUpdateRecord(billNo) : GetAddRecord(ref billNo);
string detailSql = GetDetailRecord(detailGuid, billNo).ToString();
// 检查单据头数据合法性
if (string.IsNullOrEmpty(masterSql)) return false;
@@ -182,6 +194,37 @@ namespace Lskj.PubBomImport
}
return saveResult;
}
+ private string GetUpdateRecord(string parmaryValue)
+ {
+ StringBuilder updateBuilder = new StringBuilder();
+ DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", billModel.MasterTable));
+ string errorMessage = string.Empty;//数据不符合数据库规范的信息
+ // 修改单据
+ foreach (ControlModel model in this.ControlObj.ControlModels)
+ {
+ if (!model.IsSave ||
+ model.FieldName.Equals(billModel.RtagidKey, StringComparison.OrdinalIgnoreCase) ||
+ model.FieldType == ControlType.LabPic ||
+ model.FieldType == ControlType.LabPicEx)
+ continue;
+ BaseUserControl userControl = this.ControlObj.FindControl(model);
+ if (userControl != null)
+ {
+ string fieldValue = this.ControlObj.GetControlValue(model);
+ if (SystemInfo.Instance.TrimWhiteSpace)
+ fieldValue = fieldValue.Trim();
+ if (fieldValue == "****") continue;
+
+ errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue);
+ if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0;
+
+ updateBuilder.Append(string.IsNullOrEmpty(fieldValue) ? string.Format("{0}={1}", model.FieldName, this.ControlObj.GetNullValue(model)) : string.Format("{0}=N'{1}',", model.FieldName, fieldValue.Contains("'") ? fieldValue.Replace("'", "''") : fieldValue));
+
+ }
+ }
+ if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage;
+ return string.Format("update {0} set {1} where {2}='{3}'", billModel.MasterTable, updateBuilder.ToString().TrimEnd(','), billModel.PrimaryKey, parmaryValue);
+ }
private string GetAddRecord(ref string parmaryValue)
{
if (billModel.NewVer == 0)
@@ -213,15 +256,20 @@ namespace Lskj.PubBomImport
model.FieldType == ControlType.LabPic ||
model.FieldType == ControlType.LabPicEx)
continue;
+
string fieldValue = this.ControlObj.GetControlValue(model);
if (SystemInfo.Instance.TrimWhiteSpace)
fieldValue = fieldValue.Trim();
if (fieldValue == "****") continue;
+
errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue);
if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0;
+
fieldBuilder.Append(model.FieldName + ",");
valueBuilder.Append(string.IsNullOrEmpty(fieldValue) ? this.ControlObj.GetNullValue(model) : string.Format("N'{0}',", fieldValue));
+
}
+ if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage;
// 增加主键
fieldBuilder.Append(billModel.PrimaryKey);
valueBuilder.Append("N'" + parmaryValue + "'");
@@ -331,13 +379,108 @@ namespace Lskj.PubBomImport
}
private void SetBillStatus(DataRow rowItem)
{
- // 单据为新增状态
- this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true;
- this.lbTitle.Text = billModel.TypeName + "(新增)";
- this.lblOrderNo.Text = BillImpl.GetBillNo(billModel.BillSeq);
- this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true;
- this.cb_templete.Enabled = true;
- this.billModel.SaveState = false;
- this.ControlObj.SetReadOnlyAllControl(false);
- this.rdBlue.Enabled = this.rdRed.Enabled = true;
- // 通过右键菜单打开单据,假如明细有数据则在初始化时使用传入数据.
+ if (rowItem != null)
+ {
+ // 单据为修改状态,无需设置赋值时不需要计算面板属性
+ bool isReadOnly = !string.IsNullOrEmpty(billModel.ModifyCond) && !ReplaceHelper.ReplaceRowParamCond(rowItem, billModel.ModifyCond);
+ this.ControlObj.CanExecControl = false; // 单据为修改状态时,无需计算面板属性
+ this.lbTitle.Text = billModel.TypeName + "(修改)";
+ this.lblOrderNo.Text = rowItem[billModel.PrimaryKey] + "";
+ this.rdBlue.Checked = "0".Equals(rowItem[billModel.RtagidKey] + "");
+ this.rdRed.Checked = "1".Equals(rowItem[billModel.RtagidKey] + "");
+ billModel.SaveState = true;
+ this.rdBlue.Enabled = this.rdRed.Enabled = false;
+ this.ControlObj.SetReadOnlyAllControl(isReadOnly);
+ this.ControlObj.SetAllControlValue(rowItem);
+ this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = !isReadOnly;
+ this.ControlObj.CanExecControl = true;
+ this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = !isReadOnly;
+ this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = rdBlue.Checked ? Color.Blue : Color.Red;
+ this.gcMain.GridView.OptionsBehavior.Editable = !isReadOnly;
+ // 上一次查询
+ int oldRowHandle = this.gcMain.GridView.FocusedRowHandle;
+ //获取数据源并排序
+ DataTable dt = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, billModel.DetailSql));
+ if (dt.Columns.Contains(billModel.DetailOrderField))
+ {
+ DataView dataView = dt.AsDataView();
+ dataView.Sort = billModel.DetailOrderField;
+ dt = dataView.ToTable();
+ }
+ if (billModel.DetailTreeTable)
+ {
+ //判断是否有tap_id和tap_pid
+ (this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(dt);
+ this.gcMain.GridView.SelectRowHandler(oldRowHandle);
+ }
+ else
+ {
+ this.gcMain.GridControl.DataSource = dt;
+ this.gcMain.GridView.SelectRowHandler(oldRowHandle);
+ if (billModel.SelectLast && dt.Rows.Count > 0)
+ {
+ this.gcMain.GridView.SelectRowHandler(dt.Rows.Count - 1);
+ }
+ }
+ BaseUserControl userControl = this.ControlObj.FindControl(billModel.RtagidKey);
+ if (userControl != null)
+ {
+ userControl.EditText = this.rdRed.Checked ? "1" : "0";
+ }
+ }
+ else
+ {
+ // 单据为新增状态
+ this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true;
+ this.lbTitle.Text = billModel.TypeName + "(新增)";
+ this.lblOrderNo.Text = BillImpl.GetBillNo(billModel.BillSeq);
+ this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true;
+ this.cb_templete.Enabled = true;
+ billModel.SaveState = false;
+ this.ControlObj.SetReadOnlyAllControl(false);
+ this.rdBlue.Enabled = this.rdRed.Enabled = true;
+ // 通过右键菜单打开单据,假如明细有数据则在初始化时使用传入数据.
+ if (billModel.DetailTreeTable)
+ {
+ (this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true;
+ (this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(BillImpl.GetDataTableResult(billModel.DetailSql));
+ }
+ else
+ {
+ this.gcMain.GridView.OptionsBehavior.Editable = true;
+ this.gcMain.GridControl.DataSource = BillImpl.GetDataTableResult(billModel.DetailSql);
+ }
+ BaseUserControl userControl = this.ControlObj.FindControl(billModel.RtagidKey);
+ if (userControl != null)
+ {
+ userControl.EditText = this.rdRed.Checked ? "1" : "0";
+ }
+ }
+ this.lbTitle.Invalidate();
+ }
+ public void OnBillAdd()
+ {
+ this.SetBillStatus(null);
+ this.ControlObj.ResetControlValue(billModel.ManuallyTriggerCorrelation, true);
+ }
+ public void AddOrUpdateBill(DataRow rowItem, DataTable newSource)
+ {
+ string masterSql = rowItem == null ? billModel.MasterSql.Replace("{" + billModel.PrimaryKey + "}", this.lblOrderNo.Text) : ReplaceHelper.ReplaceRowParam(rowItem, billModel.MasterSql);
+ // 加载单据信息
+ DataRow mainRow = BillImpl.GetDataRowResult(masterSql);
+ this.SetBillStatus(mainRow);
+ if (!billModel.SaveState)
+ {
+ this.InitializeHeader(rowItem);
+ }
+ string controlSql = "select '' as billdocument_id,'0' affirmer,'0' rtagid,'{材料代码}' as productid";
+ if (mainRow != null)
+ {
+ //更新
+ DataTable source = this.gcMain.GridControl.DataSourceTable();
+ List deleteRows = new List();
+ foreach (DataRow sourceRow in source.Rows)
+ {
+ string productId = sourceRow["ProductId"] + "";
+ DataRow newSourceRow = newSource.Rows.Cast().Where(n => (n["ProductId"] + "").Equals(productId)).FirstOrDefault();
+
\ No newline at end of file
diff --git a/插件库/Lskj.PubBomImport/FrmMain.cs b/插件库/Lskj.PubBomImport/FrmMain.cs
index 8e4e0be..09ce76a 100644
--- a/插件库/Lskj.PubBomImport/FrmMain.cs
+++ b/插件库/Lskj.PubBomImport/FrmMain.cs
@@ -150,6 +150,56 @@ namespace Lskj.PubBomImport
this.Close();
}
}
+ else if (Model.ShowType.Equals("3"))
+ {
+ 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.StartImportInQDFile(dirPath);
+ };
+ frmProgress.ImportTimer.Enabled = true;
+ frmProgress.ShowDialog();
+ frmProgress.Dispose();
+ }
+ else
+ {
+ this.Close();
+ }
+ }
+ //else if (Model.ShowType.Equals("4"))//禁用
+ //{
+ // 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.StartImportInMxFileNew(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 1bc416c..dd0d560 100644
--- a/插件库/Lskj.PubBomImport/FrmProgress.cs
+++ b/插件库/Lskj.PubBomImport/FrmProgress.cs
@@ -32,6 +32,8 @@ using Lskj.Business;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Lskj.Business.Impl;
+using System.Text.RegularExpressions;
+using Lskj.Util;
namespace Lskj.PubBomImport
{
@@ -118,7 +120,8 @@ namespace Lskj.PubBomImport
string controlSql = "select '' as billdocument_id,'0' affirmer,'0' rtagid,'{材料代码}' as productid";
frmBillInfo.InitializeHeader(Model.MaintabFocusedRow, controlSql);
SetProcessBar(60, 0);
- frmBillInfo.BillSave();
+ string billNo = "";
+ frmBillInfo.BillSave(ref billNo);
SetProcessBar(80, 0);
frmBillInfo.OnBillAdd();
string productId = Model.MaintabFocusedRow["材料代码"] + "";
@@ -134,7 +137,6 @@ namespace Lskj.PubBomImport
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);
@@ -157,15 +159,19 @@ namespace Lskj.PubBomImport
{
int.TryParse(detailRow["amount"] + "", out int lastAmount);
detailRow["tamount"] = tamount;
- detailRow["amount"] = tamount > 0 ? (lastAmount * tamount) + "" : lastAmount + "";
+ detailRow["amount"] = lastAmount;
}
frmBillInfo.GcMainView.GridControl.DataSource = detailTable;
SetProcessBar(20, allCount);
frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql);
SetProcessBar(40, allCount);
- frmBillInfo.BillSave();
+ string childBillNo = "";
+ frmBillInfo.BillSave(ref childBillNo);
SetProcessBar(60, allCount);
frmBillInfo.OnBillAdd();
+ //记录历史版本号
+ string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
+ SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, childBillNo));
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);
@@ -324,7 +330,8 @@ namespace Lskj.PubBomImport
string controlSql = "select '' as billdocument_id,'0' affirmer,'0' rtagid,'{材料代码}' as productid";
frmBillInfo.InitializeHeader(Model.MaintabFocusedRow, controlSql);
SetProcessBar(60, 0);
- frmBillInfo.BillSave();
+ string billNo = "";
+ frmBillInfo.BillSave(ref billNo);
SetProcessBar(80, 0);
frmBillInfo.OnBillAdd();
string productId = Model.MaintabFocusedRow["材料代码"] + "";
@@ -348,53 +355,54 @@ namespace Lskj.PubBomImport
string code = (dataRow["图号"] + "").Trim();
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
{
- string tempFileName = childFileDic[code];
- FileInfo childInfo = new FileInfo(tempFileName);
- if (childInfo != null)
+ DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{code}'");
+ if (productRow == null)
{
- 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)
+ 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"] = lastAmount;
+ }
+ frmBillInfo.GcMainView.GridControl.DataSource = detailTable;
+ SetProcessBar(20, allCount);
+ frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql);
+ SetProcessBar(40, allCount);
+ string childBillNo = "";
+ frmBillInfo.BillSave(ref childBillNo);
+ SetProcessBar(60, allCount);
+ frmBillInfo.OnBillAdd();
+ //记录历史版本号
+ string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
+ SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, childBillNo));
+ 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);
+ SetProcessBar(100, finishCount);
+ SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
+ }
+ else
{
- int.TryParse(detailRow["amount"] + "", out int lastAmount);
- detailRow["tamount"] = tamount;
- detailRow["amount"] = tamount > 0 ? (lastAmount * tamount) + "" : lastAmount + "";
+ throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
}
- 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}");
- }
- else
- {
- throw new Exception($"Bom明细附件{code}获取失败\r\nBom导入失败");
- SetProcessBar(100, finishCount);
- SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
}
}
}
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message);
+ MessageUtil.Show(ex.Message);
}
finally
{
@@ -410,7 +418,400 @@ namespace Lskj.PubBomImport
}
else
{
- MessageUtil.Show("主文件不符合规则");
+ MessageUtil.Show("不是MX文件");
+ this.DialogResult = DialogResult.Cancel;
+ Close();
+ ImportTimer?.Dispose();
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageUtil.Show(ex.Message);
+ this.DialogResult = DialogResult.Cancel;
+ Close();
+ ImportTimer?.Dispose();
+ }
+ }
+ ///
+ /// 开始导入
+ ///
+ ///
+ public void StartImportInQDFile(string dirPath)
+ {
+ try
+ {
+ Model = frmMain.Model;
+ string pattern = @"([A-Za-z]+)(\d*)$";
+ //原物料名称
+ string productCode = Model.MaintabFocusedRow != null && Model.MaintabFocusedRow.Table.Columns.Contains("productid") ? Model.MaintabFocusedRow["productid"] + "" : "";
+ Match match = Regex.Match(productCode, pattern);
+ if (match.Success)
+ {
+ string sourceModel = match.Groups[1].Value;
+ string sourceVersion = match.Groups[2].Value;
+ sourceVersion = string.IsNullOrEmpty(sourceVersion) ? "0" : sourceVersion;
+ //修改后的文件名
+ string newProductCode = Model.MaintabFocusedRow != null && Model.MaintabFocusedRow.Table.Columns.Contains("model_info") ? Model.MaintabFocusedRow["model_info"] + "" : "";
+ FileInfo parentInfo = new FileInfo(dirPath);
+ if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD") || parentInfo.Name.Trim().StartsWith("ZZQD")))
+ {
+ string code = "";
+ string name = "";
+ string namepattern = @"^(.+?)\s+(.+)$";
+ Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
+ if (namematch.Success)
+ {
+ code = namematch.Groups[1].Value;
+ name = namematch.Groups[2].Value;
+ }
+ if (!newProductCode.Equals(code))//选择的文件和版本文件名不匹配
+ {
+ throw new Exception($"修改的文件名{newProductCode}和选择的文件名{code}不匹配");
+ }
+ match = Regex.Match(code, pattern);
+ if (match.Success)
+ {
+ string newModel = match.Groups[1].Value;
+ string newVersion = match.Groups[2].Value;
+ newVersion = string.IsNullOrEmpty(newVersion) ? "0" : newVersion;
+ string selectSql = $"select * from p_fm_filetab where sname like '{code}%'";
+ DataRow fileRow = BaseImpl.GetDataRowResult(selectSql);
+ if (fileRow != null)
+ {
+ //如果存在相同版本的文件
+ throw new Exception("已经存在相同版本的文件");
+ }
+ else
+ {
+ if (sourceModel.Equals(newModel))
+ {
+ //更新并备份清单
+ FrmBillInfo frmBillInfo = new FrmBillInfo();
+ frmBillInfo.OnControlSourceBind += (s, args) =>
+ {
+ Task task = new Task(() =>
+ {
+ try
+ {
+ int.TryParse(Model.FirstRowIndex, out int index);
+ frmMain.FirstRowIndex = index;
+ if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
+ {
+ FileInfo childInfo = new FileInfo(dirPath);
+ if (childInfo != null)
+ {
+ DataTable childTable = new DataTable();
+ foreach (GridColumn gridColumn in frmBillInfo.GcMainView.Columns)
+ {
+ if (!childTable.Columns.Contains(gridColumn.FieldName))
+ {
+ childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType);
+ }
+ }
+ frmBillInfo.GcMainView.GridControl.DataSource = childTable;
+ SetProcessBar(0, 0);
+ 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"] = 1;
+ detailRow["amount"] = lastAmount;
+ }
+ frmBillInfo.GcMainView.GridControl.DataSource = detailTable;
+ SetProcessBar(20, 0);
+ string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{productCode}' as productid";
+ billMasterSql = ReplaceHelper.ReplaceRowParam(Model.MaintabFocusedRow, billMasterSql);
+ // 处理单据表头数据
+ DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
+ SetProcessBar(40, 0);
+ frmBillInfo.AddOrUpdateBill(masterRow, detailTable);
+ SetProcessBar(60, 0);
+ //备份Bom清单明细
+ string bakBomListSql = @"delete bom_BillListlogTab where parentProduct = '{0}';insert into bom_BillListlogTab select * from bom_BillListTab where parentProduct = '{0}';";
+ SqlHelper.ExecuteNonQuery(string.Format(bakBomListSql, productCode));
+ string billNo = "";
+ frmBillInfo.BillSave(ref billNo);
+ SetProcessBar(80, 0);
+ frmBillInfo.OnBillAdd();
+ //记录历史版本号
+ string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
+ SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, billNo));
+ //上传文件
+ bool isUpload = UploadFile(childInfo.FullName, billNo, out string msg);
+ SetProcessBar(100, 100);
+ SetProcessLabelAllMsg($"总进度:1/1");
+ }
+ else
+ {
+ throw new Exception($"Bom明细获取失败\r\nBom导入失败");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageUtil.Show(ex.Message);
+ }
+ finally
+ {
+ this.DialogResult = DialogResult.OK;
+ this.Close();
+ ImportTimer?.Dispose();
+ }
+ });
+ task.Start();
+ };
+ frmBillInfo.OnLoad(Model);
+ frmMain.ParentView = frmBillInfo.GcMainView;
+ }
+ else
+ {
+ //新建清单
+ StringBuilder stringBuilder = new StringBuilder();
+ if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
+ {
+ stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{code}')");
+ stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{code.Replace("'", "''")}','{name.Replace("'", "''")}','','0199') end;");
+ }
+ if (!string.IsNullOrEmpty(stringBuilder.ToString()))
+ {
+ SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
+ }
+ FrmBillInfo frmBillInfo = new FrmBillInfo();
+ frmBillInfo.OnControlSourceBind += (s, args) =>
+ {
+ Task task = new Task(() =>
+ {
+ try
+ {
+ int.TryParse(Model.FirstRowIndex, out int index);
+ frmMain.FirstRowIndex = index;
+ if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
+ {
+ FileInfo childInfo = new FileInfo(dirPath);
+ if (childInfo != null)
+ {
+ DataTable childTable = new DataTable();
+ foreach (GridColumn gridColumn in frmBillInfo.GcMainView.Columns)
+ {
+ if (!childTable.Columns.Contains(gridColumn.FieldName))
+ {
+ childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType);
+ }
+ }
+ frmBillInfo.GcMainView.GridControl.DataSource = childTable;
+ SetProcessBar(0, 0);
+ 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"] = 1;
+ detailRow["amount"] = lastAmount;
+ }
+ frmBillInfo.GcMainView.GridControl.DataSource = detailTable;
+ SetProcessBar(20, 0);
+ string controlSql = $"select '' as billdocument_id,'0' affirmer,'0' rtagid,'{code}' as productid";
+ frmBillInfo.InitializeHeader(null, controlSql);
+ SetProcessBar(40, 0);
+ string billNo = "";
+ frmBillInfo.BillSave(ref billNo);
+ SetProcessBar(60, 0);
+ frmBillInfo.OnBillAdd();
+ SetProcessBar(80, 0);
+ //记录历史版本号
+ string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
+ SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, billNo));
+ //上传文件
+ bool isUpload = UploadFile(childInfo.FullName, billNo, out string msg);
+ SetProcessBar(100, 100);
+ SetProcessLabelAllMsg($"总进度:1/1");
+ }
+ else
+ {
+ throw new Exception($"Bom明细获取失败\r\nBom导入失败");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageUtil.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($"文件名{code}不符合规则");
+ }
+ }
+ else
+ {
+ MessageUtil.Show("不是QD或ZZQD文件");
+ this.DialogResult = DialogResult.Cancel;
+ Close();
+ ImportTimer?.Dispose();
+ }
+ }
+ else
+ {
+ throw new Exception($"文件名{productCode}不符合规则");
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageUtil.Show(ex.Message);
+ this.DialogResult = DialogResult.Cancel;
+ Close();
+ ImportTimer?.Dispose();
+ }
+ }
+ ///
+ /// 开始导入
+ ///
+ ///
+ public void StartImportInMxFileNew(string dirPath)
+ {
+ try
+ {
+ Model = frmMain.Model;
+ FileInfo parentInfo = new FileInfo(dirPath);
+ if (parentInfo != null && parentInfo.Name.Trim().StartsWith("MX"))
+ {
+ 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导入失败");
+ }
+ }
+ }
+ }
+ }
+ FrmBillInfo frmBillInfo = new FrmBillInfo();
+ frmBillInfo.OnControlSourceBind += (s, args) =>
+ {
+ Task task = new Task(() =>
+ {
+ try
+ {
+ SetProcessBar(0, 0);
+ SetProcessMsg($"正在导入:{Path.GetFileName(parentInfo.FullName)}");
+ 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["图号"] + "").Trim();
+ if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
+ {
+ 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导入失败");
+ }
+ }
+ }
+ 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);
+ string billNo = "";
+ frmBillInfo.BillSave(ref billNo);
+ 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, 100);
+ SetProcessLabelAllMsg($"总进度:1/1");
+ }
+ catch (Exception ex)
+ {
+ MessageUtil.Show(ex.Message);
+ }
+ finally
+ {
+ this.DialogResult = DialogResult.OK;
+ this.Close();
+ ImportTimer?.Dispose();
+ }
+ });
+ task.Start();
+ };
+ frmBillInfo.OnLoad(Model);
+ frmMain.ParentView = frmBillInfo.GcMainView;
+ }
+ else
+ {
+ MessageUtil.Show("不是MX文件");
this.DialogResult = DialogResult.Cancel;
Close();
ImportTimer?.Dispose();