diff --git a/插件库/Lskj.PubBomImport/DllBaseClass.cs b/插件库/Lskj.PubBomImport/DllBaseClass.cs
index eee1110..9da94f1 100644
--- a/插件库/Lskj.PubBomImport/DllBaseClass.cs
+++ b/插件库/Lskj.PubBomImport/DllBaseClass.cs
@@ -1,111 +1,153 @@
-/******************************
-* 说明: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;
-
-namespace Lskj.PubBomImport
-{
- ///
- /// PubSpec 模块
- ///
- 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; }
- }
- ///
- /// PubSpecialImport入库参数
- ///
- public class DynamicBomImport : DynamicModel
- {
- public string MenuName = "";
- public string FirstRowIndex = "";
- public string SpecialValueIndex = "";
- public string SheetName = "";
- ///
- /// 读取筛选条件
- ///
- public string ReadTableCond = "";
- ///
- /// 忽略合并明细列标题行
- ///
- public bool CustomerServiceApp = false;
- ///
- /// 显示模式,如果为1则隐藏配置界面
- ///
- public string ShowType = "";
- ///
- /// 单据 BillMasterSql
- ///
- public string BillMasterSql = "";
- ///
- /// 单据 BillDetailSql
- ///
- public string BillDetailSql = "";
- public DynamicBomImport(string[] args)
- : base(args)
- {
- // 右键菜单打开的模块没有moduleId,部分特殊模块没有moduleId比如添加界面.
- MenuName = args[0];
- if (!string.IsNullOrEmpty(args[5]))
- {
- base.ModuleId = Convert.ToInt32(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]))
- {
- SpecialValueIndex = 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
\ No newline at end of file
+/******************************
+* 说明: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
+{
+ ///
+ /// PubSpec 模块
+ ///
+ 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; }
+ }
+ ///
+ /// PubSpecialImport入库参数
+ ///
+ public class DynamicBomImport : DynamicModel
+ {
+ public string PupupMenuId = "";
+ public string MenuName = "";
+ public string FirstRowIndex = "";
+ public string SpecialValueIndex = "";
+ public string SheetName = "";
+ ///
+ /// 读取筛选条件
+ ///
+ public string ReadTableCond = "";
+ ///
+ /// 忽略合并明细列标题行
+ ///
+ public bool CustomerServiceApp = false;
+ ///
+ /// 显示模式,如果为1则隐藏配置界面
+ ///
+ public string ShowType = "";
+ ///
+ /// 单据 BillMasterSql
+ ///
+ public string BillMasterSql = "";
+ ///
+ /// 单据 BillDetailSql
+ ///
+ public string BillDetailSql = "";
+ ///
+ /// 原始物料名称字段
+ ///
+ public string BeforeBomFieldName = "";
+ ///
+ /// 修改后物料名称字段
+ ///
+ public string AfterBomFieldName = "";
+ ///
+ /// 新增后的修改数据sql
+ ///
+ 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]))
+ {
+ SpecialValueIndex = 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(args[args.Length - 1]);
+ JArray jArray = new JArray();
+ jArray.Add(rowObject);
+ DataTable dataTable = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(jArray));
+ this.MaintabFocusedRow = dataTable.Rows[0];
+ }
+ catch (Exception)
+ {
+ }
+ }
+ if (BaseImpl.HasExistsTable("p_systemPopupPmsTab"))
+ {
\ No newline at end of file
diff --git a/插件库/Lskj.PubBomImport/FrmBillInfo.cs b/插件库/Lskj.PubBomImport/FrmBillInfo.cs
index b06b68f..d72e71d 100644
--- a/插件库/Lskj.PubBomImport/FrmBillInfo.cs
+++ b/插件库/Lskj.PubBomImport/FrmBillInfo.cs
@@ -483,33 +483,4 @@ namespace Lskj.PubBomImport
{
string productId = sourceRow["ProductId"] + "";
DataRow newSourceRow = newSource.Rows.Cast().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;
- }
- }
- }
-}
+
\ No newline at end of file
diff --git a/插件库/Lskj.PubBomImport/FrmMain.cs b/插件库/Lskj.PubBomImport/FrmMain.cs
index a9e3a46..20ea0c4 100644
--- a/插件库/Lskj.PubBomImport/FrmMain.cs
+++ b/插件库/Lskj.PubBomImport/FrmMain.cs
@@ -80,7 +80,7 @@ namespace Lskj.PubBomImport
InitGridColumns();
InitMulitControl();
InitDataSource();
- if (showType)
+ if (showTypeValue == 0 || showTypeValue == 3 || (showTypeValue > 0 && showType))
{
OnBtnImportClick(null, null);
}
@@ -101,13 +101,45 @@ namespace Lskj.PubBomImport
{
try
{
- if (Model.ShowType.Equals("1"))
+ if (Model.ShowType.Equals("0"))//多选文件并返回到表中
+ {
+ OpenFileDialog dialog = new OpenFileDialog();
+ dialog.Multiselect = true;
+ dialog.InitialDirectory = Properties.Settings.Default.LastSelectFolder;
+ dialog.Title = "选择导入文件";
+ dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
+ DialogResult dialogResult = dialog.ShowDialog();
+ if (dialogResult == DialogResult.OK)
+ {
+ Properties.Settings.Default.LastSelectFolder = Path.GetDirectoryName(dialog.FileName);
+ BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
+ {
+ ShowType = Model.ShowType,
+ AfterBomFieldName = Model.AfterBomFieldName,
+ FileNames = dialog.FileNames
+ };
+ FormDialogModel dialogModel = new FormDialogModel()
+ {
+ DialogDllName = "Lskj.PubBomImport.dll",
+ PubDialogType = DialogType.PubAddRecord,
+ ReturnTag = bomImpRtnModel
+ };
+ this.Tag = dialogModel;
+ }
+ else
+ {
+ this.Close();
+ }
+ }
+ else if (Model.ShowType.Equals("1"))
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
+ dialog.SelectedPath = Properties.Settings.Default.LastSelectFolder;
dialog.Description = "选择导入文件夹";
DialogResult dialogResult = dialog.ShowDialog();
if (dialogResult == DialogResult.OK)
{
+ Properties.Settings.Default.LastSelectFolder = dialog.SelectedPath;
string dirPath = dialog.SelectedPath;
FrmProgress frmProgress = new FrmProgress();
frmProgress.frmMain = this;
@@ -128,11 +160,13 @@ namespace Lskj.PubBomImport
else if (Model.ShowType.Equals("2"))
{
OpenFileDialog dialog = new OpenFileDialog();
+ dialog.InitialDirectory = Properties.Settings.Default.LastSelectFolder;
dialog.Title = "选择导入文件";
dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
DialogResult dialogResult = dialog.ShowDialog();
if (dialogResult == DialogResult.OK)
{
+ Properties.Settings.Default.LastSelectFolder = Path.GetDirectoryName(dialog.FileName);
string dirPath = dialog.FileName;
FrmProgress frmProgress = new FrmProgress();
frmProgress.frmMain = this;
@@ -152,57 +186,61 @@ namespace Lskj.PubBomImport
}
else if (Model.ShowType.Equals("3"))
{
- OpenFileDialog dialog = new OpenFileDialog();
- dialog.Title = "选择导入文件";
- dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
- DialogResult dialogResult = dialog.ShowDialog();
- if (dialogResult == DialogResult.OK)
+ DataTable sourceTable = StaticControl.RightMenuGridView.GridControl.DataSourceTable();
+ if (StaticControl.RightMenuGridView.Tag is Dictionary filesDic)
{
- string dirPath = dialog.FileName;
FrmProgress frmProgress = new FrmProgress();
frmProgress.frmMain = this;
+ frmProgress.Model = Model;
frmProgress.ImportTimer.Tick += (ts, te) =>
{
frmProgress.ImportTimer.Enabled = false;
- frmProgress.StartImportInQDFile(dirPath);
+ frmProgress.StartImportInQDFile(sourceTable, filesDic);
};
frmProgress.ImportTimer.Enabled = true;
- frmProgress.OnImportCallBack += OnImportCallBack;
- frmProgress.ShowDialog();
-
+ DialogResult dialogResult = frmProgress.ShowDialog();
+ BomImpRtnModel bomImpRtnModel = new BomImpRtnModel()
+ {
+ ShowType = Model.ShowType,
+ AfterBomFieldName = Model.AfterBomFieldName,
+ CanSave = dialogResult == DialogResult.OK
+ };
+ FormDialogModel dialogModel = new FormDialogModel()
+ {
+ DialogDllName = "Lskj.PubBomImport.dll",
+ PubDialogType = DialogType.PubAddRecord,
+ ReturnTag = bomImpRtnModel
+ };
+ this.Tag = dialogModel;
frmProgress.Dispose();
}
- else
- {
- this.Close();
- }
}
- //else if (Model.ShowType.Equals("4"))//禁用
- //{
- // OpenFileDialog dialog = new OpenFileDialog();
- // dialog.Title = "选择导入文件";
- // dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
- // DialogResult dialogResult = dialog.ShowDialog();
- // if (dialogResult == DialogResult.OK)
- // {
- // string dirPath = dialog.FileName;
- // FrmProgress frmProgress = new FrmProgress();
- // frmProgress.frmMain = this;
- // frmProgress.ImportTimer.Tick += (ts, te) =>
- // {
- // frmProgress.ImportTimer.Enabled = false;
- // frmProgress.StartImportInMxFileNew(dirPath);
- // };
- // frmProgress.ImportTimer.Enabled = true;
- // frmProgress.ShowDialog();
- // frmProgress.Dispose();
- // }
- // else
- // {
- // this.Close();
- // }
- //}
}
+ //else if (Model.ShowType.Equals("4"))//禁用
+ //{
+ // OpenFileDialog dialog = new OpenFileDialog();
+ // dialog.Title = "选择导入文件";
+ // dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
+ // DialogResult dialogResult = dialog.ShowDialog();
+ // if (dialogResult == DialogResult.OK)
+ // {
+ // string dirPath = dialog.FileName;
+ // FrmProgress frmProgress = new FrmProgress();
+ // frmProgress.frmMain = this;
+ // frmProgress.ImportTimer.Tick += (ts, te) =>
+ // {
+ // frmProgress.ImportTimer.Enabled = false;
+ // frmProgress.StartImportInMxFileNew(dirPath);
+ // };
+ // frmProgress.ImportTimer.Enabled = true;
+ // frmProgress.ShowDialog();
+ // frmProgress.Dispose();
+ // }
+ // else
+ // {
+ // this.Close();
+ // }
+ //}
catch (Exception ex)
{
MessageUtil.Show(ex.Message);
@@ -213,22 +251,6 @@ namespace Lskj.PubBomImport
this.Dispose();
}
}
- ///
- /// 导入后关闭回调
- ///
- ///
- ///
- private void OnImportCallBack(object sender, EventArgs e)
- {
- FormDialogModel dialogModel = new FormDialogModel()
- {
- DialogDllName = "Lskj.PubBomImport.dll",
- PubDialogType = DialogType.PubAddRecord,
- ReturnTag = Model.ShowType
- };
- this.Tag = dialogModel;
- }
-
///
/// 读取按钮点击
///
diff --git a/插件库/Lskj.PubBomImport/FrmProgress.cs b/插件库/Lskj.PubBomImport/FrmProgress.cs
index dfff309..6e6684b 100644
--- a/插件库/Lskj.PubBomImport/FrmProgress.cs
+++ b/插件库/Lskj.PubBomImport/FrmProgress.cs
@@ -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
///
public partial class FrmProgress : Form
{
- ///
- /// Occurs when [on add record call back].
- ///
- 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
///
///
- public void StartImportInQDFile(string dirPath)
+ public void StartImportInQDFile(DataTable sourceTable, Dictionary 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)
{
diff --git a/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj b/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj
index f1f4c84..26a1444 100644
--- a/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj
+++ b/插件库/Lskj.PubBomImport/Lskj.PubBomImport.csproj
@@ -84,6 +84,11 @@
FrmProgress.cs
+
+ True
+ True
+ Settings.settings
+
@@ -124,5 +129,12 @@
Lskj.Util
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
\ No newline at end of file
diff --git a/插件库/Lskj.PubBomImport/Properties/Settings.Designer.cs b/插件库/Lskj.PubBomImport/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..be00b06
--- /dev/null
+++ b/插件库/Lskj.PubBomImport/Properties/Settings.Designer.cs
@@ -0,0 +1,14 @@
+//------------------------------------------------------------------------------
+//
+// 此代码由工具生成。
+// 运行时版本:4.0.30319.42000
+//
+// 对此文件的更改可能会导致不正确的行为,并且如果
+// 重新生成代码,这些更改将会丢失。
+//
+//------------------------------------------------------------------------------
+
+namespace Lskj.PubBomImport.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttrib
\ No newline at end of file
diff --git a/插件库/Lskj.PubBomImport/Properties/Settings.settings b/插件库/Lskj.PubBomImport/Properties/Settings.settings
new file mode 100644
index 0000000..ecda03c
--- /dev/null
+++ b/插件库/Lskj.PubBomImport/Properties/Settings.settings
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/插件库/Lskj.PubBomImport/app.config b/插件库/Lskj.PubBomImport/app.config
new file mode 100644
index 0000000..7078b78
--- /dev/null
+++ b/插件库/Lskj.PubBomImport/app.config
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file