SVN r539
SVN-Revision: r539
This commit is contained in:
@@ -548,9 +548,52 @@ namespace Lskj.PubBomImport
|
|||||||
{
|
{
|
||||||
//更新
|
//更新
|
||||||
DataTable source = this.gcMain.GridControl.DataSourceTable();
|
DataTable source = this.gcMain.GridControl.DataSourceTable();
|
||||||
|
|
||||||
List<DataRow> deleteRows = new List<DataRow>();
|
List<DataRow> deleteRows = new List<DataRow>();
|
||||||
foreach (DataRow sourceRow in source.Rows)
|
foreach (DataRow sourceRow in source.Rows)
|
||||||
{
|
{
|
||||||
string productId = sourceRow["ProductId"] + "";
|
string productId = sourceRow["ProductId"] + "";
|
||||||
DataRow newSourceRow = newSource.Rows.Cast<DataRow>().Where(n => (n["ProductId"] + "").Equals(productId)).FirstOrDefault();
|
DataRow newSourceRow = newSource.Rows.Cast<DataRow>().Where(n => (n["ProductId"] + "").Equals(productId)).FirstOrDefault();
|
||||||
|
if (newSourceRow != null)
|
||||||
|
{
|
||||||
|
sourceRow["tamount"] = newSourceRow["tamount"];
|
||||||
|
sourceRow["amount"] = newSourceRow["amount"];
|
||||||
|
newSource.Rows.Remove(newSourceRow);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
deleteRows.Add(sourceRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (DataRow deleteRow in deleteRows)
|
||||||
|
{
|
||||||
|
source.Rows.Remove(deleteRow);
|
||||||
|
}
|
||||||
|
foreach (DataRow newSourceRow in newSource.Rows)
|
||||||
|
{
|
||||||
|
DataRow newRow = source.NewRow();
|
||||||
|
newRow.ItemArray = newSourceRow.ItemArray;
|
||||||
|
source.Rows.Add(newRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//新增
|
||||||
|
this.gcMain.GridControl.DataSource = newSource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void AddOrUpdateBillByZZQD(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.GridC
|
||||||
+139
-120
@@ -80,7 +80,7 @@ namespace Lskj.PubBomImport
|
|||||||
InitGridColumns();
|
InitGridColumns();
|
||||||
InitMulitControl();
|
InitMulitControl();
|
||||||
InitDataSource();
|
InitDataSource();
|
||||||
if (showTypeValue == 0 || showTypeValue == 3 || showTypeValue == 5 || showTypeValue == 55 || (showTypeValue > 0 && showType))
|
if (showTypeValue == 0 || showTypeValue == 3 || showTypeValue == 4 || showTypeValue == 5 || showTypeValue == 55 || (showTypeValue > 0 && showType))
|
||||||
{
|
{
|
||||||
OnBtnImportClick(null, null);
|
OnBtnImportClick(null, null);
|
||||||
}
|
}
|
||||||
@@ -160,60 +160,120 @@ namespace Lskj.PubBomImport
|
|||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Model.ShowType.Equals("1"))
|
//else if (Model.ShowType.Equals("1"))
|
||||||
{
|
//{
|
||||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
// FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||||
dialog.SelectedPath = Properties.Settings.Default.LastSelectFolder;
|
// dialog.SelectedPath = Properties.Settings.Default.LastSelectFolder;
|
||||||
dialog.Description = "选择导入文件夹";
|
// dialog.Description = "选择导入文件夹";
|
||||||
DialogResult dialogResult = dialog.ShowDialog();
|
// DialogResult dialogResult = dialog.ShowDialog();
|
||||||
if (dialogResult == DialogResult.OK)
|
// if (dialogResult == DialogResult.OK)
|
||||||
{
|
// {
|
||||||
Properties.Settings.Default.LastSelectFolder = dialog.SelectedPath;
|
// Properties.Settings.Default.LastSelectFolder = dialog.SelectedPath;
|
||||||
string dirPath = dialog.SelectedPath;
|
// string dirPath = dialog.SelectedPath;
|
||||||
FrmProgress frmProgress = new FrmProgress();
|
// FrmProgress frmProgress = new FrmProgress();
|
||||||
frmProgress.frmMain = this;
|
// frmProgress.frmMain = this;
|
||||||
frmProgress.ImportTimer.Tick += (ts, te) =>
|
// frmProgress.ImportTimer.Tick += (ts, te) =>
|
||||||
{
|
// {
|
||||||
frmProgress.ImportTimer.Enabled = false;
|
// frmProgress.ImportTimer.Enabled = false;
|
||||||
frmProgress.StartImportInDir(dirPath);
|
// frmProgress.StartImportInDir(dirPath);
|
||||||
};
|
// };
|
||||||
frmProgress.ImportTimer.Enabled = true;
|
// frmProgress.ImportTimer.Enabled = true;
|
||||||
frmProgress.ShowDialog();
|
// frmProgress.ShowDialog();
|
||||||
frmProgress.Dispose();
|
// frmProgress.Dispose();
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
this.Close();
|
// this.Close();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
else if (Model.ShowType.Equals("2"))
|
//else if (Model.ShowType.Equals("2"))
|
||||||
{
|
//{
|
||||||
OpenFileDialog dialog = new OpenFileDialog();
|
// OpenFileDialog dialog = new OpenFileDialog();
|
||||||
dialog.InitialDirectory = Properties.Settings.Default.LastSelectFolder;
|
// dialog.InitialDirectory = Properties.Settings.Default.LastSelectFolder;
|
||||||
dialog.Title = "选择导入文件";
|
// dialog.Title = "选择导入文件";
|
||||||
dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
|
// dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
|
||||||
DialogResult dialogResult = dialog.ShowDialog();
|
// DialogResult dialogResult = dialog.ShowDialog();
|
||||||
if (dialogResult == DialogResult.OK)
|
// if (dialogResult == DialogResult.OK)
|
||||||
{
|
// {
|
||||||
Properties.Settings.Default.LastSelectFolder = Path.GetDirectoryName(dialog.FileName);
|
// Properties.Settings.Default.LastSelectFolder = Path.GetDirectoryName(dialog.FileName);
|
||||||
string dirPath = dialog.FileName;
|
// string dirPath = dialog.FileName;
|
||||||
FrmProgress frmProgress = new FrmProgress();
|
// FrmProgress frmProgress = new FrmProgress();
|
||||||
frmProgress.frmMain = this;
|
// frmProgress.frmMain = this;
|
||||||
frmProgress.ImportTimer.Tick += (ts, te) =>
|
// frmProgress.ImportTimer.Tick += (ts, te) =>
|
||||||
{
|
// {
|
||||||
frmProgress.ImportTimer.Enabled = false;
|
// frmProgress.ImportTimer.Enabled = false;
|
||||||
frmProgress.StartImportInMxFile(dirPath);
|
// frmProgress.StartImportInMxFile(dirPath);
|
||||||
};
|
// };
|
||||||
frmProgress.ImportTimer.Enabled = true;
|
// frmProgress.ImportTimer.Enabled = true;
|
||||||
frmProgress.ShowDialog();
|
// frmProgress.ShowDialog();
|
||||||
frmProgress.Dispose();
|
// frmProgress.Dispose();
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
this.Close();
|
// this.Close();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
else if (Model.ShowType.Equals("3"))//新增多个清单文件
|
//else if (Model.ShowType.Equals("3"))//新增多个清单文件
|
||||||
|
//{
|
||||||
|
// 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.StartImportInQDFile(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("4"))//新增或修改单个清单文件
|
||||||
{
|
{
|
||||||
BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
|
BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
|
||||||
{
|
{
|
||||||
@@ -228,75 +288,34 @@ namespace Lskj.PubBomImport
|
|||||||
ReturnTag = bomImpRtnModel
|
ReturnTag = bomImpRtnModel
|
||||||
};
|
};
|
||||||
this.Tag = dialogModel;
|
this.Tag = dialogModel;
|
||||||
DataTable sourceTable = StaticControl.RightMenuGridView.GridControl.DataSourceTable();
|
FrmProgress frmProgress = new FrmProgress();
|
||||||
if (sourceTable.Columns.Contains("BomFieldNameDir"))
|
frmProgress.frmMain = this;
|
||||||
|
frmProgress.Model = Model;
|
||||||
|
frmProgress.ImportTimer.Tick += (ts, te) =>
|
||||||
{
|
{
|
||||||
List<DataRow> selectRows = new List<DataRow>();
|
frmProgress.ImportTimer.Enabled = false;
|
||||||
foreach (DataRow sourceRow in sourceTable.Rows)
|
frmProgress.StartImportInQDFile();
|
||||||
{
|
};
|
||||||
if (sourceRow.RowState == DataRowState.Deleted)
|
frmProgress.ImportTimer.Enabled = true;
|
||||||
{
|
DialogResult dialogResult = frmProgress.ShowDialog();
|
||||||
continue;
|
bomImpRtnModel.CanSave = dialogResult == DialogResult.OK;
|
||||||
}
|
frmProgress.Dispose();
|
||||||
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.StartImportInQDFile(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("4"))//新增或修改单个清单文件
|
else if (Model.ShowType.Equals("44"))//通过已经上传的数据来解析并且建立BOM
|
||||||
{
|
{
|
||||||
OpenFileDialog dialog = new OpenFileDialog();
|
|
||||||
dialog.Title = "选择导入文件";
|
FrmProgress frmProgress = new FrmProgress();
|
||||||
dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
|
frmProgress.frmMain = this;
|
||||||
DialogResult dialogResult = dialog.ShowDialog();
|
frmProgress.Model = Model;
|
||||||
if (dialogResult == DialogResult.OK)
|
frmProgress.ImportTimer.Tick += (ts, te) =>
|
||||||
{
|
{
|
||||||
string dirPath = dialog.FileName;
|
frmProgress.ImportTimer.Enabled = false;
|
||||||
FrmProgress frmProgress = new FrmProgress();
|
string billDocument = Model.MaintabFocusedRow != null && Model.MaintabFocusedRow.Table.Columns.Contains("qms_wjgg_billdocument_id") ? Model.MaintabFocusedRow["qms_wjgg_billdocument_id"] + "" : "";
|
||||||
frmProgress.frmMain = this;
|
frmProgress.StartExecBomUpdate(billDocument);
|
||||||
frmProgress.ImportTimer.Tick += (ts, te) =>
|
};
|
||||||
{
|
frmProgress.ImportTimer.Enabled = true;
|
||||||
frmProgress.ImportTimer.Enabled = false;
|
frmProgress.ShowDialog();
|
||||||
frmProgress.StartImportInQDFile(dirPath);
|
frmProgress.Dispose();
|
||||||
};
|
|
||||||
frmProgress.ImportTimer.Enabled = true;
|
|
||||||
frmProgress.ShowDialog();
|
|
||||||
frmProgress.Dispose();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (Model.ShowType.Equals("5"))//通过文件名进行文件上传和逻辑记录
|
else if (Model.ShowType.Equals("5"))//通过文件名进行文件上传和逻辑记录
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,4 @@
|
|||||||
/******************************
|
using System;
|
||||||
* 说明:下载进度窗口
|
|
||||||
* 创建人:龚宇超
|
|
||||||
* 创建日期:2018-02-09
|
|
||||||
* 修改人:
|
|
||||||
* 修改日期:
|
|
||||||
* 修改备注:
|
|
||||||
* 版本:1.0.0.0
|
|
||||||
******************************/
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@@ -513,45 +504,31 @@ namespace Lskj.PubBomImport
|
|||||||
/// 开始导入3
|
/// 开始导入3
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dirPaths"></param>
|
/// <param name="dirPaths"></param>
|
||||||
public void StartImportInQDFile(List<DataRow> selectRows)
|
public void StartImportInQDFile()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (DataRow sourceRow in selectRows)
|
string namepattern = @"^(.+?)\s+(.+)$";
|
||||||
|
string pattern = @"^(.*?)(\d+)?$";
|
||||||
|
string primaryValue = StaticControl.RightMenuMyControl.PrimaryValue;
|
||||||
|
ControlModel controlModel = StaticControl.RightMenuMyControl.ControlModels.Where(n => n.LabelText.Equals("物料编码")).FirstOrDefault();
|
||||||
|
if (controlModel == null)
|
||||||
{
|
{
|
||||||
if (sourceRow.RowState == DataRowState.Deleted)
|
MessageUtil.Show($"物料编码不存在");
|
||||||
|
}
|
||||||
|
string productCode = StaticControl.RightMenuMyControl.GetControlValue(controlModel);
|
||||||
|
if (string.IsNullOrEmpty(productCode))
|
||||||
|
{
|
||||||
|
MessageUtil.Show($"物料编码不能为空");
|
||||||
|
}
|
||||||
|
List<LabelRemarkEdit> labelRemarkList = new List<LabelRemarkEdit>();
|
||||||
|
List<ControlModel> uploadModels = StaticControl.RightMenuMyControl.ControlModels.Where(n => n.FileUploadControl).ToList();
|
||||||
|
foreach (ControlModel uploadModel in uploadModels)
|
||||||
|
{
|
||||||
|
BaseUserControl uploadControl = StaticControl.RightMenuMyControl.FindControl(uploadModel);
|
||||||
|
if (uploadControl != null && uploadControl is LabelRemarkEdit labelRemarkEdit && !string.IsNullOrEmpty(labelRemarkEdit.filepath) && File.Exists(labelRemarkEdit.filepath))
|
||||||
{
|
{
|
||||||
continue;
|
labelRemarkList.Add(labelRemarkEdit);
|
||||||
}
|
|
||||||
string fileName = sourceRow[Model.AfterBomFieldName] + "";
|
|
||||||
string dirPath = sourceRow["BomFieldNameDir"] + "";
|
|
||||||
FileInfo parentInfo = null;
|
|
||||||
if (string.IsNullOrEmpty(dirPath))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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 frmBillInfo = new FrmBillInfo();
|
||||||
@@ -561,127 +538,387 @@ namespace Lskj.PubBomImport
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (DataRow sourceRow in selectRows)
|
foreach (LabelRemarkEdit labelRemark in labelRemarkList)
|
||||||
{
|
{
|
||||||
if (sourceRow.RowState == DataRowState.Deleted)
|
int childIndex = labelRemarkList.IndexOf(labelRemark);
|
||||||
{
|
int allCount = (int)((decimal)(childIndex) / (labelRemarkList.Count) * 100);
|
||||||
continue;
|
int finishCount = (int)((decimal)(1 + childIndex) / (labelRemarkList.Count) * 100);
|
||||||
}
|
string dirPath = labelRemark.filepath;
|
||||||
int childIndex = selectRows.IndexOf(sourceRow);
|
|
||||||
int allCount = (int)((decimal)(childIndex) / (selectRows.Count) * 100);
|
|
||||||
int finishCount = (int)((decimal)(1 + childIndex) / (selectRows.Count) * 100);
|
|
||||||
string fileName = sourceRow[Model.AfterBomFieldName] + "";
|
|
||||||
string dirPath = sourceRow["BomFieldNameDir"] + "";
|
|
||||||
FileInfo parentInfo = null;
|
FileInfo parentInfo = null;
|
||||||
if (string.IsNullOrEmpty(dirPath))
|
if (string.IsNullOrEmpty(dirPath))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
parentInfo = new FileInfo(dirPath);
|
parentInfo = new FileInfo(dirPath);
|
||||||
Model = frmMain.Model;
|
//如果是QD文件
|
||||||
string pattern = @"([A-Za-z]+)(\d*)$";
|
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD")))
|
||||||
string namepattern = @"^(.+?)\s+(.+)$";
|
|
||||||
//原物料名称
|
|
||||||
string productCode = sourceRow != null && sourceRow.Table.Columns.Contains(Model.BeforeBomFieldName) ? sourceRow[Model.BeforeBomFieldName] + "" : "";
|
|
||||||
Match match = Regex.Match(productCode, pattern);
|
|
||||||
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD") || parentInfo.Name.Trim().StartsWith("ZZQD")))
|
|
||||||
{
|
{
|
||||||
string code = "";
|
string code = "";
|
||||||
string name = "";
|
string name = "";
|
||||||
|
string sourceCode = "";
|
||||||
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
|
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
|
||||||
if (namematch.Success)
|
if (namematch.Success)
|
||||||
{
|
{
|
||||||
code = namematch.Groups[1].Value;
|
code = namematch.Groups[1].Value.Trim();
|
||||||
name = namematch.Groups[2].Value;
|
name = namematch.Groups[2].Value.Trim();
|
||||||
}
|
}
|
||||||
match = Regex.Match(code, pattern);
|
Match match = Regex.Match(code, pattern);
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
{
|
{
|
||||||
//更新或新增并备份清单
|
sourceCode = match.Groups[1].Value;
|
||||||
int.TryParse(Model.FirstRowIndex, out int index);
|
}
|
||||||
frmMain.FirstRowIndex = index;
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
if (code.StartsWith("QD"))
|
||||||
|
{
|
||||||
|
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{sourceCode}')");
|
||||||
|
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{sourceCode.Replace("'", "''")}','{name.Replace("'", "''")}','','0199') end;");
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||||
|
{
|
||||||
|
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||||
|
}
|
||||||
|
//更新或新增并备份清单
|
||||||
|
int.TryParse(Model.FirstRowIndex, out int index);
|
||||||
|
frmMain.FirstRowIndex = index;
|
||||||
|
//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(() =>
|
||||||
{
|
{
|
||||||
DataTable historyTable = BaseImpl.GetDataTableResult($"select * from bom_BillListlogTab where ParentProduct = '{productCode}' and historyVer = '{code}'");
|
detailTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
|
||||||
if (historyTable != null && historyTable.Rows.Count > 0)
|
}));
|
||||||
{
|
foreach (DataRow detailRow in detailTable.Rows)
|
||||||
//已经存在该版本则不进行任何操作
|
{
|
||||||
continue;
|
int.TryParse(detailRow["amount"] + "", out int amount);
|
||||||
}
|
detailRow["tamount"] = amount;
|
||||||
FileInfo childInfo = new FileInfo(dirPath);
|
detailRow["amount"] = amount;
|
||||||
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);
|
|
||||||
}));
|
|
||||||
foreach (DataRow detailRow in detailTable.Rows)
|
|
||||||
{
|
|
||||||
int.TryParse(detailRow["amount"] + "", out int lastAmount);
|
|
||||||
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";
|
|
||||||
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(() =>
|
|
||||||
{
|
|
||||||
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, code, out string msg, out string _);
|
|
||||||
SetProcessBar(100, finishCount);
|
|
||||||
SetProcessLabelAllMsg($"总进度:{childIndex + 1}/{selectRows.Count }");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception($"Bom明细获取失败\r\nBom导入失败");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
SetProcessBar(20, allCount);
|
||||||
|
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{sourceCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{sourceCode}' as productid";
|
||||||
|
// 处理单据表头数据
|
||||||
|
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
|
||||||
|
SetProcessBar(40, allCount);
|
||||||
|
frmBillInfo.AddOrUpdateBill(masterRow, detailTable);
|
||||||
|
SetProcessBar(60, allCount);
|
||||||
|
string guid = Guid.NewGuid() + "";
|
||||||
|
frmBillInfo.BillSaveSql(guid);
|
||||||
|
SetProcessBar(80, allCount);
|
||||||
|
//记录guid
|
||||||
|
string updateGuidSql = @"update QMS_wenjiangenggaitab set qms_wjgg_uuid = '{0}' where qms_wjgg_billdocument_Id = '{1}'";
|
||||||
|
SqlHelper.ExecuteNonQuery(string.Format(updateGuidSql, guid, primaryValue));
|
||||||
|
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));
|
||||||
|
//上传文件
|
||||||
|
//bool isUpload = UploadFile(childInfo.FullName, code, out string msg, out string _);
|
||||||
|
//SetProcessBar(100, finishCount);
|
||||||
|
//SetProcessLabelAllMsg($"总进度:{childIndex + 1}/{selectRows.Count }");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool isUpload = UploadFile(parentInfo.FullName, "", out string msg, out string _);
|
throw new Exception($"Bom明细获取失败\r\nBom导入失败");
|
||||||
SetProcessBar(100, finishCount);
|
|
||||||
SetProcessLabelAllMsg($"总进度:{childIndex + 1}/{selectRows.Count }");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
//如果是ZZQD文件
|
||||||
|
else if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("ZZQD")))
|
||||||
{
|
{
|
||||||
throw new Exception($"{parentInfo.Name}不是QD或ZZQD文件");
|
string code = "";
|
||||||
|
string name = "";
|
||||||
|
string sourceCode = "";
|
||||||
|
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
|
||||||
|
if (namematch.Success)
|
||||||
|
{
|
||||||
|
code = namematch.Groups[1].Value.Trim();
|
||||||
|
name = namematch.Groups[2].Value.Trim();
|
||||||
|
}
|
||||||
|
Match match = Regex.Match(code, pattern);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
sourceCode = match.Groups[1].Value;
|
||||||
|
}
|
||||||
|
//更新或新增并备份清单
|
||||||
|
int.TryParse(Model.FirstRowIndex, out int index);
|
||||||
|
frmMain.FirstRowIndex = index;
|
||||||
|
//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);
|
||||||
|
}));
|
||||||
|
foreach (DataRow detailRow in detailTable.Rows)
|
||||||
|
{
|
||||||
|
int.TryParse(detailRow["amount"] + "", out int lastAmount);
|
||||||
|
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";
|
||||||
|
// 处理单据表头数据
|
||||||
|
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
|
||||||
|
if (masterRow == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"BOM建立单{productCode}不存在");
|
||||||
|
}
|
||||||
|
SetProcessBar(40, allCount);
|
||||||
|
frmBillInfo.AddOrUpdateBillByZZQD(masterRow, detailTable);
|
||||||
|
SetProcessBar(60, allCount);
|
||||||
|
string guid = Guid.NewGuid() + "";
|
||||||
|
frmBillInfo.BillSaveSql(guid);
|
||||||
|
SetProcessBar(80, allCount);
|
||||||
|
//记录guid
|
||||||
|
string updateGuidSql = @"update QMS_wenjiangenggaitab set qms_wjgg_uuid = '{0}' where qms_wjgg_billdocument_Id = '{1}'";
|
||||||
|
SqlHelper.ExecuteNonQuery(string.Format(updateGuidSql, guid, primaryValue));
|
||||||
|
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));
|
||||||
|
//上传文件
|
||||||
|
//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导入失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//如果是MX文件
|
||||||
|
else if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("MX")))
|
||||||
|
{
|
||||||
|
string code = "";
|
||||||
|
string name = "";
|
||||||
|
string sourceCode = "";
|
||||||
|
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
|
||||||
|
if (namematch.Success)
|
||||||
|
{
|
||||||
|
code = namematch.Groups[1].Value.Trim();
|
||||||
|
name = namematch.Groups[2].Value.Trim();
|
||||||
|
}
|
||||||
|
Match match = Regex.Match(code, pattern);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
sourceCode = match.Groups[1].Value;
|
||||||
|
}
|
||||||
|
//更新或新增并备份清单
|
||||||
|
int.TryParse(Model.FirstRowIndex, out int index);
|
||||||
|
frmMain.FirstRowIndex = index;
|
||||||
|
//DataTable historyTable = BaseImpl.GetDataTableResult($"select * from bom_BillListlogTab where ParentProduct = '{productCode}' and historyVer = '{code}'");
|
||||||
|
//if (historyTable != null && historyTable.Rows.Count > 0)
|
||||||
|
//{
|
||||||
|
// //已经存在该版本则不进行任何操作
|
||||||
|
// continue;
|
||||||
|
//}
|
||||||
|
if (parentInfo != null)
|
||||||
|
{
|
||||||
|
if (Directory.Exists("BomImportTemp"))
|
||||||
|
{
|
||||||
|
Directory.Delete("BomImportTemp", true);
|
||||||
|
}
|
||||||
|
Directory.CreateDirectory("BomImportTemp");
|
||||||
|
DataTable parentTable = ExcelToDatatable(parentInfo.FullName, Model, "", 5);
|
||||||
|
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable();
|
||||||
|
Dictionary<string, string> childFileDic = new Dictionary<string, string>();
|
||||||
|
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 childCode = (dataRow["图号"] + "").Trim();
|
||||||
|
if (childCode.StartsWith("QD") || childCode.StartsWith("ZZQD"))
|
||||||
|
{
|
||||||
|
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{childCode}')");
|
||||||
|
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{childCode.Replace("'", "''")}','{(dataRow["名称"] + "").Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}','0199') end;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||||
|
{
|
||||||
|
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||||
|
}
|
||||||
|
frmBillInfo.OnBillAdd();
|
||||||
|
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 childCode = parentRow["图号"] + "";
|
||||||
|
if (childCode.StartsWith("QD") || childCode.StartsWith("ZZQD"))
|
||||||
|
{
|
||||||
|
string tempFileName = childFileDic[childCode];
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (DataRow parentRow in parentTable.Rows)
|
||||||
|
{
|
||||||
|
int.TryParse(parentRow["套数"] + "", out int tamount);
|
||||||
|
string childCode = parentRow["图号"] + "";
|
||||||
|
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||||
|
{
|
||||||
|
string tempFileName = childFileDic[childCode];
|
||||||
|
FileInfo childInfo = new FileInfo(tempFileName);
|
||||||
|
if (childInfo == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"MX明细中不包含文件{childCode}");
|
||||||
|
}
|
||||||
|
if (childInfo != null)
|
||||||
|
{
|
||||||
|
if (code.StartsWith("ZZQD"))
|
||||||
|
{
|
||||||
|
DataTable zzqdTable = ExcelToDatatable(childInfo.FullName, Model, "", index);
|
||||||
|
//frmMain.Invoke(new Action(() =>
|
||||||
|
//{
|
||||||
|
// zzqdTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
|
||||||
|
//}));
|
||||||
|
DataView filterDataView = new DataView(zzqdTable);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(Model.ReadTableCond))
|
||||||
|
{
|
||||||
|
filterDataView.RowFilter = Model.ReadTableCond;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
zzqdTable = filterDataView.ToTable();
|
||||||
|
foreach (DataRow zzqdItem in zzqdTable.Rows)
|
||||||
|
{
|
||||||
|
DataRow childRow = childTable.NewRow();
|
||||||
|
childRow["ProductId"] = zzqdItem["物料编码"] + "";
|
||||||
|
childRow["appellation"] = zzqdItem["名称"] + "";
|
||||||
|
childRow["bak"] = code;
|
||||||
|
childRow["tamount"] = parentRow["套数"] + "";
|
||||||
|
int.TryParse(zzqdItem["数量"] + "", out int amount);
|
||||||
|
childRow["amount"] = amount * tamount;
|
||||||
|
childTable.Rows.Add(childRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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明细数据为空");
|
||||||
|
}
|
||||||
|
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{productCode}' as productid";
|
||||||
|
// 处理单据表头数据
|
||||||
|
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
|
||||||
|
if (masterRow == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"BOM建立单{productCode}不存在");
|
||||||
|
}
|
||||||
|
SetProcessBar(40, allCount);
|
||||||
|
frmBillInfo.AddOrUpdateBill(masterRow, childTable);
|
||||||
|
SetProcessBar(60, allCount);
|
||||||
|
string guid = Guid.NewGuid() + "";
|
||||||
|
frmBillInfo.BillSaveSql(guid);
|
||||||
|
SetProcessBar(80, allCount);
|
||||||
|
//记录guid
|
||||||
|
string updateGuidSql = @"update QMS_wenjiangenggaitab set qms_wjgg_uuid = '{0}' where qms_wjgg_billdocument_Id = '{1}'";
|
||||||
|
SqlHelper.ExecuteNonQuery(string.Format(updateGuidSql, guid, primaryValue));
|
||||||
|
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));
|
||||||
|
//上传文件
|
||||||
|
//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导入失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.DialogResult = DialogResult.OK;
|
this.DialogResult = DialogResult.OK;
|
||||||
@@ -895,6 +1132,11 @@ namespace Lskj.PubBomImport
|
|||||||
{
|
{
|
||||||
throw new Exception($"保存失败\r\n请重新进行BOM上传后保存");
|
throw new Exception($"保存失败\r\n请重新进行BOM上传后保存");
|
||||||
}
|
}
|
||||||
|
DataRow billRow = BaseImpl.GetDataRowResult($"select qms_maddf_billdocument_id from qms_BillFileAddMaintab where qms_maddf_productid = '{productId}'");
|
||||||
|
if (billRow != null)
|
||||||
|
{
|
||||||
|
throw new Exception($"物料编码{productId}的BOM新增单已存在");
|
||||||
|
}
|
||||||
FileInfo mxInfo = new FileInfo(mxDirPath);
|
FileInfo mxInfo = new FileInfo(mxDirPath);
|
||||||
if (mxInfo != null)
|
if (mxInfo != null)
|
||||||
{
|
{
|
||||||
@@ -1116,8 +1358,9 @@ namespace Lskj.PubBomImport
|
|||||||
foreach (DataRow detailRow in detailTable.Rows)
|
foreach (DataRow detailRow in detailTable.Rows)
|
||||||
{
|
{
|
||||||
int.TryParse(detailRow["amount"] + "", out int amount);
|
int.TryParse(detailRow["amount"] + "", out int amount);
|
||||||
|
//数量暂定为自身数量
|
||||||
detailRow["tamount"] = amount;
|
detailRow["tamount"] = amount;
|
||||||
detailRow["amount"] = amount * tamount;
|
detailRow["amount"] = amount;
|
||||||
}
|
}
|
||||||
if (detailTable.Rows.Count == 0)
|
if (detailTable.Rows.Count == 0)
|
||||||
{
|
{
|
||||||
@@ -1270,6 +1513,75 @@ namespace Lskj.PubBomImport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// 根据已上传的数据进行Bom修改
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="selectRows"></param>
|
||||||
|
public void StartExecBomUpdate(string billdocument)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(billdocument))
|
||||||
|
{
|
||||||
|
throw new Exception($"单据编号不能为空");
|
||||||
|
}
|
||||||
|
DataRow sourceRow = BaseImpl.GetDataRowResult($"select qms_wjgg_billdocument_id,qms_wjgg_uuid from QMS_wenjiangenggaitab where qms_wjgg_billdocument_id = '{billdocument}'");
|
||||||
|
if (sourceRow == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"Bom变更单{billdocument}不存在");
|
||||||
|
}
|
||||||
|
Task task = new Task(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string execGuid = sourceRow["qms_wjgg_uuid"] + "";
|
||||||
|
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 = 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}'");
|
||||||
|
}
|
||||||
|
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>
|
||||||
/// 根据已上传的数据进行Bom生成
|
/// 根据已上传的数据进行Bom生成
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="selectRows"></param>
|
/// <param name="selectRows"></param>
|
||||||
@@ -1682,7 +1994,7 @@ namespace Lskj.PubBomImport
|
|||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(token))
|
if (!string.IsNullOrEmpty(token))
|
||||||
{
|
{
|
||||||
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, Model.ModuleCode, HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(name), "DoWebUpload", speciesno);
|
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, "1000202", HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(name), "DoWebUpload", speciesno);
|
||||||
HttpTools.setting("application/x-www-form-urlencoded", null, null);
|
HttpTools.setting("application/x-www-form-urlencoded", null, null);
|
||||||
string result = "";
|
string result = "";
|
||||||
CookieCollection cookieCollection = null;
|
CookieCollection cookieCollection = null;
|
||||||
@@ -1792,7 +2104,7 @@ namespace Lskj.PubBomImport
|
|||||||
if (!string.IsNullOrEmpty(token))
|
if (!string.IsNullOrEmpty(token))
|
||||||
{
|
{
|
||||||
//DeleteFileExists(token, name, Model.ModuleCode, idValue, speciesno);
|
//DeleteFileExists(token, name, Model.ModuleCode, idValue, speciesno);
|
||||||
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, Model.ModuleCode, HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(name), "DoWebUpload", speciesno);
|
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, "1000202", HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(name), "DoWebUpload", speciesno);
|
||||||
HttpTools.setting("application/x-www-form-urlencoded", null, null);
|
HttpTools.setting("application/x-www-form-urlencoded", null, null);
|
||||||
string result = "";
|
string result = "";
|
||||||
CookieCollection cookieCollection = null;
|
CookieCollection cookieCollection = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user