using DevExpress.XtraEditors; using DevExpress.XtraGrid.Columns; using Lskj.Control; using Lskj.Core; using Lskj.Model; using Lskj.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace mes_BgManage { public partial class FrmMain : BaseForm { #region 公共字段 /// /// 公共版焜入口参数 /// public DynamicBgModel moduleModel; /// /// 版辊所关联的所有表格 /// public List GridList = new List(); /// /// 版辊所关联的所有表格 /// public List TextList = new List(); /// /// 所有删除按钮 /// public List DelBtnList = new List(); /// /// 所有panel /// public List panControlList = new List(); #endregion public FrmMain() { InitializeComponent(); } /// /// 说明:窗体加载时 /// 创建人:龚宇超 /// 创建日期:2017-09-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The instance containing the event data. protected override void OnLoad(EventArgs e) { InitControls(); SetFormPoint(); AutoColWidth(); } #region 方法 /// /// 说明:创建界面 /// 创建人:王一帆 /// 创建日期:2022-04-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. public void InitControls() { this.GridList.AddRange(new List { oneGcEX, twoGcEX, thrGcEX, forGcEX, fivGcEX, sixGcEX });//注册表格界面集合 this.TextList.AddRange(new List { oneText, twoText, thrText, forText, fivText, sixText });//注册文本框集合 this.DelBtnList.AddRange(new List { oneDelbtn, twoDelBtn, thrDelBtn, forDelBtn, fivDelBtn, sixDelBtn }); this.panControlList.AddRange(new List { oneGcPanel, twoGcPanel, thrGcPanel, forGcPanel, fivGcPanel, sixGcPanel }); this.SizeChanged += new EventHandler(OnFrmMain_SizeChanged); this.FormClosing += new FormClosingEventHandler(OnFrmMain_FormClosing); BindingGridStructure(); BindingDelBtnEvent(); InitTextEven(); InitGridData(); } /// /// 绑定所有删除按钮的点击事件 /// DyBgModel Clientid private void BindingDelBtnEvent() { for (int i = 0; i < this.DelBtnList.Count; i++) { DelBtnList[i].Click += new EventHandler(OnFrmMain_Click); } } /// /// 绑定所有文本的回车事件 /// DyBgModel Clientid public void InitTextEven() { for (int i = 0; i < TextList.Count; i++) { TextList[i].KeyDown += OnKeyDown; TextList[i].Tag = i + 1; } } /// /// 所有文本框的回车事件 /// /// /// private void OnKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { TextBox textBox = sender as TextBox; moduleModel.gridIndex = textBox.Tag + ""; moduleModel.textBox = textBox.Text; moduleModel.rowCount = this.GridList[Convert.ToInt32(moduleModel.gridIndex) - 1].GridView.DataRowCount; // 弹出版锟控件 UnionControl frmAddRole = new UnionControl(); frmAddRole.InitUnionControl(moduleModel); if (frmAddRole.ShowDialog() == DialogResult.OK) { TextList[frmAddRole.focusToIndex - 1].Focus(); InitGridData(); } } } /// /// 所有删除按钮点击事件 /// /// /// private void OnFrmMain_Click(object sender, EventArgs e) { try { DevExpress.XtraEditors.SimpleButton delBtn = (DevExpress.XtraEditors.SimpleButton)sender; int btnIndex = this.DelBtnList.IndexOf(delBtn); int focusRowIndex = GridList[btnIndex].GridView.GetFocusedDataSourceRowIndex(); DataRow focusRow = (GridList[btnIndex].gridControl.DataSource as DataTable).Rows[focusRowIndex]; string delSqlStr = string.Format("delete from P_FixedAssetsDYTab where id='{0}';update P_FixedAssetsMlTab set ZtTig=1 where id='{1}'", focusRow["id"] + "", focusRow["pid"] + ""); SqlHelper.ExecuteNonQuery(delSqlStr); this.InitGridData(); } catch (Exception) { } } /// /// 调整宽度 /// /// /// private void OnFrmMain_SizeChanged(object sender, EventArgs e) { AutoColWidth(); } /// /// 记录位置 /// /// /// private void OnFrmMain_FormClosing(object sender, FormClosingEventArgs e) { IniHelper.Write(string.Format("mes_BgManagePointX_{0}", this.moduleModel.ModuleCode), this.Location.X + ""); IniHelper.Write(string.Format("mes_BgManagePointY_{0}", this.moduleModel.ModuleCode), this.Location.Y + ""); IniHelper.Write(string.Format("mes_BgManageSizeWidth_{0}", this.moduleModel.ModuleCode), this.Size.Width + ""); IniHelper.Write(string.Format("mes_BgManageSizeHeight_{0}", this.moduleModel.ModuleCode), this.Size.Height + ""); } /// /// 绑定所有表格的表结构 /// DyBgModel Clientid private void BindingGridStructure() { for (int i = 0; i < this.GridList.Count; i++) { GridControlEx gridEx = GridList[i]; gridEx.GridView.Columns.AddVisible("ProductId", "版辊编码"); gridEx.GridView.Columns.AddVisible("Appellation", "版辊名称"); gridEx.GridView.Columns.AddVisible("Model", "版辊型号"); gridEx.GridView.Columns.AddVisible("Spec", "版辊规格"); gridEx.GridView.Columns.AddVisible("OriginBill", "版辊钢号"); gridEx.GridView.Columns["ProductId"].Visible = false; gridEx.GridView.OptionsView.ShowIndicator = false; gridEx.GridView.OptionsBehavior.Editable = false; } } /// /// 调整宽度 /// private void AutoColWidth() { for (int i = 0; i < this.panControlList.Count; i++) { panControlList[i].Width = this.mainPanel.Width / 6; } } private void SetFormPoint() { try { string pointX = IniHelper.Read(string.Format("mes_BgManagePointX_{0}", this.moduleModel.ModuleCode)); string pointY = IniHelper.Read(string.Format("mes_BgManagePointY_{0}", this.moduleModel.ModuleCode)); string sizeWidth = IniHelper.Read(string.Format("mes_BgManageSizeWidth_{0}", this.moduleModel.ModuleCode)); string sizeHeight = IniHelper.Read(string.Format("mes_BgManageSizeHeight_{0}", this.moduleModel.ModuleCode)); if (!string.IsNullOrEmpty(pointX) && !string.IsNullOrEmpty(pointY)) { this.Location = new Point(Convert.ToInt32(pointX), Convert.ToInt32(pointY)); } if (!string.IsNullOrEmpty(sizeWidth) && !string.IsNullOrEmpty(sizeHeight)) { this.Size = new Size(Convert.ToInt32(sizeWidth), Convert.ToInt32(sizeHeight)); } } catch (Exception) { } } /// /// 初始化所有表格的数据源 /// DyBgModel Clientid public void InitGridData() { for (int i = 0; i < GridList.Count; i++) { String gridDataSql = string.Format(@"select aa.ProductId,aa.Appellation,aa.Model,aa.Spec,aa.OriginBill,a.id,aa.id as pid from P_FixedAssetsDYTab a join P_FixedAssetsMlTab aa on a.LProductid = aa.ProductId where a.JtID = '{0}' and a.planlistid = '{1}' and a.siteid = '{2}'", moduleModel.DyBgModel, moduleModel.Clientid, i + 1); GridList[i].gridControl.DataSource = SqlHelper.ExecuteDataTable(gridDataSql); } } #endregion } }