SVN r510
SVN-Revision: r510
This commit is contained in:
@@ -194,6 +194,75 @@ namespace Lskj.PubBomImport
|
|||||||
}
|
}
|
||||||
return saveResult;
|
return saveResult;
|
||||||
}
|
}
|
||||||
|
public bool BillSaveSql(ref string guid, int comfirm = 0, bool canTipMsg = true)
|
||||||
|
{
|
||||||
|
guid = Guid.NewGuid() + "";
|
||||||
|
bool saveResult = false;
|
||||||
|
if (ControlObj.VerifyNull())
|
||||||
|
{
|
||||||
|
// 保存之前先进行表格更新
|
||||||
|
if (billModel.DetailTreeTable)
|
||||||
|
{
|
||||||
|
(this.gcMain as TreeGridControlEx).TreeListObj.PostEditor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.gcMain.GridView.PostEditor();
|
||||||
|
this.gcMain.GridView.UpdateCurrentRow();
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (this.gcMain.VerifyNull())
|
||||||
|
{
|
||||||
|
if (this.gcMain.RepeatedVerificationNames.Count > 0 && this.gcMain.VerifyDuplicateColumns())
|
||||||
|
{
|
||||||
|
//MessageUtil.Show("表格中数据内容重复,保存失败!");
|
||||||
|
return saveResult;
|
||||||
|
}
|
||||||
|
string billNo = this.lblOrderNo.Text.Trim();
|
||||||
|
string detailGuid = Guid.NewGuid().ToString();
|
||||||
|
string masterSql = billModel.SaveState ? GetUpdateRecord(billNo) : GetAddRecord(ref billNo);
|
||||||
|
string detailSql = GetDetailRecord(detailGuid, billNo).ToString();
|
||||||
|
// 检查单据头数据合法性
|
||||||
|
if (string.IsNullOrEmpty(masterSql)) return false;
|
||||||
|
// 验证明细合法性
|
||||||
|
if (string.IsNullOrEmpty(detailSql) && !billModel.SaveNullDetail)
|
||||||
|
{
|
||||||
|
MessageUtil.Show(ResourceKeys.BillDetailIsNotNull);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
string tipMsg = string.Empty;
|
||||||
|
|
||||||
|
//param[0].Value = masterSql;
|
||||||
|
//param[1].Value = billNo;
|
||||||
|
//param[2].Value = detailGuid;
|
||||||
|
//param[3].Value = ERPInfo.Instance.UserId;
|
||||||
|
//param[4].Value = billWay;// --1新增,2为修改,3为删除
|
||||||
|
//param[5].Value = billSeq;
|
||||||
|
//param[6].Value = "";
|
||||||
|
//param[7].Value = auditFlag;
|
||||||
|
//param[8].Value = comfirm;
|
||||||
|
|
||||||
|
BaseImpl.ExecSqlValue($"insert into p_bomImportExecTab (guid,detailTable,masterSql,detailSql,billNo,detailGuid,UserId,billWay,billSeq,auditFlag,comfirm,newVer) " +
|
||||||
|
$"values ('{guid}','{billModel.DetailTable}','{masterSql.Replace("'", "''")}','{detailSql.Replace("'", "''")}','{billNo}','{detailGuid.Replace("'", "''")}','{ERPInfo.Instance.UserId}','{(billModel.SaveState ? 2 : 1)}','{billModel.BillSeq}','0','{comfirm}','{billModel.NewVer}')");
|
||||||
|
//int result = BillImpl.BillSave(masterSql, detailSql, billModel.DetailTable, ref billNo, detailGuid, billModel.BillSeq, billModel.SaveState ? 2 : 1, comfirm, out tipMsg, 0, billModel.NewVer);
|
||||||
|
//if (result == 1)
|
||||||
|
//{
|
||||||
|
// saveResult = true;
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// throw new Exception($"保存Bom失败\r\n{tipMsg}");
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"保存Bom失败\r\n{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return saveResult;
|
||||||
|
}
|
||||||
private string GetUpdateRecord(string parmaryValue)
|
private string GetUpdateRecord(string parmaryValue)
|
||||||
{
|
{
|
||||||
StringBuilder updateBuilder = new StringBuilder();
|
StringBuilder updateBuilder = new StringBuilder();
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ namespace Lskj.PubBomImport
|
|||||||
InitGridColumns();
|
InitGridColumns();
|
||||||
InitMulitControl();
|
InitMulitControl();
|
||||||
InitDataSource();
|
InitDataSource();
|
||||||
if (showTypeValue == 0 || showTypeValue == 3 || (showTypeValue > 0 && showType))
|
if (showTypeValue == 0 || showTypeValue == 3 || showTypeValue == 5 || showTypeValue == 55 || (showTypeValue > 0 && showType))
|
||||||
{
|
{
|
||||||
OnBtnImportClick(null, null);
|
OnBtnImportClick(null, null);
|
||||||
}
|
}
|
||||||
@@ -131,6 +131,35 @@ namespace Lskj.PubBomImport
|
|||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (Model.ShowType.Equals("00"))//选择文件夹并返回文件列表到表中
|
||||||
|
{
|
||||||
|
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||||
|
dialog.SelectedPath = Properties.Settings.Default.LastSelectFolder;
|
||||||
|
dialog.Description = "选择导入文件夹";
|
||||||
|
DialogResult dialogResult = dialog.ShowDialog();
|
||||||
|
if (dialogResult == DialogResult.OK)
|
||||||
|
{
|
||||||
|
Properties.Settings.Default.LastSelectFolder = dialog.SelectedPath;
|
||||||
|
string[] fileNames = Directory.GetFiles(dialog.SelectedPath);
|
||||||
|
BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
|
||||||
|
{
|
||||||
|
ShowType = Model.ShowType,
|
||||||
|
AfterBomFieldName = Model.AfterBomFieldName,
|
||||||
|
FileNames = 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"))
|
else if (Model.ShowType.Equals("1"))
|
||||||
{
|
{
|
||||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||||
@@ -217,10 +246,7 @@ namespace Lskj.PubBomImport
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
parentInfo = new FileInfo(dirPath);
|
parentInfo = new FileInfo(dirPath);
|
||||||
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD") || parentInfo.Name.Trim().StartsWith("ZZQD")))
|
selectRows.Add(sourceRow);
|
||||||
{
|
|
||||||
selectRows.Add(sourceRow);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (selectRows.Count > 0)
|
if (selectRows.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -272,6 +298,82 @@ namespace Lskj.PubBomImport
|
|||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (Model.ShowType.Equals("5"))//通过文件名进行文件上传和逻辑记录
|
||||||
|
{
|
||||||
|
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<DataRow> selectRows = new List<DataRow>();
|
||||||
|
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.StartImportInFiles(selectRows);
|
||||||
|
};
|
||||||
|
frmProgress.ImportTimer.Enabled = true;
|
||||||
|
DialogResult dialogResult = frmProgress.ShowDialog();
|
||||||
|
bomImpRtnModel.CanSave = dialogResult == DialogResult.OK;
|
||||||
|
frmProgress.Dispose();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Model.ShowType.Equals("55"))//通过已经上传的数据来解析并且建立BOM
|
||||||
|
{
|
||||||
|
|
||||||
|
FrmProgress frmProgress = new FrmProgress();
|
||||||
|
frmProgress.frmMain = this;
|
||||||
|
frmProgress.Model = Model;
|
||||||
|
frmProgress.ImportTimer.Tick += (ts, te) =>
|
||||||
|
{
|
||||||
|
frmProgress.ImportTimer.Enabled = false;
|
||||||
|
string productId = Model.MaintabFocusedRow != null && Model.MaintabFocusedRow.Table.Columns.Contains("ProductId") ? Model.MaintabFocusedRow["ProductId"] + "" : "";
|
||||||
|
frmProgress.StartCreateBom(productId);
|
||||||
|
};
|
||||||
|
frmProgress.ImportTimer.Enabled = true;
|
||||||
|
frmProgress.ShowDialog();
|
||||||
|
frmProgress.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ namespace Lskj.PubBomImport
|
|||||||
string updateParentVerSql = @"update bom_BillListTab set Ver = '{0}' where Billdocument_Id='{1}' and ProductId='{0}'";
|
string updateParentVerSql = @"update bom_BillListTab set Ver = '{0}' where Billdocument_Id='{1}' and ProductId='{0}'";
|
||||||
SqlHelper.ExecuteNonQuery(string.Format(updateParentVerSql, idValue, billdocumentId));
|
SqlHelper.ExecuteNonQuery(string.Format(updateParentVerSql, idValue, billdocumentId));
|
||||||
//上传文件
|
//上传文件
|
||||||
bool isUpload = UploadFile(parentInfo.FullName, idValue, out string msg);
|
bool isUpload = UploadFile(parentInfo.FullName, idValue, out string msg, out string _);
|
||||||
SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
|
SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
|
||||||
SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
|
SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
|
||||||
int.TryParse(Model.FirstRowIndex, out int index);
|
int.TryParse(Model.FirstRowIndex, out int index);
|
||||||
@@ -242,7 +242,7 @@ namespace Lskj.PubBomImport
|
|||||||
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}'";
|
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));
|
SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
|
||||||
SetProcessBar(80, allCount);
|
SetProcessBar(80, allCount);
|
||||||
isUpload = UploadFile(childInfo.FullName, idValue, out msg);
|
isUpload = UploadFile(childInfo.FullName, idValue, out msg, out string _);
|
||||||
SetProcessBar(100, finishCount);
|
SetProcessBar(100, finishCount);
|
||||||
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ namespace Lskj.PubBomImport
|
|||||||
FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
|
FileInfo childInfo = fileInfos.Where(n => n.Name.StartsWith(code)).FirstOrDefault();
|
||||||
if (childInfo != null)
|
if (childInfo != null)
|
||||||
{
|
{
|
||||||
isUpload = UploadFile(childInfo.FullName, idValue, out msg);
|
isUpload = UploadFile(childInfo.FullName, idValue, out msg, out string _);
|
||||||
SetProcessBar(100, finishCount);
|
SetProcessBar(100, finishCount);
|
||||||
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
||||||
}
|
}
|
||||||
@@ -413,7 +413,7 @@ namespace Lskj.PubBomImport
|
|||||||
string updateParentVerSql = @"update bom_BillListTab set Ver = '{0}' where Billdocument_Id='{1}' and ProductId='{0}'";
|
string updateParentVerSql = @"update bom_BillListTab set Ver = '{0}' where Billdocument_Id='{1}' and ProductId='{0}'";
|
||||||
SqlHelper.ExecuteNonQuery(string.Format(updateParentVerSql, idValue, billdocumentId));
|
SqlHelper.ExecuteNonQuery(string.Format(updateParentVerSql, idValue, billdocumentId));
|
||||||
//上传文件
|
//上传文件
|
||||||
bool isUpload = UploadFile(parentInfo.FullName, idValue, out string msg);
|
bool isUpload = UploadFile(parentInfo.FullName, idValue, out string msg, out string _);
|
||||||
SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
|
SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
|
||||||
SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
|
SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
|
||||||
int.TryParse(Model.FirstRowIndex, out int index);
|
int.TryParse(Model.FirstRowIndex, out int index);
|
||||||
@@ -584,109 +584,104 @@ namespace Lskj.PubBomImport
|
|||||||
//原物料名称
|
//原物料名称
|
||||||
string productCode = sourceRow != null && sourceRow.Table.Columns.Contains(Model.BeforeBomFieldName) ? sourceRow[Model.BeforeBomFieldName] + "" : "";
|
string productCode = sourceRow != null && sourceRow.Table.Columns.Contains(Model.BeforeBomFieldName) ? sourceRow[Model.BeforeBomFieldName] + "" : "";
|
||||||
Match match = Regex.Match(productCode, pattern);
|
Match match = Regex.Match(productCode, pattern);
|
||||||
if (match.Success)
|
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD") || parentInfo.Name.Trim().StartsWith("ZZQD")))
|
||||||
{
|
{
|
||||||
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD") || parentInfo.Name.Trim().StartsWith("ZZQD")))
|
string code = "";
|
||||||
|
string name = "";
|
||||||
|
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
|
||||||
|
if (namematch.Success)
|
||||||
{
|
{
|
||||||
string code = "";
|
code = namematch.Groups[1].Value;
|
||||||
string name = "";
|
name = namematch.Groups[2].Value;
|
||||||
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
|
}
|
||||||
if (namematch.Success)
|
match = Regex.Match(code, pattern);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
//更新或新增并备份清单
|
||||||
|
int.TryParse(Model.FirstRowIndex, out int index);
|
||||||
|
frmMain.FirstRowIndex = index;
|
||||||
|
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||||
{
|
{
|
||||||
code = namematch.Groups[1].Value;
|
DataTable historyTable = BaseImpl.GetDataTableResult($"select * from bom_BillListlogTab where ParentProduct = '{productCode}' and historyVer = '{code}'");
|
||||||
name = namematch.Groups[2].Value;
|
if (historyTable != null && historyTable.Rows.Count > 0)
|
||||||
}
|
|
||||||
match = Regex.Match(code, pattern);
|
|
||||||
if (match.Success)
|
|
||||||
{
|
|
||||||
//更新或新增并备份清单
|
|
||||||
int.TryParse(Model.FirstRowIndex, out int index);
|
|
||||||
frmMain.FirstRowIndex = index;
|
|
||||||
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
|
||||||
{
|
{
|
||||||
DataTable historyTable = BaseImpl.GetDataTableResult($"select * from bom_BillListlogTab where ParentProduct = '{productCode}' and historyVer = '{code}'");
|
//已经存在该版本则不进行任何操作
|
||||||
if (historyTable != null && historyTable.Rows.Count > 0)
|
continue;
|
||||||
|
}
|
||||||
|
FileInfo childInfo = new FileInfo(dirPath);
|
||||||
|
if (childInfo != null)
|
||||||
|
{
|
||||||
|
frmBillInfo.OnBillAdd();
|
||||||
|
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);
|
||||||
continue;
|
}));
|
||||||
|
foreach (DataRow detailRow in detailTable.Rows)
|
||||||
|
{
|
||||||
|
int.TryParse(detailRow["amount"] + "", out int lastAmount);
|
||||||
|
detailRow["tamount"] = 1;
|
||||||
|
detailRow["amount"] = lastAmount;
|
||||||
}
|
}
|
||||||
FileInfo childInfo = new FileInfo(dirPath);
|
SetProcessBar(20, allCount);
|
||||||
if (childInfo != null)
|
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(sourceRow, billMasterSql);
|
||||||
|
// 处理单据表头数据
|
||||||
|
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
|
||||||
|
SetProcessBar(40, allCount);
|
||||||
|
frmBillInfo.AddOrUpdateBill(masterRow, detailTable);
|
||||||
|
SetProcessBar(60, allCount);
|
||||||
|
string billNo = "";
|
||||||
|
frmBillInfo.BillSave(ref billNo);
|
||||||
|
SetProcessBar(80, allCount);
|
||||||
|
frmBillInfo.OnBillAdd();
|
||||||
|
//记录历史版本号
|
||||||
|
string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
|
||||||
|
SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, billNo));
|
||||||
|
//备份Bom清单明细
|
||||||
|
string bakBomListSql = @"delete bom_BillListlogTab where parentProduct = '{0}' and historyVer = (select top 1 historyVer from bom_BillListTab where parentProduct = '{0}');insert into bom_BillListlogTab select * from bom_BillListTab where parentProduct = '{0}';";
|
||||||
|
SqlHelper.ExecuteNonQuery(string.Format(bakBomListSql, productCode));
|
||||||
|
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
frmBillInfo.OnBillAdd();
|
if (sourceRow.Table.Columns.Contains("qms_laddf_RelatedId"))
|
||||||
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);
|
sourceRow["qms_laddf_RelatedId"] = billNo;
|
||||||
detailRow["tamount"] = 1;
|
|
||||||
detailRow["amount"] = lastAmount;
|
|
||||||
}
|
}
|
||||||
SetProcessBar(20, allCount);
|
}));
|
||||||
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{productCode}' as productid";
|
//执行配置的保存后sql
|
||||||
billMasterSql = ReplaceHelper.ReplaceRowParam(sourceRow, billMasterSql);
|
if (!string.IsNullOrEmpty(Model.AfterAddBomSql))
|
||||||
// 处理单据表头数据
|
{
|
||||||
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
|
string afterAddBomSql = ReplaceHelper.ReplaceRowParam(sourceRow, Model.AfterAddBomSql);
|
||||||
SetProcessBar(40, allCount);
|
SqlHelper.ExecuteNonQuery(afterAddBomSql);
|
||||||
frmBillInfo.AddOrUpdateBill(masterRow, detailTable);
|
|
||||||
SetProcessBar(60, allCount);
|
|
||||||
string billNo = "";
|
|
||||||
frmBillInfo.BillSave(ref billNo);
|
|
||||||
SetProcessBar(80, allCount);
|
|
||||||
frmBillInfo.OnBillAdd();
|
|
||||||
//记录历史版本号
|
|
||||||
string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
|
|
||||||
SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, billNo));
|
|
||||||
//备份Bom清单明细
|
|
||||||
string bakBomListSql = @"delete bom_BillListlogTab where parentProduct = '{0}' and historyVer = (select top 1 historyVer from bom_BillListTab where parentProduct = '{0}');insert into bom_BillListlogTab select * from bom_BillListTab where parentProduct = '{0}';";
|
|
||||||
SqlHelper.ExecuteNonQuery(string.Format(bakBomListSql, productCode));
|
|
||||||
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
if (sourceRow.Table.Columns.Contains("qms_laddf_RelatedId"))
|
|
||||||
{
|
|
||||||
sourceRow["qms_laddf_RelatedId"] = billNo;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
//执行配置的保存后sql
|
|
||||||
if (!string.IsNullOrEmpty(Model.AfterAddBomSql))
|
|
||||||
{
|
|
||||||
string afterAddBomSql = ReplaceHelper.ReplaceRowParam(sourceRow, Model.AfterAddBomSql);
|
|
||||||
SqlHelper.ExecuteNonQuery(afterAddBomSql);
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(Model.AfterAddBomSql))
|
|
||||||
{
|
|
||||||
//string afterAddBomSql = ReplaceHelper.ReplaceRowParam(sourceRow, Model.AfterAddBomSql);
|
|
||||||
//SqlHelper.ExecuteNonQuery(afterAddBomSql);
|
|
||||||
}
|
|
||||||
//上传文件
|
|
||||||
bool isUpload = UploadFile(childInfo.FullName, billNo, out string msg);
|
|
||||||
SetProcessBar(100, finishCount);
|
|
||||||
SetProcessLabelAllMsg($"总进度:{childIndex + 1}/{selectRows.Count }");
|
|
||||||
}
|
}
|
||||||
else
|
if (!string.IsNullOrEmpty(Model.AfterAddBomSql))
|
||||||
{
|
{
|
||||||
throw new Exception($"Bom明细获取失败\r\nBom导入失败");
|
//string afterAddBomSql = ReplaceHelper.ReplaceRowParam(sourceRow, Model.AfterAddBomSql);
|
||||||
|
//SqlHelper.ExecuteNonQuery(afterAddBomSql);
|
||||||
}
|
}
|
||||||
|
//上传文件
|
||||||
|
bool isUpload = UploadFile(childInfo.FullName, code, out string msg, out string _);
|
||||||
|
SetProcessBar(100, finishCount);
|
||||||
|
SetProcessLabelAllMsg($"总进度:{childIndex + 1}/{selectRows.Count }");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"Bom明细获取失败\r\nBom导入失败");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception($"文件名{code}不符合规则");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception($"{parentInfo.Name}不是QD或ZZQD文件");
|
bool isUpload = UploadFile(parentInfo.FullName, "", out string msg, out string _);
|
||||||
|
SetProcessBar(100, finishCount);
|
||||||
|
SetProcessLabelAllMsg($"总进度:{childIndex + 1}/{selectRows.Count }");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception($"文件名{productCode}不符合规则");
|
throw new Exception($"{parentInfo.Name}不是QD或ZZQD文件");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.DialogResult = DialogResult.OK;
|
this.DialogResult = DialogResult.OK;
|
||||||
@@ -829,7 +824,7 @@ namespace Lskj.PubBomImport
|
|||||||
string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
|
string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
|
||||||
SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, billNo));
|
SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, billNo));
|
||||||
//上传文件
|
//上传文件
|
||||||
bool isUpload = UploadFile(childInfo.FullName, billNo, out string msg);
|
bool isUpload = UploadFile(childInfo.FullName, billNo, out string msg, out string _);
|
||||||
SetProcessBar(100, 100);
|
SetProcessBar(100, 100);
|
||||||
SetProcessLabelAllMsg($"总进度:1/1");
|
SetProcessLabelAllMsg($"总进度:1/1");
|
||||||
}
|
}
|
||||||
@@ -882,6 +877,449 @@ namespace Lskj.PubBomImport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 开始导入5
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dirPaths"></param>
|
||||||
|
public void StartImportInFiles(List<DataRow> selectRows)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int execOrder = 1;
|
||||||
|
DataRow mxRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith("MX")).FirstOrDefault();
|
||||||
|
if (mxRow != null)
|
||||||
|
{
|
||||||
|
string mxFileName = mxRow[Model.AfterBomFieldName] + "";
|
||||||
|
string mxDirPath = mxRow["BomFieldNameDir"] + "";
|
||||||
|
string productId = mxRow["BomMxMainProduct"] + "";
|
||||||
|
if (string.IsNullOrEmpty(productId))
|
||||||
|
{
|
||||||
|
throw new Exception($"未选择物料编码");
|
||||||
|
}
|
||||||
|
FileInfo mxInfo = new FileInfo(mxDirPath);
|
||||||
|
if (mxInfo != null)
|
||||||
|
{
|
||||||
|
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
||||||
|
DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, "", 5);
|
||||||
|
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "") && !string.IsNullOrEmpty(n["名称"] + "")).ToList().CopyToDataTable();
|
||||||
|
foreach (DataRow parentRow in parentTable.Rows)
|
||||||
|
{
|
||||||
|
string fileName = (parentRow["图号"] + "").Trim();
|
||||||
|
if (fileName.StartsWith("QD") || fileName.StartsWith("ZZQD"))
|
||||||
|
{
|
||||||
|
DataRow childRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(fileName)).FirstOrDefault();
|
||||||
|
if (childRow != null)
|
||||||
|
{
|
||||||
|
string childFileName = childRow[Model.AfterBomFieldName] + "";
|
||||||
|
string childDirPath = childRow["BomFieldNameDir"] + "";
|
||||||
|
FileInfo childInfo = new FileInfo(childDirPath);
|
||||||
|
if (childInfo == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"MX明细中不包含文件{childFileName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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,SpeciesNo) values ('{(dataRow["图号"] + "").Replace("'", "''")}','{(dataRow["名称"] + "").Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}','0199') end;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||||
|
{
|
||||||
|
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||||
|
}
|
||||||
|
frmBillInfo.OnControlSourceBind += (s, args) =>
|
||||||
|
{
|
||||||
|
Task task = new Task(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool isUpload = false;
|
||||||
|
string msg = "";
|
||||||
|
DataRow parentProductRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'");
|
||||||
|
if (parentProductRow == null)
|
||||||
|
{
|
||||||
|
frmBillInfo.OnBillAdd();
|
||||||
|
SetProcessBar(0, 0);
|
||||||
|
SetProcessMsg($"正在导入:{Path.GetFileName(mxInfo.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["图号"] + "";
|
||||||
|
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||||
|
{
|
||||||
|
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
|
||||||
|
if (childInfoRow != null)
|
||||||
|
{
|
||||||
|
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
|
||||||
|
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
|
||||||
|
FileInfo childInfo = new FileInfo(childDirPath);
|
||||||
|
if (childInfo == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"MX明细中不包含文件{childFileName}");
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SetProcessBar(20, 0);
|
||||||
|
if (childTable.Rows.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception($"MX明细数据为空");
|
||||||
|
}
|
||||||
|
SetProcessBar(40, 0);
|
||||||
|
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productId}') as billdocument_id,'0' affirmer,'0' rtagid,'{productId}' as productid";
|
||||||
|
billMasterSql = ReplaceHelper.ReplaceRowParam(Model.MaintabFocusedRow, billMasterSql);
|
||||||
|
// 处理单据表头数据
|
||||||
|
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
|
||||||
|
SetProcessBar(60, 0);
|
||||||
|
frmBillInfo.AddOrUpdateBill(masterRow, childTable);
|
||||||
|
string guid = "";
|
||||||
|
frmBillInfo.BillSaveSql(ref guid);
|
||||||
|
SetProcessBar(80, 0);
|
||||||
|
//确认不反写子集
|
||||||
|
//string billdocumentId = Model.MaintabFocusedRow["单据编号"] + "";
|
||||||
|
//string billdocumentId = BaseImpl.GetResult("") + "";//
|
||||||
|
//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));
|
||||||
|
//上传文件
|
||||||
|
isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010107", out msg, out string fileId);
|
||||||
|
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
|
||||||
|
{
|
||||||
|
mxRow["qms_laddf_FileId"] = fileId;
|
||||||
|
}
|
||||||
|
if (mxRow.Table.Columns.Contains("qms_laddf_Exec"))
|
||||||
|
{
|
||||||
|
mxRow["qms_laddf_Exec"] = guid;
|
||||||
|
}
|
||||||
|
if (mxRow.Table.Columns.Contains("qms_laddf_ExecOrder"))
|
||||||
|
{
|
||||||
|
mxRow["qms_laddf_ExecOrder"] = execOrder;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
execOrder += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010107", out msg, out string fileId);
|
||||||
|
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
|
||||||
|
{
|
||||||
|
mxRow["qms_laddf_FileId"] = fileId;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||||
|
{
|
||||||
|
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
|
||||||
|
if (childInfoRow != null)
|
||||||
|
{
|
||||||
|
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
|
||||||
|
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
|
||||||
|
FileInfo childInfo = new FileInfo(childDirPath);
|
||||||
|
if (childInfo == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"MX明细中不包含文件{childFileName}");
|
||||||
|
}
|
||||||
|
if (childInfo != null)
|
||||||
|
{
|
||||||
|
DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{code}'");
|
||||||
|
if (productRow == null)
|
||||||
|
{
|
||||||
|
if ((code.StartsWith("QD") || code.StartsWith("ZZQD")))
|
||||||
|
{
|
||||||
|
frmBillInfo.OnBillAdd();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
if (detailTable.Rows.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception($"{code}明细数据为空");
|
||||||
|
}
|
||||||
|
SetProcessBar(40, 0);
|
||||||
|
string childBillMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{code}') as billdocument_id,'0' affirmer,'0' rtagid,'{code}' as productid";
|
||||||
|
// 处理单据表头数据
|
||||||
|
DataRow childMasterRow = BillImpl.GetDataRowResult(childBillMasterSql);
|
||||||
|
SetProcessBar(60, 0);
|
||||||
|
frmBillInfo.AddOrUpdateBill(childMasterRow, detailTable);
|
||||||
|
string childGuid = "";
|
||||||
|
frmBillInfo.BillSaveSql(ref childGuid);
|
||||||
|
SetProcessBar(80, 0);
|
||||||
|
//记录历史版本号
|
||||||
|
//string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
|
||||||
|
//SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, childBillNo));
|
||||||
|
//备份Bom清单明细
|
||||||
|
//string bakBomListSql = @"delete bom_BillListlogTab where parentProduct = '{0}' and historyVer = (select top 1 historyVer from bom_BillListTab where parentProduct = '{0}');insert into bom_BillListlogTab select * from bom_BillListTab where parentProduct = '{0}';";
|
||||||
|
//SqlHelper.ExecuteNonQuery(string.Format(bakBomListSql, code));
|
||||||
|
//确认不关联
|
||||||
|
//更新明细关联版本号
|
||||||
|
//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 = UploadFileToAudit(childInfo.FullName, code, "010107", out msg, out string childFieldId);
|
||||||
|
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
|
||||||
|
{
|
||||||
|
childInfoRow["qms_laddf_FileId"] = childFieldId;
|
||||||
|
}
|
||||||
|
if (childInfoRow.Table.Columns.Contains("qms_laddf_Exec"))
|
||||||
|
{
|
||||||
|
childInfoRow["qms_laddf_Exec"] = childGuid;
|
||||||
|
}
|
||||||
|
if (childInfoRow.Table.Columns.Contains("qms_laddf_ExecOrder"))
|
||||||
|
{
|
||||||
|
childInfoRow["qms_laddf_ExecOrder"] = execOrder;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
execOrder += 1;
|
||||||
|
SetProcessBar(100, finishCount);
|
||||||
|
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isUpload = UploadFileToAudit(childInfo.FullName, code, "010107", out msg, out string existFieldId);
|
||||||
|
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
|
||||||
|
{
|
||||||
|
childInfoRow["qms_laddf_FileId"] = existFieldId;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"目录中不包含文件{code}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DataRow childInfoRow = selectRows.Where(n => (n[Model.AfterBomFieldName] + "").StartsWith(code)).FirstOrDefault();
|
||||||
|
if (childInfoRow != null)
|
||||||
|
{
|
||||||
|
string childFileName = childInfoRow[Model.AfterBomFieldName] + "";
|
||||||
|
string childDirPath = childInfoRow["BomFieldNameDir"] + "";
|
||||||
|
FileInfo childInfo = new FileInfo(childDirPath);
|
||||||
|
if (childInfo == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"目录中不包含文件{code}");
|
||||||
|
}
|
||||||
|
if (childInfo != null)
|
||||||
|
{
|
||||||
|
isUpload = UploadFileToAudit(childInfo.FullName, productId, "010107", out msg, out string otherFieldId);
|
||||||
|
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
if (childInfoRow.Table.Columns.Contains("qms_laddf_FileId"))
|
||||||
|
{
|
||||||
|
childInfoRow["qms_laddf_FileId"] = otherFieldId;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
SetProcessBar(100, finishCount);
|
||||||
|
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"目录中不包含文件{code}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("未包含MX文件");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageUtil.Show(ex.Message);
|
||||||
|
this.DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
ImportTimer?.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据已上传的数据进行Bom生成
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="selectRows"></param>
|
||||||
|
public void StartCreateBom(string parentProductId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(parentProductId))
|
||||||
|
{
|
||||||
|
throw new Exception($"物料编码不能为空");
|
||||||
|
}
|
||||||
|
string billdocumentId = BaseImpl.GetResult($"select qms_maddf_billdocument_id from qms_BillFileAddMaintab where qms_maddf_productid = '{parentProductId}'") + "";
|
||||||
|
if (string.IsNullOrEmpty(billdocumentId))
|
||||||
|
{
|
||||||
|
throw new Exception($"未查询到物料编码{parentProductId}的Bom单据号");
|
||||||
|
}
|
||||||
|
if (Directory.Exists("BomImportTemp"))
|
||||||
|
{
|
||||||
|
Directory.Delete("BomImportTemp", true);
|
||||||
|
}
|
||||||
|
Directory.CreateDirectory("BomImportTemp");
|
||||||
|
DataTable sourceTable = BaseImpl.GetDataTableResult($"select qms_laddf_productid,qms_laddf_FileId,qms_laddf_Exec from qms_BillFileAddlisttab where qms_laddf_billdocument_id = '{billdocumentId}' order by qms_laddf_ExecOrder");
|
||||||
|
Task task = new Task(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (DataRow sourceRow in sourceTable.Rows)
|
||||||
|
{
|
||||||
|
string productid = sourceRow["qms_laddf_productid"] + "";
|
||||||
|
string fileId = sourceRow["qms_laddf_FileId"] + "";
|
||||||
|
string execGuid = sourceRow["qms_laddf_Exec"] + "";
|
||||||
|
int childIndex = sourceTable.Rows.IndexOf(sourceRow);
|
||||||
|
int allCount = (int)((decimal)(childIndex) / (sourceTable.Rows.Count) * 100);
|
||||||
|
int finishCount = (int)((decimal)(1 + childIndex) / (sourceTable.Rows.Count) * 100);
|
||||||
|
Model = frmMain.Model;
|
||||||
|
DataRow execRow = BaseImpl.GetDataRowResult($"select * from p_bomImportExecTab where isnull(success,0) = 0 and guid = '{execGuid}'");
|
||||||
|
if (execRow != null)
|
||||||
|
{
|
||||||
|
string masterSql = execRow["masterSql"] + "";
|
||||||
|
string detailSql = execRow["detailSql"] + "";
|
||||||
|
string detailTable = execRow["detailTable"] + "";
|
||||||
|
string detailGuid = execRow["detailGuid"] + "";
|
||||||
|
string billSeq = execRow["billSeq"] + "";
|
||||||
|
int.TryParse(execRow["billWay"] + "", out int billWay);
|
||||||
|
int.TryParse(execRow["comfirm"] + "", out int comfirm);
|
||||||
|
int.TryParse(execRow["auditFlag"] + "", out int auditFlag);
|
||||||
|
int.TryParse(execRow["newVer"] + "", out int newVer);
|
||||||
|
string billNo = billWay == 1 ? BillImpl.GetBillNo(billSeq) : execRow["billNo"] + "";
|
||||||
|
int result = BillImpl.BillSave(masterSql, detailSql, detailTable, ref billNo, detailGuid, billSeq, billWay, comfirm, out string tipMsg, auditFlag, newVer);
|
||||||
|
if (result == 1)
|
||||||
|
{
|
||||||
|
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set success = 1 where guid = '{execGuid}'");
|
||||||
|
using (WebClient webClient = new WebClient())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DataRow fileRow = BaseImpl.GetDataRowResult($"select webpath,sname from p_fm_filetab where fileId = '{fileId}'");
|
||||||
|
if (fileRow != null)
|
||||||
|
{
|
||||||
|
string webpath = fileRow["webpath"] + "";
|
||||||
|
string sName = fileRow["sname"] + "";
|
||||||
|
webpath = webpath.StartsWith("/") ? webpath : $"/{webpath}";
|
||||||
|
string url = $"{SystemInfo.Instance.OAUrl}/{webpath}";
|
||||||
|
string tempFileName = $"BomImportTemp/{sName}";
|
||||||
|
webClient.DownloadFile(url, tempFileName);
|
||||||
|
bool isUpload = UploadFileToAudit(tempFileName, productid, "010106", out string msg, out string otherFieldId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"Bom明细附件{productid}获取失败\r\nBom导入失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw new Exception($"Bom明细附件{productid}获取失败\r\nBom导入失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"保存Bom失败\r\n{tipMsg}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageUtil.Show(ex.Message);
|
||||||
|
this.DialogResult = DialogResult.Cancel;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
this.Close();
|
||||||
|
ImportTimer?.Dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
task.Start();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageUtil.Show(ex.Message);
|
||||||
|
this.DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
ImportTimer?.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
/// 显示当前文件
|
/// 显示当前文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
@@ -1133,11 +1571,12 @@ namespace Lskj.PubBomImport
|
|||||||
/// <param name="filePath"></param>
|
/// <param name="filePath"></param>
|
||||||
/// <param name="msg"></param>
|
/// <param name="msg"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private bool UploadFile(string filePath, string idValue, out string msg)
|
private bool UploadFile(string filePath, string idValue, out string msg, out string outFileId)
|
||||||
{
|
{
|
||||||
bool isUpload = false;
|
bool isUpload = false;
|
||||||
string File = filePath;
|
string File = filePath;
|
||||||
string returnMsg = "";
|
string returnMsg = "";
|
||||||
|
string fileId = "";
|
||||||
string postUrl = "";
|
string postUrl = "";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1150,7 +1589,7 @@ namespace Lskj.PubBomImport
|
|||||||
string fileStream = Convert.ToBase64String(fileBytes);
|
string fileStream = Convert.ToBase64String(fileBytes);
|
||||||
string userId = ERPInfo.Instance.UserId;
|
string userId = ERPInfo.Instance.UserId;
|
||||||
DateTime uploadTime = DateTime.Now;
|
DateTime uploadTime = DateTime.Now;
|
||||||
string speciesno = " 010102";
|
string speciesno = "010102";
|
||||||
// 检查扩展名是否为 .xlsx 或 .xls
|
// 检查扩展名是否为 .xlsx 或 .xls
|
||||||
if (suffix.Equals(".xlsx", StringComparison.OrdinalIgnoreCase) ||
|
if (suffix.Equals(".xlsx", StringComparison.OrdinalIgnoreCase) ||
|
||||||
suffix.Equals(".xls", StringComparison.OrdinalIgnoreCase))
|
suffix.Equals(".xls", StringComparison.OrdinalIgnoreCase))
|
||||||
@@ -1198,6 +1637,10 @@ namespace Lskj.PubBomImport
|
|||||||
string isSuccess = jsonObject["success"] + "";
|
string isSuccess = jsonObject["success"] + "";
|
||||||
if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
|
if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
|
if (jsonObject.ContainsKey("other"))
|
||||||
|
{
|
||||||
|
fileId = jsonObject["other"] + "";
|
||||||
|
}
|
||||||
isUpload = true;
|
isUpload = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1232,4 +1675,107 @@ namespace Lskj.PubBomImport
|
|||||||
returnMsg = ex.Message;
|
returnMsg = ex.Message;
|
||||||
throw new Exception($"文件{Path.GetFileName(filePath)}上传失败\r\n{ex.Message}");
|
throw new Exception($"文件{Path.GetFileName(filePath)}上传失败\r\n{ex.Message}");
|
||||||
isUpload = false;
|
isUpload = false;
|
||||||
|
}
|
||||||
|
msg = returnMsg;
|
||||||
|
outFileId = fileId;
|
||||||
|
return isUpload;
|
||||||
|
}
|
||||||
|
private bool UploadFileToAudit(string filePath, string idValue, string speciesno, out string msg, out string outFileId)
|
||||||
|
{
|
||||||
|
bool isUpload = false;
|
||||||
|
string File = filePath;
|
||||||
|
string returnMsg = "";
|
||||||
|
string fileId = "";
|
||||||
|
string postUrl = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//获取文件信息
|
||||||
|
FileInfo fileInfo = new FileInfo(File);
|
||||||
|
string suffix = Path.GetExtension(File);
|
||||||
|
string name = fileInfo.Name;
|
||||||
|
DateTime creationTime = fileInfo.CreationTime;
|
||||||
|
byte[] fileBytes = ConvertFileToBytes(File);
|
||||||
|
string fileStream = Convert.ToBase64String(fileBytes);
|
||||||
|
string userId = ERPInfo.Instance.UserId;
|
||||||
|
DateTime uploadTime = DateTime.Now;
|
||||||
|
//上传文件到服务器目录
|
||||||
|
postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&speciesno={8}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}";
|
||||||
|
if (!string.IsNullOrEmpty(idValue))
|
||||||
|
{
|
||||||
|
string token = "";
|
||||||
|
string loginUrl = $"{SystemInfo.Instance.OAUrl}/Api/SysUserAjaxApi.ashx";
|
||||||
|
HttpTools.setting("application/x-www-form-urlencoded", null, null, HttpTools.Encode.UTF8);
|
||||||
|
Dictionary<string, string> loginPmsDic = new Dictionary<string, string>();
|
||||||
|
loginPmsDic.Add("method", "Login");
|
||||||
|
loginPmsDic.Add("username", ERPInfo.Instance.UserName);
|
||||||
|
loginPmsDic.Add("password", ERPInfo.Instance.InPassWord);
|
||||||
|
HttpWebResponse loginResponse = HttpTools.Post(loginUrl, "", loginPmsDic, HttpTools.Method.POST, out CookieCollection loginCookie, out string loginResult);
|
||||||
|
if (loginResponse != null && !string.IsNullOrEmpty(loginResult))
|
||||||
|
{
|
||||||
|
JObject jObject = JsonConvert.DeserializeObject<JObject>(loginResult);
|
||||||
|
if (jObject.ContainsKey("success"))
|
||||||
|
{
|
||||||
|
if ((jObject["success"] + "").Equals("True"))
|
||||||
|
{
|
||||||
|
if (jObject.ContainsKey("token"))
|
||||||
|
{
|
||||||
|
token = jObject["token"] + "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(token))
|
||||||
|
{
|
||||||
|
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, Model.ModuleCode, idValue, "file", fileBytes.Length, 0, name, "DoWebUpload", speciesno);
|
||||||
|
HttpTools.setting("application/x-www-form-urlencoded", null, null);
|
||||||
|
string result = "";
|
||||||
|
CookieCollection cookieCollection = null;
|
||||||
|
Dictionary<string, string> headerDic = new Dictionary<string, string>();
|
||||||
|
headerDic.Add("Authorization", $"Bearer {token}");
|
||||||
|
HttpWebResponse webResponse = HttpTools.Post(postUrl, fileStream, null, headerDic, HttpTools.Method.POST, out cookieCollection, out result);
|
||||||
|
if (webResponse != null && !string.IsNullOrEmpty(result))
|
||||||
|
{
|
||||||
|
JObject jsonObject = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(result);
|
||||||
|
string isSuccess = jsonObject["success"] + "";
|
||||||
|
if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
if (jsonObject.ContainsKey("other"))
|
||||||
|
{
|
||||||
|
fileId = jsonObject["other"] + "";
|
||||||
|
}
|
||||||
|
isUpload = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (jsonObject.ContainsKey("msg"))
|
||||||
|
{
|
||||||
|
returnMsg = jsonObject["msg"] + "";
|
||||||
|
}
|
||||||
|
isUpload = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnMsg = "上传请求失败";
|
||||||
|
isUpload = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnMsg = loginResult;
|
||||||
|
isUpload = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnMsg = "上传节点值不能为空";
|
||||||
|
isUpload = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
returnMsg = ex.Message;
|
||||||
|
throw new Exception($"文件{Path.GetFileName(filePath)}上传失败\r\n{ex.Message}");
|
||||||
|
isUpload = false;
|
||||||
|
}
|
||||||
|
msg = returnM
|
||||||
Reference in New Issue
Block a user