using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Layout; using CommonLib; using DevExpress.XtraGrid.Columns; using DevExpress.XtraEditors.Repository; using DevExpress.XtraEditors.Controls; namespace Lskj.MyControl { public partial class CardControlEx : UserControl { #region 私有属性 #endregion #region 公有属性 public string ModuleKey; public string FormKey; public int ModuleType; public int CardWidth = 0; /// /// 汇总字段 /// public DataTable SumFieldsTable; public GridControl GridControl { get { return gridControl1; } } public LayoutView LayoutView { get { return gridMain; } } #endregion public CardControlEx() { InitializeComponent(); gridMain.DoubleClick += new EventHandler(gridMain_DoubleClick); } private void gridMain_DoubleClick(object sender, EventArgs e) { if (gridControl1.ContextMenuStrip != null) { foreach (ToolStripMenuItem item in gridControl1.ContextMenuStrip.Items) { if (item.Tag == null) continue; DataRow dr = item.Tag as DataRow; if (dr == null) continue; if (dr.Table.Columns.Contains("DBClickEvent")) { if (dr["DBClickEvent"] + "" == "1") { item.PerformClick(); break; } } } } } /// /// 设置列 /// /// public void SetColumns(DataTable dtTable) { try { if (dtTable == null) return; // 设置默认宽度 if (CardWidth == 0) CardWidth = gridMain.CardMinSize.Width; string bmpFieldName = string.Empty; //获取图片列 DataRow bmpRow = dtTable.Rows.Cast().FirstOrDefault(x => x["fieldsqltag"] + "" == "100"); if (bmpRow != null) { int imageWidth = dtTable.Columns.Contains("imageWidth") ? Convert.ToInt32(bmpRow["imageWidth"] + "") : 120; int imageHeight = dtTable.Columns.Contains("imageHeight") ? Convert.ToInt32(bmpRow["imageHeight"] + "") : 180; int otherWidth = CardWidth > imageWidth ? CardWidth - imageWidth : CardWidth; lvBmp.FieldName = bmpFieldName = bmpRow["fieldname"] + "_image"; lvBmp.OptionsColumn.FixedWidth = false; lvBmp.LayoutViewField.MaxSize = new Size(imageWidth, imageHeight); lvBmp.LayoutViewField.MinSize = new System.Drawing.Size(imageWidth, imageHeight); lvBmp.LayoutViewField.Size = new System.Drawing.Size(imageWidth, imageHeight); (lvBmp.ColumnEdit as RepositoryItemPictureEdit).SizeMode = PictureSizeMode.Squeeze; lvBmp.LayoutViewField.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom; lvf1.EditorPreferredWidth = imageWidth; gridMain.CardMinSize = new Size(CardWidth, imageHeight); lvf7.EditorPreferredWidth = lvf6.EditorPreferredWidth = lvf5.EditorPreferredWidth = lvf4.EditorPreferredWidth = lvf3.EditorPreferredWidth = lvf2.EditorPreferredWidth = otherWidth; } else { lvBmp.Image = null; } DataRow[] rows = dtTable.Rows.Cast().Where(x => !string.IsNullOrEmpty(x["cardEnable"] + "") && Convert.ToInt32(x["cardEnable"] + "") > 0).OrderBy(y => y["orderid"]).ToArray(); for (int i = 0; i < rows.Length; i++) { DataRow item = rows[i]; if ((i < 6 && bmpRow != null) || (i < 7 && bmpRow == null)) { LayoutViewColumn col = gridMain.Columns.ColumnByName("lvColumn" + (i + 2)); if (col != null && item["fieldname"] + "" != bmpFieldName) { col.Caption = item["username1"] + ""; col.FieldName = item["fieldname"] + ""; } } } } catch (Exception) { } } /// /// 重置表格列 /// /// public DataTable ResetColumns(DataTable columns) { try { if (string.IsNullOrEmpty(FormKey)) return columns; DataTable dtColumns = SqlHelper.ExecuteDataSet(string.Format("select *,isnull(isvisible,0) as visible1,case when isnull(isvisible,0)=0 then 0 else fieldwidth end as width from P_systemGridConfigTab where formkey='{0}' and operatorid='{1}'", FormKey, ERPInfo.Instance.EmployeeId)).Tables[0]; foreach (DataRow row in dtColumns.Rows) { string fieldname = row["fieldname"] + ""; string orderid = row["orderid"] + ""; string fieldWidth = row["Width"] + ""; string fieldVisible = (Convert.ToInt32(row["visible1"]) == 1 ? 0 : 1) + ""; foreach (DataRow item in columns.Rows) { if (fieldname.ToLower() == (item["fieldname"] + "").ToLower()) { item["orderid"] = orderid; item["width"] = fieldWidth; } } } DataView dv = columns.DefaultView; dv.Sort = "orderid asc"; return dv.ToTable(); } catch (Exception ex) { } return columns; } } }