SVN-Revision: r761
This commit is contained in:
wyf
2025-06-19 12:44:42 +00:00
parent 9e417d3d93
commit 30e8452e5d
3 changed files with 448 additions and 325 deletions
+156 -153
View File
@@ -1,153 +1,156 @@
/******************************
* 说明:PubSpec 模块
* 创建人:龚宇超
* 创建日期:2018-01-02
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lskj.Util;
using Lskj.Business;
using System.Windows.Forms;
using Lskj.Model;
using DevExpress.XtraGrid.Views.Grid;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Data;
using Lskj.Business.Impl;
namespace Lskj.PubBomImport
{
/// <summary>
/// PubSpec 模块
/// </summary>
public class DllBaseClass : IForm
{
public DllBaseClass()
{
}
public DllBaseClass(string[] obj)
{
try
{
FrmMain main = new FrmMain();
this.SubForm = main;
main.Model = new DynamicBomImport(obj);
}
catch (Exception ex)
{
LogUtil.WriteError("Lskj.PubSpecialImport.dll--参数错误-->" + obj.ToString(), ex);
}
}
public Form SubForm { get; set; }
}
/// <summary>
/// PubSpecialImport入库参数
/// </summary>
public class DynamicBomImport : DynamicModel
{
public string PupupMenuId = "";
public string MenuName = "";
public string FirstRowIndex = "";
public string MainFieldDic = "";
public string SheetName = "";
/// <summary>
/// 读取筛选条件
/// </summary>
public string ReadTableCond = "";
/// <summary>
/// 忽略合并明细列标题行
/// </summary>
public bool CustomerServiceApp = false;
/// <summary>
/// 显示模式,如果为1则隐藏配置界面
/// </summary>
public string ShowType = "";
/// <summary>
/// 单据 BillMasterSql
/// </summary>
public string BillMasterSql = "";
/// <summary>
/// 单据 BillDetailSql
/// </summary>
public string BillDetailSql = "";
/// <summary>
/// 原始物料名称字段
/// </summary>
public string BeforeBomFieldName = "";
/// <summary>
/// 修改后物料名称字段
/// </summary>
public string AfterBomFieldName = "";
/// <summary>
/// 新增后的修改数据sql
/// </summary>
public string AfterAddBomSql = "";
public DynamicBomImport(string[] args)
: base(args)
{
// 右键菜单打开的模块没有moduleId,部分特殊模块没有moduleId比如添加界面.
MenuName = args[0];
if (args.Length > 5 && !string.IsNullOrWhiteSpace(args[5]))
{
PupupMenuId = args[5] + "";
}
if (args.Length > 6 && !string.IsNullOrWhiteSpace(args[6]))
{
base.ModuleCode = args[6] + "";
}
if (args.Length > 7 && !string.IsNullOrWhiteSpace(args[7]))
{
FirstRowIndex = args[7] + "";
}
if (args.Length > 8 && !string.IsNullOrWhiteSpace(args[8]))
{
MainFieldDic = args[8] + "";
}
if (args.Length > 9 && !string.IsNullOrWhiteSpace(args[9]))
{
SheetName = args[9] + "";
}
if (args.Length > 10 && !string.IsNullOrWhiteSpace(args[10]))
{
ReadTableCond = args[10] + "";
}
if (args.Length > 11 && !string.IsNullOrWhiteSpace(args[11]))
{
CustomerServiceApp = (args[11] + "").Equals("1");
}
if (args.Length > 12 && !string.IsNullOrWhiteSpace(args[12]))
{
ShowType = args[12] + "";
}
if (args.Length > 13 && !string.IsNullOrWhiteSpace(args[13]))
{
BillMasterSql = args[13] + "";
}
if (args.Length > 14 && !string.IsNullOrWhiteSpace(args[14]))
{
BillDetailSql = args[14] + "";
}
if (!string.IsNullOrEmpty(args[args.Length - 1]))
{
try
{
JObject rowObject = JsonConvert.DeserializeObject<JObject>(args[args.Length - 1]);
JArray jArray = new JArray();
jArray.Add(rowObject);
DataTable dataTable = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(jArray));
this.MaintabFocusedRow = dataTable.Rows[0];
}
catch (Exception)
{
}
}
if (BaseImpl.HasExistsTable("p_systemPopupPmsTab"))
{
/******************************
* 说明:PubSpec 模块
* 创建人:龚宇超
* 创建日期:2018-01-02
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lskj.Util;
using Lskj.Business;
using System.Windows.Forms;
using Lskj.Model;
using DevExpress.XtraGrid.Views.Grid;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Data;
using Lskj.Business.Impl;
namespace Lskj.PubBomImport
{
/// <summary>
/// PubSpec 模块
/// </summary>
public class DllBaseClass : IForm
{
public DllBaseClass()
{
}
public DllBaseClass(string[] obj)
{
try
{
FrmMain main = new FrmMain();
this.SubForm = main;
main.Model = new DynamicBomImport(obj);
}
catch (Exception ex)
{
LogUtil.WriteError("Lskj.PubSpecialImport.dll--参数错误-->" + obj.ToString(), ex);
}
}
public Form SubForm { get; set; }
}
/// <summary>
/// PubSpecialImport入库参数
/// </summary>
public class DynamicBomImport : DynamicModel
{
public string PupupMenuId = "";
public string MenuName = "";
public string FirstRowIndex = "";
public string MainFieldDic = "";
public string SheetName = "";
/// <summary>
/// 读取筛选条件
/// </summary>
public string ReadTableCond = "";
/// <summary>
/// 忽略合并明细列标题行
/// </summary>
public bool CustomerServiceApp = false;
/// <summary>
/// 显示模式,如果为1则隐藏配置界面
/// </summary>
public string ShowType = "";
/// <summary>
/// 单据 BillMasterSql
/// </summary>
public string BillMasterSql = "";
/// <summary>
/// 单据 BillDetailSql
/// </summary>
public string BillDetailSql = "";
/// <summary>
/// 原始物料名称字段
/// </summary>
public string BeforeBomFieldName = "";
/// <summary>
/// 修改后物料名称字段
/// </summary>
public string AfterBomFieldName = "";
/// <summary>
/// 新增后的修改数据sql
/// </summary>
public string AfterAddBomSql = "";
public DynamicBomImport(string[] args)
: base(args)
{
// 右键菜单打开的模块没有moduleId,部分特殊模块没有moduleId比如添加界面.
MenuName = args[0];
if (args.Length > 5 && !string.IsNullOrWhiteSpace(args[5]))
{
PupupMenuId = args[5] + "";
}
if (args.Length > 6 && !string.IsNullOrWhiteSpace(args[6]))
{
base.ModuleCode = args[6] + "";
}
if (args.Length > 7 && !string.IsNullOrWhiteSpace(args[7]))
{
FirstRowIndex = args[7] + "";
}
if (args.Length > 8 && !string.IsNullOrWhiteSpace(args[8]))
{
MainFieldDic = args[8] + "";
}
if (args.Length > 9 && !string.IsNullOrWhiteSpace(args[9]))
{
SheetName = args[9] + "";
}
if (args.Length > 10 && !string.IsNullOrWhiteSpace(args[10]))
{
ReadTableCond = args[10] + "";
}
if (args.Length > 11 && !string.IsNullOrWhiteSpace(args[11]))
{
CustomerServiceApp = (args[11] + "").Equals("1");
}
if (args.Length > 12 && !string.IsNullOrWhiteSpace(args[12]))
{
ShowType = args[12] + "";
}
if (args.Length > 13 && !string.IsNullOrWhiteSpace(args[13]))
{
BillMasterSql = args[13] + "";
}
if (args.Length > 14 && !string.IsNullOrWhiteSpace(args[14]))
{
BillDetailSql = args[14] + "";
}
if (!string.IsNullOrEmpty(args[args.Length - 1]))
{
try
{
JObject rowObject = JsonConvert.DeserializeObject<JObject>(args[args.Length - 1]);
JArray jArray = new JArray();
jArray.Add(rowObject);
DataTable dataTable = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(jArray));
this.MaintabFocusedRow = dataTable.Rows[0];
}
catch (Exception)
{
}
}
if (BaseImpl.HasExistsTable("p_systemPopupPmsTab"))
{
DataTable pmsTable = BaseImpl.GetDataTableResult($"select * from p_systemPopupPmsTab where unionId='{PupupMenuId}'");
EnumerableRowCollection<DataRow> dataRows = pmsTable.AsEnumerable();
DataRow pm
+7 -3
View File
@@ -195,7 +195,7 @@ namespace Lskj.PubBomImport
}
return saveResult;
}
public bool BillSaveSql(string guid, int comfirm = 0, bool canTipMsg = true)
public bool BillSaveSql(string guid, string zzqdTag = "", int comfirm = 0, bool canTipMsg = true)
{
bool saveResult = false;
if (ControlObj.VerifyNull())
@@ -243,8 +243,8 @@ namespace Lskj.PubBomImport
//param[7].Value = auditFlag;
//param[8].Value = comfirm;
SqlHelper.ExecuteNonQuery($"delete p_bomImportExecTab where guid = '{guid}'");
SqlHelper.ExecuteNonQuery($"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}')");
SqlHelper.ExecuteNonQuery($"insert into p_bomImportExecTab (guid,detailTable,masterSql,detailSql,billNo,detailGuid,UserId,billWay,billSeq,auditFlag,comfirm,newVer,zzqdtag) " +
$"values ('{guid}','{billModel.DetailTable}','{masterSql.Replace("'", "''")}','{detailSql.Replace("'", "''")}','{billNo}','{detailGuid.Replace("'", "''")}','{ERPInfo.Instance.UserId}','{(billModel.SaveState ? 2 : 1)}','{billModel.BillSeq}','0','{comfirm}','{billModel.NewVer}','{zzqdTag}')");
//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)
//{
@@ -261,6 +261,10 @@ namespace Lskj.PubBomImport
throw new Exception($"保存Bom失败\r\n{ex.Message}");
}
}
else
{
throw new Exception($"保存Bom失败\r\n验证失败");
}
return saveResult;
}
private string GetUpdateRecord(string parmaryValue)
+285 -169
View File
@@ -1211,6 +1211,7 @@ namespace Lskj.PubBomImport
GetFileCodeInfo(beforeName, out string beforeSourceCode, out string beforeSourceName, out string beforeSourceBB, out int beforeSourceBC);
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);
@@ -1219,29 +1220,168 @@ namespace Lskj.PubBomImport
labelRemarkList.Add(labelRemarkEdit);
}
}
FrmBillInfo frmBillInfo = new FrmBillInfo();
frmBillInfo.OnControlSourceBind += (s, args) =>
LabelRemarkEdit labelRemark = null;
if (labelRemarkList.Count > 0)
{
Task task = new Task(() =>
labelRemark = labelRemarkList[0];
}
if (labelRemark == null)
{
throw new Exception("变更数据异常,请检查");
}
string dirPath = labelRemark.filepath;
FileInfo parentInfo = null;
if (string.IsNullOrEmpty(dirPath))
{
throw new Exception("变更文件目录地址不存在");
}
parentInfo = new FileInfo(dirPath);
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("ZZQD")))
{
FrmBillInfo frmBillInfo = new FrmBillInfo();
frmBillInfo.OnControlSourceBind += (s, args) =>
{
try
Task task = new Task(() =>
{
foreach (LabelRemarkEdit labelRemark in labelRemarkList)
try
{
int childIndex = labelRemarkList.IndexOf(labelRemark);
int allCount = (int)((decimal)(childIndex) / (labelRemarkList.Count) * 100);
int finishCount = (int)((decimal)(1 + childIndex) / (labelRemarkList.Count) * 100);
string dirPath = labelRemark.filepath;
FileInfo parentInfo = null;
if (string.IsNullOrEmpty(dirPath))
int childIndex = 0;
int allCount = (int)((decimal)(childIndex) / 1 * 100);
int finishCount = (int)((decimal)(1 + childIndex) / 1 * 100);
//如果是ZZQD文件
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("ZZQD")))
{
continue;
}
parentInfo = new FileInfo(dirPath);
//if (true)
//{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
DataTable filetable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{sourceCode}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{sourceCode}%'");
int childMaxBc = -1;
foreach (DataRow fileRow in filetable.Rows)
{
string fileName = fileRow["sname"] + "";
string fileId = fileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= childMaxBc)
{
childMaxBc = fileBC;
}
}
if (beforeSourceCode.Equals(sourceCode) && sourceBC <= childMaxBc)//变更版次
{
throw new Exception($"变更版本{sourceBB}的版次{sourceBC}必须大于最大版次{childMaxBc}\r\n不允许变更");
}
if (!beforeSourceCode.Equals(sourceCode) && filetable.Rows.Count > 0)//变更版本
{
throw new Exception($"变更版本{sourceBB}已存在,请进行版次变更");
}
//}
//变更ZZQD将原本的ZZQD数据进行档案备份
CopyZZQDToCopy(topProductId);
//更新或新增并备份清单
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;
detailRow["bak"] = sourceCode;
detailRow["bombb"] = sourceBB;
detailRow["bombc"] = sourceBC;
}
SetProcessBar(20, allCount);
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab_copy where productid = '{sourceCode}') as billdocument_id,'0' affirmer,'0' rtagid,'{sourceCode}' as productid,'{sourceCode}' as bak,'{sourceBB}' as bombb,'{sourceBC}' as bombc";
// 处理单据表头数据
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
if (masterRow == null)
{
throw new Exception($"BOM建立单{topProductId}不存在");
}
SetProcessBar(40, allCount);
frmBillInfo.AddOrUpdateBill(masterRow, detailTable);
//frmBillInfo.AddOrUpdateBillByZZQD(masterRow, detailTable);
SetProcessBar(60, allCount);
string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid, sourceCode);
//BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider.ToString().Replace("'", "''")}' where guid = '{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.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.OK;
}));
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.Cancel;
}));
BaseImpl.ExecSqlValue($"delete QMS_wenjiangenggaitab where qms_wjgg_billdocument_Id = '{primaryValue}'");
}
finally
{
this.Invoke(new Action(() =>
{
this.Close();
ImportTimer?.Dispose();
}));
}
});
task.Start();
};
Model.ChangeModuleCode("9100102");//改变模块编码
frmBillInfo.OnLoad(Model);
frmMain.ParentView = frmBillInfo.GcMainView;
}
else
{
FrmBillInfo frmBillInfo = new FrmBillInfo();
frmBillInfo.OnControlSourceBind += (s, args) =>
{
Task task = new Task(() =>
{
try
{
int childIndex = 0;
int allCount = (int)((decimal)(childIndex) / 1 * 100);
int finishCount = (int)((decimal)(1 + childIndex) / 1 * 100);
//如果是QD文件
if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD")))
{
@@ -1341,101 +1481,6 @@ namespace Lskj.PubBomImport
throw new Exception($"Bom明细获取失败\r\nBom导入失败");
}
}
//如果是ZZQD文件
else if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("ZZQD")))
{
GetFileCodeInfo(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), out string sourceCode, out string sourceName, out string sourceBB, out int sourceBC);
DataTable filetable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{sourceCode}' and dllcoid = '1000202') and speciesno = '010106' and sname like '{sourceCode}%'");
int childMaxBc = -1;
foreach (DataRow fileRow in filetable.Rows)
{
string fileName = fileRow["sname"] + "";
string fileId = fileRow["fileId"] + "";
GetFileCodeInfo(fileName, out string fileCode, out string name, out string fileBB, out int fileBC);
if (fileBC >= childMaxBc)
{
childMaxBc = fileBC;
}
}
if (beforeSourceCode.Equals(sourceCode) && sourceBC <= childMaxBc)//变更版次
{
throw new Exception($"变更版本{sourceBB}的版次{sourceBC}必须大于最大版次{childMaxBc}\r\n不允许变更");
}
if (!beforeSourceCode.Equals(sourceCode) && filetable.Rows.Count > 0)//变更版本
{
throw new Exception($"变更版本{sourceBB}已存在,请进行版次变更");
}
//StringBuilder insertbulider = new StringBuilder();
//string mxCode = BaseImpl.GetResult($"select MxFileName from FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';") + "";
//insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{beforeSourceCode}';");
//insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{topProductId}' and RelatedAttachmentName = '{sourceCode}';");
//insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{topProductId}','{mxCode}','{sourceCode}','{ERPInfo.Instance.UserName}','变更');");
//更新或新增并备份清单
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;
detailRow["bak"] = sourceCode;
detailRow["bombb"] = sourceBB;
detailRow["bombc"] = sourceBC;
}
SetProcessBar(20, allCount);
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid = '{topProductId}') as billdocument_id,'0' affirmer,'0' rtagid,'{topProductId}' as productid";
// 处理单据表头数据
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
if (masterRow == null)
{
throw new Exception($"BOM建立单{topProductId}不存在");
}
SetProcessBar(40, allCount);
frmBillInfo.AddOrUpdateBillByZZQD(masterRow, detailTable);
SetProcessBar(60, allCount);
string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid);
//BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider.ToString().Replace("'", "''")}' where guid = '{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")))
{
@@ -1460,6 +1505,10 @@ namespace Lskj.PubBomImport
{
throw new Exception($"变更版本{sourceBB}已存在,请进行版次变更");
}
//变更MX将原本的ZZQD数据进行档案备份
CopyZZQDToCopy(topProductId);
//更新或新增并备份清单
int.TryParse(Model.FirstRowIndex, out int index);
frmMain.FirstRowIndex = index;
@@ -1532,6 +1581,7 @@ namespace Lskj.PubBomImport
frmBillInfo.OnBillAdd();
SetProcessBar(0, 0);
SetProcessMsg($"正在导入:{Path.GetFileName(parentInfo.FullName)}");
string zzqdTag = "";
DataTable childTable = frmBillInfo.GcMainView.GridControl.DataSourceTable().Clone();
StringBuilder insertbulider = new StringBuilder();
insertbulider.AppendLine($"delete FileAttachmentMapping where MaterialCode = '{topProductId}';");
@@ -1573,7 +1623,8 @@ namespace Lskj.PubBomImport
}
else if (childCode.StartsWith("ZZQD"))
{
throw new Exception($"MX{sourceCode}未获取到ZZQD附件");
zzqdTag = childCode;
//throw new Exception($"{sourceCode}未获取到ZZQD附件");
}
}
if (childInfo != null)
@@ -1581,36 +1632,37 @@ namespace Lskj.PubBomImport
GetFileCodeInfo(Path.GetFileNameWithoutExtension(childInfo.Name).Trim(), out string childsourceCode, out string childsourceName, out string childsourceBB, out int childsourceBC);
if (childCode.StartsWith("ZZQD"))
{
DataTable zzqdTable = ExcelToDatatable(childInfo.FullName, Model, "", index);
//frmMain.Invoke(new Action(() =>
zzqdTag = childCode;
//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
//{
// 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["物料编码"] + "").Trim();
childRow["appellation"] = zzqdItem["名称"] + "";
childRow["bak"] = childsourceCode;
childRow["bombb"] = childsourceBB;
childRow["bombc"] = childsourceBC;
childRow["tamount"] = parentRow["套数"] + "";
int.TryParse(zzqdItem["数量"] + "", out int amount);
childRow["amount"] = amount * tamount;
childTable.Rows.Add(childRow);
}
// 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["物料编码"] + "").Trim();
// childRow["appellation"] = zzqdItem["名称"] + "";
// childRow["bak"] = childsourceCode;
// childRow["bombb"] = childsourceBB;
// childRow["bombc"] = childsourceBC;
// childRow["tamount"] = parentRow["套数"] + "";
// int.TryParse(zzqdItem["数量"] + "", out int amount);
// childRow["amount"] = amount * tamount;
// childTable.Rows.Add(childRow);
//}
}
else if (childCode.StartsWith("QD"))
{
@@ -1643,7 +1695,7 @@ namespace Lskj.PubBomImport
frmBillInfo.AddOrUpdateBill(masterRow, childTable);
SetProcessBar(60, allCount);
string guid = Guid.NewGuid() + "";
frmBillInfo.BillSaveSql(guid);
frmBillInfo.BillSaveSql(guid, zzqdTag);
BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider.ToString().Replace("'", "''")}' where guid = '{guid}'");
SetProcessBar(80, allCount);
//记录guid
@@ -1705,34 +1757,34 @@ namespace Lskj.PubBomImport
//insertbulider.AppendLine($"insert into FileAttachmentMapping (MaterialCode,MxFileName,RelatedAttachmentName,OperatorUser,ChangeStatus) values ('{topProductId}','{mxCode}','{sourceCode}','{ERPInfo.Instance.UserName}','变更');");
//BaseImpl.ExecSqlValue($"update p_bomImportExecTab set afterSql = '{insertbulider.ToString().Replace("'", "''")}' where guid = '{guid}'");
}
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.OK;
}));
}
this.Invoke(new Action(() =>
catch (Exception ex)
{
this.DialogResult = DialogResult.OK;
}));
}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
this.Invoke(new Action(() =>
MessageUtil.Show(ex.Message);
this.Invoke(new Action(() =>
{
this.DialogResult = DialogResult.Cancel;
}));
BaseImpl.ExecSqlValue($"delete QMS_wenjiangenggaitab where qms_wjgg_billdocument_Id = '{primaryValue}'");
}
finally
{
this.DialogResult = DialogResult.Cancel;
}));
BaseImpl.ExecSqlValue($"delete QMS_wenjiangenggaitab where qms_wjgg_billdocument_Id = '{primaryValue}'");
}
finally
{
this.Invoke(new Action(() =>
{
this.Close();
ImportTimer?.Dispose();
}));
}
});
task.Start();
};
frmBillInfo.OnLoad(Model);
frmMain.ParentView = frmBillInfo.GcMainView;
this.Invoke(new Action(() =>
{
this.Close();
ImportTimer?.Dispose();
}));
}
});
task.Start();
};
frmBillInfo.OnLoad(Model);
frmMain.ParentView = frmBillInfo.GcMainView;
}
}
catch (Exception ex)
{
@@ -4051,4 +4103,68 @@ namespace Lskj.PubBomImport
string pattern = @"^(.*?)(\d+)?$";
var match = Regex.Match(fileName, namepattern);
code = "";
spec = "";
spec = "";
name = "";
extension = "";
bb = "";
bc = 0;
if (match.Success)
{
code = match.Groups[1].Value.Trim();
spec = match.Groups[2].Value.Trim();
name = match.Groups[3].Value.Trim();
extension = match.Groups[4].Value.Trim();
match = Regex.Match(spec, pattern);
if (match.Success)
{
string childsourceCode = match.Groups[1].Value;
int.TryParse(match.Groups[2].Value, out bc);//版次
Match bbMatch = Regex.Match(childsourceCode, @"^.*?([A-Za-z]+)(\d*)$");
if (bbMatch.Success)
{
bb = bbMatch.Groups[1].Value.Trim();
}
}
return true;
}
else
{
return false;
}
}
private void CopyZZQDToCopy(string topProductId)
{
string zzqdCode = SqlHelper.ExecuteScalar($" SELECT bak FROM bom_BillListTab WHERE Billdocument_Id = (select top 1 billdocument_id from bom_BillTab where productid = '{topProductId}') and bak like 'ZZQD%';") + "";
DataTable copyTable = SqlHelper.ExecuteDataTable($"select top 1 billdocument_id from bom_billTab_copy where productid = '{zzqdCode}'");
if ((copyTable != null && copyTable.Rows.Count > 0) || string.IsNullOrEmpty(zzqdCode))
{
return;
}
string sql = $@"INSERT INTO bom_billTab_copy
(
ProductId, Builder, Auditor, Operatedate, Remark, TechnicsCode, TechnicsName, ProductPeriod,
Stuff_cost, Worker_cost, Billdocument_Id, stepOverName, stepOverId, stepOverTime, stepOver, endTime,
stepTime, happenTime, stepDirection, nextStepCode, stepCode, billType, Rtagid, OperatorId, Affirmer,
AffirmDate, ban, bom_appellation, bom_spec, bom_model, bom_ProductDescrip, waste_flag, waste_time,
waste_oper, pStepCode, printCount, printLastTime, printLastOper, previewCount, previewLastTime,
previewLastOper, cancelFlag, cancelTime, cancelOper, wasteoper, wastetime, enableflag, mappellation,
mspec, mmodel, clientid, BillModuleID, taoshu, Productunitname, productidbak, yfitemname, JYBJ,
str2, lskjimport_errorFlag, version, xn_tig, bak, bombb, bombc
)
SELECT top 1
'{zzqdCode}', Builder, Auditor, Operatedate, Remark, TechnicsCode, TechnicsName, ProductPeriod,
Stuff_cost, Worker_cost, Billdocument_Id, stepOverName, stepOverId, stepOverTime, stepOver, endTime,
stepTime, happenTime, stepDirection, nextStepCode, stepCode, billType, Rtagid, OperatorId, Affirmer,
AffirmDate, ban, bom_appellation, bom_spec, bom_model, bom_ProductDescrip, waste_flag, waste_time,
waste_oper, pStepCode, printCount, printLastTime, printLastOper, previewCount, previewLastTime,
previewLastOper, cancelFlag, cancelTime, cancelOper, wasteoper, wastetime, enableflag, mappellation,
mspec, mmodel, clientid, BillModuleID, taoshu, Productunitname, productidbak, yfitemname, JYBJ,
str2, lskjimport_errorFlag, version, xn_tig, bak, bombb, bombc
FROM bom_billTab where productid = '{topProductId}';
INSERT INTO bom_BillListTab_copy
(
ProductId, Famount, Amount, ParentProduct, amountx, ProcedureID, WorkingProcedure, Bak, Ver,
SoureMode, SoureObj, autoPick, Billdocument_Id, custom_ProductDescrip, bomFlag, encapsulation, serialnumber,
lsidx_id, workorderid, providerid, mx_ProductId, amountLoss, ProductSx, lstr1, lstr2, productidbak,
cltype, parentbillno, lskjimport_errorFlag, clProductId, bom_workordername, bom_workordernameTm, isbcp,
tamount,