SVN r464
SVN-Revision: r464
This commit is contained in:
@@ -35,6 +35,7 @@ using Lskj.Business.Impl;
|
||||
using System.Text.RegularExpressions;
|
||||
using Lskj.Util;
|
||||
using System.Web;
|
||||
using Lskj.Control.Model;
|
||||
|
||||
namespace Lskj.PubBomImport
|
||||
{
|
||||
@@ -44,10 +45,6 @@ namespace Lskj.PubBomImport
|
||||
/// </summary>
|
||||
public partial class FrmProgress : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Occurs when [on add record call back].
|
||||
/// </summary>
|
||||
public event EventHandler OnImportCallBack;
|
||||
public FrmMain frmMain;
|
||||
public DynamicBomImport Model;
|
||||
public System.Windows.Forms.Timer ImportTimer = new System.Windows.Forms.Timer();
|
||||
@@ -508,260 +505,196 @@ namespace Lskj.PubBomImport
|
||||
/// 开始导入3
|
||||
/// </summary>
|
||||
/// <param name="dirPaths"></param>
|
||||
public void StartImportInQDFile(string dirPath)
|
||||
public void StartImportInQDFile(DataTable sourceTable, Dictionary<string, string> filesDic)
|
||||
{
|
||||
try
|
||||
{
|
||||
Model = frmMain.Model;
|
||||
string pattern = @"([A-Za-z]+)(\d*)$";
|
||||
//原物料名称
|
||||
string productCode = Model.MaintabFocusedRow != null && Model.MaintabFocusedRow.Table.Columns.Contains("qms_laddf_productid") ? Model.MaintabFocusedRow["qms_laddf_productid"] + "" : "";
|
||||
Match match = Regex.Match(productCode, pattern);
|
||||
if (match.Success)
|
||||
foreach (DataRow sourceRow in sourceTable.Rows)
|
||||
{
|
||||
string sourceModel = match.Groups[1].Value;
|
||||
string sourceVersion = match.Groups[2].Value;
|
||||
sourceVersion = string.IsNullOrEmpty(sourceVersion) ? "0" : sourceVersion;
|
||||
//修改后的文件名
|
||||
string newProductCode = Model.MaintabFocusedRow != null && Model.MaintabFocusedRow.Table.Columns.Contains("qms_laddf_appellationV123") ? Model.MaintabFocusedRow["qms_laddf_appellationV123"] + "" : "";
|
||||
FileInfo parentInfo = new FileInfo(dirPath);
|
||||
if (sourceRow.RowState == DataRowState.Deleted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string fileName = sourceRow[Model.AfterBomFieldName] + "";
|
||||
string dirPath = filesDic.ContainsKey(fileName) ? filesDic[fileName] : "";
|
||||
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 newcode = newProductCode.Trim();
|
||||
string newname = "";
|
||||
string namepattern = @"^(.+?)\s+(.+)$";
|
||||
Match newProductCodematch = Regex.Match(Path.GetFileNameWithoutExtension(newProductCode).Trim(), namepattern);
|
||||
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
|
||||
if (namematch.Success)
|
||||
{
|
||||
code = namematch.Groups[1].Value;
|
||||
name = namematch.Groups[2].Value;
|
||||
}
|
||||
if (newProductCodematch.Success)
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||
{
|
||||
newcode = newProductCodematch.Groups[1].Value;
|
||||
newname = newProductCodematch.Groups[2].Value;
|
||||
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 (!newcode.Equals(code))//选择的文件和版本文件名不匹配
|
||||
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||
{
|
||||
throw new Exception($"修改的文件名{newProductCode}和选择的文件名{code}不匹配");
|
||||
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||
}
|
||||
match = Regex.Match(code, pattern);
|
||||
if (match.Success)
|
||||
}
|
||||
}
|
||||
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
||||
frmBillInfo.OnControlSourceBind += (s, args) =>
|
||||
{
|
||||
Task task = new Task(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
string newModel = match.Groups[1].Value;
|
||||
string newVersion = match.Groups[2].Value;
|
||||
newVersion = string.IsNullOrEmpty(newVersion) ? "0" : newVersion;
|
||||
string selectSql = $"select * from p_fm_filetab where sname like '{code}%'";
|
||||
DataRow fileRow = BaseImpl.GetDataRowResult(selectSql);
|
||||
if (fileRow != null)
|
||||
foreach (DataRow sourceRow in sourceTable.Rows)
|
||||
{
|
||||
//如果存在相同版本的文件
|
||||
throw new Exception("已经存在相同版本的文件");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sourceModel.Equals(newModel))
|
||||
if (sourceRow.RowState == DataRowState.Deleted)
|
||||
{
|
||||
//新建清单
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
string fileName = sourceRow[Model.AfterBomFieldName] + "";
|
||||
string dirPath = filesDic.ContainsKey(fileName) ? filesDic[fileName] : "";
|
||||
FileInfo parentInfo = null;
|
||||
if (string.IsNullOrEmpty(dirPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
parentInfo = new FileInfo(dirPath);
|
||||
Model = frmMain.Model;
|
||||
string pattern = @"([A-Za-z]+)(\d*)$";
|
||||
//原物料名称
|
||||
string productCode = sourceRow != null && sourceRow.Table.Columns.Contains(Model.BeforeBomFieldName) ? sourceRow[Model.BeforeBomFieldName] + "" : "";
|
||||
Match match = Regex.Match(productCode, pattern);
|
||||
if (match.Success)
|
||||
{
|
||||
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD") || parentInfo.Name.Trim().StartsWith("ZZQD")))
|
||||
{
|
||||
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{code}')");
|
||||
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{code.Replace("'", "''")}','{name.Replace("'", "''")}','','0199') end;");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||
}
|
||||
//更新并备份清单
|
||||
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
||||
frmBillInfo.OnControlSourceBind += (s, args) =>
|
||||
{
|
||||
Task task = new Task(() =>
|
||||
string code = "";
|
||||
string name = "";
|
||||
string namepattern = @"^(.+?)\s+(.+)$";
|
||||
Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
|
||||
if (namematch.Success)
|
||||
{
|
||||
try
|
||||
code = namematch.Groups[1].Value;
|
||||
name = namematch.Groups[2].Value;
|
||||
}
|
||||
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"))
|
||||
{
|
||||
int.TryParse(Model.FirstRowIndex, out int index);
|
||||
frmMain.FirstRowIndex = index;
|
||||
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||
FileInfo childInfo = new FileInfo(dirPath);
|
||||
if (childInfo != null)
|
||||
{
|
||||
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(() =>
|
||||
{
|
||||
frmBillInfo.OnBillAdd();
|
||||
SetProcessBar(0, 0);
|
||||
SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}");
|
||||
DataTable detailTable = new DataTable();
|
||||
frmMain.Invoke(new Action(() =>
|
||||
detailTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
|
||||
}));
|
||||
foreach (DataRow detailRow in detailTable.Rows)
|
||||
{
|
||||
int.TryParse(detailRow["amount"] + "", out int lastAmount);
|
||||
detailRow["tamount"] = 1;
|
||||
detailRow["amount"] = lastAmount;
|
||||
}
|
||||
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);
|
||||
//备份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));
|
||||
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));
|
||||
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||
{
|
||||
if (sourceRow.Table.Columns.Contains("qms_laddf_RelatedId"))
|
||||
{
|
||||
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;
|
||||
sourceRow["qms_laddf_RelatedId"] = billNo;
|
||||
}
|
||||
SetProcessBar(20, 0);
|
||||
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{productCode}' as productid";
|
||||
billMasterSql = ReplaceHelper.ReplaceRowParam(Model.MaintabFocusedRow, billMasterSql);
|
||||
// 处理单据表头数据
|
||||
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
|
||||
SetProcessBar(40, 0);
|
||||
frmBillInfo.AddOrUpdateBill(masterRow, detailTable);
|
||||
SetProcessBar(60, 0);
|
||||
//备份Bom清单明细
|
||||
string bakBomListSql = @"delete bom_BillListlogTab where parentProduct = '{0}' 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));
|
||||
string billNo = "";
|
||||
frmBillInfo.BillSave(ref billNo);
|
||||
SetProcessBar(80, 0);
|
||||
frmBillInfo.OnBillAdd();
|
||||
//记录历史版本号
|
||||
string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
|
||||
SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, billNo));
|
||||
//上传文件
|
||||
bool isUpload = UploadFile(childInfo.FullName, billNo, out string msg);
|
||||
SetProcessBar(100, 100);
|
||||
SetProcessLabelAllMsg($"总进度:1/1");
|
||||
}
|
||||
else
|
||||
}));
|
||||
//执行配置的保存后sql
|
||||
if (!string.IsNullOrEmpty(Model.AfterAddBomSql))
|
||||
{
|
||||
throw new Exception($"Bom明细获取失败\r\nBom导入失败");
|
||||
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}/{sourceTable.Rows.Count }");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Bom明细获取失败\r\nBom导入失败");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (this.OnImportCallBack != null)
|
||||
this.OnImportCallBack(null, null);
|
||||
this.DialogResult = DialogResult.OK;
|
||||
this.Close();
|
||||
ImportTimer?.Dispose();
|
||||
}
|
||||
});
|
||||
task.Start();
|
||||
};
|
||||
frmBillInfo.OnLoad(Model);
|
||||
frmMain.ParentView = frmBillInfo.GcMainView;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"文件名{code}不符合规则");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("不是QD或ZZQD文件");
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
ImportTimer?.Dispose();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//新建清单
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||
{
|
||||
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{code}')");
|
||||
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{code.Replace("'", "''")}','{name.Replace("'", "''")}','','0199') end;");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||
}
|
||||
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
||||
frmBillInfo.OnControlSourceBind += (s, args) =>
|
||||
{
|
||||
Task task = new Task(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(Model.FirstRowIndex, out int index);
|
||||
frmMain.FirstRowIndex = index;
|
||||
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
|
||||
{
|
||||
FileInfo childInfo = new FileInfo(dirPath);
|
||||
if (childInfo != null)
|
||||
{
|
||||
DataTable childTable = new DataTable();
|
||||
foreach (GridColumn gridColumn in frmBillInfo.GcMainView.Columns)
|
||||
{
|
||||
if (!childTable.Columns.Contains(gridColumn.FieldName))
|
||||
{
|
||||
childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType);
|
||||
}
|
||||
}
|
||||
frmBillInfo.GcMainView.GridControl.DataSource = childTable;
|
||||
SetProcessBar(0, 0);
|
||||
SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}");
|
||||
DataTable detailTable = new DataTable();
|
||||
frmMain.Invoke(new Action(() =>
|
||||
{
|
||||
detailTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
|
||||
}));
|
||||
foreach (DataRow detailRow in detailTable.Rows)
|
||||
{
|
||||
int.TryParse(detailRow["amount"] + "", out int lastAmount);
|
||||
detailRow["tamount"] = 1;
|
||||
detailRow["amount"] = lastAmount;
|
||||
}
|
||||
frmBillInfo.GcMainView.GridControl.DataSource = detailTable;
|
||||
SetProcessBar(20, 0);
|
||||
string controlSql = $"select '' as billdocument_id,'0' affirmer,'0' rtagid,'{code}' as productid";
|
||||
frmBillInfo.InitializeHeader(null, controlSql);
|
||||
SetProcessBar(40, 0);
|
||||
string billNo = "";
|
||||
frmBillInfo.BillSave(ref billNo);
|
||||
SetProcessBar(60, 0);
|
||||
frmBillInfo.OnBillAdd();
|
||||
SetProcessBar(80, 0);
|
||||
//记录历史版本号
|
||||
string updateHistoryVerSql = @"update bom_BillListTab set historyVer = '{0}' where Billdocument_Id='{1}'";
|
||||
SqlHelper.ExecuteNonQuery(string.Format(updateHistoryVerSql, code, billNo));
|
||||
//上传文件
|
||||
bool isUpload = UploadFile(childInfo.FullName, billNo, out string msg);
|
||||
SetProcessBar(100, 100);
|
||||
SetProcessLabelAllMsg($"总进度:1/1");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Bom明细获取失败\r\nBom导入失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (this.OnImportCallBack != null)
|
||||
this.OnImportCallBack(null, null);
|
||||
this.DialogResult = DialogResult.OK;
|
||||
this.Close();
|
||||
ImportTimer?.Dispose();
|
||||
}
|
||||
});
|
||||
task.Start();
|
||||
};
|
||||
frmBillInfo.OnLoad(Model);
|
||||
frmMain.ParentView = frmBillInfo.GcMainView;
|
||||
throw new Exception($"文件名{productCode}不符合规则");
|
||||
}
|
||||
}
|
||||
this.DialogResult = DialogResult.OK;
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"文件名{code}不符合规则");
|
||||
MessageUtil.Show(ex.Message);
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("不是QD或ZZQD文件");
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
ImportTimer?.Dispose();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"文件名{productCode}不符合规则");
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Close();
|
||||
ImportTimer?.Dispose();
|
||||
}
|
||||
});
|
||||
task.Start();
|
||||
};
|
||||
frmBillInfo.OnLoad(Model);
|
||||
frmMain.ParentView = frmBillInfo.GcMainView;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user