SVN r735
SVN-Revision: r735
This commit is contained in:
+12
-206
@@ -29,62 +29,20 @@ namespace Lskj.PubBomImportNew
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.btnImport = new DevExpress.XtraEditors.SimpleButton();
|
||||
this.btnRead = new DevExpress.XtraEditors.SimpleButton();
|
||||
this.pl_bottom = new DevExpress.XtraEditors.PanelControl();
|
||||
this.btnCancel = new DevExpress.XtraEditors.SimpleButton();
|
||||
this.btnOk = new DevExpress.XtraEditors.SimpleButton();
|
||||
this.pl_cond = new DevExpress.XtraEditors.PanelControl();
|
||||
this.condTxtEdit = new DevExpress.XtraEditors.TextEdit();
|
||||
this.lb_cond = new System.Windows.Forms.Label();
|
||||
this.pl_purview = new DevExpress.XtraEditors.PanelControl();
|
||||
this.purview_Mulit = new Lskj.Control.LabelMultiAutoTextEdit();
|
||||
this.lb_purview = new System.Windows.Forms.Label();
|
||||
this.tips = new DevExpress.XtraEditors.PanelControl();
|
||||
this.tipsEdit = new DevExpress.XtraEditors.TextEdit();
|
||||
this.splitMainContainer = new DevExpress.XtraEditors.SplitContainerControl();
|
||||
this.gcMain = new Lskj.Control.GridControlEx();
|
||||
this.gc_Right = new Lskj.Control.GridControlEx();
|
||||
this.btnRead = new DevExpress.XtraEditors.SimpleButton();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_bottom)).BeginInit();
|
||||
this.pl_bottom.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_cond)).BeginInit();
|
||||
this.pl_cond.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.condTxtEdit.Properties)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_purview)).BeginInit();
|
||||
this.pl_purview.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.tips)).BeginInit();
|
||||
this.tips.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.tipsEdit.Properties)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitMainContainer)).BeginInit();
|
||||
this.splitMainContainer.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnImport
|
||||
//
|
||||
this.btnImport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnImport.Location = new System.Drawing.Point(764, 10);
|
||||
this.btnImport.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.btnImport.Name = "btnImport";
|
||||
this.btnImport.Size = new System.Drawing.Size(97, 31);
|
||||
this.btnImport.TabIndex = 11;
|
||||
this.btnImport.Text = "导入数据";
|
||||
//
|
||||
// btnRead
|
||||
//
|
||||
this.btnRead.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnRead.Location = new System.Drawing.Point(656, 10);
|
||||
this.btnRead.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.btnRead.Name = "btnRead";
|
||||
this.btnRead.Size = new System.Drawing.Size(97, 31);
|
||||
this.btnRead.TabIndex = 10;
|
||||
this.btnRead.Text = "读取Excel";
|
||||
//
|
||||
// pl_bottom
|
||||
//
|
||||
this.pl_bottom.Appearance.BackColor = System.Drawing.Color.Transparent;
|
||||
this.pl_bottom.Appearance.Options.UseBackColor = true;
|
||||
this.pl_bottom.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
||||
this.pl_bottom.Controls.Add(this.btnImport);
|
||||
this.pl_bottom.Controls.Add(this.btnCancel);
|
||||
this.pl_bottom.Controls.Add(this.btnRead);
|
||||
this.pl_bottom.Controls.Add(this.btnOk);
|
||||
@@ -113,132 +71,6 @@ namespace Lskj.PubBomImportNew
|
||||
this.btnOk.TabIndex = 10;
|
||||
this.btnOk.Text = "保存绑定";
|
||||
//
|
||||
// pl_cond
|
||||
//
|
||||
this.pl_cond.Appearance.BackColor = System.Drawing.Color.White;
|
||||
this.pl_cond.Appearance.Options.UseBackColor = true;
|
||||
this.pl_cond.Controls.Add(this.condTxtEdit);
|
||||
this.pl_cond.Controls.Add(this.lb_cond);
|
||||
this.pl_cond.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.pl_cond.Location = new System.Drawing.Point(0, 0);
|
||||
this.pl_cond.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.pl_cond.Name = "pl_cond";
|
||||
this.pl_cond.Size = new System.Drawing.Size(872, 42);
|
||||
this.pl_cond.TabIndex = 12;
|
||||
//
|
||||
// condTxtEdit
|
||||
//
|
||||
this.condTxtEdit.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.condTxtEdit.Location = new System.Drawing.Point(87, 2);
|
||||
this.condTxtEdit.Name = "condTxtEdit";
|
||||
this.condTxtEdit.Properties.Appearance.BackColor = System.Drawing.Color.White;
|
||||
this.condTxtEdit.Properties.Appearance.Options.UseBackColor = true;
|
||||
this.condTxtEdit.Properties.AutoHeight = false;
|
||||
this.condTxtEdit.Properties.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
||||
this.condTxtEdit.Size = new System.Drawing.Size(783, 38);
|
||||
this.condTxtEdit.TabIndex = 5;
|
||||
//
|
||||
// lb_cond
|
||||
//
|
||||
this.lb_cond.BackColor = System.Drawing.Color.White;
|
||||
this.lb_cond.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.lb_cond.Location = new System.Drawing.Point(2, 2);
|
||||
this.lb_cond.Name = "lb_cond";
|
||||
this.lb_cond.Size = new System.Drawing.Size(85, 38);
|
||||
this.lb_cond.TabIndex = 3;
|
||||
this.lb_cond.Text = "筛选条件:";
|
||||
this.lb_cond.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// pl_purview
|
||||
//
|
||||
this.pl_purview.Appearance.BackColor = System.Drawing.Color.White;
|
||||
this.pl_purview.Appearance.Options.UseBackColor = true;
|
||||
this.pl_purview.Controls.Add(this.purview_Mulit);
|
||||
this.pl_purview.Controls.Add(this.lb_purview);
|
||||
this.pl_purview.Cursor = System.Windows.Forms.Cursors.Default;
|
||||
this.pl_purview.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.pl_purview.Location = new System.Drawing.Point(0, 42);
|
||||
this.pl_purview.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.pl_purview.Name = "pl_purview";
|
||||
this.pl_purview.Size = new System.Drawing.Size(872, 21);
|
||||
this.pl_purview.TabIndex = 13;
|
||||
//
|
||||
// purview_Mulit
|
||||
//
|
||||
this.purview_Mulit.BackColor = System.Drawing.Color.White;
|
||||
this.purview_Mulit.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.purview_Mulit.EditText = "";
|
||||
this.purview_Mulit.FontSize = 0F;
|
||||
this.purview_Mulit.LabelText = "名称";
|
||||
this.purview_Mulit.Location = new System.Drawing.Point(135, 2);
|
||||
this.purview_Mulit.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.purview_Mulit.Model = null;
|
||||
this.purview_Mulit.Name = "purview_Mulit";
|
||||
this.purview_Mulit.NullText = "";
|
||||
this.purview_Mulit.ReadOnly = false;
|
||||
this.purview_Mulit.Required = false;
|
||||
this.purview_Mulit.Size = new System.Drawing.Size(735, 17);
|
||||
this.purview_Mulit.TabIndex = 4;
|
||||
this.purview_Mulit.TextBoxProhibition = false;
|
||||
//
|
||||
// lb_purview
|
||||
//
|
||||
this.lb_purview.BackColor = System.Drawing.Color.White;
|
||||
this.lb_purview.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.lb_purview.Location = new System.Drawing.Point(2, 2);
|
||||
this.lb_purview.Name = "lb_purview";
|
||||
this.lb_purview.Size = new System.Drawing.Size(133, 17);
|
||||
this.lb_purview.TabIndex = 3;
|
||||
this.lb_purview.Text = "条件可编辑人员:";
|
||||
this.lb_purview.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// tips
|
||||
//
|
||||
this.tips.Appearance.BackColor = System.Drawing.Color.White;
|
||||
this.tips.Appearance.Options.UseBackColor = true;
|
||||
this.tips.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Office2003;
|
||||
this.tips.Controls.Add(this.tipsEdit);
|
||||
this.tips.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.tips.Location = new System.Drawing.Point(0, 63);
|
||||
this.tips.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.tips.Name = "tips";
|
||||
this.tips.Size = new System.Drawing.Size(872, 42);
|
||||
this.tips.TabIndex = 14;
|
||||
//
|
||||
// tipsEdit
|
||||
//
|
||||
this.tipsEdit.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.tipsEdit.EditValue = "请导入Excel模板";
|
||||
this.tipsEdit.Location = new System.Drawing.Point(2, 2);
|
||||
this.tipsEdit.Name = "tipsEdit";
|
||||
this.tipsEdit.Properties.Appearance.BackColor = System.Drawing.Color.White;
|
||||
this.tipsEdit.Properties.Appearance.ForeColor = System.Drawing.Color.Red;
|
||||
this.tipsEdit.Properties.Appearance.Options.UseBackColor = true;
|
||||
this.tipsEdit.Properties.Appearance.Options.UseForeColor = true;
|
||||
this.tipsEdit.Properties.AutoHeight = false;
|
||||
this.tipsEdit.Properties.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
||||
this.tipsEdit.Properties.ReadOnly = true;
|
||||
this.tipsEdit.Size = new System.Drawing.Size(868, 38);
|
||||
this.tipsEdit.TabIndex = 6;
|
||||
//
|
||||
// splitMainContainer
|
||||
//
|
||||
this.splitMainContainer.Appearance.BackColor = System.Drawing.Color.Transparent;
|
||||
this.splitMainContainer.Appearance.Options.UseBackColor = true;
|
||||
this.splitMainContainer.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Default;
|
||||
this.splitMainContainer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.splitMainContainer.Location = new System.Drawing.Point(0, 105);
|
||||
this.splitMainContainer.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.splitMainContainer.Name = "splitMainContainer";
|
||||
this.splitMainContainer.Panel1.Controls.Add(this.gcMain);
|
||||
this.splitMainContainer.Panel1.Text = "Panel1";
|
||||
this.splitMainContainer.Panel2.Controls.Add(this.gc_Right);
|
||||
this.splitMainContainer.Panel2.Text = "Panel2";
|
||||
this.splitMainContainer.Size = new System.Drawing.Size(872, 444);
|
||||
this.splitMainContainer.SplitterPosition = 500;
|
||||
this.splitMainContainer.TabIndex = 17;
|
||||
this.splitMainContainer.Text = "splitContainerControl1";
|
||||
//
|
||||
// gcMain
|
||||
//
|
||||
this.gcMain.AdapterObj = null;
|
||||
@@ -247,45 +79,19 @@ namespace Lskj.PubBomImportNew
|
||||
this.gcMain.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.gcMain.Name = "gcMain";
|
||||
this.gcMain.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
|
||||
this.gcMain.Size = new System.Drawing.Size(500, 444);
|
||||
this.gcMain.TabIndex = 16;
|
||||
this.gcMain.Size = new System.Drawing.Size(872, 549);
|
||||
this.gcMain.TabIndex = 17;
|
||||
//
|
||||
// gc_Right
|
||||
// btnRead
|
||||
//
|
||||
this.gc_Right.AdapterObj = null;
|
||||
this.gc_Right.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.gc_Right.Location = new System.Drawing.Point(0, 0);
|
||||
this.gc_Right.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.gc_Right.Name = "gc_Right";
|
||||
this.gc_Right.SiftEnumObj = Lskj.Control.GridControlEx.HeaderSiftEnum.Sum;
|
||||
this.gc_Right.Size = new System.Drawing.Size(367, 444);
|
||||
this.gc_Right.TabIndex = 18;
|
||||
this.btnRead.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnRead.Location = new System.Drawing.Point(762, 10);
|
||||
this.btnRead.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.btnRead.Name = "btnRead";
|
||||
this.btnRead.Size = new System.Drawing.Size(97, 31);
|
||||
this.btnRead.TabIndex = 10;
|
||||
this.btnRead.Text = "读取Excel";
|
||||
//
|
||||
// FrmMain
|
||||
//
|
||||
this.Appearance.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.Appearance.Options.UseBackColor = true;
|
||||
this.Appearance.Options.UseFont = true;
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.ClientSize = new System.Drawing.Size(872, 599);
|
||||
this.Controls.Add(this.splitMainContainer);
|
||||
this.Controls.Add(this.tips);
|
||||
this.Controls.Add(this.pl_purview);
|
||||
this.Controls.Add(this.pl_cond);
|
||||
this.Controls.Add(this.pl_bottom);
|
||||
this.Name = "FrmMain";
|
||||
this.Opacity = 0D;
|
||||
this.Text = "表格导入";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_bottom)).EndInit();
|
||||
this.pl_bottom.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_cond)).EndInit();
|
||||
this.pl_cond.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.condTxtEdit.Properties)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_purview)).EndInit();
|
||||
this.pl_purview.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.tips)).EndInit();
|
||||
this.tips.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.tipsEdit.Properties)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitMainContainer)).EndInit();
|
||||
this.splitMainContainer.ResumeLayout(false);
|
||||
this.ResumeLayout(f
|
||||
this.Appear
|
||||
@@ -61,10 +61,8 @@ namespace Lskj.PubBomImportNew
|
||||
{
|
||||
try
|
||||
{
|
||||
InitlizeSpiltLocation();
|
||||
InitEvents();
|
||||
InitGridColumns();
|
||||
InitMulitControl();
|
||||
InitDataSource();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -75,33 +73,6 @@ namespace Lskj.PubBomImportNew
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 导入按钮点击
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnBtnImportClick(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
OpenFileDialog dialog = new OpenFileDialog();
|
||||
dialog.Multiselect = false;
|
||||
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);
|
||||
FrmProgress frmProgress = new FrmProgress();
|
||||
frmProgress.StartImportInFileByZB(dialog.FileName.ToList());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取按钮点击
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@@ -118,34 +89,31 @@ namespace Lskj.PubBomImportNew
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
string fileName = importFileName = dialog.FileName;
|
||||
tipsEdit.Text = string.Format("当前读取文件:{0},请绑定列后点击导入", Path.GetFileName(fileName));
|
||||
string colFields = this.gcMain.GridView.Columns.ToString(',');
|
||||
int.TryParse(Model.FirstRowIndex, out FirstRowIndex);
|
||||
DataTable dataTable = ExcelToDatatable(fileName, Model, Model.SheetName, FirstRowIndex);
|
||||
int.TryParse(Model.stratRowHand, out FirstRowIndex);
|
||||
DataTable dataTable = ExcelToDatatable(fileName, Model, "", FirstRowIndex);
|
||||
DataTable importTable = GetSourceTable(dataTable);
|
||||
DataTable sourceTable = this.gcMain.GridControl.DataSource as DataTable;
|
||||
if (dataTable != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Model.ReadTableCond))
|
||||
{
|
||||
DataView view = new DataView(dataTable);
|
||||
view.RowFilter = Model.ReadTableCond;
|
||||
dataTable = view.ToTable();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
this.gc_Right.SetGridViewDataSource(dataTable);
|
||||
}
|
||||
//if (dataTable != null)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(Model.ReadTableCond))
|
||||
// {
|
||||
// DataView view = new DataView(dataTable);
|
||||
// view.RowFilter = Model.ReadTableCond;
|
||||
// dataTable = view.ToTable();
|
||||
// }
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// }
|
||||
//}
|
||||
if (sourceTable != null && sourceTable.Rows.Count > 0)
|
||||
{
|
||||
if (sourceTable.Rows.Count != importTable.Rows.Count)
|
||||
{
|
||||
this.gcMain.SetGridViewDataSource(importTable);
|
||||
this.condTxtEdit.Text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -164,22 +132,18 @@ namespace Lskj.PubBomImportNew
|
||||
if (!isComplete)
|
||||
{
|
||||
this.gcMain.SetGridViewDataSource(importTable);
|
||||
this.condTxtEdit.Text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.gcMain.SetGridViewDataSource(importTable);
|
||||
this.condTxtEdit.Text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
tipsEdit.Text = "请导入Excel模板";
|
||||
gc_Right.SetGridViewDataSource(new DataTable());
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
}
|
||||
@@ -192,8 +156,6 @@ namespace Lskj.PubBomImportNew
|
||||
{
|
||||
try
|
||||
{
|
||||
string condFilter = this.condTxtEdit.Text.Trim();
|
||||
string condPurview = this.purview_Mulit.EditValue;
|
||||
string unionColumn = GetUnionColumn();
|
||||
string sql = "if exists(select * from P_SpecialImportTab where moduleId = '{0}' and rightMenuName = '{1}') " +
|
||||
"begin " +
|
||||
@@ -202,7 +164,7 @@ namespace Lskj.PubBomImportNew
|
||||
"else begin " +
|
||||
"insert into P_SpecialImportTab (moduleId,rightMenuName,Ls_CondFilter,Ls_UnionColumn,Ls_CondPurview) values ('{0}','{1}','{2}','{3}','{4}') " +
|
||||
"end";
|
||||
sql = string.Format(sql, Model.ModuleCode, Model.ModuleId, condFilter.Replace("'", "''"), unionColumn.Replace("'", "''"), condPurview.Replace("'", "''"));
|
||||
sql = string.Format(sql, Model.ModuleCode, Model.ModuleId, "", unionColumn.Replace("'", "''"), "");
|
||||
SqlHelper.ExecuteNonQuery(sql);
|
||||
MessageUtil.Show("保存成功");
|
||||
}
|
||||
@@ -234,25 +196,6 @@ namespace Lskj.PubBomImportNew
|
||||
MessageUtil.Show(string.Format("取消绑定列失败,原因:{0}", ex.Message));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 分隔条位置改变时
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnSplitMainContainerPositionChanged(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.Model != null)
|
||||
{
|
||||
IniHelper.Write(string.Format("PubSpecialImport_SplitMain_{0}", this.Model.ModuleCode), this.splitMainContainer.SplitterPosition + "");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region 方法
|
||||
/// <summary>
|
||||
@@ -261,28 +204,8 @@ namespace Lskj.PubBomImportNew
|
||||
private void InitEvents()
|
||||
{
|
||||
this.btnRead.Click += OnBtnReadClick;
|
||||
this.btnImport.Click += OnBtnImportClick;
|
||||
this.btnOk.Click += OnBtnOkClick;
|
||||
this.btnCancel.Click += OnBtnCancelClick;
|
||||
this.splitMainContainer.SplitterPositionChanged += OnSplitMainContainerPositionChanged;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置分割条位置
|
||||
/// </summary>
|
||||
private void InitlizeSpiltLocation()
|
||||
{
|
||||
try
|
||||
{
|
||||
string splitMainWidth = IniHelper.Read(string.Format("PubSpecialImport_SplitMain_{0}", this.Model.ModuleCode));//通过Key获取Value值
|
||||
if (!string.IsNullOrEmpty(splitMainWidth))
|
||||
{
|
||||
this.splitMainContainer.SplitterPosition = Convert.ToInt32(splitMainWidth);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化表格列
|
||||
@@ -315,37 +238,6 @@ namespace Lskj.PubBomImportNew
|
||||
searchEdit.View.Tag = searchEdit;
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化多选控件
|
||||
/// </summary>
|
||||
private void InitMulitControl()
|
||||
{
|
||||
if (!ERPInfo.Instance.UserName.Equals("管理员"))
|
||||
{
|
||||
pl_purview.Visible = false;
|
||||
return;
|
||||
}
|
||||
purview_Mulit.LabelText = "";
|
||||
purview_Mulit.ValueMember = "UserId";
|
||||
purview_Mulit.TextField = "UserName";
|
||||
purview_Mulit.ValueField = "UserId";
|
||||
purview_Mulit.Model = new ControlModel()
|
||||
{
|
||||
FieldType = ControlType.LabMultiSelectValue,
|
||||
};
|
||||
string fields = string.Empty;
|
||||
if (BaseImpl.HasExistsColumn("P_EmployeeTab", "SignBmp"))
|
||||
fields = ",SignBmp";
|
||||
if (BaseImpl.HasExistsColumn("P_EmployeeTab", "Password"))
|
||||
fields += ",Password";
|
||||
if (BaseImpl.HasExistsColumn("P_EmployeeTab", "AD_Id"))
|
||||
fields += ",AD_Id";
|
||||
string sqlValue = string.Format("select EmployeeId UserId,LoginAccount UserCode,EmployeeName UserName {0} from P_EmployeeTab WHERE sign=0 and UseFlag=1 order by loginaccount", fields);
|
||||
DataTable dataSource = SqlHelper.ExecuteDataTable(sqlValue);
|
||||
purview_Mulit.SourceSQL = sqlValue;
|
||||
purview_Mulit.SetDataSource(dataSource);
|
||||
purview_Mulit.TextEdit.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化数据
|
||||
/// </summary>
|
||||
private void InitDataSource()
|
||||
@@ -401,17 +293,7 @@ namespace Lskj.PubBomImportNew
|
||||
if (dataTable != null && dataTable.Rows.Count > 0)
|
||||
{
|
||||
DataRow dataRow = dataTable.Rows[0];
|
||||
string condFilter = dataRow["Ls_CondFilter"] + "";
|
||||
string unionColumn = dataRow["Ls_UnionColumn"] + "";
|
||||
string condPurview = dataRow["Ls_CondPurview"] + "";
|
||||
|
||||
string[] values = condPurview.Trim(',').Split(',');
|
||||
if (!values.Contains(ERPInfo.Instance.UserId))
|
||||
{
|
||||
condTxtEdit.ReadOnly = true;
|
||||
}
|
||||
this.condTxtEdit.Text = condFilter;
|
||||
this.purview_Mulit.EditText = condPurview;
|
||||
List<string> unionColumnList = unionColumn.Split(',').ToList();
|
||||
DataTable sourceTable = GetSourceTable(unionColumnList);
|
||||
this.gcMain.GridControl.DataSource = sourceTable;
|
||||
@@ -525,7 +407,7 @@ namespace Lskj.PubBomImportNew
|
||||
startRow = mergrRange.LastRow + 1;
|
||||
if (mergrRange != null)
|
||||
{
|
||||
if (mergrRange.FirstColumn < mergrRange.LastColumn && !Model.CustomerServiceApp)
|
||||
if (mergrRange.FirstColumn < mergrRange.LastColumn)//&& !Model.CustomerServiceApp
|
||||
{
|
||||
isBandTitle = true;
|
||||
bandRow = sheet.GetRow(mergrRange.LastRow + 1);
|
||||
@@ -764,18 +646,18 @@ namespace Lskj.PubBomImportNew
|
||||
GridView gridView = ParentView;
|
||||
DataTable columnsTable = gcMain.gridControl.DataSourceTable();
|
||||
DataTable table = gridView.GridControl.DataSourceTable();
|
||||
DataTable sourceDataTable = ExcelToDatatable(fileName, Model, Model.SheetName, FirstRowIndex);
|
||||
DataTable sourceDataTable = ExcelToDatatable(fileName, Model, "", FirstRowIndex);
|
||||
DataView filterDataView = new DataView(sourceDataTable);
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Model.ReadTableCond))
|
||||
{
|
||||
filterDataView.RowFilter = Model.ReadTableCond;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
//try
|
||||
//{
|
||||
// if (!string.IsNullOrEmpty(Model.ReadTableCond))
|
||||
// {
|
||||
// filterDataView.RowFilter = Model.ReadTableCond;
|
||||
// }
|
||||
//}
|
||||
//catch (Exception)
|
||||
//{
|
||||
//}
|
||||
List<DataRow> dataRows = columnsTable.Rows.Cast<DataRow>().Where(n => !string.IsNullOrEmpty(n["excelFieldName"] + "") && !string.IsNullOrEmpty(n["clientFieldName"] + "")).ToList();
|
||||
int index = gridView is BandedGridView ? FirstRowIndex + 1 : FirstRowIndex;
|
||||
isBillImport = index == FirstRowIndex ? true : isBillImport;
|
||||
@@ -807,7 +689,7 @@ namespace Lskj.PubBomImportNew
|
||||
startRow = mergrRange.LastRow + 1;
|
||||
if (mergrRange != null)
|
||||
{
|
||||
if (mergrRange.FirstColumn < mergrRange.LastColumn && !Model.CustomerServiceApp)
|
||||
if (mergrRange.FirstColumn < mergrRange.LastColumn)//&& !Model.CustomerServiceApp
|
||||
{
|
||||
isBandTitle = true;
|
||||
bandRow = sheet.GetRow(mergrRange.LastRow + 1);
|
||||
@@ -870,7 +752,7 @@ namespace Lskj.PubBomImportNew
|
||||
ToAssignment = true;
|
||||
CurrentRow = i;
|
||||
DataRow rowSource = sourceDataTable.Rows[i - startRow];
|
||||
if (!filterDataView.Cast<DataRowView>().Any(rowView => rowView.Row == rowSource) || !ValidateCond(condTxtEdit.Text, rowSource))
|
||||
if (!filterDataView.Cast<DataRowView>().Any(rowView => rowView.Row == rowSource))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -893,7 +775,7 @@ namespace Lskj.PubBomImportNew
|
||||
startRow = mergrRange.LastRow + 1;
|
||||
if (mergrRange != null)
|
||||
{
|
||||
if (mergrRange.FirstColumn < mergrRange.LastColumn && !Model.CustomerServiceApp)
|
||||
if (mergrRange.FirstColumn < mergrRange.LastColumn)//&& !Model.CustomerServiceApp
|
||||
{
|
||||
isBandTitle = true;
|
||||
bandRow = sheet.GetRow(mergrRange.LastRow + 1);
|
||||
|
||||
+17
-14
@@ -31,13 +31,13 @@ namespace Lskj.PubBomImportNew
|
||||
{
|
||||
this.gcMain = new Lskj.Control.GridControlEx();
|
||||
this.pl_top = new DevExpress.XtraEditors.PanelControl();
|
||||
this.btnCover = new DevExpress.XtraEditors.SimpleButton();
|
||||
this.btnImport = new DevExpress.XtraEditors.SimpleButton();
|
||||
this.btnRead = new DevExpress.XtraEditors.SimpleButton();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.pl_bottom = new DevExpress.XtraEditors.PanelControl();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.pl_main = new DevExpress.XtraEditors.PanelControl();
|
||||
this.btnCover = new DevExpress.XtraEditors.SimpleButton();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_top)).BeginInit();
|
||||
this.pl_top.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pl_bottom)).BeginInit();
|
||||
@@ -75,6 +75,18 @@ namespace Lskj.PubBomImportNew
|
||||
this.pl_top.Size = new System.Drawing.Size(1394, 64);
|
||||
this.pl_top.TabIndex = 3;
|
||||
//
|
||||
// btnCover
|
||||
//
|
||||
this.btnCover.Appearance.ForeColor = System.Drawing.Color.Red;
|
||||
this.btnCover.Appearance.Options.UseForeColor = true;
|
||||
this.btnCover.Location = new System.Drawing.Point(260, 12);
|
||||
this.btnCover.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.btnCover.Name = "btnCover";
|
||||
this.btnCover.Size = new System.Drawing.Size(110, 38);
|
||||
this.btnCover.TabIndex = 11;
|
||||
this.btnCover.Text = "设计关联";
|
||||
this.btnCover.Click += new System.EventHandler(this.OnBtnCoverClick);
|
||||
//
|
||||
// btnImport
|
||||
//
|
||||
this.btnImport.Location = new System.Drawing.Point(141, 12);
|
||||
@@ -83,6 +95,7 @@ namespace Lskj.PubBomImportNew
|
||||
this.btnImport.Size = new System.Drawing.Size(110, 38);
|
||||
this.btnImport.TabIndex = 11;
|
||||
this.btnImport.Text = "导入数据";
|
||||
this.btnImport.Click += new System.EventHandler(this.OnImportButtonClick);
|
||||
//
|
||||
// btnRead
|
||||
//
|
||||
@@ -92,6 +105,7 @@ namespace Lskj.PubBomImportNew
|
||||
this.btnRead.Size = new System.Drawing.Size(110, 38);
|
||||
this.btnRead.TabIndex = 10;
|
||||
this.btnRead.Text = "读取Excel";
|
||||
this.btnRead.Click += new System.EventHandler(this.OnReadButtonClick);
|
||||
//
|
||||
// label2
|
||||
//
|
||||
@@ -100,7 +114,7 @@ namespace Lskj.PubBomImportNew
|
||||
this.label2.Location = new System.Drawing.Point(1076, 22);
|
||||
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(298, 22);
|
||||
this.label2.Size = new System.Drawing.Size(199, 14);
|
||||
this.label2.TabIndex = 9;
|
||||
this.label2.Text = "说明:不需要导入的列可以拖拽丢弃";
|
||||
//
|
||||
@@ -123,7 +137,7 @@ namespace Lskj.PubBomImportNew
|
||||
this.label1.Location = new System.Drawing.Point(4, 12);
|
||||
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(824, 22);
|
||||
this.label1.Size = new System.Drawing.Size(551, 14);
|
||||
this.label1.TabIndex = 1;
|
||||
this.label1.Text = "操作提示:请先读取需要导入的Excel文件,然后对需要导入的数据进行核对修改后,点击【确认导入】";
|
||||
//
|
||||
@@ -140,17 +154,6 @@ namespace Lskj.PubBomImportNew
|
||||
this.pl_main.Size = new System.Drawing.Size(1394, 927);
|
||||
this.pl_main.TabIndex = 5;
|
||||
//
|
||||
// btnCover
|
||||
//
|
||||
this.btnCover.Appearance.ForeColor = System.Drawing.Color.Red;
|
||||
this.btnCover.Appearance.Options.UseForeColor = true;
|
||||
this.btnCover.Location = new System.Drawing.Point(260, 12);
|
||||
this.btnCover.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.btnCover.Name = "btnCover";
|
||||
this.btnCover.Size = new System.Drawing.Size(110, 38);
|
||||
this.btnCover.TabIndex = 11;
|
||||
this.btnCover.Text = "设计关联";
|
||||
//
|
||||
// FrmMain2
|
||||
//
|
||||
this.Appearance.BackColor = System.Drawing.SystemColors.Control;
|
||||
|
||||
@@ -39,6 +39,9 @@ using System.Diagnostics;
|
||||
using DevExpress.XtraGrid.Views.BandedGrid;
|
||||
using DevExpress.Utils;
|
||||
using Lskj.Control;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using DevExpress.XtraGrid.Views.Grid;
|
||||
|
||||
namespace Lskj.PubBomImportNew
|
||||
{
|
||||
@@ -96,6 +99,10 @@ namespace Lskj.PubBomImportNew
|
||||
/// </summary>
|
||||
public GridControlEx ParentGridEx;
|
||||
|
||||
/// <summary>
|
||||
/// 缓存列对象
|
||||
/// </summary>
|
||||
private static List<GridColumnModel> ColumnList = new List<GridColumnModel>();
|
||||
/// <summary>
|
||||
/// 源表格
|
||||
/// </summary>
|
||||
@@ -108,17 +115,20 @@ namespace Lskj.PubBomImportNew
|
||||
/// 导入返回控件值
|
||||
/// </summary>
|
||||
public List<string> ImportReturnValue = new List<string>();
|
||||
public int FirstRowIndex = 0;
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
DataRow modelRow = MainImpl.GetSystemdllTab(Model.ModuleCode);//获取模块信息
|
||||
int.TryParse(Model.stratRowHand + "", out FirstRowIndex);
|
||||
DataRow modelRow = MainImpl.GetSystemdllTab(Model.ModuleCode);//获取模块信息
|
||||
if (modelRow != null)
|
||||
{
|
||||
this.SysModel = new ModuleModel(modelRow);
|
||||
InitializeControl(this.SysModel.MenuTable, this.Model.ModuleCode, _parmaryKey, this.gcMain, this.SysModel.PrefixKey, this.Model.primkey, this.Model.keyvalue, this.Model.FormText, this.SysModel.ConcatenatedPrefix);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("请检查模板是否配置正确!");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +137,7 @@ namespace Lskj.PubBomImportNew
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
this._tableColumns = BaseModuleImpl.GetBaseGridColumns(menuCode);
|
||||
this._tableName = tableName;
|
||||
this._menuCode = menuCode;
|
||||
@@ -163,7 +173,6 @@ namespace Lskj.PubBomImportNew
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -305,49 +314,31 @@ namespace Lskj.PubBomImportNew
|
||||
}
|
||||
}
|
||||
}
|
||||
public string GetValueByImportText(DataRow row, string fieldName, string text)
|
||||
/// <summary>
|
||||
/// 获取导入到下拉框里的显示值
|
||||
/// </summary>
|
||||
/// <param name="row"></param>
|
||||
/// <param name="fieldName"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="isBillImport"></param>
|
||||
/// <returns></returns>
|
||||
public string GetValueByImportText(DataRow row, string fieldName, string text, bool isBillImport = false)
|
||||
{
|
||||
string value = text;
|
||||
foreach (GridColumnModel model in this.ValueGridColumnTable.Keys)
|
||||
foreach (GridColumnModel model in ValueGridColumnTable.Keys)
|
||||
{
|
||||
if (model.FieldName.Equals(fieldName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string selWhere = "1=1";
|
||||
DataTable table = this.ValueGridColumnTable[model];
|
||||
if (model.FieldType == ControlType.LabMultiSelectValue || model.FieldType == ControlType.LabMultiSelectValueNew || model.FieldType == ControlType.LabMultiSelectValueParam)
|
||||
DataTable table = ValueGridColumnTable[model];
|
||||
if (table != null && table.Rows.Count > 0)
|
||||
{
|
||||
string[] splitString = text.Split(',');
|
||||
string nemValue = string.Empty;
|
||||
foreach (string newText in splitString)
|
||||
{
|
||||
if (table != null && table.Rows.Count > 0)
|
||||
{
|
||||
DataRow rowItemValue = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.TextMember] + "" == newText);
|
||||
DataRow rowItemText = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.ValueMember] + "" == newText);
|
||||
value = rowItemValue != null ? rowItemValue[model.ValueMember] + "" : rowItemText != null ? rowItemText[model.ValueMember] + "" : "";
|
||||
}
|
||||
else
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
nemValue += value + ',';
|
||||
}
|
||||
value = nemValue.TrimEnd(',');
|
||||
DataRow rowItemValue = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.TextMember] + "" == text);
|
||||
DataRow rowItemText = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.ValueMember] + "" == text);
|
||||
value = rowItemValue != null ? rowItemValue[isBillImport ? model.ValueMember : model.TextMember] + "" : rowItemText != null ? rowItemText[isBillImport ? model.ValueMember : model.TextMember] + "" : "";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (table != null && table.Rows.Count > 0)
|
||||
{
|
||||
DataRow rowItemValue = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.TextMember] + "" == text);
|
||||
DataRow rowItemText = table.Rows.Cast<DataRow>().FirstOrDefault(x => x[model.ValueMember] + "" == text);
|
||||
value = rowItemValue != null ? rowItemValue[model.ValueMember] + "" : rowItemText != null ? rowItemText[model.ValueMember] + "" : "";
|
||||
}
|
||||
else
|
||||
value = "";
|
||||
|
||||
}
|
||||
|
||||
value = "";
|
||||
}
|
||||
}
|
||||
return value;
|
||||
@@ -866,6 +857,19 @@ namespace Lskj.PubBomImportNew
|
||||
{
|
||||
try
|
||||
{
|
||||
if (BaseImpl.HasExistsTable("P_SpecialImportTab"))
|
||||
{
|
||||
string searchSql = string.Format("select * from P_SpecialImportTab where moduleId = '{0}' and rightMenuName = '{1}'", Model.ModuleCode, Model.ModuleId);
|
||||
DataTable dataTable = SqlHelper.ExecuteDataTable(searchSql);
|
||||
if (dataTable == null || dataTable.Rows.Count == 0)
|
||||
{
|
||||
MessageUtil.Show("未配置关联\r\n请联系管理员进行配置");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("未配置关联\r\n请联系管理员进行配置");
|
||||
}
|
||||
OpenFileDialog dialog = new OpenFileDialog();
|
||||
dialog.Title = "选择导入文件";
|
||||
// dialog.Filter = "Excel|*.xls|Excel|*.xlsx";
|
||||
@@ -882,7 +886,9 @@ namespace Lskj.PubBomImportNew
|
||||
//bool isMultipleHeader = false;
|
||||
//if (this._gridEx is BandedGridControlEx) isMultipleHeader = true;
|
||||
//this.gcMain.GridView.Tag = isMultipleHeader;
|
||||
gcData = this.gcMain.GridView.ToExcelDataTable(fileName, colFields, true);
|
||||
|
||||
gcData = ToExcelDataTable(fileName, out int count, out int errorCount, true);
|
||||
|
||||
|
||||
|
||||
//设置默认值
|
||||
@@ -990,8 +996,8 @@ namespace Lskj.PubBomImportNew
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
@@ -1015,9 +1021,17 @@ namespace Lskj.PubBomImportNew
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设计关联
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void OnBtnCoverClick(object sender, EventArgs e)
|
||||
{
|
||||
FrmMain frmMain = new FrmMain();
|
||||
frmMain.Model = Model;
|
||||
frmMain.ShowDialog();
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断导入条件
|
||||
/// </summary>
|
||||
@@ -1097,3 +1111,810 @@ namespace Lskj.PubBomImportNew
|
||||
string[] fields = model.UnionFields.Trim(',').Split(',');
|
||||
DataRow rowResult = BaseImpl.GetDataRowResult(unionValues);
|
||||
if (rowResult != null)
|
||||
{
|
||||
for (int i = 0; i < fields.Length; i++)
|
||||
{
|
||||
string field = fields[i];
|
||||
string value = rowResult.Table.Columns.Contains(field) ? rowResult[field] + "" : null;
|
||||
rowItem[field] = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 设置为空
|
||||
for (int i = 0; i < fields.Length; i++)
|
||||
{
|
||||
string field = fields[i];
|
||||
rowItem[field] = DBNull.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Instance.WriteError(ex);
|
||||
LogUtil.WriteError("计算列关联字段--错误-->" + unionValues, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取表格数据
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="sheetName"></param>
|
||||
/// <param name="isFirstRowColumn"></param>
|
||||
/// <returns></returns>
|
||||
public DataTable ExcelToDatatable(string fileName, DynamicBomImportNew 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 != null && 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="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="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="fileName"></param>
|
||||
/// <param name="colFields"></param>
|
||||
/// <param name="isDirectImport"></param>
|
||||
/// <param name="isBillImport"></param>
|
||||
/// <returns></returns>
|
||||
public DataTable ToExcelDataTable(string fileName, out int count, out int errorCount, bool isDirectImport = false, bool isBillImport = false)
|
||||
{
|
||||
count = 0;
|
||||
errorCount = 0;
|
||||
GridView gridView = gcMain.GridView;
|
||||
|
||||
DataTable columnsTable = new DataTable();
|
||||
string searchSql = string.Format("select * from P_SpecialImportTab where moduleId = '{0}' and rightMenuName = '{1}'", Model.ModuleCode, Model.ModuleId);
|
||||
DataTable dataTable = SqlHelper.ExecuteDataTable(searchSql);
|
||||
if (dataTable != null && dataTable.Rows.Count > 0)
|
||||
{
|
||||
DataRow dataRow = dataTable.Rows[0];
|
||||
string unionColumn = dataRow["Ls_UnionColumn"] + "";
|
||||
List<string> unionColumnList = unionColumn.Split(',').ToList();
|
||||
columnsTable = GetSourceTable(unionColumnList);
|
||||
}
|
||||
|
||||
DataTable table = gridView.GridControl.DataSourceTable();
|
||||
|
||||
DataTable sourceDataTable = ExcelToDatatable(fileName, Model, "", FirstRowIndex);
|
||||
DataView filterDataView = new DataView(sourceDataTable);
|
||||
try
|
||||
{
|
||||
//if (!string.IsNullOrEmpty(Model.ReadTableCond))
|
||||
//{
|
||||
// filterDataView.RowFilter = Model.ReadTableCond;
|
||||
//}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
List<DataRow> dataRows = columnsTable.Rows.Cast<DataRow>().Where(n => !string.IsNullOrEmpty(n["excelFieldName"] + "") && !string.IsNullOrEmpty(n["clientFieldName"] + "")).ToList();
|
||||
int index = gridView is BandedGridView ? FirstRowIndex + 1 : FirstRowIndex;
|
||||
isBillImport = index == FirstRowIndex ? true : isBillImport;
|
||||
string fileExt = Path.GetExtension(fileName).ToLower();
|
||||
|
||||
int CurrentRow = 0;//当前行数
|
||||
int CurrentColumn = 0;//当前列数
|
||||
string columnName = string.Empty;//当前列名
|
||||
bool ToAssignment = false;//是否在给新表赋值
|
||||
|
||||
try
|
||||
{
|
||||
ISheet sheet = ExcelHelper.GetSheet(fileName);
|
||||
IRow firstRow = sheet.GetRow(index);
|
||||
IRow bandRow = null;
|
||||
int startRow = FirstRowIndex + 1;
|
||||
string bandTitel = string.Empty;
|
||||
ColumnList.Clear();
|
||||
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, index, 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 headerName = "";
|
||||
if (!isBandTitle || bandRow == null)
|
||||
{
|
||||
headerName = GetCellValue(titleCell);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(GetCellValue(bandCell)))
|
||||
{
|
||||
headerName = $"{GetCellValue(titleCell)}|{GetCellValue(bandCell)}";
|
||||
}
|
||||
if (string.IsNullOrEmpty(headerName))
|
||||
{
|
||||
cellCount -= 1;
|
||||
continue;
|
||||
}
|
||||
DataRow row = columnsTable.Rows.Cast<DataRow>().Where(x => (x["excelFieldName"] + "").Equals(headerName)).FirstOrDefault();
|
||||
headerName = row != null ? row["clientFieldName"] + "" : headerName;
|
||||
if (string.IsNullOrWhiteSpace(headerName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
GridColumn col = gridView.Columns.OfType<GridColumn>().FirstOrDefault(x => x.FieldName.Equals(headerName));
|
||||
if (col != null)
|
||||
{
|
||||
if (!table.Columns.Contains(col.FieldName))
|
||||
{
|
||||
table.Columns.Add(col.FieldName, col.ColumnType);
|
||||
}
|
||||
ColumnList.Add(col.Tag as GridColumnModel);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("未找到列->" + headerName + "");
|
||||
}
|
||||
}
|
||||
InitializeValueGrid();
|
||||
bool AutoImportCal = SystemInfo.Instance.AutoImportCal;//是否执行计算公式
|
||||
for (int i = startRow; i <= sheet.LastRowNum; i++)
|
||||
{
|
||||
ToAssignment = true;
|
||||
CurrentRow = i;
|
||||
DataRow rowSource = sourceDataTable.Rows[i - startRow];
|
||||
if (!filterDataView.Cast<DataRowView>().Any(rowView => rowView.Row == rowSource))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
GridColumn col = new GridColumn();
|
||||
IRow row = sheet.GetRow(i);
|
||||
if (row == null) continue;
|
||||
bandTitel = string.Empty;
|
||||
DataRow dataRow = table.NewRow();
|
||||
//if (i == sheet.LastRowNum && fileExt == ".xlsx") break;
|
||||
for (int j = row.FirstCellNum; j < firstRow.LastCellNum; j++)
|
||||
{
|
||||
CurrentColumn = j;
|
||||
ICell cell = row.GetCell(j);
|
||||
ICell titleCell = firstRow.GetCell(j);
|
||||
ICell bandCell = null;
|
||||
bool isBandTitle = false;
|
||||
if (titleCell.IsMergedCell)
|
||||
{
|
||||
CellRangeAddress mergrRange = FindMergedRegion(sheet, index, j);
|
||||
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(j);
|
||||
CellRangeAddress bandMergrRange = FindMergedRegion(sheet, mergrRange.LastRow + 1, j);
|
||||
if (bandMergrRange != null)
|
||||
{
|
||||
startRow = bandMergrRange.LastRow + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startRow = mergrRange.LastRow + 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
startRow = mergrRange.LastRow + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isBandTitle || bandRow == null)
|
||||
{
|
||||
columnName = GetCellValue(titleCell);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(GetCellValue(bandCell)))
|
||||
{
|
||||
columnName = $"{GetCellValue(titleCell)}|{GetCellValue(bandCell)}";
|
||||
}
|
||||
if (string.IsNullOrEmpty(columnName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
DataRow colDataRow = dataRows.Where(n => (n["excelFieldName"] + "").Equals(columnName)).FirstOrDefault();
|
||||
if (colDataRow == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
columnName = colDataRow["clientFieldName"] + "";
|
||||
//if (!bandTitel.Equals(Bandcell + "") && !string.IsNullOrEmpty(Bandcell + "")) bandTitel = Bandcell + "";
|
||||
col = gridView.Columns.OfType<GridColumn>().FirstOrDefault(x => x.FieldName.Equals(columnName));
|
||||
if (col == null) continue;
|
||||
GridColumnModel model = col.Tag as GridColumnModel;
|
||||
if (cell != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (cell.CellType == CellType.Blank)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (cell.CellType == CellType.Numeric && (cell + "").StartsWith("-"))
|
||||
{
|
||||
dataRow[col.FieldName] = cell.NumericCellValue;
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cell.CellType == CellType.Numeric)
|
||||
{
|
||||
|
||||
//GridColumnModel model = col.Tag as GridColumnModel;
|
||||
if (model != null && isDirectImport && (model.FieldType == ControlType.LabDate ||
|
||||
model.FieldType == ControlType.LabDateTime ||
|
||||
model.FieldType == ControlType.LabDateTimeShort ||
|
||||
model.FieldType == ControlType.LabTime ||
|
||||
model.FieldType == ControlType.LabShortTime))
|
||||
{
|
||||
string fieldValue = ToDateTimeValue(cell.NumericCellValue + "");
|
||||
if (fieldValue != "")
|
||||
{
|
||||
dataRow[col.FieldName] = Convert.ToDateTime(fieldValue);
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataRow[col.FieldName] = cell.NumericCellValue;
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//GridColumnModel model = col.Tag as GridColumnModel;
|
||||
if (model != null && isDirectImport && (model.FieldType == ControlType.LabTreeType ||
|
||||
model.FieldType == ControlType.LabComboxValue ||
|
||||
model.FieldType == ControlType.LabComboxValueParam ||
|
||||
model.FieldType == ControlType.LabAutoCompleteValue ||
|
||||
model.FieldType == ControlType.LabAutoCompleteValueParam ||
|
||||
model.FieldType == ControlType.LabMultiSelectValue ||
|
||||
model.FieldType == ControlType.LabMultiSelectValueParam
|
||||
|| model.FieldType == ControlType.LabTreeLookValue
|
||||
))
|
||||
{
|
||||
bool isEmpty = model.CanNull;
|
||||
string fieldValue = GetValueByImportText(dataRow, col.FieldName, cell + "", isBillImport);
|
||||
if ((model.FieldType == ControlType.LabMultiSelectValue ||
|
||||
model.FieldType == ControlType.LabMultiSelectValueParam) && GetCellValue(cell).Contains(","))
|
||||
{
|
||||
string[] cellText = GetCellValue(cell).Split(',');
|
||||
foreach (string cellValue in cellText)
|
||||
{
|
||||
fieldValue += GetValueByImportText(dataRow, col.FieldName, cellValue, isBillImport) + ',';
|
||||
}
|
||||
fieldValue = fieldValue.TrimEnd(',');
|
||||
}
|
||||
if (string.IsNullOrEmpty(fieldValue))
|
||||
{
|
||||
if (isEmpty)
|
||||
{
|
||||
MessageUtil.Show("该列不允许为空->" + col.Caption + "");
|
||||
}
|
||||
else
|
||||
{
|
||||
GridColumn column = gridView.Columns[col.FieldName];
|
||||
if (column.ColumnType.Name.ToLower().IndexOf("int") >= 0)
|
||||
if (column.ColumnType.Name.ToLower() == "string")
|
||||
dataRow[col.FieldName] = "";
|
||||
if (column.ColumnType.Name.ToLower().IndexOf("char") >= 0)
|
||||
dataRow[col.FieldName] = "";
|
||||
if (column.ColumnType.Name.ToLower().IndexOf("int") >= 0)
|
||||
dataRow[col.FieldName] = 0;
|
||||
if (column.ColumnType.Name.ToLower() == "decimal")
|
||||
dataRow[col.FieldName] = 0;
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataRow[col.FieldName] = fieldValue;
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IRichTextString richTextString = (IRichTextString)cell.RichStringCellValue;
|
||||
if (fileExt == ".xlsx")
|
||||
{
|
||||
cell.SetCellValue(richTextString);
|
||||
}
|
||||
else if (fileExt == ".xls")
|
||||
{
|
||||
string cellValue = string.Empty;
|
||||
for (int m = 0; m < richTextString.Length; m++)
|
||||
{
|
||||
|
||||
//string aaa = richTextString.String.Substring(m , 1);
|
||||
//short aaa = richTextString.GetFontAtIndex(m);
|
||||
IFont font = sheet.Workbook.GetFontAt(richTextString.GetFontAtIndex(m));//richTextString.GetFontAtIndex(m)
|
||||
|
||||
string str = string.Empty;
|
||||
string code = richTextString.ToString().Substring(m, 1);
|
||||
switch (font.TypeOffset)
|
||||
{
|
||||
case FontSuperScript.Sub:
|
||||
str = ChemistryHelper.GetSubChar(code);
|
||||
break;
|
||||
|
||||
case FontSuperScript.Super:
|
||||
str = ChemistryHelper.GetSuperChar(code);
|
||||
break;
|
||||
default:
|
||||
str = code;
|
||||
break;
|
||||
}
|
||||
cellValue = cellValue + str;
|
||||
}
|
||||
cell.SetCellValue(cellValue);
|
||||
}
|
||||
dataRow[col.FieldName] = GetCellValue(cell);
|
||||
if (AutoImportCal)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||||
{
|
||||
SetUnionValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
SetCalcValue(model, dataRow[col.FieldName] + "", dataRow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
table.Rows.Add(dataRow);
|
||||
count += 1;
|
||||
}
|
||||
ToAssignment = false;
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
|
||||
if (ToAssignment && (CurrentRow != 0 || CurrentColumn != 0))
|
||||
{
|
||||
string value = string.Format("第{0}行,第{1}列 {2},值出现异常", CurrentRow, CurrentColumn + 1, columnName);
|
||||
MessageUtil.Show(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.DeleteLastTotalRow);
|
||||
}
|
||||
}
|
||||
catch (IOException exe)
|
||||
{
|
||||
//string Message = ErrorMessage.PromptErrorMessage(exe);
|
||||
//MessageUtil.Show(Message, exe.Message);
|
||||
MessageUtil.Show(string.Format(ResourceKeys.UseingFile, Path.GetFileName(fileName)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//MessageUtil.Show(ResourceKeys.ImportFault + ex.Message);
|
||||
LogUtil.WriteError("读取excel出错!", ex);
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
return table.TrimEmptyRows();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算列计算公式
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="fieldValue"></param>
|
||||
/// <param name="rowItem"></param>
|
||||
private void SetCalcValue(GridColumnModel model, string fieldValue, DataRow rowItem)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (rowItem != null && model != null)
|
||||
{
|
||||
foreach (GridColumn col in this.ParentView.Columns)
|
||||
{
|
||||
GridColumnModel colModel = col.Tag as GridColumnModel;
|
||||
if (colModel == null) continue;
|
||||
string defultValue = colModel.DefaultValue;
|
||||
if (colModel.FieldType == 7 && rowItem.Table.Columns.Contains(col.FieldName) && string.IsNullOrEmpty(rowItem[col.FieldName] + "") && !string.IsNullOrEmpty(colModel.DefaultValue))
|
||||
{
|
||||
defultValue = ReplaceHelper.ReplaceUserInfo(colModel.DefaultValue);
|
||||
if (defultValue.StartsWith("@"))
|
||||
{
|
||||
defultValue = BaseImpl.GetDefaultValue(ReplaceHelper.ReplaceRowParam(rowItem, defultValue));
|
||||
}
|
||||
|
||||
if (IsNumberic(defultValue)) rowItem[col.FieldName] = defultValue;//colModel.DefaultValue;
|
||||
|
||||
}
|
||||
}
|
||||
List<GridColumnModel> calcModels = ColumnList.FindAll(x => !string.IsNullOrEmpty(x.CalcExpr)).OrderBy(y => y.CalcOrder).ToList();
|
||||
foreach (GridColumnModel gridModel in calcModels)
|
||||
{
|
||||
// 计算顺序小于当前控件则不计算
|
||||
if (gridModel.CalcOrder < model.CalcOrder) continue;
|
||||
|
||||
if (!gridModel.FieldName.Equals(model.FieldName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
bool isTruncate = false;
|
||||
string calcExpr = gridModel.CalcExpr;
|
||||
if (calcExpr.StartsWith("@truncate:"))
|
||||
{
|
||||
calcExpr = calcExpr.Substring(10);
|
||||
isTruncate = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (calcExpr.StartsWith("@"))
|
||||
{
|
||||
result = BaseImpl.GetDefaultValue(ReplaceHelper.ReplaceRowParam(rowItem, calcExpr));
|
||||
}
|
||||
else
|
||||
{
|
||||
calcExpr = ReplaceHelper.ReplaceRowParam(rowItem, calcExpr);
|
||||
result = EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr)) + "";
|
||||
}
|
||||
if (isTruncate)
|
||||
{
|
||||
result += result.Contains(".") ? "0000000000" : ".0000000000";
|
||||
rowItem[gridModel.FieldName] = result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1);
|
||||
//this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
double d = 0;
|
||||
if (!string.IsNullOrEmpty(result) &&
|
||||
!"NaN".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||||
!"非数字".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||||
!"undefined".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||||
result != "∞" && result != "-∞" &&
|
||||
!"正无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||||
!"负无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||||
double.TryParse(result, out d))
|
||||
{
|
||||
if (string.IsNullOrEmpty(gridModel.DataFormat))
|
||||
{
|
||||
result = Math.Round(Convert.ToDouble(d), model.Decimals, MidpointRounding.AwayFromZero) + "";
|
||||
}
|
||||
else
|
||||
{
|
||||
//计算后先执行保存小数位数
|
||||
if (SystemInfo.Instance.ComputeFormatting) result = string.Format("{0:" + gridModel.DataFormat + "}", Convert.ToDecimal(result));
|
||||
}
|
||||
if (model.FieldType == 7 && result.Contains('%'))
|
||||
{
|
||||
result = (double.Parse(result.Replace("%", "")) * 0.01).ToString();
|
||||
}
|
||||
rowItem[gridModel.FieldName] = result;
|
||||
// 判断计算列有无关联值
|
||||
GridColumnModel UnionModel = calcModels.FirstOrDefault(x => x.FieldName == gridModel.FieldName);
|
||||
if (!string.IsNullOrEmpty(UnionModel.UnionFields))
|
||||
{
|
||||
this.SetUnionValue(UnionModel, rowItem[gridModel.FieldName] + "", rowItem);
|
||||
}
|
||||
//this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Instance.WriteError(ex);
|
||||
LogUtil.WriteError("计算列计算公式--错误-->" + rowItem[gridModel.FieldName], ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断输入的字符串是否可以转换成数值类型
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsNumberic(string str)
|
||||
{
|
||||
double vsNum;
|
||||
bool isNum;
|
||||
isNum = double.TryParse(str, System.Globalization.NumberStyles.Float,
|
||||
System.Globalization.NumberFormatInfo.InvariantInfo, out vsNum);
|
||||
return isNum;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取数据源
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private DataTable GetSourceTable(DataTable dataTable)
|
||||
{
|
||||
DataTable sourceTable = new DataTable();
|
||||
sourceTable.Columns.Add("excelFieldName");
|
||||
sourceTable.Columns.Add("clientFieldName");
|
||||
if (dataTable != null)
|
||||
{
|
||||
foreach (DataColumn col in dataTable.Columns)
|
||||
{
|
||||
DataRow dataRow = sourceTable.NewRow();
|
||||
dataRow["excelFieldName"] = col.ColumnName;
|
||||
sourceTable.Rows.Add(dataRow);
|
||||
}
|
||||
}
|
||||
return sourceTable;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Lskj.PubBomImport
|
||||
namespace Lskj.PubBomImportNew
|
||||
{
|
||||
partial class FrmProgress
|
||||
{
|
||||
|
||||
@@ -51,211 +51,210 @@ namespace Lskj.PubBomImportNew
|
||||
/// <param name="dirPaths"></param>
|
||||
public void StartImportInFileByZB(List<DataRow> selectRows)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists("BomImportTemp"))
|
||||
{
|
||||
Directory.Delete("BomImportTemp", true);
|
||||
}
|
||||
Directory.CreateDirectory("BomImportTemp");
|
||||
int execOrder = 1;
|
||||
if (selectRows.Count > 1)
|
||||
{
|
||||
throw new Exception($"不允许选择多个文件");
|
||||
}
|
||||
DataRow mxRow = selectRows[0];
|
||||
if (mxRow != null)
|
||||
{
|
||||
string mxDirPath = mxRow["BomFieldNameDir"] + "";
|
||||
string productId = mxRow["BomMxMainProduct"] + "";
|
||||
string addState = mxRow["BomMxAddState"] + "";
|
||||
if (string.IsNullOrEmpty(Model.MainFieldDic))
|
||||
{
|
||||
throw new Exception($"字段对应关系配置异常");
|
||||
}
|
||||
if (string.IsNullOrEmpty(productId))
|
||||
{
|
||||
throw new Exception($"保存失败\r\n请重新进行BOM上传后保存");
|
||||
}
|
||||
if (addState.Equals("新增"))
|
||||
{
|
||||
DataRow billRow = BaseImpl.GetDataRowResult($"select qms_maddf_billdocument_id from qms_BillFileAddMaintab where qms_maddf_productid = '{productId}' and isnull(qms_maddf_addMode,'0') = '0'");
|
||||
if (billRow != null)
|
||||
{
|
||||
throw new Exception($"物料编码{productId}的BOM新增单已存在审批流\r\n请进行审批");
|
||||
}
|
||||
DataRow billbomRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'");
|
||||
if (billRow != null)
|
||||
{
|
||||
throw new Exception($"物料编码{productId}的BOM建立单已存在\r\n请进行修改操作");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DataRow billbomRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}' and stepover = '1'");
|
||||
if (billbomRow != null)
|
||||
{
|
||||
throw new Exception($"物料编码{productId}的BOM建立单已终审\r\n禁止修改操作");
|
||||
}
|
||||
}
|
||||
FileInfo mxInfo = null;
|
||||
if (!string.IsNullOrEmpty(mxDirPath))
|
||||
{
|
||||
mxInfo = new FileInfo(mxDirPath);
|
||||
}
|
||||
if (mxInfo != null)
|
||||
{
|
||||
DataTable mxfiletable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{productId}' and dllcoid = '1000202') and speciesno = '010106' and sname = '{mxInfo.Name}'");
|
||||
if (mxfiletable.Rows.Count > 0)
|
||||
{
|
||||
throw new Exception($"该文件已存在,请确认后再创建BOM");
|
||||
}
|
||||
FrmBillInfo frmBillInfo = new FrmBillInfo();
|
||||
int.TryParse(Model.FirstRowIndex + "", out int firstRowIndex);
|
||||
DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, Model.SheetName, firstRowIndex);
|
||||
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)
|
||||
//{
|
||||
// string code = (dataRow["图号"] + "").Trim();
|
||||
// if (code.StartsWith("QD"))
|
||||
// {
|
||||
// int createCode = ProductSaveUnique(code.Replace("'", "''"), (dataRow["名称"] + "").Replace("'", "''"), (dataRow["备注"] + "").Replace("'", "''"), "1000202_1", out string pid, out string msg);
|
||||
// if ((createCode + "").Equals("-1"))
|
||||
// {
|
||||
// throw new Exception($"虚拟物料创建失败\r\n{msg}");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||
//{
|
||||
// SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||
//}
|
||||
frmBillInfo.OnControlSourceBind += (s, args) =>
|
||||
{
|
||||
Task task = new Task(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(Model.FirstRowIndex, out int index);
|
||||
frmMain.FirstRowIndex = index;
|
||||
bool isUpload = false;
|
||||
string msg = "";
|
||||
Dictionary<string, DataRow> maxBcFileDic = new Dictionary<string, DataRow>();
|
||||
Dictionary<string, DataTable> fileTableDic = new Dictionary<string, DataTable>();
|
||||
#region 新增或修改MX
|
||||
frmBillInfo.OnBillAdd();
|
||||
SetProcessBar(0, 0);
|
||||
SetProcessMsg($"正在导入:{Path.GetFileName(mxInfo.FullName)}");
|
||||
DataTable childTable = frmBillInfo.GcMainView.GridControl.DataSourceTable().Clone();
|
||||
var mxCodeRows = parentTable.AsEnumerable();
|
||||
string[] fieldDic = Model.MainFieldDic.Split(',');
|
||||
foreach (DataRow parentRow in parentTable.Rows)
|
||||
{
|
||||
string code = (parentRow["物料编码"] + "").Trim();
|
||||
int codeCount = mxCodeRows.Where(n => (n["物料编码"] + "").Trim().StartsWith(code)).Count();
|
||||
if (codeCount > 1)//只允许存在一个
|
||||
{
|
||||
throw new Exception($"文件中的物料编码{code}重复,请修改");
|
||||
}
|
||||
DataRow childRow = childTable.NewRow();
|
||||
foreach (string item in fieldDic)
|
||||
{
|
||||
string[] fieldArray = item.Split('^');
|
||||
string key0 = fieldArray[0];
|
||||
string key1 = fieldArray[1];
|
||||
childRow[key0] = parentRow[key1] + "";
|
||||
}
|
||||
//childRow["ProductId"] = parentRow["物料编码"] + "";
|
||||
//childRow["appellation"] = parentRow["名称"] + "";
|
||||
//childRow["bak"] = parentRow["备注"] + "";
|
||||
//childRow["tamount"] = parentRow["数量"] + "";
|
||||
//childRow["amount"] = parentRow["数量"] + "";
|
||||
childTable.Rows.Add(childRow);
|
||||
}
|
||||
SetProcessBar(20, 0);
|
||||
if (childTable.Rows.Count == 0)
|
||||
{
|
||||
throw new Exception($"明细数据不能空");
|
||||
}
|
||||
SetProcessBar(40, 0);
|
||||
string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productId}') as billdocument_id,'0' affirmer,'0' rtagid,'{productId}' as productid,'' as bak,'' as bombb,'' as bombc";
|
||||
// 处理单据表头数据
|
||||
DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
|
||||
SetProcessBar(60, 0);
|
||||
frmBillInfo.AddOrUpdateBill(masterRow, childTable);
|
||||
string guid = Guid.NewGuid() + "";
|
||||
frmBillInfo.BillSaveSql(guid);
|
||||
SetProcessBar(80, 0);
|
||||
//上传文件
|
||||
string uploadMxFileId = "";
|
||||
if (mxfiletable.Rows.Count == 0)
|
||||
{
|
||||
isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out uploadMxFileId);
|
||||
if (!isUpload)
|
||||
{
|
||||
throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}");
|
||||
}
|
||||
}
|
||||
StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||
{
|
||||
if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
|
||||
{
|
||||
int.TryParse(uploadMxFileId, out int qms_laddf_FileId);
|
||||
mxRow["qms_laddf_FileId"] = qms_laddf_FileId;
|
||||
}
|
||||
if (mxRow.Table.Columns.Contains("qms_laddf_Exec"))
|
||||
{
|
||||
mxRow["qms_laddf_Exec"] = guid;
|
||||
}
|
||||
if (mxRow.Table.Columns.Contains("qms_laddf_ExecOrder"))
|
||||
{
|
||||
mxRow["qms_laddf_ExecOrder"] = execOrder;
|
||||
}
|
||||
}));
|
||||
execOrder += 1;
|
||||
#endregion
|
||||
SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
|
||||
SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
ImportTimer?.Dispose();
|
||||
}));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
ImportTimer?.Dispose();
|
||||
}));
|
||||
}
|
||||
});
|
||||
task.Start();
|
||||
};
|
||||
frmBillInfo.OnLoad(Model);
|
||||
frmMain.ParentView = frmBillInfo.GcMainView;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("文件不存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageUtil.Show(ex.Message);
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
ImportTimer?.Dispose();
|
||||
}));
|
||||
}
|
||||
//try
|
||||
//{
|
||||
// if (Directory.Exists("BomImportTemp"))
|
||||
// {
|
||||
// Directory.Delete("BomImportTemp", true);
|
||||
// }
|
||||
// Directory.CreateDirectory("BomImportTemp");
|
||||
// int execOrder = 1;
|
||||
// if (selectRows.Count > 1)
|
||||
// {
|
||||
// throw new Exception($"不允许选择多个文件");
|
||||
// }
|
||||
// DataRow mxRow = selectRows[0];
|
||||
// if (mxRow != null)
|
||||
// {
|
||||
// string mxDirPath = mxRow["BomFieldNameDir"] + "";
|
||||
// string productId = mxRow["BomMxMainProduct"] + "";
|
||||
// string addState = mxRow["BomMxAddState"] + "";
|
||||
// if (string.IsNullOrEmpty(Model.MainFieldDic))
|
||||
// {
|
||||
// throw new Exception($"字段对应关系配置异常");
|
||||
// }
|
||||
// if (string.IsNullOrEmpty(productId))
|
||||
// {
|
||||
// throw new Exception($"保存失败\r\n请重新进行BOM上传后保存");
|
||||
// }
|
||||
// if (addState.Equals("新增"))
|
||||
// {
|
||||
// DataRow billRow = BaseImpl.GetDataRowResult($"select qms_maddf_billdocument_id from qms_BillFileAddMaintab where qms_maddf_productid = '{productId}' and isnull(qms_maddf_addMode,'0') = '0'");
|
||||
// if (billRow != null)
|
||||
// {
|
||||
// throw new Exception($"物料编码{productId}的BOM新增单已存在审批流\r\n请进行审批");
|
||||
// }
|
||||
// DataRow billbomRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}'");
|
||||
// if (billRow != null)
|
||||
// {
|
||||
// throw new Exception($"物料编码{productId}的BOM建立单已存在\r\n请进行修改操作");
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// DataRow billbomRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid='{productId}' and stepover = '1'");
|
||||
// if (billbomRow != null)
|
||||
// {
|
||||
// throw new Exception($"物料编码{productId}的BOM建立单已终审\r\n禁止修改操作");
|
||||
// }
|
||||
// }
|
||||
// FileInfo mxInfo = null;
|
||||
// if (!string.IsNullOrEmpty(mxDirPath))
|
||||
// {
|
||||
// mxInfo = new FileInfo(mxDirPath);
|
||||
// }
|
||||
// if (mxInfo != null)
|
||||
// {
|
||||
// DataTable mxfiletable = BaseImpl.GetDataTableResult($"select sname,fileId,webpath from p_fm_filetab where parentid in (select dirid from P_fm_DirectoryTab where pid = '{productId}' and dllcoid = '1000202') and speciesno = '010106' and sname = '{mxInfo.Name}'");
|
||||
// if (mxfiletable.Rows.Count > 0)
|
||||
// {
|
||||
// throw new Exception($"该文件已存在,请确认后再创建BOM");
|
||||
// }
|
||||
// int.TryParse(Model.FirstRowIndex + "", out int firstRowIndex);
|
||||
// DataTable parentTable = ExcelToDatatable(mxInfo.FullName, Model, Model.SheetName, firstRowIndex);
|
||||
// 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)
|
||||
// //{
|
||||
// // string code = (dataRow["图号"] + "").Trim();
|
||||
// // if (code.StartsWith("QD"))
|
||||
// // {
|
||||
// // int createCode = ProductSaveUnique(code.Replace("'", "''"), (dataRow["名称"] + "").Replace("'", "''"), (dataRow["备注"] + "").Replace("'", "''"), "1000202_1", out string pid, out string msg);
|
||||
// // if ((createCode + "").Equals("-1"))
|
||||
// // {
|
||||
// // throw new Exception($"虚拟物料创建失败\r\n{msg}");
|
||||
// // }
|
||||
// // }
|
||||
// //}
|
||||
// //if (!string.IsNullOrEmpty(stringBuilder.ToString()))
|
||||
// //{
|
||||
// // SqlHelper.ExecuteNonQuery(stringBuilder.ToString());
|
||||
// //}
|
||||
// frmBillInfo.OnControlSourceBind += (s, args) =>
|
||||
// {
|
||||
// Task task = new Task(() =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// int.TryParse(Model.FirstRowIndex, out int index);
|
||||
// frmMain.FirstRowIndex = index;
|
||||
// bool isUpload = false;
|
||||
// string msg = "";
|
||||
// Dictionary<string, DataRow> maxBcFileDic = new Dictionary<string, DataRow>();
|
||||
// Dictionary<string, DataTable> fileTableDic = new Dictionary<string, DataTable>();
|
||||
// #region 新增或修改MX
|
||||
// frmBillInfo.OnBillAdd();
|
||||
// SetProcessBar(0, 0);
|
||||
// SetProcessMsg($"正在导入:{Path.GetFileName(mxInfo.FullName)}");
|
||||
// DataTable childTable = frmBillInfo.GcMainView.GridControl.DataSourceTable().Clone();
|
||||
// var mxCodeRows = parentTable.AsEnumerable();
|
||||
// string[] fieldDic = Model.MainFieldDic.Split(',');
|
||||
// foreach (DataRow parentRow in parentTable.Rows)
|
||||
// {
|
||||
// string code = (parentRow["物料编码"] + "").Trim();
|
||||
// int codeCount = mxCodeRows.Where(n => (n["物料编码"] + "").Trim().StartsWith(code)).Count();
|
||||
// if (codeCount > 1)//只允许存在一个
|
||||
// {
|
||||
// throw new Exception($"文件中的物料编码{code}重复,请修改");
|
||||
// }
|
||||
// DataRow childRow = childTable.NewRow();
|
||||
// foreach (string item in fieldDic)
|
||||
// {
|
||||
// string[] fieldArray = item.Split('^');
|
||||
// string key0 = fieldArray[0];
|
||||
// string key1 = fieldArray[1];
|
||||
// childRow[key0] = parentRow[key1] + "";
|
||||
// }
|
||||
// //childRow["ProductId"] = parentRow["物料编码"] + "";
|
||||
// //childRow["appellation"] = parentRow["名称"] + "";
|
||||
// //childRow["bak"] = parentRow["备注"] + "";
|
||||
// //childRow["tamount"] = parentRow["数量"] + "";
|
||||
// //childRow["amount"] = parentRow["数量"] + "";
|
||||
// childTable.Rows.Add(childRow);
|
||||
// }
|
||||
// SetProcessBar(20, 0);
|
||||
// if (childTable.Rows.Count == 0)
|
||||
// {
|
||||
// throw new Exception($"明细数据不能空");
|
||||
// }
|
||||
// SetProcessBar(40, 0);
|
||||
// string billMasterSql = $"select (select top 1 billdocument_id from bom_BillTab where productid='{productId}') as billdocument_id,'0' affirmer,'0' rtagid,'{productId}' as productid,'' as bak,'' as bombb,'' as bombc";
|
||||
// // 处理单据表头数据
|
||||
// DataRow masterRow = BillImpl.GetDataRowResult(billMasterSql);
|
||||
// SetProcessBar(60, 0);
|
||||
// frmBillInfo.AddOrUpdateBill(masterRow, childTable);
|
||||
// string guid = Guid.NewGuid() + "";
|
||||
// frmBillInfo.BillSaveSql(guid);
|
||||
// SetProcessBar(80, 0);
|
||||
// //上传文件
|
||||
// string uploadMxFileId = "";
|
||||
// if (mxfiletable.Rows.Count == 0)
|
||||
// {
|
||||
// isUpload = UploadFileToAudit(mxInfo.FullName, productId, "010106", out msg, out uploadMxFileId);
|
||||
// if (!isUpload)
|
||||
// {
|
||||
// throw new Exception($"{mxInfo.Name}附件上传失败\r\n{msg}");
|
||||
// }
|
||||
// }
|
||||
// StaticControl.RightMenuGridView.GridControl.Invoke(new Action(() =>
|
||||
// {
|
||||
// if (mxRow.Table.Columns.Contains("qms_laddf_FileId"))
|
||||
// {
|
||||
// int.TryParse(uploadMxFileId, out int qms_laddf_FileId);
|
||||
// mxRow["qms_laddf_FileId"] = qms_laddf_FileId;
|
||||
// }
|
||||
// if (mxRow.Table.Columns.Contains("qms_laddf_Exec"))
|
||||
// {
|
||||
// mxRow["qms_laddf_Exec"] = guid;
|
||||
// }
|
||||
// if (mxRow.Table.Columns.Contains("qms_laddf_ExecOrder"))
|
||||
// {
|
||||
// mxRow["qms_laddf_ExecOrder"] = execOrder;
|
||||
// }
|
||||
// }));
|
||||
// execOrder += 1;
|
||||
// #endregion
|
||||
// SetProcessBar(100, (1 / (parentTable.Rows.Count + 1)) * 100);
|
||||
// SetProcessLabelAllMsg($"总进度:{1}/{parentTable.Rows.Count + 1}");
|
||||
// this.Invoke(new Action(() =>
|
||||
// {
|
||||
// this.DialogResult = DialogResult.OK;
|
||||
// Close();
|
||||
// ImportTimer?.Dispose();
|
||||
// }));
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// MessageUtil.Show(ex.Message);
|
||||
// this.Invoke(new Action(() =>
|
||||
// {
|
||||
// this.DialogResult = DialogResult.Cancel;
|
||||
// Close();
|
||||
// ImportTimer?.Dispose();
|
||||
// }));
|
||||
// }
|
||||
// });
|
||||
// task.Start();
|
||||
// };
|
||||
// frmBillInfo.OnLoad(Model);
|
||||
// frmMain.ParentView = frmBillInfo.GcMainView;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new Exception("文件不存在");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// MessageUtil.Show(ex.Message);
|
||||
// this.Invoke(new Action(() =>
|
||||
// {
|
||||
// this.DialogResult = DialogResult.Cancel;
|
||||
// Close();
|
||||
// ImportTimer?.Dispose();
|
||||
// }));
|
||||
//}
|
||||
}
|
||||
public int ProductSaveUnique(string spec, string appellation, string bak, string billSeq, out string productId, out string tipMsg)
|
||||
{
|
||||
@@ -417,7 +416,7 @@ namespace Lskj.PubBomImportNew
|
||||
startRow = mergrRange.LastRow + 1;
|
||||
if (mergrRange != null)
|
||||
{
|
||||
if (mergrRange.FirstColumn < mergrRange.LastColumn && !Model.CustomerServiceApp)
|
||||
if (mergrRange.FirstColumn < mergrRange.LastColumn)//&& !Model.CustomerServiceApp
|
||||
{
|
||||
isBandTitle = true;
|
||||
bandRow = sheet.GetRow(mergrRange.LastRow + 1);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{8C507C31-8C19-46C9-82F8-85DDCAE69190}</ProjectGuid>
|
||||
<ProjectGuid>{2808D18D-FE0D-450B-8DDC-6B46CBB7A453}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Lskj.PubBomImport</RootNamespace>
|
||||
<AssemblyName>Lskj.PubBomImport</AssemblyName>
|
||||
@@ -66,18 +66,18 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DllBaseClass.cs" />
|
||||
<Compile Include="FrmBillInfo.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmBillInfo.Designer.cs">
|
||||
<DependentUpon>FrmBillInfo.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrmMain.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmMain.Designer.cs">
|
||||
<DependentUpon>FrmMain.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrmMain2.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmMain2.Designer.cs">
|
||||
<DependentUpon>FrmMain2.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrmProgress.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -93,12 +93,12 @@
|
||||
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="FrmBillInfo.resx">
|
||||
<DependentUpon>FrmBillInfo.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FrmMain.resx">
|
||||
<DependentUpon>FrmMain.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FrmMain2.resx">
|
||||
<DependentUpon>FrmMain2.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FrmProgress.resx">
|
||||
<DependentUpon>FrmProgress.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
@@ -5,5 +5,5 @@ using System.Runtime.InteropServices;
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Lskj.PubBomImport")]
|
||||
[assembly: AssemblyDe
|
||||
[assembly: AssemblyTitle("Lskj.PubBomImportNew")]
|
||||
[assembly: AssemblyDescr
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Lskj.PubBomImport.Properties {
|
||||
namespace Lskj.PubBomImportNew.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttrib
|
||||
@@ -1,5 +1,5 @@
|
||||
<?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">
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Lskj.PubBomImportNew.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="LastSelectFolder" Type="System.String" Scope="User">
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
<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" />
|
||||
<section name="Lskj.PubBomImportNew.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>
|
||||
<Lskj.PubBomImportNew.Properties.Settings>
|
||||
<setting name="LastSelectFolder" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
</Lskj.PubBomImport.Properties.Settings>
|
||||
</Lskj.PubBomImportNew.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user