SVN r389
SVN-Revision: r389
This commit is contained in:
+1
-1
@@ -642,9 +642,9 @@ namespace Lskj.PubBomImport
|
||||
//
|
||||
// FrmBillInfo
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(666, 518);
|
||||
this.Controls.Add(this.pl_main);
|
||||
this.Name = "FrmBillInfo";
|
||||
this.Size = new System.Drawing.Size(666, 518);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_main)).EndInit();
|
||||
this.pl_main.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_main_center)).EndInit();
|
||||
|
||||
@@ -19,12 +19,13 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Lskj.PubBomImport
|
||||
{
|
||||
public partial class FrmBillInfo : Form
|
||||
public partial class FrmBillInfo : UserControl
|
||||
{
|
||||
public DynamicBomImport Model;
|
||||
public DynamicBillModel SysModel;
|
||||
public BillModel billModel;
|
||||
public MyControl ControlObj;
|
||||
public event EventHandler OnControlSourceBind;
|
||||
/// <summary>
|
||||
/// 单据明细列
|
||||
/// </summary>
|
||||
@@ -76,6 +77,13 @@ namespace Lskj.PubBomImport
|
||||
DataTable groups = BaseModuleImpl.GetAddGroupData(billModel.FormKey);//获取主信息分组数据
|
||||
ControlObj = new MyControl() { Model = SysModel };//主表控件
|
||||
ControlObj.OtherParams = SysModel.OtherParams();
|
||||
ControlObj.OnDataSourceBindCallBack += (s, e) =>
|
||||
{
|
||||
if (OnControlSourceBind != null)
|
||||
{
|
||||
OnControlSourceBind(null, null);
|
||||
}
|
||||
};
|
||||
ControlObj.InitControl(controls, this.pl_main_center_master, groups);
|
||||
if (SysModel.GridEnumObj == GridEnum.BandedGridView || billModel.AutoMultiHeader == 1)
|
||||
{
|
||||
|
||||
@@ -100,148 +100,37 @@ namespace Lskj.PubBomImport
|
||||
{
|
||||
try
|
||||
{
|
||||
//bool showType = Model != null && Model.ShowType.Equals("1") && !ERPInfo.Instance.UserName.Equals("管理员");
|
||||
//string fileName = importFileName;
|
||||
//if (File.Exists(fileName))
|
||||
//{
|
||||
// this.Hide();
|
||||
// WaitForm.ShowForm("正在导入数据...");
|
||||
// this.ParentView.GridControl.DataSource = this.ToExcelDataTable(fileName, out int count, out int errorCount, true);
|
||||
// WaitForm.HideForm();
|
||||
// if (!showType)
|
||||
// {
|
||||
// MessageUtil.Show(string.Format("成功导入{0}条数据,错误{1}条数据", count, errorCount));
|
||||
// }
|
||||
// this.Close();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// MessageUtil.Show("导入Excel文件不存在");
|
||||
// tipsEdit.Text = "请导入Excel模板";
|
||||
// btnImport.Enabled = false;
|
||||
//}
|
||||
//DialogResult dialogResult = frmBillInfo.ShowDialog();
|
||||
//if (dialogResult == DialogResult.OK)
|
||||
//{
|
||||
//}
|
||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||
dialog.Description = "选择导入文件夹";
|
||||
DialogResult dialogResult = dialog.ShowDialog();
|
||||
if (dialogResult == DialogResult.OK)
|
||||
{
|
||||
WaitForm.ShowForm("数据导入中");
|
||||
string dirPath = dialog.SelectedPath;
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(dirPath);
|
||||
FileInfo[] fileInfos = directoryInfo.GetFiles();
|
||||
FileInfo parentInfo = fileInfos.Where(n => n.Name.StartsWith("MX") && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (parentInfo != null)
|
||||
FrmProgress frmProgress = new FrmProgress();
|
||||
frmProgress.frmMain = this;
|
||||
frmProgress.ImportTimer.Tick += (ts, te) =>
|
||||
{
|
||||
WaitForm.ShowForm("数据导入中");
|
||||
DataTable parentTable = ExcelToDatatable(parentInfo.FullName, "", 5);
|
||||
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (DataRow dataRow in parentTable.Rows)
|
||||
{
|
||||
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{(dataRow["图号"] + "").Trim()}')");
|
||||
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak) values ('{(dataRow["图号"] + "").Trim().Replace("'", "''")}','{(dataRow["名称"] + "").Trim().Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}') end;");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||
}
|
||||
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
||||
frmBillInfo.OnLoad(Model);
|
||||
ParentView = frmBillInfo.GcMainView;
|
||||
frmBillInfo.ControlObj.OnDataSourceBindCallBack += (s, args) =>
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
WaitForm.ShowForm("数据导入中");
|
||||
DataTable childTable = new DataTable();
|
||||
foreach (GridColumn gridColumn in ParentView.Columns)
|
||||
{
|
||||
if (!childTable.Columns.Contains(gridColumn.FieldName))
|
||||
{
|
||||
childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType);
|
||||
}
|
||||
}
|
||||
foreach (DataRow parentRow in parentTable.Rows)
|
||||
{
|
||||
DataRow childRow = childTable.NewRow();
|
||||
childRow["ProductId"] = (parentRow["图号"] + "").Trim();
|
||||
childRow["appellation"] = (parentRow["名称"] + "").Trim();
|
||||
childRow["bak"] = (parentRow["备注"] + "").Trim();
|
||||
childRow["tamount"] = parentRow["套数"] + "";
|
||||
childRow["amount"] = parentRow["套数"] + "";
|
||||
childTable.Rows.Add(childRow);
|
||||
}
|
||||
ParentView.GridControl.DataSource = childTable;
|
||||
string controlSql = "select '' as billdocument_id,'0' affirmer,'0' rtagid,'{材料代码}' as productid";
|
||||
frmBillInfo.InitializeHeader(Model.MaintabFocusedRow, controlSql);
|
||||
frmBillInfo.BillSave();
|
||||
frmBillInfo.OnBillAdd();
|
||||
string productId = (Model.MaintabFocusedRow["材料代码"] + "").Trim();
|
||||
string billdocumentId = (Model.MaintabFocusedRow["单据编号"] + "").Trim();
|
||||
string updateParentVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id='{1}' and ProductId='{0}'";
|
||||
SqlHelper.ExecuteNonQuery(string.Format(updateParentVerSql, productId, billdocumentId));
|
||||
int.TryParse(Model.FirstRowIndex, out int index);
|
||||
FirstRowIndex = index;
|
||||
foreach (DataRow dataRow in parentTable.Rows)
|
||||
{
|
||||
int.TryParse(dataRow["套数"] + "", out int tamount);
|
||||
string code = (dataRow["图号"] + "").Trim();
|
||||
FileInfo childInfo = fileInfos.Where(n => n.Name.Contains(code) && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (childInfo != null)
|
||||
{
|
||||
DataTable detailTable = this.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"] = tamount;
|
||||
detailRow["amount"] = tamount > 0 ? (lastAmount * tamount) + "" : lastAmount + "";
|
||||
}
|
||||
ParentView.GridControl.DataSource = detailTable;
|
||||
frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql);
|
||||
frmBillInfo.BillSave();
|
||||
frmBillInfo.OnBillAdd();
|
||||
string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'";
|
||||
SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
WaitForm.HideForm();
|
||||
this.Close();
|
||||
}
|
||||
}));
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitForm.HideForm();
|
||||
MessageUtil.Show("未包含结构文件");
|
||||
this.Close();
|
||||
}
|
||||
frmProgress.ImportTimer.Enabled = false;
|
||||
frmProgress.StartImport(dirPath);
|
||||
};
|
||||
frmProgress.ImportTimer.Enabled = true;
|
||||
frmProgress.ShowDialog();
|
||||
frmProgress.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitForm.HideForm();
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WaitForm.HideForm();
|
||||
MessageUtil.Show(ex.Message);
|
||||
this.Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取按钮点击
|
||||
@@ -973,7 +862,7 @@ namespace Lskj.PubBomImport
|
||||
/// <param name="isDirectImport"></param>
|
||||
/// <param name="isBillImport"></param>
|
||||
/// <returns></returns>
|
||||
private DataTable ToExcelDataTable(string fileName, out int count, out int errorCount, bool isDirectImport = false, bool isBillImport = false)
|
||||
public DataTable ToExcelDataTable(string fileName, out int count, out int errorCount, bool isDirectImport = false, bool isBillImport = false)
|
||||
{
|
||||
count = 0;
|
||||
errorCount = 0;
|
||||
@@ -1737,4 +1626,31 @@ namespace Lskj.PubBomImport
|
||||
{
|
||||
case CellType.String:
|
||||
cellValue = cell.StringCellValue;
|
||||
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
cellValue = cell.NumericCellValue.ToString();
|
||||
break;
|
||||
case CellType.Boolean:
|
||||
cellValue = cell.BooleanCellValue.ToString();
|
||||
break;
|
||||
case CellType.Blank:
|
||||
break;
|
||||
default:
|
||||
cellValue.ToString();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cellValue = cell.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return cellValue;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
namespace Lskj.PubBomImport
|
||||
{
|
||||
partial class FrmProgress
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmProgress));
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.splitter1 = new System.Windows.Forms.Splitter();
|
||||
this.progressBarTotal = new System.Windows.Forms.ProgressBar();
|
||||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
this.labelCurrentItem = new System.Windows.Forms.Label();
|
||||
this.progressBarCurrent = new System.Windows.Forms.ProgressBar();
|
||||
this.lblAll = new System.Windows.Forms.Label();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.splitter2 = new System.Windows.Forms.Splitter();
|
||||
this.panel2.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label3.Location = new System.Drawing.Point(11, 8);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(104, 12);
|
||||
this.label3.TabIndex = 0;
|
||||
this.label3.Text = "系统正在导入Bom";
|
||||
//
|
||||
// splitter1
|
||||
//
|
||||
this.splitter1.BackColor = System.Drawing.SystemColors.InactiveBorder;
|
||||
this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.splitter1.Location = new System.Drawing.Point(0, 31);
|
||||
this.splitter1.Name = "splitter1";
|
||||
this.splitter1.Size = new System.Drawing.Size(462, 2);
|
||||
this.splitter1.TabIndex = 10;
|
||||
this.splitter1.TabStop = false;
|
||||
//
|
||||
// progressBarTotal
|
||||
//
|
||||
this.progressBarTotal.Location = new System.Drawing.Point(16, 71);
|
||||
this.progressBarTotal.Name = "progressBarTotal";
|
||||
this.progressBarTotal.Size = new System.Drawing.Size(438, 12);
|
||||
this.progressBarTotal.Step = 1;
|
||||
this.progressBarTotal.TabIndex = 4;
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
this.panel2.Controls.Add(this.progressBarTotal);
|
||||
this.panel2.Controls.Add(this.labelCurrentItem);
|
||||
this.panel2.Controls.Add(this.progressBarCurrent);
|
||||
this.panel2.Controls.Add(this.lblAll);
|
||||
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panel2.ForeColor = System.Drawing.SystemColors.ControlDark;
|
||||
this.panel2.Location = new System.Drawing.Point(0, 31);
|
||||
this.panel2.Name = "panel2";
|
||||
this.panel2.Size = new System.Drawing.Size(462, 101);
|
||||
this.panel2.TabIndex = 8;
|
||||
//
|
||||
// labelCurrentItem
|
||||
//
|
||||
this.labelCurrentItem.AutoSize = true;
|
||||
this.labelCurrentItem.Location = new System.Drawing.Point(14, 16);
|
||||
this.labelCurrentItem.Name = "labelCurrentItem";
|
||||
this.labelCurrentItem.Size = new System.Drawing.Size(65, 12);
|
||||
this.labelCurrentItem.TabIndex = 0;
|
||||
this.labelCurrentItem.Text = "正在导入:";
|
||||
//
|
||||
// progressBarCurrent
|
||||
//
|
||||
this.progressBarCurrent.Location = new System.Drawing.Point(15, 33);
|
||||
this.progressBarCurrent.Name = "progressBarCurrent";
|
||||
this.progressBarCurrent.Size = new System.Drawing.Size(438, 12);
|
||||
this.progressBarCurrent.Step = 1;
|
||||
this.progressBarCurrent.TabIndex = 5;
|
||||
//
|
||||
// lblAll
|
||||
//
|
||||
this.lblAll.AutoSize = true;
|
||||
this.lblAll.Location = new System.Drawing.Point(14, 55);
|
||||
this.lblAll.Name = "lblAll";
|
||||
this.lblAll.Size = new System.Drawing.Size(53, 12);
|
||||
this.lblAll.TabIndex = 2;
|
||||
this.lblAll.Text = "总进度:";
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.BackColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||
this.panel1.Controls.Add(this.label3);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(462, 31);
|
||||
this.panel1.TabIndex = 7;
|
||||
//
|
||||
// splitter2
|
||||
//
|
||||
this.splitter2.BackColor = System.Drawing.SystemColors.InactiveBorder;
|
||||
this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.splitter2.Location = new System.Drawing.Point(0, 132);
|
||||
this.splitter2.Name = "splitter2";
|
||||
this.splitter2.Size = new System.Drawing.Size(462, 2);
|
||||
this.splitter2.TabIndex = 11;
|
||||
this.splitter2.TabStop = false;
|
||||
//
|
||||
// FrmProgress
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(462, 134);
|
||||
this.Controls.Add(this.splitter1);
|
||||
this.Controls.Add(this.panel2);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.splitter2);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
|
||||
@@ -0,0 +1,559 @@
|
||||
/******************************
|
||||
* 说明:下载进度窗口
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2018-02-09
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Net;
|
||||
using Lskj.Control;
|
||||
using System.Threading.Tasks;
|
||||
using Lskj.Core;
|
||||
using DevExpress.XtraGrid.Columns;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.SS.Util;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using Lskj.Model;
|
||||
using Lskj.Control.BrowserSetting;
|
||||
using Lskj.Business;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Lskj.Business.Impl;
|
||||
|
||||
namespace Lskj.PubBomImport
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度窗口
|
||||
/// </summary>
|
||||
public partial class FrmProgress : Form
|
||||
{
|
||||
public FrmMain frmMain;
|
||||
public DynamicBomImport Model;
|
||||
public System.Windows.Forms.Timer ImportTimer = new System.Windows.Forms.Timer();
|
||||
public FrmProgress()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.ControlBox = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始导入
|
||||
/// </summary>
|
||||
/// <param name="dirPaths"></param>
|
||||
public void StartImport(string dirPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
Model = frmMain.Model;
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(dirPath);
|
||||
FileInfo[] fileInfos = directoryInfo.GetFiles();
|
||||
FileInfo parentInfo = fileInfos.Where(n => n.Name.StartsWith("MX") && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (parentInfo != null)
|
||||
{
|
||||
DataTable parentTable = ExcelToDatatable(parentInfo.FullName, Model, "", 5);
|
||||
parentTable = parentTable.Rows.Cast<DataRow>().Where(n => int.TryParse(n["序号"] + "", out _) && !string.IsNullOrEmpty(n["图号"] + "")).ToList().CopyToDataTable();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (DataRow dataRow in parentTable.Rows)
|
||||
{
|
||||
stringBuilder.AppendLine($"if not exists (select productid from p_ProductTab where productid = '{dataRow["图号"] + ""}')");
|
||||
stringBuilder.AppendLine($"begin insert into p_ProductTab (productid,appellation,bak) values ('{(dataRow["图号"] + "").Replace("'", "''")}','{(dataRow["名称"] + "").Replace("'", "''")}','{(dataRow["备注"] + "").Replace("'", "''")}') end;");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||
}
|
||||
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
||||
frmBillInfo.OnControlSourceBind += (s, args) =>
|
||||
{
|
||||
Task task = new Task(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
SetProcessBar(0, 0);
|
||||
SetProcessMsg($"正在导入:{Path.GetFileName(parentInfo.FullName)}");
|
||||
DataTable childTable = new DataTable();
|
||||
foreach (GridColumn gridColumn in frmBillInfo.GcMainView.Columns)
|
||||
{
|
||||
if (!childTable.Columns.Contains(gridColumn.FieldName))
|
||||
{
|
||||
childTable.Columns.Add(gridColumn.FieldName, gridColumn.ColumnType);
|
||||
}
|
||||
}
|
||||
List<DataRow> deleteRows = new List<DataRow>();
|
||||
foreach (DataRow parentRow in parentTable.Rows)
|
||||
{
|
||||
string code = parentRow["图号"] + "";
|
||||
FileInfo childInfo = fileInfos.Where(n => n.Name.Contains(code) && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (childInfo != null)
|
||||
{
|
||||
DataRow childRow = childTable.NewRow();
|
||||
childRow["ProductId"] = parentRow["图号"] + "";
|
||||
childRow["appellation"] = parentRow["名称"] + "";
|
||||
childRow["bak"] = parentRow["备注"] + "";
|
||||
childRow["tamount"] = parentRow["套数"] + "";
|
||||
childRow["amount"] = parentRow["套数"] + "";
|
||||
childTable.Rows.Add(childRow);
|
||||
}
|
||||
else
|
||||
{
|
||||
deleteRows.Add(parentRow);
|
||||
}
|
||||
}
|
||||
foreach (DataRow item in deleteRows)
|
||||
{
|
||||
parentTable.Rows.Remove(item);
|
||||
}
|
||||
SetProcessBar(20, 0);
|
||||
frmBillInfo.GcMainView.GridControl.DataSource = childTable;
|
||||
SetProcessBar(40, 0);
|
||||
string controlSql = "select '' as billdocument_id,'0' affirmer,'0' rtagid,'{材料代码}' as productid";
|
||||
frmBillInfo.InitializeHeader(Model.MaintabFocusedRow, controlSql);
|
||||
SetProcessBar(60, 0);
|
||||
frmBillInfo.BillSave();
|
||||
SetProcessBar(80, 0);
|
||||
frmBillInfo.OnBillAdd();
|
||||
string productId = Model.MaintabFocusedRow["材料代码"] + "";
|
||||
string billdocumentId = Model.MaintabFocusedRow["单据编号"] + "";
|
||||
string idValue = BaseImpl.GetResult($"select top 1 billdocument_id from bom_billListTab where ParentProduct = '{productId}'") + "";
|
||||
string updateParentVerSql = @"update bom_BillListTab set Ver = '{0}' where Billdocument_Id='{1}' and ProductId='{0}'";
|
||||
SqlHelper.ExecuteNonQuery(string.Format(updateParentVerSql, idValue, billdocumentId));
|
||||
//上传文件
|
||||
bool isUpload = UploadFile(parentInfo.FullName, idValue, out string msg);
|
||||
SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
|
||||
SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
|
||||
int.TryParse(Model.FirstRowIndex, out int index);
|
||||
frmMain.FirstRowIndex = index;
|
||||
foreach (DataRow dataRow in parentTable.Rows)
|
||||
{
|
||||
int childIndex = parentTable.Rows.IndexOf(dataRow);
|
||||
int nowCount = 1 + childIndex;
|
||||
int allCount = (int)((decimal)(1 + childIndex) / (parentTable.Rows.Count + 1) * 100);
|
||||
int finishCount = (int)((decimal)(1 + nowCount) / (parentTable.Rows.Count + 1) * 100);
|
||||
int.TryParse(dataRow["套数"] + "", out int tamount);
|
||||
string code = dataRow["图号"] + "";
|
||||
FileInfo childInfo = fileInfos.Where(n => n.Name.Contains(code) && n.Extension.Equals(".xlsx", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||||
if (childInfo != null)
|
||||
{
|
||||
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"] = tamount;
|
||||
detailRow["amount"] = tamount > 0 ? (lastAmount * tamount) + "" : lastAmount + "";
|
||||
}
|
||||
frmBillInfo.GcMainView.GridControl.DataSource = detailTable;
|
||||
SetProcessBar(20, allCount);
|
||||
frmBillInfo.InitializeHeader(dataRow, Model.BillMasterSql);
|
||||
SetProcessBar(40, allCount);
|
||||
frmBillInfo.BillSave();
|
||||
SetProcessBar(60, allCount);
|
||||
frmBillInfo.OnBillAdd();
|
||||
string updateChildVerSql = @"update bom_BillListTab set Ver = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{0}') where Billdocument_Id = (select top 1 billdocument_id from bom_billListTab where ParentProduct = '{1}') and ProductId='{0}'";
|
||||
SqlHelper.ExecuteNonQuery(string.Format(updateChildVerSql, code, productId));
|
||||
SetProcessBar(80, allCount);
|
||||
//上传文件
|
||||
isUpload = UploadFile(childInfo.FullName, idValue, out msg);
|
||||
SetProcessBar(100, finishCount);
|
||||
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetProcessBar(100, finishCount);
|
||||
SetProcessLabelAllMsg($"总进度:{nowCount + 1}/{parentTable.Rows.Count + 1}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.DialogResult = DialogResult.OK;
|
||||
this.Close();
|
||||
ImportTimer?.Dispose();
|
||||
}
|
||||
});
|
||||
task.Start();
|
||||
};
|
||||
frmBillInfo.OnLoad(Model);
|
||||
frmMain.ParentView = frmBillInfo.GcMainView;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("未包含结构文件");
|
||||
Close();
|
||||
ImportTimer?.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
Close();
|
||||
ImportTimer?.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 显示当前文件
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
private void SetProcessMsg(string text)
|
||||
{
|
||||
this.labelCurrentItem.Invoke(new Action(() =>
|
||||
{
|
||||
this.labelCurrentItem.Text = text;
|
||||
}));
|
||||
}
|
||||
private void SetProcessLabelAllMsg(string text)
|
||||
{
|
||||
this.lblAll.Invoke(new Action(() =>
|
||||
{
|
||||
this.lblAll.Text = text;
|
||||
}));
|
||||
}
|
||||
/// <summary>
|
||||
/// 显示当前进度
|
||||
/// </summary>
|
||||
/// <param name="current"></param>
|
||||
/// <param name="total"></param>
|
||||
private void SetProcessBar(int current, int total)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.progressBarCurrent.Value = current;
|
||||
this.progressBarTotal.Value = total;
|
||||
}));
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取表格数据
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="sheetName"></param>
|
||||
/// <param name="isFirstRowColumn"></param>
|
||||
/// <returns></returns>
|
||||
public DataTable ExcelToDatatable(string fileName, DynamicBomImport Model, string sheetName = "", int firstRowIndex = 0)
|
||||
{
|
||||
DataTable data = new DataTable();
|
||||
FileStream fs;
|
||||
IWorkbook workbook = null;
|
||||
try
|
||||
{
|
||||
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
|
||||
if (fileName.IndexOf(".xlsx") > 0) // 2007版本
|
||||
{
|
||||
workbook = new XSSFWorkbook(fs);
|
||||
}
|
||||
else if (fileName.IndexOf(".xls") > 0) // 2003版本
|
||||
{
|
||||
workbook = new HSSFWorkbook(fs);
|
||||
}
|
||||
ISheet sheet;
|
||||
if (!string.IsNullOrEmpty(sheetName))
|
||||
{
|
||||
sheet = workbook.GetSheet(sheetName);//根据给定的sheet名称获取数据
|
||||
}
|
||||
else
|
||||
{
|
||||
//也可以根据sheet编号来获取数据
|
||||
sheet = workbook.GetSheetAt(0);//获取第几个sheet表(此处表示如果没有给定sheet名称,默认是第一个sheet表)
|
||||
}
|
||||
if (sheet != null)
|
||||
{
|
||||
int startRow = firstRowIndex + 1;
|
||||
IRow firstRow = sheet.GetRow(firstRowIndex);
|
||||
IRow bandRow = null;
|
||||
int cellCount = firstRow.LastCellNum;
|
||||
for (int i = firstRow.FirstCellNum; i < firstRow.LastCellNum; i++)//第一行列数循环
|
||||
{
|
||||
ICell titleCell = firstRow.GetCell(i);
|
||||
ICell bandCell = null;
|
||||
bool isBandTitle = false;
|
||||
if (titleCell.IsMergedCell)
|
||||
{
|
||||
CellRangeAddress mergrRange = FindMergedRegion(sheet, firstRowIndex, i);
|
||||
startRow = mergrRange.LastRow + 1;
|
||||
if (mergrRange != null)
|
||||
{
|
||||
if (mergrRange.FirstColumn < mergrRange.LastColumn && !Model.CustomerServiceApp)
|
||||
{
|
||||
isBandTitle = true;
|
||||
bandRow = sheet.GetRow(mergrRange.LastRow + 1);
|
||||
titleCell = firstRow.GetCell(mergrRange.FirstColumn);
|
||||
bandCell = bandRow.GetCell(i);
|
||||
CellRangeAddress bandMergrRange = FindMergedRegion(sheet, mergrRange.LastRow + 1, i);
|
||||
if (bandMergrRange != null)
|
||||
{
|
||||
startRow = bandMergrRange.LastRow + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startRow = mergrRange.LastRow + 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
startRow = mergrRange.LastRow + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
string fieldName = "";
|
||||
if (!isBandTitle || bandRow == null)
|
||||
{
|
||||
fieldName = GetCellValue(titleCell);
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldName = $"{GetCellValue(titleCell)}|{GetCellValue(bandCell)}";
|
||||
}
|
||||
if (string.IsNullOrEmpty(fieldName) && titleCell.IsMergedCell)
|
||||
{
|
||||
cellCount -= 1;
|
||||
continue;
|
||||
}
|
||||
DataColumn column = new DataColumn(fieldName);//获取标题
|
||||
data.Columns.Add(column);//添加列
|
||||
}
|
||||
//最后一行的标号
|
||||
int rowCount = sheet.LastRowNum;
|
||||
for (int i = startRow; i <= rowCount; i++)//循环遍历所有行
|
||||
{
|
||||
IRow row = sheet.GetRow(i);//第几行
|
||||
if (row == null)
|
||||
{
|
||||
continue; //没有数据的行默认是null;
|
||||
}
|
||||
//将excel表每一行的数据添加到datatable的行中
|
||||
DataRow dataRow = data.NewRow();
|
||||
int dataRowIndex = 0;
|
||||
for (int j = firstRow.FirstCellNum; j < cellCount; j++)
|
||||
{
|
||||
ICell cell = row.GetCell(j);
|
||||
if (cell.IsMergedCell)
|
||||
{
|
||||
CellRangeAddress mergrRange = FindMergedRegion(sheet, i, j);
|
||||
if (j == mergrRange.FirstColumn)
|
||||
{
|
||||
dataRow[dataRowIndex] = GetCellValue(row.GetCell(j));
|
||||
dataRowIndex += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (row.GetCell(j) != null) //同理,没有数据的单元格都默认是null
|
||||
{
|
||||
dataRow[dataRowIndex] = GetCellValue(row.GetCell(j));
|
||||
dataRowIndex += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
data.Rows.Add(dataRow);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new IOException(string.Format("读取模板内容失败,原因:{0}", ex.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(string.Format("读取模板内容失败,原因:{0}", ex.Message));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取单元格值
|
||||
/// </summary>
|
||||
/// <param name="cell"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCellValue(ICell cell)
|
||||
{
|
||||
string cellValue = "";
|
||||
try
|
||||
{
|
||||
if (cell != null)
|
||||
{
|
||||
// 根据单元格类型获取值
|
||||
switch (cell.CellType)
|
||||
{
|
||||
case CellType.String:
|
||||
cellValue = cell.StringCellValue;
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
cellValue = cell.NumericCellValue.ToString();
|
||||
break;
|
||||
case CellType.Boolean:
|
||||
cellValue = cell.BooleanCellValue.ToString();
|
||||
break;
|
||||
case CellType.Formula://单元格中带有公式,根据类型继续判断
|
||||
switch (cell.CachedFormulaResultType)
|
||||
{
|
||||
case CellType.String:
|
||||
cellValue = cell.StringCellValue;
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
cellValue = cell.NumericCellValue.ToString();
|
||||
break;
|
||||
case CellType.Boolean:
|
||||
cellValue = cell.BooleanCellValue.ToString();
|
||||
break;
|
||||
case CellType.Blank:
|
||||
break;
|
||||
default:
|
||||
cellValue.ToString();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cellValue = cell.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return cellValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取合并区域
|
||||
/// </summary>
|
||||
/// <param name="sheet"></param>
|
||||
/// <param name="rowIndex"></param>
|
||||
/// <param name="columnIndex"></param>
|
||||
/// <returns></returns>
|
||||
private CellRangeAddress FindMergedRegion(ISheet sheet, int rowIndex, int columnIndex)
|
||||
{
|
||||
int mergedRegionsCount = sheet.NumMergedRegions;
|
||||
|
||||
for (int i = 0; i < mergedRegionsCount; i++)
|
||||
{
|
||||
CellRangeAddress mergedRegion = sheet.GetMergedRegion(i);
|
||||
if (mergedRegion.IsInRange(rowIndex, columnIndex))
|
||||
{
|
||||
return mergedRegion; // 返回合并区域
|
||||
}
|
||||
}
|
||||
return null; // 未找到合并区域
|
||||
}
|
||||
/// <summary>
|
||||
/// 上传文件
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <returns></returns>
|
||||
private bool UploadFile(string filePath, string idValue, out string msg)
|
||||
{
|
||||
bool isUpload = false;
|
||||
string File = filePath;
|
||||
string returnMsg = "";
|
||||
string postUrl = "";
|
||||
try
|
||||
{
|
||||
//获取文件信息
|
||||
FileInfo fileInfo = new FileInfo(File);
|
||||
string suffix = Path.GetExtension(File);
|
||||
string name = fileInfo.Name;
|
||||
DateTime creationTime = fileInfo.CreationTime;
|
||||
byte[] fileBytes = ConvertFileToBytes(File);
|
||||
string fileStream = Convert.ToBase64String(fileBytes);
|
||||
string userId = ERPInfo.Instance.UserId;
|
||||
DateTime uploadTime = DateTime.Now;
|
||||
//上传文件到服务器目录
|
||||
postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&speciesno={8}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}";
|
||||
if (!string.IsNullOrEmpty(idValue))
|
||||
{
|
||||
string token = "";
|
||||
string loginUrl = $"{SystemInfo.Instance.OAUrl}/Api/SysUserAjaxApi.ashx";
|
||||
HttpTools.setting("application/x-www-form-urlencoded", null, null, HttpTools.Encode.UTF8);
|
||||
Dictionary<string, string> loginPmsDic = new Dictionary<string, string>();
|
||||
loginPmsDic.Add("method", "Login");
|
||||
loginPmsDic.Add("username", ERPInfo.Instance.UserName);
|
||||
loginPmsDic.Add("password", ERPInfo.Instance.InPassWord);
|
||||
HttpWebResponse loginResponse = HttpTools.Post(loginUrl, "", loginPmsDic, HttpTools.Method.POST, out CookieCollection loginCookie, out string loginResult);
|
||||
if (loginResponse != null && !string.IsNullOrEmpty(loginResult))
|
||||
{
|
||||
JObject jObject = JsonConvert.DeserializeObject<JObject>(loginResult);
|
||||
if (jObject.ContainsKey("success"))
|
||||
{
|
||||
if ((jObject["success"] + "").Equals("True"))
|
||||
{
|
||||
if (jObject.ContainsKey("token"))
|
||||
{
|
||||
token = jObject["token"] + "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, Model.ModuleCode, idValue, "file", fileBytes.Length, 0, name, "DoWebUpload", "010105");
|
||||
HttpTools.setting("application/x-www-form-urlencoded", null, null);
|
||||
string result = "";
|
||||
CookieCollection cookieCollection = null;
|
||||
Dictionary<string, string> headerDic = new Dictionary<string, string>();
|
||||
headerDic.Add("Authorization", $"Bearer {token}");
|
||||
HttpWebResponse webResponse = HttpTools.Post(postUrl, fileStream, null, headerDic, HttpTools.Method.POST, out cookieCollection, out result);
|
||||
if (webResponse != null && !string.IsNullOrEmpty(result))
|
||||
{
|
||||
JObject jsonObject = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(result);
|
||||
string isSuccess = jsonObject["success"] + "";
|
||||
if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
isUpload = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jsonObject.ContainsKey("msg"))
|
||||
{
|
||||
returnMsg = jsonObject["msg"] + "";
|
||||
}
|
||||
isUpload = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnMsg = "上传请求失败";
|
||||
isUpload = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnMsg = loginResult;
|
||||
isUpload = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnMsg = "上传节点值不能为空";
|
||||
isUpload = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnMsg = ex.Message;
|
||||
isUpload = false;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -38,7 +38,7 @@
|
||||
<Reference Include="DevExpress.XtraTreeList.v15.2, Version=15.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.1.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\引用DLL\Newtonsoft.Json.dll</HintPath>
|
||||
<HintPath>D:\工作\lserp_cs_6.0\引用DLL\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI">
|
||||
<HintPath>..\..\..\引用DLL\NPOI.dll</HintPath>
|
||||
@@ -64,18 +64,18 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DllBaseClass.cs" />
|
||||
<Compile Include="FrmBillInfo.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmBillInfo.cs" />
|
||||
<Compile Include="FrmBillInfo.Designer.cs">
|
||||
<DependentUpon>FrmBillInfo.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrmMain.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmMain.cs" />
|
||||
<Compile Include="FrmMain.Designer.cs">
|
||||
<DependentUpon>FrmMain.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrmProgress.cs" />
|
||||
<Compile Include="FrmProgress.Designer.cs">
|
||||
<DependentUpon>FrmProgress.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
|
||||
</ItemGroup>
|
||||
@@ -86,6 +86,10 @@
|
||||
<EmbeddedResource Include="FrmMain.resx">
|
||||
<DependentUpon>FrmMain.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FrmProgress.resx">
|
||||
<DependentUpon>FrmProgress.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\licenses.licx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lskj.Business\Lskj.Business.csproj">
|
||||
|
||||
Reference in New Issue
Block a user