CRM之菜單管理(二)
阿新 • • 發佈:2018-01-04
函數 系統菜單 構造 prop 初始化 read 代碼 view cti
四、文件及函數
1、文件說明
(1)LQMenu.dbml:創建Linq To SQL類,使其對應數據庫中的core_menu表
(2)MyFuncLib.cs:常見的公共函數類,將系統中經常用到的公共的函數放入其中
(3)BLMenu.cs:對LQMenu.dbml的數據操作層,用於存放數據增刪改查函數,及其他與數據庫有關的函數
(4)FormMenu.cs:窗體的主函數
2、FormMenu_Load函數
使用InitDgv函數來初始化DataGridView,當需要修改的時候可以直接在代碼中進行修改。該函數還調用了MyFuncLib.InitDgv,以及後續的兩個函數InitDgvColumns以及IsNumber。
(1)FormMenu.InitDgv()
/// <summary> 用代碼的方式構造dataGridView,便於修改裏面的內容 /// /// </summary> private void InitDGV() { StringBuilder sb = new StringBuilder(); sb.Append("Type=text,Width=100,Visible=true,ReadOnly=false,Frozen=true,Format=,NullValue=,"); sb.Append("Order=false,Alignment=left,MaxInputLength=30,Name=menuName,HeaderText=菜單名稱"); sb.Append(";Type=text,Width=90,Visible=true,ReadOnly=false,Frozen=false,Format=,NullValue=,"); sb.Append("Order=false,Alignment=left,MaxInputLength=30,Name=subMenuName,HeaderText=二級菜單"); sb.Append(";Type=text,Width=100,Visible=true,ReadOnly=true,Frozen=false,Format=,NullValue=,"); sb.Append("Order=false,Alignment=left,MaxInputLength=30,Name=title,HeaderText=菜單文本"); sb.Append(";Type=checkbox,Width=70,Visible=true,ReadOnly=false,Frozen=false,Format=,NullValue=0,"); sb.Append("Order=false,Alignment=left,MaxInputLength=30,Name=isForm,HeaderText=是否窗體"); sb.Append(";Type=text,Width=100,Visible=true,ReadOnly=false,Frozen=false,Format=,NullValue=,"); sb.Append("Order=false,Alignment=left,MaxInputLength=100,Name=methodNames,HeaderText=方法列表"); sb.Append(";Type=text,Width=100,Visible=true,ReadOnly=true,Frozen=false,Format=,NullValue=,"); sb.Append("Order=false,Alignment=left,MaxInputLength=30,Name=fullName,HeaderText=完整名稱"); sb.Append(";Type=checkbox,Width=70,Visible=true,ReadOnly=true,Frozen=false,Format=,NullValue=0,"); sb.Append("Order=false,Alignment=left,MaxInputLength=30,Name=hasChildren,HeaderText=包含下級"); sb.Append(";Type=checkbox,Width=70,Visible=true,ReadOnly=true,Frozen=false,Format=,NullValue=1,"); sb.Append("Order=false,Alignment=left,MaxInputLength=30,Name=isSys,HeaderText=系統菜單"); sb.Append(";Type=checkbox,Width=30,Visible=false,ReadOnly=false,Frozen=false,Format=,NullValue=,"); sb.Append("Order=false,Alignment=center,MaxInputLength=,Name=parentId,HeaderText=parentId"); sb.Append(";Type=text,Width=100,Visible=false,ReadOnly=false,Frozen=false,Format=,NullValue=0,"); sb.Append("Order=false,Alignment=left,MaxInputLength=,Name=ID_,HeaderText=ID_"); dataGridViewMenu.AutoGenerateColumns = false; dataGridViewMenu.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; dataGridViewMenu.RowHeadersWidth = 41; dataGridViewMenu.Columns.Clear(); dataGridViewMenu.SelectionMode = DataGridViewSelectionMode.FullRowSelect; MyFuncLib.InitDgv(dataGridViewMenu, sb.ToString()); }
(2)
/// <summary> 初始化dataGridView各列 /// /// </summary> /// <param name="d">DataGirdView</param> /// <param name="c">Column</param> /// <param name="type">type(如text,int,decimal,checkbox,date,datetime</param> /// <param name="maxInputLength">最大程度</param> /// <param name="source">數據源</param> private static void InitDgvColumns(DataGridView d, DataGridViewColumn c, string type, string maxInputLength, string source) { if ("text".Equals(type)) { #region text DataGridViewTextBoxColumn c2 = new DataGridViewTextBoxColumn(); c2.Name = c.Name; c2.DataPropertyName = c.DataPropertyName; c2.HeaderText = c.HeaderText; c2.Width = c.Width; c2.Visible = c.Visible; c2.ReadOnly = c.ReadOnly; c2.Frozen = c.Frozen; c2.DefaultCellStyle = c.DefaultCellStyle; c2.HeaderCell.Style = c.HeaderCell.Style; c2.SortMode = c.SortMode; c2.Tag = c.Tag; if (IsNumber(maxInputLength)) c2.MaxInputLength = int.Parse(maxInputLength); d.Columns.Add(c2); #endregion } else if ("decimal".Equals(type)) { #region decimal DataGridViewTextBoxColumn c2 = new DataGridViewTextBoxColumn(); c2.Name = c.Name; c2.DataPropertyName = c.DataPropertyName; c2.HeaderText = c.HeaderText; c2.Width = c.Width; c2.Visible = c.Visible; c2.ReadOnly = c.ReadOnly; c2.Frozen = c.Frozen; c2.DefaultCellStyle = c.DefaultCellStyle; c2.HeaderCell.Style = c.HeaderCell.Style; c2.SortMode = c.SortMode; c2.Tag = c.Tag; if (IsNumber(maxInputLength)) c2.MaxInputLength = int.Parse(maxInputLength); d.Columns.Add(c2); #endregion } else if ("int".Equals(type)) { #region int DataGridViewTextBoxColumn c2 = new DataGridViewTextBoxColumn(); c2.Name = c.Name; c2.DataPropertyName = c.DataPropertyName; c2.HeaderText = c.HeaderText; c2.Width = c.Width; c2.Visible = c.Visible; c2.ReadOnly = c.ReadOnly; c2.Frozen = c.Frozen; c2.DefaultCellStyle = c.DefaultCellStyle; c2.HeaderCell.Style = c.HeaderCell.Style; c2.SortMode = c.SortMode; c2.Tag = c.Tag; if (IsNumber(maxInputLength)) c2.MaxInputLength = int.Parse(maxInputLength); d.Columns.Add(c2); #endregion } else if ("date".Equals(type)) { #region date DataGridViewTextBoxColumn c2 = new DataGridViewTextBoxColumn(); c2.Name = c.Name; c2.DataPropertyName = c.DataPropertyName; c2.HeaderText = c.HeaderText; c2.Width = c.Width; c2.Visible = c.Visible; c2.ReadOnly = c.ReadOnly; c2.Frozen = c.Frozen; c2.DefaultCellStyle = c.DefaultCellStyle; c2.HeaderCell.Style = c.HeaderCell.Style; c2.SortMode = c.SortMode; c2.Tag = c.Tag; if (IsNumber(maxInputLength)) c2.MaxInputLength = int.Parse(maxInputLength); d.Columns.Add(c2); #endregion } else if ("datetime".Equals(type)) { #region datetime DataGridViewTextBoxColumn c2 = new DataGridViewTextBoxColumn(); c2.Name = c.Name; c2.DataPropertyName = c.DataPropertyName; c2.HeaderText = c.HeaderText; c2.Width = c.Width; c2.Visible = c.Visible; c2.ReadOnly = c.ReadOnly; c2.Frozen = c.Frozen; c2.DefaultCellStyle = c.DefaultCellStyle; c2.HeaderCell.Style = c.HeaderCell.Style; c2.SortMode = c.SortMode; c2.Tag = c.Tag; if (IsNumber(maxInputLength)) c2.MaxInputLength = int.Parse(maxInputLength); d.Columns.Add(c2); #endregion } else if ("checkbox".Equals(type) || "check".Equals(type)) { #region checkbox DataGridViewCheckBoxColumn c2 = new DataGridViewCheckBoxColumn(); c2.Name = c.Name; c2.DataPropertyName = c.DataPropertyName; c2.HeaderText = c.HeaderText; c2.Width = c.Width; c2.Visible = c.Visible; c2.ReadOnly = c.ReadOnly; c2.Frozen = c.Frozen; c2.HeaderCell.Style = c.HeaderCell.Style; c2.SortMode = c.SortMode; c2.Tag = c.Tag; c2.TrueValue = 1; c2.FalseValue = 0; d.Columns.Add(c2); #endregion } }
CRM之菜單管理(二)