SVN-Revision: r464
This commit is contained in:
wyf
2025-04-09 09:46:13 +00:00
parent fc0781a421
commit ffa4627f8f
8 changed files with 433 additions and 415 deletions
+153 -111
View File
@@ -1,111 +1,153 @@
/****************************** /******************************
* 说明:PubSpec 模块 * 说明:PubSpec 模块
* 创建人:龚宇超 * 创建人:龚宇超
* 创建日期:2018-01-02 * 创建日期:2018-01-02
* 修改人: * 修改人:
* 修改日期: * 修改日期:
* 修改备注: * 修改备注:
* 版本:1.0.0.0 * 版本:1.0.0.0
******************************/ ******************************/
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Lskj.Util; using Lskj.Util;
using Lskj.Business; using Lskj.Business;
using System.Windows.Forms; using System.Windows.Forms;
using Lskj.Model; using Lskj.Model;
using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Data; using System.Data;
using Lskj.Business.Impl;
namespace Lskj.PubBomImport
{ namespace Lskj.PubBomImport
/// <summary> {
/// PubSpec 模块 /// <summary>
/// </summary> /// PubSpec 模块
public class DllBaseClass : IForm /// </summary>
{ public class DllBaseClass : IForm
public DllBaseClass() {
{ public DllBaseClass()
{
}
public DllBaseClass(string[] obj) }
{ public DllBaseClass(string[] obj)
try {
{ try
FrmMain main = new FrmMain(); {
this.SubForm = main; FrmMain main = new FrmMain();
main.Model = new DynamicBomImport(obj); this.SubForm = main;
} main.Model = new DynamicBomImport(obj);
catch (Exception ex) }
{ catch (Exception ex)
LogUtil.WriteError("Lskj.PubSpecialImport.dll--参数错误-->" + obj.ToString(), ex); {
} LogUtil.WriteError("Lskj.PubSpecialImport.dll--参数错误-->" + obj.ToString(), ex);
} }
public Form SubForm { get; set; } }
} public Form SubForm { get; set; }
/// <summary> }
/// PubSpecialImport入库参数 /// <summary>
/// </summary> /// PubSpecialImport入库参数
public class DynamicBomImport : DynamicModel /// </summary>
{ public class DynamicBomImport : DynamicModel
public string MenuName = ""; {
public string FirstRowIndex = ""; public string PupupMenuId = "";
public string SpecialValueIndex = ""; public string MenuName = "";
public string SheetName = ""; public string FirstRowIndex = "";
/// <summary> public string SpecialValueIndex = "";
/// 读取筛选条件 public string SheetName = "";
/// </summary> /// <summary>
public string ReadTableCond = ""; /// 读取筛选条件
/// <summary> /// </summary>
/// 忽略合并明细列标题行 public string ReadTableCond = "";
/// </summary> /// <summary>
public bool CustomerServiceApp = false; /// 忽略合并明细列标题行
/// <summary> /// </summary>
/// 显示模式,如果为1则隐藏配置界面 public bool CustomerServiceApp = false;
/// </summary> /// <summary>
public string ShowType = ""; /// 显示模式,如果为1则隐藏配置界面
/// <summary> /// </summary>
/// 单据 BillMasterSql public string ShowType = "";
/// </summary> /// <summary>
public string BillMasterSql = ""; /// 单据 BillMasterSql
/// <summary> /// </summary>
/// 单据 BillDetailSql public string BillMasterSql = "";
/// </summary> /// <summary>
public string BillDetailSql = ""; /// 单据 BillDetailSql
public DynamicBomImport(string[] args) /// </summary>
: base(args) public string BillDetailSql = "";
{ /// <summary>
// 右键菜单打开的模块没有moduleId,部分特殊模块没有moduleId比如添加界面. /// 原始物料名称字段
MenuName = args[0]; /// </summary>
if (!string.IsNullOrEmpty(args[5])) public string BeforeBomFieldName = "";
{ /// <summary>
base.ModuleId = Convert.ToInt32(args[5]); /// 修改后物料名称字段
} /// </summary>
if (args.Length > 6 && !string.IsNullOrWhiteSpace(args[6])) public string AfterBomFieldName = "";
{ /// <summary>
base.ModuleCode = args[6]; /// 新增后的修改数据sql
} /// </summary>
if (args.Length > 7 && !string.IsNullOrWhiteSpace(args[7])) public string AfterAddBomSql = "";
{ public DynamicBomImport(string[] args)
FirstRowIndex = args[7] + ""; : base(args)
} {
if (args.Length > 8 && !string.IsNullOrWhiteSpace(args[8])) // 右键菜单打开的模块没有moduleId,部分特殊模块没有moduleId比如添加界面.
{ MenuName = args[0];
SpecialValueIndex = args[8] + "";
} if (args.Length > 5 && !string.IsNullOrWhiteSpace(args[5]))
if (args.Length > 9 && !string.IsNullOrWhiteSpace(args[9])) {
{ PupupMenuId = args[5] + "";
SheetName = args[9] + ""; }
} if (args.Length > 6 && !string.IsNullOrWhiteSpace(args[6]))
if (args.Length > 10 && !string.IsNullOrWhiteSpace(args[10])) {
{ base.ModuleCode = args[6] + "";
ReadTableCond = args[10] + ""; }
} if (args.Length > 7 && !string.IsNullOrWhiteSpace(args[7]))
if (args.Length > 11 && !string.IsNullOrWhiteSpace(args[11])) {
{ FirstRowIndex = args[7] + "";
CustomerServiceApp = (args[11] + "").Equals("1"); }
} if (args.Length > 8 && !string.IsNullOrWhiteSpace(args[8]))
if (args.Length > 12 && !string.IsNullOrWhiteSpace {
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<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"))
{
+1 -30
View File
@@ -483,33 +483,4 @@ namespace Lskj.PubBomImport
{ {
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;
}
}
}
}
+79 -57
View File
@@ -80,7 +80,7 @@ namespace Lskj.PubBomImport
InitGridColumns(); InitGridColumns();
InitMulitControl(); InitMulitControl();
InitDataSource(); InitDataSource();
if (showType) if (showTypeValue == 0 || showTypeValue == 3 || (showTypeValue > 0 && showType))
{ {
OnBtnImportClick(null, null); OnBtnImportClick(null, null);
} }
@@ -101,13 +101,45 @@ namespace Lskj.PubBomImport
{ {
try 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(); FolderBrowserDialog dialog = new FolderBrowserDialog();
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;
string dirPath = dialog.SelectedPath; string dirPath = dialog.SelectedPath;
FrmProgress frmProgress = new FrmProgress(); FrmProgress frmProgress = new FrmProgress();
frmProgress.frmMain = this; frmProgress.frmMain = this;
@@ -128,11 +160,13 @@ namespace Lskj.PubBomImport
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.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);
string dirPath = dialog.FileName; string dirPath = dialog.FileName;
FrmProgress frmProgress = new FrmProgress(); FrmProgress frmProgress = new FrmProgress();
frmProgress.frmMain = this; frmProgress.frmMain = this;
@@ -152,57 +186,61 @@ namespace Lskj.PubBomImport
} }
else if (Model.ShowType.Equals("3")) else if (Model.ShowType.Equals("3"))
{ {
OpenFileDialog dialog = new OpenFileDialog(); DataTable sourceTable = StaticControl.RightMenuGridView.GridControl.DataSourceTable();
dialog.Title = "选择导入文件"; if (StaticControl.RightMenuGridView.Tag is Dictionary<string, string> filesDic)
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 frmProgress = new FrmProgress();
frmProgress.frmMain = this; frmProgress.frmMain = this;
frmProgress.Model = Model;
frmProgress.ImportTimer.Tick += (ts, te) => frmProgress.ImportTimer.Tick += (ts, te) =>
{ {
frmProgress.ImportTimer.Enabled = false; frmProgress.ImportTimer.Enabled = false;
frmProgress.StartImportInQDFile(dirPath); frmProgress.StartImportInQDFile(sourceTable, filesDic);
}; };
frmProgress.ImportTimer.Enabled = true; frmProgress.ImportTimer.Enabled = true;
frmProgress.OnImportCallBack += OnImportCallBack; DialogResult dialogResult = frmProgress.ShowDialog();
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(); 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) catch (Exception ex)
{ {
MessageUtil.Show(ex.Message); MessageUtil.Show(ex.Message);
@@ -213,22 +251,6 @@ namespace Lskj.PubBomImport
this.Dispose(); this.Dispose();
} }
} }
/// <summary>
/// 导入后关闭回调
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnImportCallBack(object sender, EventArgs e)
{
FormDialogModel dialogModel = new FormDialogModel()
{
DialogDllName = "Lskj.PubBomImport.dll",
PubDialogType = DialogType.PubAddRecord,
ReturnTag = Model.ShowType
};
this.Tag = dialogModel;
}
/// <summary> /// <summary>
/// 读取按钮点击 /// 读取按钮点击
/// </summary> /// </summary>
+150 -217
View File
@@ -35,6 +35,7 @@ using Lskj.Business.Impl;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Lskj.Util; using Lskj.Util;
using System.Web; using System.Web;
using Lskj.Control.Model;
namespace Lskj.PubBomImport namespace Lskj.PubBomImport
{ {
@@ -44,10 +45,6 @@ namespace Lskj.PubBomImport
/// </summary> /// </summary>
public partial class FrmProgress : Form public partial class FrmProgress : Form
{ {
/// <summary>
/// Occurs when [on add record call back].
/// </summary>
public event EventHandler OnImportCallBack;
public FrmMain frmMain; public FrmMain frmMain;
public DynamicBomImport Model; public DynamicBomImport Model;
public System.Windows.Forms.Timer ImportTimer = new System.Windows.Forms.Timer(); public System.Windows.Forms.Timer ImportTimer = new System.Windows.Forms.Timer();
@@ -508,260 +505,196 @@ namespace Lskj.PubBomImport
/// 开始导入3 /// 开始导入3
/// </summary> /// </summary>
/// <param name="dirPaths"></param> /// <param name="dirPaths"></param>
public void StartImportInQDFile(string dirPath) public void StartImportInQDFile(DataTable sourceTable, Dictionary<string, string> filesDic)
{ {
try try
{ {
Model = frmMain.Model; foreach (DataRow sourceRow in sourceTable.Rows)
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)
{ {
string sourceModel = match.Groups[1].Value; if (sourceRow.RowState == DataRowState.Deleted)
string sourceVersion = match.Groups[2].Value; {
sourceVersion = string.IsNullOrEmpty(sourceVersion) ? "0" : sourceVersion; continue;
//修改后的文件名 }
string newProductCode = Model.MaintabFocusedRow != null && Model.MaintabFocusedRow.Table.Columns.Contains("qms_laddf_appellationV123") ? Model.MaintabFocusedRow["qms_laddf_appellationV123"] + "" : ""; string fileName = sourceRow[Model.AfterBomFieldName] + "";
FileInfo parentInfo = new FileInfo(dirPath); 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"))) if (parentInfo != null && (parentInfo.Name.Trim().StartsWith("QD") || parentInfo.Name.Trim().StartsWith("ZZQD")))
{ {
string code = ""; string code = "";
string name = ""; string name = "";
string newcode = newProductCode.Trim();
string newname = "";
string namepattern = @"^(.+?)\s+(.+)$"; string namepattern = @"^(.+?)\s+(.+)$";
Match newProductCodematch = Regex.Match(Path.GetFileNameWithoutExtension(newProductCode).Trim(), namepattern);
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;
name = namematch.Groups[2].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; stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{code}')");
newname = newProductCodematch.Groups[2].Value; 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; foreach (DataRow sourceRow in sourceTable.Rows)
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)
{ {
//如果存在相同版本的文件 if (sourceRow.RowState == DataRowState.Deleted)
throw new Exception("已经存在相同版本的文件");
}
else
{
if (sourceModel.Equals(newModel))
{ {
//新建清单 continue;
StringBuilder stringBuilder = new StringBuilder(); }
if (code.StartsWith("QD") || code.StartsWith("ZZQD")) 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}')"); string code = "";
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak,SpeciesNo) values ('{code.Replace("'", "''")}','{name.Replace("'", "''")}','','0199') end;"); string name = "";
} string namepattern = @"^(.+?)\s+(.+)$";
if (!string.IsNullOrEmpty(stringBuilder.ToString())) Match namematch = Regex.Match(Path.GetFileNameWithoutExtension(parentInfo.Name).Trim(), namepattern);
{ if (namematch.Success)
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
}
//更新并备份清单
FrmBillInfo frmBillInfo = new FrmBillInfo();
frmBillInfo.OnControlSourceBind += (s, args) =>
{
Task task = new Task(() =>
{ {
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); FileInfo childInfo = new FileInfo(dirPath);
frmMain.FirstRowIndex = index; if (childInfo != null)
if (code.StartsWith("QD") || code.StartsWith("ZZQD"))
{ {
FileInfo childInfo = new FileInfo(dirPath); frmBillInfo.OnBillAdd();
if (childInfo != null) SetProcessBar(0, allCount);
SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}");
DataTable detailTable = new DataTable();
frmMain.Invoke(new Action(() =>
{ {
frmBillInfo.OnBillAdd(); detailTable = frmMain.ToExcelDataTable(childInfo.FullName, out int count, out int errorCount, true);
SetProcessBar(0, 0); }));
SetProcessMsg($"正在导入:{Path.GetFileName(childInfo.FullName)}"); foreach (DataRow detailRow in detailTable.Rows)
DataTable detailTable = new DataTable(); {
frmMain.Invoke(new Action(() => 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); sourceRow["qms_laddf_RelatedId"] = billNo;
}));
foreach (DataRow detailRow in detailTable.Rows)
{
int.TryParse(detailRow["amount"] + "", out int lastAmount);
detailRow["tamount"] = 1;
detailRow["amount"] = lastAmount;
} }
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"; //执行配置的保存后sql
billMasterSql = ReplaceHelper.ReplaceRowParam(Model.MaintabFocusedRow, billMasterSql); if (!string.IsNullOrEmpty(Model.AfterAddBomSql))
// 处理单据表头数据
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
{ {
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) }
{ else
MessageUtil.Show(ex.Message); {
} throw new Exception($"文件名{code}不符合规则");
finally }
{ }
if (this.OnImportCallBack != null) else
this.OnImportCallBack(null, null); {
this.DialogResult = DialogResult.OK; MessageUtil.Show("不是QD或ZZQD文件");
this.Close(); this.DialogResult = DialogResult.Cancel;
ImportTimer?.Dispose(); Close();
} ImportTimer?.Dispose();
}); }
task.Start();
};
frmBillInfo.OnLoad(Model);
frmMain.ParentView = frmBillInfo.GcMainView;
} }
else else
{ {
//新建清单 throw new Exception($"文件名{productCode}不符合规则");
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;
} }
} }
this.DialogResult = DialogResult.OK;
} }
else catch (Exception ex)
{ {
throw new Exception($"文件名{code}不符合规则"); MessageUtil.Show(ex.Message);
this.DialogResult = DialogResult.Cancel;
} }
} finally
else {
{ this.Close();
MessageUtil.Show("不是QD或ZZQD文件"); ImportTimer?.Dispose();
this.DialogResult = DialogResult.Cancel; }
Close(); });
ImportTimer?.Dispose(); task.Start();
} };
} frmBillInfo.OnLoad(Model);
else frmMain.ParentView = frmBillInfo.GcMainView;
{
throw new Exception($"文件名{productCode}不符合规则");
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -84,6 +84,11 @@
<DependentUpon>FrmProgress.cs</DependentUpon> <DependentUpon>FrmProgress.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" /> <Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -124,5 +129,12 @@
<Name>Lskj.Util</Name> <Name>Lskj.Util</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
@@ -0,0 +1,14 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Lskj.PubBomImport.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttrib
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Lskj.PubBomImport.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="LastSelectFolder" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Lskj.PubBomImport.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<Lskj.PubBomImport.Properties.Settings>
<setting name="LastSelectFolder" serializeAs="String">
<value />
</setting>
</Lskj.PubBomImport.Properties.Settings>
</userSettings>
</configuration>