From 57887a4fec2df4a7da02b46c7a7af07f185fe8a0 Mon Sep 17 00:00:00 2001 From: tdx Date: Sat, 14 Jun 2025 14:43:01 +0000 Subject: [PATCH] SVN r734 SVN-Revision: r734 --- .../Lskj.PubBomImportNew/FrmMain2.Designer.cs | 40 ++-- 插件库/Lskj.PubBomImportNew/FrmMain2.cs | 212 +++--------------- 2 files changed, 40 insertions(+), 212 deletions(-) diff --git a/插件库/Lskj.PubBomImportNew/FrmMain2.Designer.cs b/插件库/Lskj.PubBomImportNew/FrmMain2.Designer.cs index 522b062..2e22c43 100644 --- a/插件库/Lskj.PubBomImportNew/FrmMain2.Designer.cs +++ b/插件库/Lskj.PubBomImportNew/FrmMain2.Designer.cs @@ -31,14 +31,13 @@ namespace Lskj.PubBomImportNew { this.gcMain = new Lskj.Control.GridControlEx(); this.pl_top = new DevExpress.XtraEditors.PanelControl(); - this.btnExport = new DevExpress.XtraEditors.SimpleButton(); - 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(); @@ -65,7 +64,6 @@ namespace Lskj.PubBomImportNew this.pl_top.Appearance.BackColor = System.Drawing.Color.Transparent; this.pl_top.Appearance.Options.UseBackColor = true; this.pl_top.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; - this.pl_top.Controls.Add(this.btnExport); this.pl_top.Controls.Add(this.btnCover); this.pl_top.Controls.Add(this.btnImport); this.pl_top.Controls.Add(this.btnRead); @@ -77,27 +75,6 @@ namespace Lskj.PubBomImportNew this.pl_top.Size = new System.Drawing.Size(1394, 64); this.pl_top.TabIndex = 3; // - // btnExport - // - this.btnExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnExport.Location = new System.Drawing.Point(938, 12); - this.btnExport.Margin = new System.Windows.Forms.Padding(4); - this.btnExport.Name = "btnExport"; - this.btnExport.Size = new System.Drawing.Size(110, 38); - this.btnExport.TabIndex = 13; - this.btnExport.Text = "导出模板"; - // - // 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 = "导入覆盖"; - // // btnImport // this.btnImport.Location = new System.Drawing.Point(141, 12); @@ -163,6 +140,17 @@ 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; @@ -176,6 +164,4 @@ namespace Lskj.PubBomImportNew this.Name = "FrmMain2"; this.Opacity = 0D; this.Text = "表格导入"; - ((System.ComponentModel.ISupportInitialize)(this.pl_top)).EndInit(); - this.pl_top.ResumeLayout(false); - \ No newline at end of file + ((System.ComponentModel.ISupportInitialize)(this.pl_top) \ No newline at end of file diff --git a/插件库/Lskj.PubBomImportNew/FrmMain2.cs b/插件库/Lskj.PubBomImportNew/FrmMain2.cs index f017297..3fa0fb7 100644 --- a/插件库/Lskj.PubBomImportNew/FrmMain2.cs +++ b/插件库/Lskj.PubBomImportNew/FrmMain2.cs @@ -47,6 +47,7 @@ namespace Lskj.PubBomImportNew /// public partial class FrmMain2 : BaseForm { + public DynamicBomImportNew Model; /// /// 判断是否是导入后的数据 /// @@ -72,7 +73,7 @@ namespace Lskj.PubBomImportNew /// private string _parmaryKey; private string _qzKey; - private string _leftField, _leftValue; + private string _primkey, _keyvalue; private string _treeColumnName; private int success = 0, failed = 0; private ModuleModel SysModel; @@ -107,10 +108,22 @@ namespace Lskj.PubBomImportNew /// 导入返回控件值 /// public List ImportReturnValue = new List(); + protected override void OnLoad(EventArgs e) + { + 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 { + MessageUtil.Show("请检查模板是否配置正确!"); + + } + } - - public void InitializeControl(string tableName, string menuCode, string parmaryKey, GridControlEx gridEx, string qzKey, string leftField, string leftValue, string Fromtext, bool ConcatenatedPrefix = true) + public void InitializeControl(string tableName, string menuCode, string parmaryKey, GridControlEx gridEx, string qzKey, string primkey, string keyvalue, string Fromtext, bool ConcatenatedPrefix = true) { try { @@ -121,8 +134,8 @@ namespace Lskj.PubBomImportNew this._parmaryKey = parmaryKey; this._gridEx = gridEx; this._qzKey = qzKey; - this._leftValue = leftValue; - this._leftField = leftField; + this._primkey = primkey; + this._keyvalue = keyvalue; this._calcFields = new List(); this._fromText = Fromtext; this.concatenatedPrefix = ConcatenatedPrefix; @@ -205,27 +218,6 @@ namespace Lskj.PubBomImportNew } else { - //foreach (GridColumn item in this._gridEx.GridView.VisibleColumns) - //{ - // if (item.FieldName.Equals("RightMenuBtnEdit")) continue; - // GridColumn col = new GridColumn(); - // col.Tag = item.Tag; - // col.FieldName = item.FieldName; - // col.Width = item.Width; - // col.Caption = item.Caption; - // col.Visible = true; - // if (this._gridEx is BandedGridControlEx) - // { - // GridColumnModel tag = item.Tag as GridColumnModel; - // if (tag.FieldText.Contains("|")) col.Caption = tag.FieldText; - // } - - // //col.AppearanceCell.Options.UseFont = true; - // //col.AppearanceCell.Font = new Font("宋体", 14f); - // this.gcMain.GridView.Columns.Add(col); - //} - //this.gcMain.SetReadOnlyColumns(_tableColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey); - //可编辑列可以触发关联,计算 this.gcMain.SetEditColumns(_tableColumns, GridCustomColumnStruct.BaseMainGridView + this.SysModel.FormKey); this.gcMain.GridView.OptionsBehavior.Editable = false;//禁止编辑 @@ -547,29 +539,16 @@ namespace Lskj.PubBomImportNew - if (this.concatenatedPrefix) + if (string.IsNullOrEmpty(this._primkey)) { - if (datatb.Columns.Contains(_qzKey + _leftField) && !string.IsNullOrWhiteSpace(_leftValue) && SysModel.AssociationLeft) + if (datatb.Columns.Contains(_primkey) && !string.IsNullOrWhiteSpace(_keyvalue)) { - if (string.IsNullOrEmpty(tmpRow[_qzKey + _leftField] + "") || (tmpRow[_qzKey + _leftField] + "").Equals("0")) + if (string.IsNullOrEmpty(tmpRow[_primkey] + "") || (tmpRow[_keyvalue] + "").Equals("0")) { - tmpRow[_qzKey + _leftField] = _leftValue; + tmpRow[_primkey] = _keyvalue; } } } - else - { - if (datatb.Columns.Contains(_leftField) && !string.IsNullOrWhiteSpace(_leftValue) && SysModel.AssociationLeft) - { - if (string.IsNullOrEmpty(tmpRow[_qzKey + _leftField] + "") || (tmpRow[_qzKey + _leftField] + "").Equals("0")) - { - tmpRow[_qzKey + _leftField] = _leftValue; - } - } - } - - - foreach (GridColumn gc in gcMain.GridView.VisibleColumns) { @@ -807,7 +786,7 @@ namespace Lskj.PubBomImportNew if (!string.IsNullOrEmpty(_treeColumnName) && col.ColumnName.ToLower() == _treeColumnName.ToLower()) { insertFields += col.ColumnName + ","; - insertValues += "N'" + _leftValue + "',"; + insertValues += "N'" + _keyvalue + "',"; } } } @@ -1011,147 +990,8 @@ namespace Lskj.PubBomImportNew } } - /// - /// 说明:导入覆盖Excel - /// 创建人:王一帆 - /// 创建日期:2021-04-07 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnCoverButtonClick(object sender, EventArgs e) - { - try - { - if (MessageUtil.Show("注意!覆盖功能将替换原有的数据请慎重使用!是否确认覆盖?", MessageBoxButtons.YesNo) != DialogResult.Yes) - return; - List ColumnNameList = GridExtend.ColumnNameList; - - string sql = "select * from " + _tableName + " where 1<>1"; - SqlDataAdapter dat = BaseImpl.GetAdapterResult(sql); - DataTable datatb = new DataTable(); - dat.Fill(datatb); - - DataTable table = this.gcMain.GridControl.DataSourceTable(); - string updateSql = "update {0} set {1} where {2}='{3}';"; - int successCount = 0; - string msg = string.Empty; - if (table != null && table.Rows.Count > 0) - { - if (!this.DetermineImportConditions()) - { - return; - } - //根据全表字段类型进行默认填充 - int currRow = 0; - foreach (DataRow row in table.Rows) - { - string updateFields = string.Empty; - foreach (DataColumn col in table.Columns) - { - if (ColumnNameList.Contains(col.ColumnName) && datatb.Columns.Contains(col.ColumnName) && table.Columns.Contains(col.ColumnName)) - { - GridColumn gridCol = this.gcMain.GridView.Columns[col.ColumnName]; - GridColumnModel gridmodel = gridCol.Tag as GridColumnModel; - if (col.ColumnName == _parmaryKey || col.ColumnName == "import_errormsg" || col.ColumnName == "lskjimport_errorFlag") continue; - if ((col.DataType == typeof(DateTime)) && (row[col.ColumnName] + "" == "")) - updateFields += string.Format("[{0}]=null,", col.ColumnName); - else if (gridmodel != null && (gridmodel.FieldType == ControlType.LabTreeType || - gridmodel.FieldType == ControlType.LabComboxValue || - gridmodel.FieldType == ControlType.LabComboxValueParam || - gridmodel.FieldType == ControlType.LabAutoCompleteValue || - gridmodel.FieldType == ControlType.LabAutoCompleteValueParam || - gridmodel.FieldType == ControlType.LabMultiSelectValue || - gridmodel.FieldType == ControlType.LabMultiSelectValueNew || - gridmodel.FieldType == ControlType.LabMultiSelectValueParam)) - { - bool isEmpty = gridmodel.CanNull; - string fieldValue = GetValueByImportText(row, gridCol.FieldName, row[gridCol.FieldName] + ""); - if (string.IsNullOrEmpty(fieldValue)) - { - if (isEmpty) - { - XtraMessageBox.Show("数据导入错误,未找到对应的编码,请检查!\r\n第" + (currRow + 1).ToString() + "行,第" + (gridCol.VisibleIndex + 1).ToString() + "列-" + gridCol.Caption, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - else - { - GridColumn column = _gridEx.GridView.Columns[gridCol.FieldName]; - if (column.ColumnType.Name.ToLower().IndexOf("int") >= 0) - if (column.ColumnType.Name.ToLower() == "string") - updateFields += string.Format("[{0}]='{1}',", gridCol.FieldName, ""); - if (column.ColumnType.Name.ToLower().IndexOf("char") >= 0) - updateFields += string.Format("[{0}]='{1}',", gridCol.FieldName, ""); - if (column.ColumnType.Name.ToLower().IndexOf("int") >= 0) - updateFields += string.Format("[{0}]='{1}',", gridCol.FieldName, "0"); - if (column.ColumnType.Name.ToLower() == "decimal") - updateFields += string.Format("[{0}]='{1}',", gridCol.FieldName, "0"); - } - } - else - { - updateFields += string.Format("[{0}]='{1}',", gridCol.FieldName, fieldValue); - } - - } - else - { - updateFields += string.Format("[{0}]='{1}',", col.ColumnName, (row[col.ColumnName] + "").Replace("'", "''")); - } - currRow++; - } - - - } - int ReRows = SqlHelper.ExecuteNonQuery(string.Format(updateSql, _tableName, updateFields.TrimEnd(','), _parmaryKey, row[_parmaryKey])); - successCount += ReRows; - if (ReRows == 0) msg += "\n主键:[" + row[_parmaryKey] + "]更新失败请检查"; - } - this._isImported = true; - if (!string.IsNullOrEmpty(_gridEx.LastSearchSql)) _gridEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(_gridEx.LastSearchSql)); - XtraMessageBox.Show("覆盖完成,成功" + successCount + "条" + msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); - //_gridEx.ParentControl.SearchLastGrid(); - - } - else - { - MessageUtil.Show(ResourceKeys.NotFountGridData); - } - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - - } - /// - /// 说明:导出模版 - /// 创建人:龚宇超 - /// 创建日期:2017-11-15 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnExportButtonClick(object sender, EventArgs e) - { - try - { - this.gcMain.GridControl.ToExcelTemplate(_fromText); - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - - } + + /// /// 说明: /// 创建人:龚宇超 @@ -1176,6 +1016,8 @@ namespace Lskj.PubBomImportNew } } + + /// /// 判断导入条件 ///