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 DevComponents.DotNetBar.SuperGrid; using DevComponents.DotNetBar.Layout; using DevComponents.DotNetBar; using DevComponents.DotNetBar.Layout; using DevComponents.DotNetBar.Controls; using System.IO; using WCS_Client.Utility; namespace WCS_Client.UC { public partial class UC_QueryPage : UserControl { public UC_QueryPage() { InitializeComponent(); //Control.CheckForIllegalCrossThreadCalls = false; SCGrid.PrimaryGrid.AutoExpandSetGroup = true; SCGrid.PrimaryGrid.ShowGroupUnderline = false; this.Btn_PageSize.ButtonCustomClick += new System.EventHandler(this.Btn_PageSize_ButtonCustomClick); this.Btn_PageSize.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Btn_PageSize_KeyDown); this.Btn_PageIndex.ButtonCustomClick += new System.EventHandler(this.Btn_PageIndex_ButtonCustomClick); this.Btn_PageIndex.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Btn_PageIndex_KeyDown); this.Btn_PageUp.Click += new System.EventHandler(this.Btn_PageUp_Click); this.Btn_PageDown.Click += new System.EventHandler(this.Btn_PageDown_Click); this.Btn_PageEnd.Click += new System.EventHandler(this.Btn_PageEnd_Click); this.Btn_ExportChk.Click += new System.EventHandler(this.Btn_ExportChk_Click); this.Btn_ExportALL.Click += new System.EventHandler(this.Btn_ExportALL_Click); this.Btn_ExportNow.Click += new System.EventHandler(this.Btn_ExportNow_Click); this.SCGrid.CellDoubleClick += new System.EventHandler(this.SCGrid_CellDoubleClick); this.SCGrid.CellMouseDown += new System.EventHandler(this.SCGrid_CellMouseDown); this.SCGrid.CellValueChanged += new System.EventHandler(this.SCGrid_CellValueChanged); this.layoutControl1.LabelTextAlignment = eTextAlignment.Right; this.SCGrid.CellValueChanged += SuperGridControl1CellValueChanged; this.SCGrid.RowSetDefaultValues += SuperGridControl1RowSetDefaultValues; } public delegate PageData QueryPageDataHandler(int PageIndex, int PageSize);//分页查询 public delegate void RefreshRoleHandler(bool ChkValue);//刷新权限 public delegate void GridDoubleClickHandler(DataRow dr);//表格双击方法 public delegate void GridMouseClickHandler (DataRow dr);//单击方法 public delegate void CellValueChangedHandler(GridCellValueChangedEventArgs e); public delegate void returnStr(PageData dat); QueryPageDataHandler _QueryPageDataMethods = null;//查询数据集方法 RefreshRoleHandler _RefreshRoleMethods = null;//刷新权限 GridDoubleClickHandler _GridDoubleClickMethods = null;//表格双击方法 CellValueChangedHandler _CellValueChangedMethods = null;//表格值改变 GridMouseClickHandler _CellMouseDownMethods = null; public const string ChkTag = "F6FC5CEF7E5B48bbB04834B22DC248C3"; List _GCList = new List();//表格列表 List _LCItemList = new List();// 查询控件 bool _IsMultiSelect = true;//单/多选标记 OpaqueLayer OpaqueLayerItem = null;//遮罩层 object CellStr = null;//单元格数据 bool IsChange = true;//单元格单击变量 string _GroupName = ""; #region [ 遮罩层 ] /// /// 显示遮罩层 /// public void ShowOpaqueLayer() { try { if (OpaqueLayerItem == null) { this.OpaqueLayerItem = new OpaqueLayer(244, true); this.Controls.Add(OpaqueLayerItem); this.OpaqueLayerItem.Dock = DockStyle.Fill; this.OpaqueLayerItem.BringToFront(); } this.OpaqueLayerItem.Enabled = true; this.OpaqueLayerItem.Visible = true; } catch { } } /// /// 隐藏遮罩层 /// public void HideOpaqueLayer() { try { if (OpaqueLayerItem != null) { this.OpaqueLayerItem.Visible = false; this.OpaqueLayerItem.Enabled = false; } } catch { //MessageBox.Show(ex.Message); } } #endregion /// /// 初始化分页查询 /// /// 查询面板高度 /// 是否启用多选 /// 是否启用导出 /// 表格列列表 /// 查询面板控件 /// 获取数据集方法 /// 单/多选改变方法 /// 表格双击方法 /// 刷新权限方法 public void Init_QueryPage(int LC_Height, bool IsMultiSelect, bool IsExport, string GroupName, List GCList, List LCItemList, QueryPageDataHandler QueryPageDataMethods, RefreshRoleHandler RefreshRoleMethods, GridDoubleClickHandler GridDoubleClickMethods, CellValueChangedHandler CellValueChangedMethods, GridMouseClickHandler CellMouseDownMethods,int frozenColumnCount=0) { _GroupName = GroupName; //设定LayoutControl宽度 this.tableLayoutPanel1.RowStyles[0].SizeType = SizeType.Absolute; this.tableLayoutPanel1.RowStyles[0].Height = (LC_Height < 0 ? 0 : LC_Height); this.tableLayoutPanel1.RowStyles[1].SizeType = SizeType.Percent; this.tableLayoutPanel1.RowStyles[1].Height = 100; //设定是否导出 this.Btn_ExportALL.Visible = IsExport; this.Btn_ExportNow.Visible = IsExport; this.Btn_ExportChk.Visible = IsExport; //方法赋值 _QueryPageDataMethods = QueryPageDataMethods; _RefreshRoleMethods = RefreshRoleMethods; _GridDoubleClickMethods = GridDoubleClickMethods; _CellValueChangedMethods = CellValueChangedMethods; _CellMouseDownMethods = CellMouseDownMethods; //清空LayoutControl _LCItemList.Clear(); this.layoutControl1.RootGroup.Items.Clear(); this.layoutControl1.Controls.Clear(); //LayoutControl添加控件 if (LCItemList != null) { foreach (LayoutControlItem LocItem in LCItemList) { this.layoutControl1.Controls.Add(LocItem.Control); this.layoutControl1.RootGroup.Items.Add(LocItem); this._LCItemList.Add(LocItem); } } //初始化LayoutControl控件. //清空SuperGrid this._GCList.Clear(); this.SCGrid.PrimaryGrid.Columns.Clear(); this.SCGrid.PrimaryGrid.DataSource = null; foreach (GridColumn gc in GCList) { if (gc == null || this.SCGrid.PrimaryGrid.Columns.Contains(gc)) { continue; } //gc.ReadOnly = true; gc.DisplayIndex = this.SCGrid.PrimaryGrid.Columns.Count; this.SCGrid.PrimaryGrid.Columns.Add(gc); _GCList.Add(gc); } //设定是否单/多选 _IsMultiSelect = IsMultiSelect; SCGrid_SetCheckBox(false); SCGrid.PrimaryGrid.RowHeaderWidth = 30; SCGrid.PrimaryGrid.ShowRowGridIndex = true; SCGrid.PrimaryGrid.RowHeaderIndexOffset = 1; SCGrid.PrimaryGrid.ShowRowHeaders = true; this.SCGrid.PrimaryGrid.FrozenColumnCount = frozenColumnCount; } public void SetGridColumnIsVisible(string GCName, bool IsReadOnly) { GridColumn gc = _GCList.Find(a => a.Name == GCName); if (gc != null) { if (IsReadOnly == false) { gc.CellStyles.Default.TextColor = Color.Red; } gc.Visible = IsReadOnly; } } public List GetQueryWhere() { return LCWhereUtil.GetWhereText(_LCItemList); } /// /// 获取LayoutControlItem列表 /// /// public void ClearLCItemValue() { LCItemUtil.ClearValue_LCItem(_LCItemList); } /// /// 获取LayoutControlItem列表 /// /// public LayoutControlItem GetLCItem(string LCName) { return _LCItemList.Find(a => a.Name == LCName); } /// /// 分页查询 /// /// 页码 /// 分页尺寸 public void RefreshData(int QPageIndex, int QPageSize) { DataTable dt = null; try { if (_QueryPageDataMethods == null) { throw new Exception(); } QPageIndex = QPageIndex < 1 ? 1 : QPageIndex; QPageSize = QPageSize < 0 ? 0 : QPageSize; PageData PageDataItem = _QueryPageDataMethods(QPageIndex, QPageSize); if (PageDataItem == null) { throw new Exception(); } dt = PageDataItem.Dt; //初始化Bar //SetLabelCallBack labDele = new SetLabelCallBack(Set_BarData); Set_BarData(PageDataItem); } catch(Exception e) { Set_BarData(null); } if (this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)) { if (dt == null) { dt = new DataTable(); } if (!dt.Columns.Contains(ChkTag)) { dt.Columns.Add(ChkTag, typeof(bool)); } } this.SCGrid.PrimaryGrid.DataSource = dt; } public void RefreshData() { RefreshData(this.Btn_PageIndex.Value, this.Btn_PageSize.Value); } //刷新权限 public void RefreshRole() { if (_RefreshRoleMethods != null) { _RefreshRoleMethods(this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)); } } public void Refresh_LCItem(string LCName, DataTable dt, string KeyField, string DisplayField) { LayoutControlItem LCItem = GetLCItem(LCName); if (LCItem.Control == null) { return; } if (LCItem.Control is ComboBoxEx) { ComboBoxEx citem = LCItem.Control as ComboBoxEx; // string s = citem.SelectedValue == null ? "" : citem.SelectedValue.ToString(); citem.DataSource = dt; citem.ValueMember = KeyField; citem.DisplayMember = DisplayField; // citem.SelectedValue = s; } else if (LCItem.Control is LC_DropChkList) { LC_DropChkList citem = LCItem.Control as LC_DropChkList; citem.RefreshData(dt, KeyField, DisplayField); } } #region [ 快捷菜单 ] private void Show_ContextMenuStrip() { ContextMenuStrip CMenus = new ContextMenuStrip(); ToolStripMenuItem tsiCopyCell = new ToolStripMenuItem(); tsiCopyCell.Text = "复制单元格"; tsiCopyCell.Click += new EventHandler(TMCopyCell_Click); CMenus.Items.Add(tsiCopyCell); //if (_IsMultiSelect) //{ // ToolStripMenuItem tsiChkbtn = new ToolStripMenuItem(); // tsiChkbtn.Text = this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag) ? "禁用多选" : "启用多选"; // tsiChkbtn.Click += new EventHandler(TMChkbtn_Click); // CMenus.Items.Add(tsiChkbtn); //} if (this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)) { ToolStripMenuItem tsiAllChk = new ToolStripMenuItem(); tsiAllChk.Text = "全部选中"; tsiAllChk.Click += new EventHandler(TMChkAllCell_Click); CMenus.Items.Add(tsiAllChk); ToolStripMenuItem tsiUAllChk = new ToolStripMenuItem(); tsiUAllChk.Text = "清空选择"; tsiUAllChk.Click += new EventHandler(TMChkUAllCell_Click); CMenus.Items.Add(tsiUAllChk); ToolStripMenuItem tsiUChk = new ToolStripMenuItem(); tsiUChk.Text = "选中指定行"; tsiUChk.Click += new EventHandler(TMChkCell_Click); CMenus.Items.Add(tsiUChk); ToolStripMenuItem tsiChk = new ToolStripMenuItem(); tsiChk.Text = "清空指定行"; tsiChk.Click += new EventHandler(TMUChkCell_Click); CMenus.Items.Add(tsiChk); } CMenus.Show(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y); } private void TMChkCell_Click(object sender, EventArgs e) { IsChange = false; foreach (GridRow gr in this.SCGrid.PrimaryGrid.SelectedRows) { if (gr == null) { continue; } gr.Cells[ChkTag].Value = true; } IsChange = true; Set_BarChkText(); } private void TMUChkCell_Click(object sender, EventArgs e) { IsChange = false; foreach (GridRow gr in this.SCGrid.PrimaryGrid.SelectedRows) { if (gr == null) { continue; } gr.Cells[ChkTag].Value = false; } IsChange = true; Set_BarChkText(); } private void TMChkAllCell_Click(object sender, EventArgs e) { IsChange = false; DataTable dt = this.SCGrid.PrimaryGrid.DataSource as DataTable; if (dt != null) { int count = dt.Rows.Count; for (int i = 0; i < count; i++) { dt.Rows[i][ChkTag] = true; } this.Refresh(); } IsChange = true; Set_BarChkText(); } private void TMChkUAllCell_Click(object sender, EventArgs e) { IsChange = false; DataTable dt = this.SCGrid.PrimaryGrid.DataSource as DataTable; if (dt != null) { int count = dt.Rows.Count; for (int i = 0; i < count; i++) { dt.Rows[i][ChkTag] = false; } this.Refresh(); } IsChange = true; Set_BarChkText(); } private void TMCopyCell_Click(object sender, EventArgs e) { Clipboard.SetDataObject(CellStr==null?CellStr:CellStr.ToString()); } private void TMChkbtn_Click(object sender, EventArgs e) { if (_IsMultiSelect) { SCGrid_SetCheckBox(!this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)); } } #endregion #region [ Bar ] private void Bar_PageQuery() { ShowOpaqueLayer(); RefreshData(); HideOpaqueLayer(); } private void Btn_PageDown_Click(object sender, EventArgs e) { Btn_PageIndex.Value = Btn_PageIndex.Value + 1; Bar_PageQuery(); } private void Btn_PageEnd_Click(object sender, EventArgs e) { Btn_PageIndex.Value = Btn_PageIndex.MaxValue; Bar_PageQuery(); } private void Btn_PageUp_Click(object sender, EventArgs e) { Btn_PageIndex.Value = Btn_PageIndex.Value - 1; Bar_PageQuery(); } private void Btn_PageOne_Click(object sender, EventArgs e) { Btn_PageIndex.Value = 1; Bar_PageQuery(); } private void Btn_PageSize_ButtonCustomClick(object sender, EventArgs e) { Bar_PageQuery(); } private void Btn_PageIndex_ButtonCustomClick(object sender, EventArgs e) { Bar_PageQuery(); } private void Btn_ExportChk_Click(object sender, EventArgs e) { string f = ExportUtil.ShowSaveFileDialog(); if (!string.IsNullOrEmpty(f)) { if (_GCList == null || _GCList.Count <= 0) { MessageUtil.ShowTips("没有可以导出数据."); return; } ShowOpaqueLayer(); ExportUtil.Execute(f, SCGrid_GetChkRows(), _GCList); HideOpaqueLayer(); MessageUtil.ShowTips(string.Format("导出数据成功,保存文件名[{0}]", f)); } } private void Btn_ExportNow_Click(object sender, EventArgs e) { string f = ExportUtil.ShowSaveFileDialog(); if (!string.IsNullOrEmpty(f)) { if (_GCList == null || _GCList.Count <= 0) { MessageUtil.ShowTips("没有可以导出数据."); return; } ShowOpaqueLayer(); ExportUtil.Execute(f, this.SCGrid.PrimaryGrid.DataSource as DataTable, _GCList); HideOpaqueLayer(); MessageUtil.ShowTips(string.Format("导出数据成功,保存文件名[{0}]", f)); } } private void Btn_ExportALL_Click(object sender, EventArgs e) { try { string f = ExportUtil.ShowSaveFileDialog(); if (!string.IsNullOrEmpty(f)) { if (_GCList == null || _GCList.Count <= 0 || _QueryPageDataMethods == null) { MessageUtil.ShowTips("没有可以导出数据."); return; } ShowOpaqueLayer(); PageData PageDataItem=_QueryPageDataMethods(1, 0); if (PageDataItem == null) { ExportUtil.Execute(f, null, _GCList); } else { ExportUtil.Execute(f, PageDataItem.Dt, _GCList); } MessageUtil.ShowTips(string.Format("导出数据成功,保存文件名[{0}]", f)); } HideOpaqueLayer(); } catch { HideOpaqueLayer(); } } private void Set_BarChkText() { bool IsChk = this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag); Lbl_Text.BeginGroup = IsChk; this.Lbl_Chk.Text = IsChk ? string.Format("选中{0}条", SCGrid_GetChkRowsQty()) : ""; } private void Set_BarData(PageData PageDataItem) { if (this.InvokeRequired) { returnStr stc = new returnStr(Set_BarData); this.Invoke(stc, PageDataItem); } else { #region if (PageDataItem == null || PageDataItem.RowsCount <= 0) { bar1.Visible = false; this.Btn_PageSize.Value = 0; this.Btn_PageIndex.Value = 0; return; } bar1.Visible = true; //分页尺寸 PageDataItem.PageSize = PageDataItem.PageSize < 0 ? 0 : PageDataItem.PageSize; Btn_PageSize.Value = PageDataItem.PageSize; Btn_PageSize.MinValue = 0; Btn_PageSize.MaxValue = int.MaxValue; //页码 PageDataItem.PageIndex = PageDataItem.PageIndex < 1 ? 1 : PageDataItem.PageIndex; //总页数 PageDataItem.PageCount = PageDataItem.PageCount < 1 ? 1 : PageDataItem.PageCount; PageDataItem.PageCount = PageDataItem.PageIndex > PageDataItem.PageCount ? PageDataItem.PageIndex : PageDataItem.PageCount; //页码设定 Btn_PageIndex.Value = PageDataItem.PageIndex; Btn_PageIndex.MinValue = 1; Btn_PageIndex.MaxValue = PageDataItem.PageCount; Btn_PageOne.Enabled = true; Btn_PageUp.Enabled = true; Btn_PageDown.Enabled = true; Btn_PageEnd.Enabled = true; Btn_PageIndex.Enabled = true; if (PageDataItem.PageIndex <= 1) { Btn_PageOne.Enabled = false; Btn_PageUp.Enabled = false; } if (PageDataItem.PageIndex >= PageDataItem.PageCount) { Btn_PageDown.Enabled = false; Btn_PageEnd.Enabled = false; } if (PageDataItem.PageCount <= 1) { Btn_PageIndex.Enabled = false; } string nos = (PageDataItem.PageSize * PageDataItem.PageIndex).ToString(); if (PageDataItem.PageSize * PageDataItem.PageIndex > PageDataItem.RowsCount) { nos = PageDataItem.RowsCount.ToString(); } Lbl_Text.Text = string.Format("页次{0}/{1}页,每页{2}条,当前{3}至{4}条,共{5}条", PageDataItem.PageIndex, PageDataItem.PageCount, PageDataItem.PageSize, PageDataItem.PageSize * (PageDataItem.PageIndex - 1) + 1, nos, PageDataItem.RowsCount); if (!string.IsNullOrEmpty(PageDataItem.DisplayText)) { Lbl_Text.Text = string.Format("{0},{1}", PageDataItem.DisplayText, Lbl_Text.Text); } Set_BarChkText(); #endregion } } private void Btn_PageSize_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { Btn_PageSize_ButtonCustomClick(null, null); } } private void Btn_PageIndex_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { Btn_PageIndex_ButtonCustomClick(null, null); } } #endregion #region [ SCGrid ] private void SCGrid_CellValueChanged(object sender, GridCellValueChangedEventArgs e) { if (IsChange && e.GridCell.GridColumn.Name == ChkTag) { Set_BarChkText(); } if (e.GridCell.GridColumn.Name != ChkTag) { if (_CellValueChangedMethods != null) { _CellValueChangedMethods(e); } } } private void SCGrid_CellMouseDown(object sender, GridCellMouseEventArgs e) { #region Right if (e.Button == MouseButtons.Right) { CellStr = e.GridCell.Value; Show_ContextMenuStrip(); } else { GridRow gr = e.GridCell.GridRow; if (gr == null) { return; } DataRowView drv = gr.DataItem as DataRowView; if (drv == null) { return; } if (_CellMouseDownMethods!=null) _CellMouseDownMethods(drv.Row); } #endregion } private void SCGrid_CellDoubleClick(object sender, GridCellDoubleClickEventArgs e) { if (_GridDoubleClickMethods != null) { GridRow gr = e.GridCell.GridRow; if (gr == null) { return; } DataRowView drv = gr.DataItem as DataRowView; if (drv == null) { return; } _GridDoubleClickMethods(drv.Row); } } /// /// 切换单/多选 /// /// true,多选|false单选 public void SCGrid_SetCheckBox(bool IsCheckBoxes) { if (IsCheckBoxes) { this.SCGrid.PrimaryGrid.Columns.Clear(); DataTable dt = this.SCGrid.PrimaryGrid.DataSource as DataTable; if (dt == null) { dt = new DataTable(); this.SCGrid.PrimaryGrid.DataSource = dt; } if (!dt.Columns.Contains(ChkTag)) { dt.Columns.Add(ChkTag, typeof(bool)); } { GridColumn gc = new GridColumn(); gc.Name = ChkTag; gc.DataPropertyName = gc.Name; gc.HeaderText = ""; gc.DisplayIndex = 0; gc.Width = 40; gc.EditorType = typeof(GridCheckBoxEditControl); gc.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter; this.SCGrid.PrimaryGrid.Columns.Add(gc); } foreach (GridColumn dc in _GCList) { // dc.ReadOnly = true; dc.DisplayIndex = this.SCGrid.PrimaryGrid.Columns.Count; this.SCGrid.PrimaryGrid.Columns.Add(dc); } this.SCGrid.PrimaryGrid.FrozenColumnCount = 1; this.SCGrid.PrimaryGrid.MultiSelect = true; } else { if (this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)) { this.SCGrid.PrimaryGrid.Columns.Remove(this.SCGrid.PrimaryGrid.Columns[ChkTag]); } DataTable dt = this.SCGrid.PrimaryGrid.DataSource as DataTable; if (dt != null) { dt.Columns.Remove(ChkTag); } this.SCGrid.PrimaryGrid.FrozenColumnCount = 0; this.SCGrid.PrimaryGrid.MultiSelect = false; } Set_BarChkText(); if (string.IsNullOrEmpty(_GroupName)) { this.SCGrid.PrimaryGrid.SetGroup(); } else { this.SCGrid.PrimaryGrid.SetGroup(this.SCGrid.PrimaryGrid.Columns[_GroupName]); } if (_RefreshRoleMethods != null) { _RefreshRoleMethods(IsCheckBoxes); } } /// /// 获取选中项数量 /// /// 选中数量 public int SCGrid_GetChkRowsQty() { if (this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)) { DataTable dt = this.SCGrid.PrimaryGrid.DataSource as DataTable; if (dt == null) { return 0; } return (from DataRow dr in dt.Rows where (dr[ChkTag] != null) && (!string.IsNullOrEmpty(dr[ChkTag].ToString()) && Boolean.Parse(dr[ChkTag].ToString())) select 1).Count(); } else { return this.SCGrid.PrimaryGrid.SelectedRowCount; } } /// /// 获取选中数据 /// public DataTable SCGrid_GetChkRows() { DataTable dt = this.SCGrid.PrimaryGrid.DataSource as DataTable; if (dt == null) { return null; } DataTable ndt = dt.Clone(); if (this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)) { List drs = (from DataRow dr in dt.Rows where (dr[ChkTag] != null) && (!string.IsNullOrEmpty(dr[ChkTag].ToString()) && Boolean.Parse(dr[ChkTag].ToString())) select dr).ToList(); foreach (DataRow dr in drs) { ndt.ImportRow(dr); } } else { foreach (GridRow gr in this.SCGrid.PrimaryGrid.SelectedRows) { DataRowView drv = gr.DataItem as DataRowView; if (drv == null) { continue; } ndt.ImportRow(drv.Row); } } return ndt; } public DataTable SCGrid_GetAllRows() { return this.SCGrid.PrimaryGrid.DataSource as DataTable; } public DataRow SCGrid_GetSelectRow(int StepQty) { int TmpRowCount = this.SCGrid.PrimaryGrid.Rows.Count; if (TmpRowCount == 0) { return null; } int SRowcount = this.SCGrid.PrimaryGrid.SelectedRowCount; int TmpRowIndex = 0; if (SRowcount == 0) { TmpRowIndex = 0; } else { int nowindex = 0; foreach (GridRow gr in this.SCGrid.PrimaryGrid.SelectedRows) { nowindex = gr.RowIndex; break; } if (StepQty == 0) { TmpRowIndex = nowindex; } else if (StepQty > 0) { if (nowindex + 1 >= TmpRowCount) { TmpRowIndex = (TmpRowCount - 1); } else { TmpRowIndex = nowindex + 1; } } else { if (nowindex - 1 <= 0) { TmpRowIndex = 0; } else { TmpRowIndex = nowindex - 1; } } } this.SCGrid.PrimaryGrid.ClearSelectedRows(); this.SCGrid.PrimaryGrid.SetSelectedRows(TmpRowIndex, 1, true); DataTable dt = this.SCGrid.PrimaryGrid.DataSource as DataTable; if (dt == null) { return null; } return dt.Rows[TmpRowIndex]; } public void SetGridColumnIsReadOnly(string GCName, bool IsReadOnly) { GridColumn gc = _GCList.Find(a => a.Name == GCName); if (gc != null) { if (IsReadOnly == false) { gc.CellStyles.Default.TextColor = Color.Red; } gc.ReadOnly = IsReadOnly; } } public DataTable GetGrid() { DataTable dt = this.SCGrid.PrimaryGrid.DataSource as DataTable; if (dt == null) { return null; } return dt; } public void UpdateGrid(DataTable _dt) { DataTable dt = this.SCGrid.PrimaryGrid.DataSource as DataTable; if (dt != null) { dt = _dt; this.Refresh(); } this.SCGrid.PrimaryGrid.DataSource = dt; } #endregion private DataSet _DataSet; #region Expand public void TSAE() { InitializeGrid_T(); } private void InitializeGrid_T() { GridPanel panel = SCGrid.PrimaryGrid; //获取单元格的值 //SelectedElementCollection col = this.superGridControl1.PrimaryGrid.GetSelectedRows(); //List cells = col.GetCells(); //textBoxX1.Text = cells[2].Value.ToString(); // SCGrid.PrimaryGrid.Filter.Visible = false; //控制表格只能选中单行 //SCGrid.PrimaryGrid.MultiSelect =true; //SCGrid.PrimaryGrid.InitialSelection = RelativeSelection.Row; //只能选中一个单元格,而不是一行单元格 SCGrid.PrimaryGrid.SelectionGranularity = SelectionGranularity.Cell; //是否显示序列号 SCGrid.PrimaryGrid.ShowRowHeaders = true; panel.RowHeaderWidth = 30; SCGrid.PrimaryGrid.RowHeaderIndexOffset = 1; this.SCGrid.PrimaryGrid.FrozenColumnCount = 1; //panel.Columns["IQC"].EditorType = typeof(MyButton); //GridRow iet = new GridRow(); //GridButtonXEditControl control = iet.Cells["IQC"].EditControl as GridButtonXEditControl; // panel.SelectionGranularity = SelectionGranularity.Row; //panel.Columns["IQC"].EditorType = typeof(FlowerButton); // panel.Columns["ButtonX"].EditorParams = new object[] { flowerImageList }; } public void sa() { InitializeGrid(); } private void InitializeGrid() { GridPanel panel = SCGrid.PrimaryGrid; panel.Name = "Customers"; panel.ShowToolTips = true; panel.MinRowHeight = 20; panel.AutoGenerateColumns = true; //panel.DefaultVisualStyles.GroupByStyles.Default.Background = _Background1; panel.SelectionGranularity = SelectionGranularity.Cell; //superGridControl1.CellValueChanged += SuperGridControl1CellValueChanged; // superGridControl1.GetCellStyle += SuperGridControl1GetCellStyle; SCGrid.DataBindingComplete += SuperGridControl1DataBindingComplete; //superGridControl1.DataBindingComplete += SuperGridControl1DataBindingComplete; } void SuperGridControl1DataBindingComplete( object sender, GridDataBindingCompleteEventArgs e) { GridPanel panel = e.GridPanel; panel.GroupByRow.Visible = true; switch (panel.DataMember) { case "WORK": CustomizeCustomerPanel(panel); break; //case "Orders": // CustomizeOrdersPanel(panel); // break; case "WORK_DTL": CustomizeDetailsPanel(panel); break; } } private void CustomizeCustomerPanel(GridPanel panel) { //panel.ColumnAutoSizeMode = ColumnAutoSizeMode.ColumnHeader; panel.DefaultVisualStyles.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter; panel.FrozenColumnCount = 3; panel.ColumnHeader.RowHeight = 30; panel.ShowRowGridIndex = true; panel.ShowRowHeaders = true; panel.RowHeaderIndexOffset = 1; panel.RowHeaderWidth = 30; panel.Columns[0].GroupBoxEffects = GroupBoxEffects.None; panel.GroupByRow.Visible = false; //需要隐藏的列 //panel.Columns["POSIDCUR"].Visible = false; panel.Columns["COMTYPE_T"].Visible = false; panel.Columns["WORKTASKSTATUS_T"].Visible = false; panel.Columns["KDAUF_T"].Visible = false; panel.Columns["KDPOS_T"].Visible = false; foreach (GridColumn column in panel.Columns) { column.ColumnSortMode = ColumnSortMode.Multiple; //column.DataPropertyName = ColName; //column.HeaderText = HeaderText; //column.ToolTip = HeaderText; } } private void CustomizeDetailsPanel(GridPanel panel) { panel.DefaultVisualStyles.CellStyles.Default.Margin = new DevComponents.DotNetBar.SuperGrid.Style.Padding(2); panel.DefaultVisualStyles.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter; //GridColumn col = new GridColumn("Price"); panel.AllowRowDelete = false; panel.AllowRowInsert = false; panel.AllowEdit = false; //col.ReadOnly = true; //col.EditorType = typeof(MyPriceEditControl); //col.GroupBoxEffects = GroupBoxEffects.None; //panel.Columns.Add(col); panel.ShowRowGridIndex = true; panel.RowHeaderIndexOffset = 1; panel.AllowRowHeaderResize = true; panel.ShowRowHeaders = false; panel.EnableCellExpressions = true; panel.ColumnHeader.RowHeight = 30; //panel.Columns[0].CellStyles.Default.Background = // new Background(Color.LavenderBlush); panel.Columns["PARENTID"].CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter; panel.DefaultVisualStyles.CaptionStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter; panel.DefaultVisualStyles.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter; panel.GroupByRow.Visible = false; panel.Columns["PARENTID"].HeaderText = "任务ID"; panel.Columns["MNO"].HeaderText = "物料编号"; panel.Columns["MNAME"].HeaderText = "物料名称"; panel.Columns["BATCH"].HeaderText = "批次"; panel.Columns["QTY"].HeaderText = "数量"; panel.Columns["REMARKS"].HeaderText = "备注"; } public void RefreshData_Work(int QPageIndex, int QPageSize) { DataTable dt = null; try { if (_QueryPageDataMethods == null) { throw new Exception(); } QPageIndex = QPageIndex < 1 ? 1 : QPageIndex; QPageSize = QPageSize < 0 ? 0 : QPageSize; PageData PageDataItem = _QueryPageDataMethods(QPageIndex, QPageSize); if (PageDataItem == null) { throw new Exception(); } dt = PageDataItem.Dt; //_DataSet = PageDataItem.st; //初始化Bar Set_BarData(PageDataItem); } catch { Set_BarData(null); } if (this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)) { if (dt == null) { dt = new DataTable(); } if (!dt.Columns.Contains(ChkTag)) { dt.Columns.Add(ChkTag, typeof(bool)); } } this.SCGrid.PrimaryGrid.DataSource = _DataSet; this.SCGrid.PrimaryGrid.DataMember = "WORK"; } public void RefreshData_Work() { RefreshData_Work(this.Btn_PageIndex.Value, this.Btn_PageSize.Value); } public DataSet SCGrid_GetChkRows_Work_Set() { DataSet ds = this.SCGrid.PrimaryGrid.DataSource as DataSet; return ds; } /// /// 获取选中数据 /// public DataTable SCGrid_GetChkRows_Work() { DataTable ndt = new DataTable(); DataSet ds = this.SCGrid.PrimaryGrid.DataSource as DataSet; if (ds != null) { DataTable dt = ds.Tables["WORK"]; if (dt == null) { return null; } ndt = dt.Clone(); if (this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)) { List drs = (from DataRow dr in dt.Rows where (dr[ChkTag] != null) && (!string.IsNullOrEmpty(dr[ChkTag].ToString()) && Boolean.Parse(dr[ChkTag].ToString())) select dr).ToList(); foreach (DataRow dr in drs) { ndt.ImportRow(dr); } } else { foreach (GridRow gr in this.SCGrid.PrimaryGrid.SelectedRows) { DataRowView drv = gr.DataItem as DataRowView; if (drv == null) { continue; } ndt.ImportRow(drv.Row); } } } return ndt; } #endregion public DataTable _dt(int QPageIndex, int QPageSize) { DataTable dt = null; try { if (_QueryPageDataMethods == null) { throw new Exception(); } QPageIndex = QPageIndex < 1 ? 1 : QPageIndex; QPageSize = QPageSize < 0 ? 0 : QPageSize; PageData PageDataItem = _QueryPageDataMethods(QPageIndex, QPageSize); if (PageDataItem == null) { throw new Exception(); } dt = PageDataItem.Dt; //初始化Bar // Set_BarData(PageDataItem); } catch { // Set_BarData(null); } return dt; } /// /// 分页查询 /// /// 页码 /// 分页尺寸 public void RefreshData_Maintenance(int QPageIndex, int QPageSize) { DataTable dt = null; try { if (_QueryPageDataMethods == null) { throw new Exception(); } QPageIndex = QPageIndex < 1 ? 1 : QPageIndex; QPageSize = QPageSize < 0 ? 0 : QPageSize; PageData PageDataItem = _QueryPageDataMethods(QPageIndex, QPageSize); if (PageDataItem == null) { throw new Exception(); } dt = PageDataItem.Dt; //初始化Bar Set_BarData(PageDataItem); } catch { Set_BarData(null); } if (this.SCGrid.PrimaryGrid.Columns.Contains(ChkTag)) { if (dt == null) { dt = new DataTable(); } if (!dt.Columns.Contains(ChkTag)) { dt.Columns.Add(ChkTag, typeof(bool)); } } GridPanel panel = SCGrid.PrimaryGrid; panel.Name = "Maintenance"; //保养报表使用 SCGrid.GetCellStyle += SuperGridControl1GetCellStyle; this.SCGrid.PrimaryGrid.DataSource = dt; } void SuperGridControl1GetCellStyle(object sender, GridGetCellStyleEventArgs e) { GridPanel panel = e.GridPanel; if (panel.Name.Equals("Maintenance") == true) { if (e.GridCell.GridColumn.Name.Equals("TERM") == true) //数据库剩余时间表头 { //if (((string)e.GridCell.Value).Equals("TERM") == true) //if(DateTime.Now.AddDays(7)>=(DateTime)e.GridCell.Value) //int sa =(Int32)e.GridCell.Value; //if ((Int32)e.GridCell.Value < 7) //{ // e.Style.TextColor = Color.Red; //} //if(((Int32)e.GridCell.Value)<0) string wqe = e.GridCell.FormattedValue; if (Convert.ToInt32(wqe) < 7) { e.Style.TextColor = Color.Red; } //if (((string)e.GridCell.Value).Equals("7") == true) // e.Style.TextColor = Color.Red; } } } private void layoutControl1_Click(object sender, EventArgs e) { } //public void AddRows(int rowCount, string values) //{ // for (int i = 0; i < rowCount; i++) // SCGrid.PrimaryGrid.Rows.Add(GetNewRow(values)); //} /// /// Creates a new GridRow /// /// //private static GridRow GetNewRow(string values) //{ // // GridRows can be created with varying parameters set // // to the GridRow constructor. In this case we are // // sending a variable list of parameters. // GridRow row = new GridRow(values); // return row; //} void SuperGridControl1RowSetDefaultValues( object sender, GridRowSetDefaultValuesEventArgs e) { // We only want to initialize new rows upon their creation, // not each time they are activated (only applicable to the InsertRow). //if (e.NewRowContext == NewRowContext.RowInit) //{ // GridRow row = e.GridRow; // row["查询角色"].Value = "agcd"; //} } void SuperGridControl1CellValueChanged( object sender, GridCellValueChangedEventArgs e) { //GridCell cell = e.GridCell; //// If the cell changing value is in the "Power State" column //// then adjust the row "Start/Stop" cell appropriately //if (cell.GridColumn.Name.Equals("查询角色") == true) //{ // GridRow row = cell.GridRow; // row.Cells["查询角色"].Value = "adafsdf"; // // Hide the cell if the switch button is off // // and reset the cell's value back to the "Start" state //} } } }