using DevExpress.Utils; using DevExpress.XtraBars; using DevExpress.XtraCharts; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Columns; using Lskj.Business; using Lskj.Business.Impl; using Lskj.Core; using Lskj.Model; using Lskj.Util; using Lskj.Control.Model; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; using Lskj.Control.SiftColControl; using DevExpress.XtraEditors.Controls; using Lskj.Control.Properties; using DevExpress.XtraGrid.Views.Grid; using Microsoft.CSharp; using Lskj.Data; using System.IO; using DevExpress.XtraGrid.Views.BandedGrid; using DevExpress.XtraPrintingLinks; using DevExpress.XtraTab; namespace Lskj.Control { public partial class FrmGridSift : BaseForm { public FrmGridSift() { InitializeComponent(); } #region 变量 private List DragItemList = new List(); /// /// 单个按钮右键菜单 /// private DevExpress.XtraBars.PopupMenu popupMenu; /// /// 统计面板右键菜单 /// private DevExpress.XtraBars.PopupMenu allpopupMenu; /// /// 图表控件 /// private ChartControlEx chart; /// /// 右键菜单产生的控件 /// private Lskj.Control.SiftColControl.DragItem rightClickItem; /// /// 所有列名 /// private List colName = null; /// /// 展示数据源 /// private DataTable source = new DataTable(); /// /// 方案字典 /// private Dictionary projectDic = new Dictionary(); /// /// 分组结果 /// private IEnumerable> groupResultLists; /// /// 主表初始显示列 /// private List gcMainColumns; /// /// 当前方案对象 /// public GridSiftProjectModel ProjectModel = new GridSiftProjectModel(); /// /// 模块Key值 /// public string CustomColumKey; /// /// 外部表格对象 /// public GridControlEx ParentGridEx; #endregion #region 事件 #region 窗体加载时 /// /// 说明:窗体加载时 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OnLoad(object sender, EventArgs e) { WaitForm.ShowForm(); try { this.source = this.ParentGridEx.GridView.GetGridViewFilteredAndSortedDataToDataTable().Copy(); InitEvent(); InitSpliterPosition();//初始化分割条位置 InitMainSpliterPosition(); InitExportDrop(); InitCheckProject(); InitLeftGrid(); InitChart(); InitResultRightMenu(); InitShowDataGrid(); InitDetailGrid(); InitProjectSelect(); this.checkRowSum.CheckState = CheckState.Checked; this.checkColSum.Enabled = false; this.splitContainerControl.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Both; this.pl_GroupByCol.AllowDrop = true; this.pl_groupByRow.AllowDrop = true; this.pl_Result.AllowDrop = true; //int top = 0; int left = 2; //foreach (DataColumn col in source.Columns)//加载所有列显示 //{ // DragItemModel dragItemModel = new DragItemModel(); // dragItemModel.name = col.ColumnName; // dragItemModel.caption = col.Caption; // Lskj.Control.SiftColControl.DragItem.MouseDownEventHanlder mouseDownEventHanlder = null; // Lskj.Control.SiftColControl.DragItem dragItem = new Lskj.Control.SiftColControl.DragItem(dragItemModel); // mouseDownEventHanlder += new Lskj.Control.SiftColControl.DragItem.MouseDownEventHanlder(startDrag); // dragItem.setMouseDownEvent(mouseDownEventHanlder); // dragItem.ItemBtn.Visible = false;//隐藏主界面关闭按钮 // dragItem.Tag = col; // //dragItem.FieldColName = col.ColumnName; // dragItem.ItemLable.Text = col.Caption; // dragItem.ItemLable.Tag = col.Caption; // dragItem.Width = dragItem.ItemLable.Width + 10 + dragItem.ItemBtn.Height; // dragItem.ItemBtn.Width = dragItem.ItemBtn.Height; // dragItem.Parent = this.pl_AllColumns; // this.DragItemList.Add(dragItem); // if (left + dragItem.Width > pl_AllColumns.Width) // { // top += dragItem.Height + 2; left = 2; // dragItem.Location = new Point(left, top); // left += dragItem.Width + 2; // } // else // { // dragItem.Location = new Point(left, top); // left += dragItem.Width + 2; // } //} } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } WaitForm.HideForm(); } #endregion #region 控件拖拽完成事件 /// /// 说明:控件拖拽完成事件 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OnDragDrop(object sender, DragEventArgs e) { try { DevExpress.XtraEditors.PanelControl panelContol = (DevExpress.XtraEditors.PanelControl)sender; if (panelContol != this.pl_Result) { List colName = new List(); foreach (Lskj.Control.SiftColControl.DragItem Item in panelContol.Controls) { colName.Add(Item.dragItemModel.name); } object item = e.Data.GetData(typeof(DataRow[])); DataRow[] rows = (DataRow[])item; foreach (DataRow row in rows) { if (colName.Contains(row["sysName"] + "")) { MessageUtil.Show(string.Format("字段:{0}已存在!", row["userName"] + "")); } else { Lskj.Control.SiftColControl.DragItem.btn_ClickEventHanlder btn_ClickEventHanlder = null; DataColumn col = this.source.Columns.Contains(row["sysName"] + "") ? this.source.Columns[row["sysName"] + ""] : null; col.Caption = row["userName"] + ""; DragItemModel dragItemModel = new DragItemModel(); dragItemModel.name = col.ColumnName; dragItemModel.caption = col.Caption; Lskj.Control.SiftColControl.DragItem dragItem = new Lskj.Control.SiftColControl.DragItem(dragItemModel); btn_ClickEventHanlder += new Lskj.Control.SiftColControl.DragItem.btn_ClickEventHanlder(deleteItem); dragItem.setClickEvent(btn_ClickEventHanlder); //dragItem.FieldColName = column.ColumnName; dragItem.ItemLable.Text = col.Caption; dragItem.ItemLable.Tag = col.Caption; dragItem.Tag = col; dragItem.Width = dragItem.ItemLable.Width + 10 + dragItem.ItemBtn.Height; dragItem.ItemBtn.Width = dragItem.ItemBtn.Height; dragItem.Parent = panelContol; dragItem.Location = new Point(2, 0); } } //if (this.pl_GroupByCol.Controls.Count != 0 && this.pl_Result.Controls.Count > 1) //{ // Lskj.Control.SiftColControl.DragItem dragItem = this.pl_Result.Controls[0] as Lskj.Control.SiftColControl.DragItem; // this.pl_Result.Controls.Clear(); // this.pl_Result.Controls.Add(dragItem); //} RedRawDragItem(panelContol); } else { object item = e.Data.GetData(typeof(DataRow[])); DataRow[] rows = (DataRow[])item; foreach (DataRow row in rows) { Lskj.Control.SiftColControl.DragItem.btn_ClickEventHanlder btn_ClickEventHanlder = null; Lskj.Control.SiftColControl.DragItem.MouseUpEventHanlder mouseUpEventHanlder = null; DataColumn col = this.source.Columns.Contains(row["sysName"] + "") ? this.source.Columns[row["sysName"] + ""] : null; col.Caption = row["userName"] + ""; DragItemModel dragItemModel = new DragItemModel(); dragItemModel.name = col.ColumnName; dragItemModel.caption = col.Caption; Lskj.Control.SiftColControl.DragItem dragItem = new Lskj.Control.SiftColControl.DragItem(dragItemModel); btn_ClickEventHanlder += new Lskj.Control.SiftColControl.DragItem.btn_ClickEventHanlder(deleteItem);//注册关闭事件 mouseUpEventHanlder += new Lskj.Control.SiftColControl.DragItem.MouseUpEventHanlder(showPopupMenu);//注册右击菜单事件 dragItem.setClickEvent(btn_ClickEventHanlder); dragItem.setMouseUpEvent(mouseUpEventHanlder); //dragItem.FieldColName = column.ColumnName; dragItem.ItemLable.Text = col.Caption; dragItem.ItemLable.Tag = col.Caption; dragItem.Tag = col; dragItem.Width = dragItem.ItemLable.Width + 10 + dragItem.ItemBtn.Height; dragItem.ItemBtn.Width = dragItem.ItemBtn.Height; dragItem.Parent = panelContol; RedRawDragItem(panelContol); } } //updateGridViewData();//数据显示更新 updateGridViewDataDynamic(); //this.gcMain.GridView.BestFitColumns(); this.leftGridView.ClearSelection(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #region 拖入控件边界 /// /// 拖入控件边界 /// /// /// private void OnDragEnter(object sender, DragEventArgs e) { try { if (e.Data.GetDataPresent(typeof(DataRow[]))) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #endregion #region 单个按钮右键菜单点击事件 /// /// 说明:单个按钮右键菜单点击事件 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OnItem_ItemClick(object sender, ItemClickEventArgs e) { try { rightClickItem.ItemLable.Text = (rightClickItem.ItemLable.Tag + string.Format("({0})", e.Item.Caption)).Replace("\r\n", ""); rightClickItem.dragItemModel.oper = e.Item.Name; rightClickItem.Width = rightClickItem.ItemLable.Width + 10 + rightClickItem.ItemBtn.Height; RedRawDragItem(this.pl_Result); AlterRepeatItem(this.pl_Result, rightClickItem); //updateGridViewData(); updateGridViewDataDynamic(); //this.gcMain.GridView.BestFitColumns(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #region 统计面板右键菜单点击事件 /// /// 说明:统计面板右键菜单点击事件 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OnAllItem_ItemClick(object sender, ItemClickEventArgs e) { try { foreach (DragItem dragItem in this.pl_Result.Controls) { this.rightClickItem = dragItem; BarItemLink operItemLink = this.popupMenu.ItemLinks.Where(n => n.Item.Name.Equals(e.Item.Name)).FirstOrDefault(); ItemClickEventArgs itemClickEventArgs = new ItemClickEventArgs(operItemLink.Item, operItemLink); OnItem_ItemClick(null, itemClickEventArgs); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #region 点击重置按钮事件 /// /// 说明:点击清除按钮事件 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. void OnBtnClear_Click(object sender, EventArgs e) { this.pl_GroupByCol.Controls.Clear(); this.pl_groupByRow.Controls.Clear(); this.pl_Result.Controls.Clear(); for (int i = 0; i < this.DetailTabControl.TabPages.Count; i++) { XtraTabPage xtraTabPage = this.DetailTabControl.TabPages[i]; if (xtraTabPage.Controls[0] is BandedGridControlEx) { (this.DetailTabControl.TabPages[i].Controls[0] as BandedGridControlEx).GridControl.DataSource = this.source.Clone(); } else if (xtraTabPage.Controls[0] is GridControlEx) { (this.DetailTabControl.TabPages[i].Controls[0] as GridControlEx).GridControl.DataSource = this.source.Clone(); } else { (this.DetailTabControl.TabPages[i].Controls[0] as ChartControlEx).cmMain.Series.Clear(); } } //updateGridViewData(); updateGridViewDataDynamic(); } #endregion #region 点击显示图表 /// /// 说明:点击显示图表 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OncheckShowChart_CheckedChanged(object sender, EventArgs e) { DevExpress.XtraEditors.CheckEdit checkEdit = (DevExpress.XtraEditors.CheckEdit)sender; if (checkEdit.CheckState == CheckState.Checked) { this.splitContainerControl.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Both; } if (checkEdit.CheckState == CheckState.Unchecked) { this.splitContainerControl.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1; } } #endregion #region 点击显示行合计 /// /// 说明:点击显示行合计 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OncheckRowSum_CheckedChanged(object sender, EventArgs e) { DevExpress.XtraEditors.CheckEdit checkEdit = (DevExpress.XtraEditors.CheckEdit)sender; if (checkEdit.CheckState == CheckState.Checked) { this.gcMain.GridView.OptionsView.ShowFooter = true; } if (checkEdit.CheckState == CheckState.Unchecked) { this.gcMain.GridView.OptionsView.ShowFooter = false; } } #endregion #region 分隔条位置改变时 /// /// 说明:获取验证返回操作参数 /// 创建人:龚宇超 /// 创建日期:2018-03-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnSplitContainerControl_SplitterPositionChanged(object sender, EventArgs e) { IniHelper.Write(string.Format("Step_spliterPositionMain_{0}", "FrmGridSift"), this.splitContainerControl.SplitterPosition + ""); } private void OnSplitMainContainerControl_SplitterPositionChanged(object sender, EventArgs e) { IniHelper.Write(string.Format("Step_spliterMainPositionMain_{0}", "FrmGridSift"), this.splitMainContainerControl.SplitterPosition + ""); } #endregion #region 导出明细Excel事件 /// /// 说明:导出明细Excel事件 /// 创建人:唐德馨 /// 创建日期:2022-10-02 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// private void OnItemExportDetail_ItemClick(object sender, ItemClickEventArgs e) { try { XtraTabPage xtraTabPage = this.DetailTabControl.SelectedTabPage; if (xtraTabPage.Text.Equals("明细表")) { if (xtraTabPage.Controls[0] is BandedGridControlEx) { (xtraTabPage.Controls[0] as BandedGridControlEx).GridControl.ToExcel(this.checkProject.EditValue + "" + "-" + xtraTabPage.Text); } else { (xtraTabPage.Controls[0] as GridControlEx).GridControl.ToExcel(this.checkProject.EditValue + "" + "-" + xtraTabPage.Text); } } else { SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "导出"; dialog.FileName = this.checkProject.EditValue + "" + "-" + xtraTabPage.Text + DateTime.Now.ToString("yyyy-MM-dd") + ".xlsx"; dialog.Filter = SystemInfo.Instance.IsXlsxFirst ? "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls|PDF文件|*.PDF|RTF文件|*.RTF|HTML文件|*.html" : "Excel文件(*.xls)|*.xls|Excel文件(*.xlsx)|*.xlsx|PDF文件|*.PDF|RTF文件|*.RTF|HTML文件|*.html"; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { WaitForm.ShowForm("导出中,请稍后..."); (xtraTabPage.Controls[0] as ChartControlEx).ChartControlObj.ExportToXlsx(dialog.FileName); WaitForm.HideForm(); MessageUtil.Show(ResourceKeys.ExportSuccess); } } } catch (Exception ex) { MessageUtil.Show(ex.Message); } } #endregion #region 导出主表Excel事件 /// /// 说明:导出Excel事件 /// 创建人:唐德馨 /// 创建日期:2022-10-02 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// private void OnItemExportExcel_ItemClick(object sender, ItemClickEventArgs e) { this.gcMain.GridControl.ToExcel(this.checkProject.EditValue + "" + "-主表"); } #endregion #region 方案选择切换事件 private void OnCheckProject_SelectedIndexChanged(object sender, EventArgs e) { WaitForm.ShowForm(); try { if (this.checkProject.SelectedIndex == 0) { GridSiftProjectModel gridSiftProjectModel = new GridSiftProjectModel(); this.ProjectModel = gridSiftProjectModel; LoadProject(this.ProjectModel); } else { string sqlStr = "select id from p_SysModuleSchemeTab where moduleId = '{0}' and name = '{1}'"; string primarykey = SqlHelper.ExecuteScalar(string.Format(sqlStr, CustomColumKey, this.checkProject.EditValue)) + ""; this.ProjectModel = new GridSiftProjectModel(primarykey); //重新加载方案 LoadProject(this.ProjectModel); } } catch (Exception ex) { MessageUtil.Show(ex.Message); } WaitForm.HideForm(); } #endregion #region 方案保存事件 private void saveBtn_Click(object sender, EventArgs e) { try { if (this.checkProject.SelectedIndex == 0)//当前为默认方案,则新建方案 { FrmGridSiftProjectAdd frmGridSiftProjectAdd = new FrmGridSiftProjectAdd(CustomColumKey, ERPInfo.Instance.UserId); if (frmGridSiftProjectAdd.ShowDialog() == DialogResult.OK) { GridSiftProjectModel projectModel = GridSiftProjectModel.Add(frmGridSiftProjectAdd.ProjectName, CustomColumKey, Convert.ToInt32(ERPInfo.Instance.UserId), frmGridSiftProjectAdd.IsPub); projectModel.Groups = GetGroupRowList(); projectModel.Cols = GetGroupColList(); projectModel.Targets = GetTargetModelList(); projectModel.Save(); this.ProjectModel = projectModel; MessageUtil.Show(string.Format("方案:{0}新增成功!", projectModel.Name)); } frmGridSiftProjectAdd.Dispose(); } else//否则保存当前方案 { this.ProjectModel.Groups = GetGroupRowList(); this.ProjectModel.Cols = GetGroupColList(); this.ProjectModel.Targets = GetTargetModelList(); this.ProjectModel.Save(); MessageUtil.Show(string.Format("方案:{0}保存成功!", this.ProjectModel.Name)); } InitCheckProject();//重新加载方案列表 this.checkProject.SelectedIndex = this.projectDic.ContainsKey(this.ProjectModel.Name + "") ? this.projectDic[this.ProjectModel.Name + ""] : 0; } catch (Exception ex) { MessageUtil.Show(ex.Message); } } #endregion #region 方案另存事件 private void saveAsBtn_Click(object sender, EventArgs e) { try { FrmGridSiftProjectAdd frmGridSiftProjectAdd = new FrmGridSiftProjectAdd(CustomColumKey, ERPInfo.Instance.UserId); if (frmGridSiftProjectAdd.ShowDialog() == DialogResult.OK) { GridSiftProjectModel projectModel = GridSiftProjectModel.Add(frmGridSiftProjectAdd.ProjectName, CustomColumKey, Convert.ToInt32(ERPInfo.Instance.UserId), frmGridSiftProjectAdd.IsPub); projectModel.Groups = GetGroupRowList(); projectModel.Cols = GetGroupColList(); projectModel.Targets = GetTargetModelList(); projectModel.Save(); this.ProjectModel = projectModel; MessageUtil.Show(string.Format("方案:{0}新增成功!", projectModel.Name)); } frmGridSiftProjectAdd.Dispose(); InitCheckProject();//重新加载方案列表 this.checkProject.SelectedIndex = this.projectDic.ContainsKey(this.ProjectModel.Name + "") ? this.projectDic[this.ProjectModel.Name + ""] : 0; } catch (Exception ex) { MessageUtil.Show(ex.Message); } } #endregion #region 方案删除事件 private void deleteBtn_Click(object sender, EventArgs e) { try { if (MessageUtil.Show("是否删除当前方案?") == DialogResult.OK) { if (this.checkProject.SelectedIndex == 0) { MessageUtil.Show("默认方案无法删除!"); } else { this.ProjectModel.Delete(); MessageUtil.Show(string.Format("方案:{0}删除成功!", this.ProjectModel.Name)); InitCheckProject();//重新加载方案列表 this.checkProject.SelectedIndex = 0;//选中默认方案 } } } catch (Exception ex) { MessageUtil.Show(ex.Message); } } #endregion #region 显示统计面板菜单 private void OnPl_Result_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { allpopupMenu.ShowPopup(System.Windows.Forms.Control.MousePosition); } } #endregion #region 双击选中行 private void OnLeftGridView_DoubleClick(object sender, EventArgs e) { GridView gridView = (GridView)sender; int index = gridView.FocusedRowHandle; int[] selectIndexs = gridView.GetSelectedRows(); if (!selectIndexs.Contains(index)) { gridView.SelectRow(index); } else { gridView.UnselectRow(index); } } #endregion #region 双击主表刷新明细 private void OnGridView_DoubleClick(object sender, EventArgs e) { try { List detailRows = new List(); DataRow focusedRow = this.gcMain.GridView.GetFocusedDataRow(); if (this.groupResultLists == null) { detailRows.Add(focusedRow); } else { string selectStr = ""; List groupRows = GetGroupRowList(); foreach (string groupRow in groupRows) { selectStr += string.Format("{0}='{1}' and ", groupRow, (focusedRow[groupRow] + "").Replace("'", "''")); } if (!string.IsNullOrEmpty(selectStr)) { detailRows = this.source.Select(selectStr.Trim().TrimEnd('d', 'n', 'a')).ToList(); } } DataTable dataTable = this.source.Clone(); detailRows.CopyToDataTable(dataTable, LoadOption.PreserveChanges); this.detailGrid.GridControl.DataSource = dataTable; } catch (Exception ex) { MessageUtil.Show(ex.Message); } } #endregion #region 窗体关闭时 private void FrmGridSift_FormClosing(object sender, FormClosingEventArgs e) { DataTable dataTable = SqlHelper.ExecuteDataTable(string.Format("select * from p_SysModuleSchemeLogTab where operatorid='{0}' and moduleId='{1}'", ERPInfo.Instance.UserId, this.CustomColumKey)); if (dataTable.Rows.Count > 0) { string updateSqlStr = "update p_SysModuleSchemeLogTab set projectid='{0}' where moduleId='{1}' and operatorid='{2}'"; updateSqlStr = string.Format(updateSqlStr, this.ProjectModel.Id + "", this.CustomColumKey + "", ERPInfo.Instance.UserId + ""); SqlHelper.ExecuteNonQuery(updateSqlStr); } else { string insertSqlStr = "insert into p_SysModuleSchemeLogTab (moduleId,operatorid,projectid) values ('{0}','{1}','{2}')"; insertSqlStr = string.Format(insertSqlStr, this.CustomColumKey + "", ERPInfo.Instance.UserId + "", this.ProjectModel.Id + ""); SqlHelper.ExecuteNonQuery(insertSqlStr); } } #endregion #endregion #region 方法 #region 删除单个控件 /// /// 说明:删除单个控件 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void deleteItem(Lskj.Control.SiftColControl.DragItem dragItem) { WaitForm.ShowForm(); DevExpress.XtraEditors.PanelControl panel = dragItem.Parent as DevExpress.XtraEditors.PanelControl; panel.Controls.Remove(dragItem); RedRawDragItem(panel); //updateGridViewData(); updateGridViewDataDynamic(); //this.gcMain.GridView.BestFitColumns(); WaitForm.HideForm(); } #endregion #region 点击开始拖拽 /// /// 说明:点击开始拖拽 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void OnLeftGridView_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { int[] selectIndexs = this.leftGridView.GetSelectedRows(); if (selectIndexs.Length > 0) { List selectRows = new List(); foreach (int index in selectIndexs) { selectRows.Add(this.leftGridView.GetDataRow(index)); } startDrag(selectRows.ToArray()); } } } private void startDrag(DataRow[] rows) { IDataObject data = new DataObject(); data.SetData(typeof(DataRow[]), rows); this.DoDragDrop(data, DragDropEffects.Copy); } #endregion #region 显示右键菜单 /// /// 说明:显示右键菜单 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void showPopupMenu(Lskj.Control.SiftColControl.DragItem dragItem, MouseEventArgs e) { if (e.Button == MouseButtons.Right && dragItem.Parent == this.pl_Result) { popupMenu.ShowPopup(System.Windows.Forms.Control.MousePosition); rightClickItem = dragItem; } } #endregion #region 拖拽完成后数据更新 /// /// 说明:拖拽完成后数据更新 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void updateGridViewData() { DataTable leftSourceTab = this.leftGridControl.DataSourceTable(); List _colName = new List(); foreach (DataRow item in leftSourceTab.Rows) { _colName.Add(item["userName"] + ""); } if (this.pl_groupByRow.Controls.Count != 0 && this.pl_GroupByCol.Controls.Count == 0) { DataTable dataTable = this.source; DataTable afterUpdate = new DataTable(); int numRow = _colName.IndexOf((this.pl_groupByRow.Controls[0] as Lskj.Control.SiftColControl.DragItem).ItemLable.Tag.ToString()); var rows = dataTable.Rows.Cast(); var resultGroupedByColumn = rows.GroupBy(r => r.ItemArray[numRow]);//获取行分组信息 afterUpdate.Columns.Add(dataTable.Columns[numRow].Caption, typeof(string)); string errorString = string.Empty; Lskj.Control.SiftColControl.DragItem errorDragItem = null; try { if (this.pl_Result.Controls.Count != 0) { foreach (Lskj.Control.SiftColControl.DragItem dragItem in this.pl_Result.Controls)//添加列信息 { if (dragItem.ItemLable.Text != dragItem.ItemLable.Tag.ToString()) afterUpdate.Columns.Add(dragItem.ItemLable.Text, typeof(string)); } int index = 0; foreach (IGrouping groupRow in resultGroupedByColumn) { DataRow dr = afterUpdate.NewRow(); dr[(this.pl_groupByRow.Controls[0] as Lskj.Control.SiftColControl.DragItem).ItemLable.Tag.ToString()] = groupRow.Key;//分组列 afterUpdate.Rows.Add(dr); foreach (Lskj.Control.SiftColControl.DragItem dragItem in this.pl_Result.Controls) { DataColumn col = dragItem.Tag as DataColumn; errorString = dragItem.dragItemModel.oper; errorDragItem = dragItem; if (dragItem.ItemLable.Text != dragItem.ItemLable.Tag.ToString()) RighMenuDecide(dragItem, afterUpdate, index, dragItem.ItemLable.Text, groupRow, col); } index++; } } else { foreach (IGrouping groupRow in resultGroupedByColumn) { DataRow dr = afterUpdate.NewRow(); dr[(this.pl_groupByRow.Controls[0] as Lskj.Control.SiftColControl.DragItem).ItemLable.Tag.ToString()] = groupRow.Key;//分组列 afterUpdate.Rows.Add(dr); } } this.gcMain.GridView.Columns.Clear(); this.gcMain.GridControl.DataSource = afterUpdate; SetColumnSumming(); try { AddChart(afterUpdate); } catch (Exception) { } } catch (Exception) { MessageUtil.Show(string.Format("当前列数据类型不允许执行{0}操作!", errorString)); errorDragItem.ItemLable.Text = errorDragItem.ItemLable.Tag.ToString() + "(计数)"; errorDragItem.dragItemModel.oper = "Num"; errorDragItem.Width = errorDragItem.ItemLable.Width + 10 + errorDragItem.ItemBtn.Height; AlterRepeatItem(this.pl_Result, errorDragItem); RedRawDragItem(this.pl_Result); updateGridViewData(); } } if (this.pl_groupByRow.Controls.Count == 0 && this.pl_GroupByCol.Controls.Count == 0) { DataTable dataTable = this.source; DataTable afterUpdate = new DataTable(); foreach (Lskj.Control.SiftColControl.DragItem dragItem in this.pl_Result.Controls) { if (dragItem.ItemLable.Text != dragItem.ItemLable.Tag.ToString()) afterUpdate.Columns.Add(dragItem.ItemLable.Text, typeof(string));//添加列 } DataRow dr = afterUpdate.NewRow(); afterUpdate.Rows.Add(dr); DataRow[] groupRow = dataTable.Select(); string errorString = string.Empty; Lskj.Control.SiftColControl.DragItem errorDragItem = null; try { int index = 0; foreach (Lskj.Control.SiftColControl.DragItem dragItem in this.pl_Result.Controls) { DataColumn col = dragItem.Tag as DataColumn; errorString = dragItem.dragItemModel.oper; errorDragItem = dragItem; if (dragItem.ItemLable.Text != dragItem.ItemLable.Tag.ToString()) RighMenuDecide(dragItem, afterUpdate, 0, dragItem.ItemLable.Text, groupRow, col); index++; } this.gcMain.GridView.Columns.Clear(); this.gcMain.GridControl.DataSource = afterUpdate; SetColumnSumming(); } catch (Exception) { MessageUtil.Show(string.Format("当前列数据类型不允许执行{0}操作!", errorString)); errorDragItem.ItemLable.Text = errorDragItem.ItemLable.Tag.ToString() + "(计数)"; errorDragItem.dragItemModel.oper = "Num"; errorDragItem.Width = errorDragItem.ItemLable.Width + 10 + errorDragItem.ItemBtn.Height; AlterRepeatItem(this.pl_Result, errorDragItem); RedRawDragItem(this.pl_Result); updateGridViewData(); } } if (this.pl_groupByRow.Controls.Count != 0 && this.pl_GroupByCol.Controls.Count != 0) { DataTable dataTable = this.source; DataTable afterUpdate = new DataTable(); var rows = dataTable.Rows.Cast(); int numRow = _colName.IndexOf((this.pl_groupByRow.Controls[0] as Lskj.Control.SiftColControl.DragItem).ItemLable.Tag.ToString()); int numCol = _colName.IndexOf((this.pl_GroupByCol.Controls[0] as Lskj.Control.SiftColControl.DragItem).ItemLable.Tag.ToString()); var resultGroupedByRow = rows.GroupBy(r => r.ItemArray[numRow]);//获取行分组信息 var resultGroupedByCol = rows.GroupBy(r => r.ItemArray[numCol]);//获取列分组信息 afterUpdate.Columns.Add(dataTable.Columns[numRow].Caption, typeof(string)); int Num = 1; foreach (IGrouping groupCol in resultGroupedByCol) { string nullColName = "Null" + Num; if (!string.IsNullOrEmpty(groupCol.Key.ToString())) afterUpdate.Columns.Add(groupCol.Key.ToString(), typeof(string));//添加列分组的列 else { afterUpdate.Columns.Add(nullColName, dataTable.Columns[numCol].DataType); Num = Num + 1; ; } } string errorString = string.Empty; Lskj.Control.SiftColControl.DragItem errorDragItem = null; try { int index = 0; foreach (IGrouping groupRow in resultGroupedByRow) { DataRow dr = afterUpdate.NewRow(); dr[(this.pl_groupByRow.Controls[0] as Lskj.Control.SiftColControl.DragItem).ItemLable.Tag.ToString()] = groupRow.Key;//分组列 afterUpdate.Rows.Add(dr); if (this.pl_Result.Controls.Count != 0) { DataColumn col = this.pl_Result.Controls[0].Tag as DataColumn; errorDragItem = this.pl_Result.Controls[0] as Lskj.Control.SiftColControl.DragItem; int _Num = 1; foreach (IGrouping groupCol in resultGroupedByCol) { var result = dataTable.Select().Where(n => n[(this.pl_GroupByCol.Controls[0].Tag as DataColumn).ColumnName].Equals(groupCol.Key) && n[(this.pl_groupByRow.Controls[0].Tag as DataColumn).ColumnName].Equals(groupRow.Key)); if (result.Count() > 0 && !string.IsNullOrEmpty(groupCol.Key.ToString())) RighMenuDecide(this.pl_Result.Controls[0] as Lskj.Control.SiftColControl.DragItem, afterUpdate, index, groupCol.Key.ToString(), result, col); else if (result.Count() > 0 && string.IsNullOrEmpty(groupCol.Key.ToString())) RighMenuDecide(this.pl_Result.Controls[0] as Lskj.Control.SiftColControl.DragItem, afterUpdate, index, "Null" + _Num, result, col); } } index++; } this.gcMain.GridView.Columns.Clear(); this.gcMain.GridControl.DataSource = afterUpdate; SetColumnSumming(); } catch (Exception) { MessageUtil.Show(string.Format("当前列数据类型不允许执行{0}操作!", errorString)); errorDragItem.ItemLable.Text = errorDragItem.ItemLable.Tag.ToString() + "(计数)"; errorDragItem.dragItemModel.oper = "Num"; errorDragItem.Width = errorDragItem.ItemLable.Width + 10 + errorDragItem.ItemBtn.Height; AlterRepeatItem(this.pl_Result, errorDragItem); RedRawDragItem(this.pl_Result); updateGridViewData(); } } if (this.pl_groupByRow.Controls.Count == 0 && this.pl_GroupByCol.Controls.Count != 0) { DataTable dataTable = this.source; DataTable afterUpdate = new DataTable(); var rows = dataTable.Rows.Cast(); int numCol = _colName.IndexOf((this.pl_GroupByCol.Controls[0] as Lskj.Control.SiftColControl.DragItem).ItemLable.Tag.ToString()); var resultGroupedByCol = rows.GroupBy(r => r.ItemArray[numCol]);//获取列分组信息 int Num = 1; foreach (IGrouping groupCol in resultGroupedByCol) { string nullColName = "Null" + Num; if (!string.IsNullOrEmpty(groupCol.Key.ToString())) afterUpdate.Columns.Add(groupCol.Key.ToString(), typeof(string));//添加列分组的列 else { afterUpdate.Columns.Add(nullColName, typeof(string));//添加列分组的列 Num = Num + 1; ; } } string errorString = string.Empty; Lskj.Control.SiftColControl.DragItem errorDragItem = null; try { int index = 0; DataRow dr = afterUpdate.NewRow(); afterUpdate.Rows.Add(dr); if (this.pl_Result.Controls.Count != 0) { errorDragItem = this.pl_Result.Controls[0] as Lskj.Control.SiftColControl.DragItem; int _Num = 1; foreach (IGrouping groupCol in resultGroupedByCol) { DataColumn col = this.pl_Result.Controls[0].Tag as DataColumn; var result = dataTable.Select().Where(n => n[(this.pl_GroupByCol.Controls[0].Tag as DataColumn).ColumnName].Equals(groupCol.Key)); if (result.Count() > 0 && !string.IsNullOrEmpty(groupCol.Key.ToString())) RighMenuDecide(this.pl_Result.Controls[0] as Lskj.Control.SiftColControl.DragItem, afterUpdate, index, groupCol.Key.ToString(), result, col); else if (result.Count() > 0 && string.IsNullOrEmpty(groupCol.Key.ToString())) RighMenuDecide(this.pl_Result.Controls[0] as Lskj.Control.SiftColControl.DragItem, afterUpdate, index, "Null" + _Num, result, col); } index++; } this.gcMain.GridView.Columns.Clear(); this.gcMain.GridControl.DataSource = afterUpdate; SetColumnSumming(); try { AddChart(afterUpdate); } catch (Exception) { } } catch (Exception) { MessageUtil.Show(string.Format("当前列数据类型不允许执行{0}操作!", errorString)); errorDragItem.ItemLable.Text = errorDragItem.ItemLable.Tag.ToString() + "(计数)"; errorDragItem.dragItemModel.oper = "Num"; errorDragItem.Width = errorDragItem.ItemLable.Width + 10 + errorDragItem.ItemBtn.Height; AlterRepeatItem(this.pl_Result, errorDragItem); RedRawDragItem(this.pl_Result); updateGridViewData(); } } if (this.pl_groupByRow.Controls.Count == 0 && this.pl_Result.Controls.Count == 0 && this.pl_GroupByCol.Controls.Count == 0) { this.gcMain.GridView.Columns.Clear(); this.gcMain.GridControl.DataSource = source; } } #endregion #region 动态分组统计 private void updateGridViewDataDynamic(bool isBatch = false) { bool isWaitShow = WaitForm.LoadForm.IsSplashFormVisible; if (!isWaitShow) { WaitForm.ShowForm(); } try { WaitForm.ShowForm(); List groupLists = GetGroupRowList(); DataTable dataTable = this.source; DataTable groupDataTable = new DataTable(); if (groupLists.Count > 0) { foreach (string group in groupLists)//创建分组列 { DataColumn col = new DataColumn(); col.ColumnName = dataTable.Columns[group].ColumnName; col.Caption = dataTable.Columns[group].Caption; col.DataType = dataTable.Columns[group].DataType; groupDataTable.Columns.Add(col); } Dictionary targetCols = new Dictionary(); foreach (DragItem dragItem in this.pl_Result.Controls)//创建统计列 { try { if (!string.IsNullOrEmpty(dragItem.dragItemModel.oper)) { DataColumn col = new DataColumn();//"GroupResult$"为统计列字段标识符 col.ColumnName = string.Format("{0}_{1}_{2}", "GroupResult$", dragItem.dragItemModel.name, dragItem.dragItemModel.oper); col.Caption = dragItem.ItemLable.Text; col.DataType = typeof(decimal); targetCols.Add(col.ColumnName, dragItem); groupDataTable.Columns.Add(col); } } catch (Exception) { } } if (groupLists.Count > 0) { var groupList = dataTable.AsEnumerable().GroupBy(dataRow => { StringBuilder stringBuilder = new StringBuilder(); groupLists.ForEach(column => stringBuilder.Append(dataRow[column] + "")); return stringBuilder + ""; }); this.groupResultLists = groupList; foreach (var group in groupList) { List groupRows = new List(); foreach (DataRow groupRow in group) { groupRows.Add(groupRow); } DataRow newRow = groupDataTable.NewRow(); foreach (DataColumn col in newRow.Table.Columns) { if (targetCols.ContainsKey(col.ColumnName))//是统计列 { string colName = targetCols[col.ColumnName].dragItemModel.name; string oper = targetCols[col.ColumnName].dragItemModel.oper; try { switch (oper) { case "Sum": newRow[col] = groupRows.Where(m => m[colName].GetType() != typeof(DBNull)).Sum(n => Convert.ToDouble(n[colName])); break; case "Avg": newRow[col] = groupRows.Where(m => m[colName].GetType() != typeof(DBNull)).Average(n => Convert.ToDouble(n[colName])); break; case "Num": newRow[col] = groupRows.Count(); break; case "Max": newRow[col] = groupRows.Where(m => m[colName].GetType() != typeof(DBNull)).Max(n => Convert.ChangeType(n[colName], col.DataType)); break; case "Min": newRow[col] = groupRows.Where(m => m[colName].GetType() != typeof(DBNull)).Min(n => Convert.ChangeType(n[colName], col.DataType)); break; } } catch (Exception) { if (!isBatch) { MessageUtil.Show(string.Format("当前列数据类型不允许执行{0}操作!", oper)); targetCols[col.ColumnName].ItemLable.Text = targetCols[col.ColumnName].ItemLable.Tag + ""; targetCols[col.ColumnName].dragItemModel.oper = ""; targetCols[col.ColumnName].Width = targetCols[col.ColumnName].ItemLable.Width + 10 + targetCols[col.ColumnName].ItemBtn.Height; updateGridViewDataDynamic(isBatch); return; } } } else { newRow[col.ColumnName] = groupRows[0][col.ColumnName]; } } groupDataTable.Rows.Add(newRow); } } } if (groupDataTable.Columns.Count > 0) { DataTable orderTable = groupDataTable.Clone(); // DataTable中的数据库空值是DBNull,不能直接和String等实际类型比较。 // 仅将DBNull作为null参与排序,非空数据仍按字段原始类型排序。 DataColumn orderColumn = groupDataTable.Columns[0]; groupDataTable.Select().OrderBy(n => n.IsNull(orderColumn) ? null : n[orderColumn]).CopyToDataTable(orderTable, LoadOption.PreserveChanges); InitShowDataGridColumns(orderTable); try { AddChart(groupDataTable); } catch (Exception) { } } //SetColumnSumming(); if (groupDataTable.Columns.Count == 0) { InitShowDataGridColumns(source); this.groupResultLists = null; } } catch (Exception ex) { } if (!isWaitShow) { WaitForm.HideForm(); } } #endregion #region 重绘拖拽控件排布 /// /// 说明:重绘拖拽控件排布 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void RedRawDragItem(System.Windows.Forms.Control panelControl) { int top = 0; int left = 2; for (int i = 0; i < panelControl.Controls.Count; i++) { if (left + panelControl.Controls[i].Width > panelControl.Width) { top += panelControl.Controls[i].Height + 2; left = 2; panelControl.Controls[i].Location = new Point(left, top); left += panelControl.Controls[i].Width + 2; } else { panelControl.Controls[i].Location = new Point(left, top); left += panelControl.Controls[i].Width + 2; } } } #endregion #region 判断当前控件是否重复 /// /// 说明:判断当前控件是否重复 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private bool AlterRepeatItem(System.Windows.Forms.Control panelControl, Lskj.Control.SiftColControl.DragItem dragItem) { List colName = new List(); foreach (Lskj.Control.SiftColControl.DragItem Item in panelControl.Controls) { colName.Add(Item.ItemLable.Text); } if (colName.Count(n => n == dragItem.ItemLable.Text) > 1) { MessageUtil.Show(string.Format("字段:{0}{1}操作重复!", dragItem.ItemLable.Tag, dragItem.dragItemModel.oper)); dragItem.ItemLable.Text = dragItem.ItemLable.Tag.ToString(); dragItem.dragItemModel.oper = ""; dragItem.Width = dragItem.ItemLable.Width + 10 + dragItem.ItemBtn.Height; return false; } else return true; } #endregion #region 右键判定条件 /// /// 说明:右键判定条件 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void RighMenuDecide(Lskj.Control.SiftColControl.DragItem dragItem, DataTable afterUpdate, int index, string colName, IEnumerable result, DataColumn col) { switch (dragItem.dragItemModel.oper) { case "Sum": afterUpdate.Rows[index][colName] = result.Where(m => m[col.ColumnName].GetType() != typeof(DBNull)).Sum(n => Convert.ToDouble(n[col.ColumnName])); break; case "Avg": afterUpdate.Rows[index][colName] = result.Where(m => m[col.ColumnName].GetType() != typeof(DBNull)).Average(n => Convert.ToDouble(n[col.ColumnName])); break; case "Num": afterUpdate.Rows[index][colName] = result.Count(); break; case "Max": afterUpdate.Rows[index][colName] = result.Where(m => m[col.ColumnName].GetType() != typeof(DBNull)).Max(n => Convert.ChangeType(n[col.ColumnName], col.DataType)); break; case "Min": afterUpdate.Rows[index][colName] = result.Where(m => m[col.ColumnName].GetType() != typeof(DBNull)).Min(n => Convert.ChangeType(n[col.ColumnName], col.DataType)); break; } } #endregion #region 显示合计 /// /// 说明:设置合计 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. private void SetColumnSumming() { foreach (GridColumn column in this.gcMain.GridView.Columns) { if (column.Summary.Count == 0) { column.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum, column.FieldName, "{0:#,###.######}") }); this.gcMain.GridView.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Sum, column.FieldName, null, "{0:#,###.######}") }); } } } #endregion #region 显示行号 /// /// 说明:显示行号 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. public static void BindCustomDrawRowIndicator(DevExpress.XtraGrid.Views.Grid.GridView view) { view.IndicatorWidth = CalcIndicatorDefaultWidth(view); view.CustomDrawRowIndicator += (s, e) => { if (e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } }; view.TopRowChanged += (s, e) => { int width = CalcIndicatorBestWidth(view); if ((view.IndicatorWidth - 4 < width || view.IndicatorWidth + 4 > width) && view.IndicatorWidth != width) { view.IndicatorWidth = width; } }; } /// /// 计算行头宽度 /// /// /// static int CalcIndicatorBestWidth(DevExpress.XtraGrid.Views.Grid.GridView view) { int count = view.TopRowIndex + ((DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo)view.GetViewInfo()).RowsInfo.Count; if (count == 0) { count = 30; } int textWidth = TextRenderer.MeasureText( count.ToString(), view.Appearance.Row.Font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.SingleLine).Width; return textWidth + 20; } /// /// 计算默认的宽度 /// /// /// static int CalcIndicatorDefaultWidth(DevExpress.XtraGrid.Views.Grid.GridView view) { var grid = view.GridControl; int rowHeight = 22;//22是Row的估计高度 if (view.RowHeight > 0) { rowHeight = view.RowHeight; } int count = grid != null ? grid.Height / rowHeight : 30; int textWidth = TextRenderer.MeasureText( count.ToString(), view.Appearance.Row.Font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.SingleLine).Width; return textWidth + 20; } #endregion #region 选中行颜色改变 private void SelectRowChangeBackColor(GridView View) { View.CustomDrawCell += View_CustomDrawCell; } private void View_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { try { GridView senderGridView = (GridView)sender; if (senderGridView.OptionsSelection.MultiSelect == true && senderGridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect) { int[] selectRows = senderGridView.GetSelectedRows(); foreach (int selectRow in selectRows) {//#9feb6a if (e.RowHandle == selectRow) e.Appearance.BackColor = ColorTranslator.FromHtml("#9feb6a"); } } else if (e.RowHandle == senderGridView.FocusedRowHandle) e.Appearance.BackColor = ColorTranslator.FromHtml("#9feb6a"); } catch (Exception ex) { MessageUtil.Show(ex.Message); } } #endregion #region 根据数据创建一个图形展现 /// /// 说明:根据数据创建一个图形展现 /// 创建人:龚宇超 /// 创建日期:2018-01-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the col. /// The col value. /// The series. /// Series. private Series CreateSeries(string colName, string colValue, Series series) { series.Points.Add(new SeriesPoint(colName + "" == "" ? "*指标为空*" : colName, colValue + "" == "" ? "0" : colValue)); series.ArgumentScaleType = ScaleType.Qualitative; series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;//显示标注标签 return series; } #endregion #region 根据数据创建一个饼图展现 /// /// 说明:根据数据创建一个饼图展现 /// 创建人:龚宇超 /// 创建日期:2018-01-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// Name of the col. /// The col value. /// The series. /// Series. private Series CreateSeriesPie(String colName, String colValue, Series series) { series.Points.Add(new SeriesPoint(colName + "" == "" ? "*指标为空*" : colName, new double[] { Convert.ToDouble(colValue + "" == "" ? "0" : colValue) })); return series; } #endregion #region 创建图表数据线 /// /// 说明:创建图表 /// 创建人:龚宇超 /// 创建日期:2018-01-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The chart. private void CreateSeriesChart(Series series, DataTable chartData, DataColumn resultCol, ViewType type) { List groupCols = chartData.Columns.Cast().Where(n => !n.ColumnName.StartsWith("GroupResult$")).ToList(); foreach (DataRow item in chartData.Rows) { string xValue = ""; for (int i = 0; i < groupCols.Count; i++) { DataColumn groupCol = groupCols[i]; GridColumn gridColumn = this.gcMain.GridView.Columns.Where(n => n.FieldName.Equals(groupCol.ColumnName)).FirstOrDefault(); if (gridColumn == null) { continue; } //int rowIndex = this.gcMain.GridView.GetVisibleIndex(i); //int rowIndex = chartData.Rows.IndexOf(item); string value = item[groupCol] + ""; string displayText = this.gcMain.GridView.GetDisplayTextByColumnValue(gridColumn, value); xValue += string.Format("{0},", displayText); } xValue = xValue.TrimEnd(','); if (type == ViewType.Pie) { string yValue = item[resultCol].ToString(); CreateSeries(xValue, yValue, series); } else { string yValue = item[resultCol].ToString(); CreateSeries(xValue, yValue, series); } } //if (this.pl_groupByRow.Controls.Count == 0) //{ // foreach (DataColumn item in chartData.Columns) // { // if (type == ViewType.Pie) // { // string xValue = item.ColumnName.ToString(); // string yValue = item.Table.Rows[1][item.ColumnName].ToString(); // CreateSeries(xValue, yValue, series); // } // else // { // string xValue = item.ColumnName.ToString(); // string yValue = item.Table.Rows[i][item.ColumnName].ToString(); // CreateSeries(xValue, yValue, series); // } // } //} } #endregion #region 创建图表 /// /// 说明:创建图表 /// 创建人:龚宇超 /// 创建日期:2018-01-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The models. /// The fields. public void CreateChart(ChartControlEx chart, DataTable chartData, ViewType type) { if (chart.cmMain.Diagram is XYDiagram) (chart.cmMain.Diagram as XYDiagram).SecondaryAxesY.Clear(); chart.cmMain.Series.Clear(); if (chartData.Rows.Count > 0 && chartData.Columns.Count > 1) { List resultCols = chartData.Columns.Cast().Where(n => n.ColumnName.StartsWith("GroupResult$")).ToList(); for (int i = 0; i < resultCols.Count; i++) { DataColumn resultCol = resultCols[i]; Series series = null; series = new Series(resultCol.Caption, type); if (series != null) { if (type == ViewType.Pie) { PiePointOptions options = series.Label.PointOptions as PiePointOptions; series.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent; series.LegendPointOptions.ValueNumericOptions.Precision = 4; ((PiePointOptions)series.LegendPointOptions).PointView = PointView.ArgumentAndValues; PieSeriesView view = series.View as PieSeriesView; view.ExplodeMode = PieExplodeMode.All; view.Rotation = 50; view.RuntimeExploding = true; series.LabelsVisibility = DefaultBoolean.True; if (options != null) { options.PercentOptions.ValueAsPercent = true; options.PointView = PointView.ArgumentAndValues; } this.CreateSeriesChart(series, chartData, resultCols[0], type); if (chart.cmMain.Series.Count == 0) { chart.cmMain.Series.Add(series); chart.cmMain.CustomDrawSeriesPoint -= CmMain_CustomDrawSeriesPoint; chart.cmMain.CustomDrawSeriesPoint += CmMain_CustomDrawSeriesPoint; } } else { this.CreateSeriesChart(series, chartData, resultCol, type); chart.cmMain.Series.Add(series); XYDiagram diagram = (XYDiagram)chart.ChartControlObj.Diagram; diagram.AxisX.VisualRange.SideMarginsValue = 0; diagram.ZoomingOptions.UseMouseWheel = true; diagram.EnableAxisXZooming = true; diagram.EnableAxisXScrolling = true; } } } } chart.cmMain.Legend.Visibility = DefaultBoolean.True; chart.cmMain.SeriesTemplate.LabelsVisibility = DefaultBoolean.True; chart.cmMain.CrosshairEnabled = DefaultBoolean.True; chart.cmMain.ToolTipEnabled = DefaultBoolean.True; } private void AddChart(DataTable chartData) { for (int i = 0; i < this.DetailTabControl.TabPages.Count; i++) { XtraTabPage xtraTabPage = this.DetailTabControl.TabPages[i]; ChartControlEx chart = this.DetailTabControl.TabPages[i].Controls[0] as ChartControlEx; switch (xtraTabPage.Text) { case "饼图": CreateChart(chart, chartData, ViewType.Pie); break; case "柱形图": CreateChart(chart, chartData, ViewType.Bar); break; case "折线图": CreateChart(chart, chartData, ViewType.Line); break; } } } #endregion #region 初始化事件 private void InitEvent() { this.BtnClear.Click += OnBtnClear_Click; this.pl_groupByRow.DragEnter += OnDragEnter; this.pl_groupByRow.DragDrop += OnDragDrop; this.pl_GroupByCol.DragEnter += OnDragEnter; this.pl_GroupByCol.DragDrop += OnDragDrop; this.pl_Result.DragEnter += OnDragEnter; this.pl_Result.DragDrop += OnDragDrop; this.checkRowSum.CheckedChanged += OncheckRowSum_CheckedChanged; this.checkShowChart.CheckedChanged += OncheckShowChart_CheckedChanged; this.splitContainerControl.SplitterPositionChanged += OnSplitContainerControl_SplitterPositionChanged; this.splitMainContainerControl.SplitterPositionChanged += OnSplitMainContainerControl_SplitterPositionChanged; this.pl_Result.MouseUp += OnPl_Result_MouseUp; this.checkProject.SelectedIndexChanged += new EventHandler(OnCheckProject_SelectedIndexChanged); this.saveBtn.Click += new EventHandler(saveBtn_Click); this.saveAsBtn.Click += new EventHandler(saveAsBtn_Click); this.deleteBtn.Click += new EventHandler(deleteBtn_Click); this.FormClosing += new FormClosingEventHandler(FrmGridSift_FormClosing); } #endregion #region 初始化分割条位置 /// /// 说明:初始化分割条位置 /// 创建人:龚宇超 /// 创建日期:2017-12-15 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitSpliterPosition() { string spliterPosition = IniHelper.Read(string.Format("Step_spliterPositionMain_{0}", "FrmGridSift")); if (!string.IsNullOrEmpty(spliterPosition)) this.splitContainerControl.SplitterPosition = Convert.ToInt32(spliterPosition); } private void InitMainSpliterPosition() { string spliterPosition = IniHelper.Read(string.Format("Step_spliterMainPositionMain_{0}", "FrmGridSift")); if (!string.IsNullOrEmpty(spliterPosition)) this.splitMainContainerControl.SplitterPosition = Convert.ToInt32(spliterPosition); } #endregion #region 初始化导出下拉按钮 /// /// 说明:初始化导出下拉按钮 /// 创建人:唐德馨 /// 创建日期:2022-10-02 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// private void InitExportDrop() { BarButtonItem itemExportExcel = new BarButtonItem(); itemExportExcel.Caption = "导出主表Excel"; itemExportExcel.ItemClick += new ItemClickEventHandler(OnItemExportExcel_ItemClick); BarButtonItem itemExportDetail = new BarButtonItem(); itemExportDetail.Caption = "导出明细Excel"; itemExportDetail.ItemClick += new ItemClickEventHandler(OnItemExportDetail_ItemClick); PopupMenu exportPopupMenu = new PopupMenu(); exportPopupMenu.Manager = this.barManager; exportPopupMenu.AddItems(new BarItem[] { itemExportExcel, itemExportDetail }); this.exportDropBtn.DropDownControl = exportPopupMenu; } #endregion #region 初始化图表展示 private void InitChart() { ViewType[] types = new ViewType[] { ViewType.Pie, ViewType.Area, ViewType.Line }; for (int i = 0; i < this.DetailTabControl.TabPages.Count; i++) { ChartControlEx chart = new ChartControlEx(); chart.GridControlObj.Visible = false; chart.Dock = DockStyle.Fill; this.DetailTabControl.TabPages[i].Controls.Add(chart); } } #endregion #region 初始化统计右键菜单 private void InitResultRightMenu() { popupMenu = new DevExpress.XtraBars.PopupMenu(barManager); BarButtonItem barButtonItemSum = new DevExpress.XtraBars.BarButtonItem(); barButtonItemSum.Caption = "求和"; barButtonItemSum.Name = "Sum"; BarButtonItem barButtonItemNum = new DevExpress.XtraBars.BarButtonItem(); barButtonItemNum.Caption = "计数"; barButtonItemNum.Name = "Num"; BarButtonItem barButtonItemAvg = new DevExpress.XtraBars.BarButtonItem(); barButtonItemAvg.Caption = "平均"; barButtonItemAvg.Name = "Avg"; BarButtonItem barButtonItemMax = new DevExpress.XtraBars.BarButtonItem(); barButtonItemMax.Caption = "最大"; barButtonItemMax.Name = "Max"; BarButtonItem barButtonItemMin = new DevExpress.XtraBars.BarButtonItem(); barButtonItemMin.Caption = "最小"; barButtonItemMin.Name = "Min"; popupMenu.AddItems(new BarButtonItem[] { barButtonItemSum, barButtonItemNum, barButtonItemAvg, barButtonItemMax, barButtonItemMin }); for (int i = 0; i < popupMenu.ItemLinks.Count; i++) { popupMenu.ItemLinks[i].BeginGroup = true;//设置分割条 popupMenu.ItemLinks[i].Item.ItemClick += OnItem_ItemClick; } allpopupMenu = new DevExpress.XtraBars.PopupMenu(barManager); BarButtonItem barButtonItemAllSum = new DevExpress.XtraBars.BarButtonItem(); barButtonItemAllSum.Caption = "一键求和"; barButtonItemAllSum.Name = "Sum"; BarButtonItem barButtonItemAllNum = new DevExpress.XtraBars.BarButtonItem(); barButtonItemAllNum.Caption = "一键计数"; barButtonItemAllNum.Name = "Num"; BarButtonItem barButtonItemAllAvg = new DevExpress.XtraBars.BarButtonItem(); barButtonItemAllAvg.Caption = "一键平均"; barButtonItemAllAvg.Name = "Avg"; BarButtonItem barButtonItemAllMax = new DevExpress.XtraBars.BarButtonItem(); barButtonItemAllMax.Caption = "一键最大"; barButtonItemAllMax.Name = "Max"; BarButtonItem barButtonItemAllMin = new DevExpress.XtraBars.BarButtonItem(); barButtonItemAllMin.Caption = "一键最小"; barButtonItemAllMin.Name = "Min"; allpopupMenu.AddItems(new BarButtonItem[] { barButtonItemAllSum, barButtonItemAllNum, barButtonItemAllAvg, barButtonItemAllMax, barButtonItemAllMin }); for (int i = 0; i < allpopupMenu.ItemLinks.Count; i++) { allpopupMenu.ItemLinks[i].BeginGroup = true;//设置分割条 allpopupMenu.ItemLinks[i].Item.ItemClick += OnAllItem_ItemClick; } } #endregion #region 初始化左侧表格 private void InitLeftGrid() { this.leftGridView.OptionsBehavior.Editable = false;//禁编 this.leftGridView.OptionsFind.FindNullPrompt = "请输入查询字符"; this.leftGridView.OptionsFind.ShowClearButton = true; this.leftGridView.OptionsFind.ShowCloseButton = false; this.leftGridView.OptionsFind.ShowFindButton = false; this.leftGridView.OptionsFind.AlwaysVisible = true; this.leftGridView.OptionsFind.FindMode = DevExpress.XtraEditors.FindMode.Always; GridAddCheckBox(this.leftGridView); BindCustomDrawRowIndicator(this.leftGridView); SelectRowChangeBackColor(this.leftGridView); DataTable colCaptionTab = new DataTable(); colCaptionTab.Columns.Add("sysName"); colCaptionTab.Columns.Add("userName"); foreach (GridColumn gridColumn in this.ParentGridEx.GridView.VisibleColumns) { if (colCaptionTab.Select(string.Format("sysName='{0}'", gridColumn.FieldName)).Length == 0) { DataRow newRow = colCaptionTab.NewRow(); newRow["sysName"] = gridColumn.FieldName; newRow["userName"] = gridColumn.Caption; colCaptionTab.Rows.Add(newRow); } } this.leftGridView.Columns["userName"].Width = this.panel_ALL.Width / 10 * 6; this.leftGridView.GetVisibleColumn(0).Width = 40; this.leftGridControl.DataSource = colCaptionTab; this.leftGridView.DoubleClick += new EventHandler(OnLeftGridView_DoubleClick); this.leftGridView.MouseMove += new MouseEventHandler(OnLeftGridView_MouseMove); } #endregion #region 初始化数据展示表格 private void InitShowDataGrid() { this.gcMain.GridView.OptionsView.ShowGroupPanel = false; this.gcMain.GridView.OptionsView.ShowFooter = true; this.gcMain.GridView.OptionsBehavior.Editable = false;//禁编 this.gcMain.SetReadOnlyColumns(this.ParentGridEx.InitGridColumsTab); this.gcMain.GridControl.DataSource = source; //this.gcMain.GridView.BestFitColumns(); this.gcMainColumns = this.gcMain.GridView.VisibleColumns.ToList(); this.gcMain.GridView.DoubleClick += new EventHandler(OnGridView_DoubleClick); //this.gridControlShowData.Tag = source; //BindCustomDrawRowIndicator(this.gridView); //SelectRowChangeBackColor(this.gridView); } private void GridView_RowStyle(object sender, RowStyleEventArgs e) { if (e.RowHandle == 3) { e.Appearance.ForeColor = Color.Red; } if (e.RowHandle == 4) { e.Appearance.BackColor = Color.Blue; } } #endregion #region 刷新构建数据展示表格列 private void InitShowDataGridColumns(DataTable table) { try { if (table == this.source) { foreach (GridColumn col in this.gcMainColumns) { col.VisibleIndex = this.gcMainColumns.IndexOf(col); } } else { List removeCols = this.gcMain.GridView.Columns.Where(n => n.FieldName.StartsWith("GroupResult$")).ToList(); GridColumn[] gridColumns = this.gcMain.GridView.Columns.Where(n => table.Columns.Contains(n.FieldName) && !n.FieldName.StartsWith("GroupResult$")).ToArray(); DataColumn[] resultCols = table.Columns.Cast().Where(n => n.ColumnName.StartsWith("GroupResult$")).ToArray(); foreach (GridColumn col in removeCols)//移除所有统计列 { this.gcMain.GridView.Columns.Remove(col); } foreach (GridColumn col in this.gcMainColumns) { if (!gridColumns.Contains(col)) { col.Visible = false; } else { col.Visible = true; } } string formatString = !string.IsNullOrEmpty(SystemInfo.Instance.GridSiftFormatString) ? $"{{{SystemInfo.Instance.GridSiftFormatString}}}" : "{0:#,##0.00}"; foreach (DataColumn resultCol in resultCols) { GridColumn gridColumn = new GridColumn(); gridColumn.FieldName = resultCol.ColumnName; gridColumn.Caption = resultCol.Caption; gridColumn.DisplayFormat.FormatType = FormatType.Numeric; gridColumn.DisplayFormat.FormatString = formatString; gridColumn.Visible = true; gridColumn.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum, gridColumn.FieldName, formatString) }); this.gcMain.GridView.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Sum, gridColumn.FieldName, null, formatString) }); this.gcMain.GridView.Columns.Add(gridColumn); } } this.gcMain.GridControl.DataSource = table; } catch (Exception ex) { MessageUtil.Show(ex.Message); } } #endregion #region 初始化明细表格 private void InitDetailGrid() { this.detailGrid.GridView.OptionsView.ShowGroupPanel = false; this.detailGrid.GridView.OptionsView.ShowFooter = true; this.detailGrid.GridView.OptionsBehavior.Editable = false;//禁编 this.detailGrid.SetReadOnlyColumns(this.ParentGridEx.InitGridColumsTab); this.detailGrid.GridView.RowStyle += GridView_RowStyle; //this.detailGrid.GridView.Columns.AddRange(this.ParentGridEx.GridView.Columns.ToArray()); this.detailGrid.GridView.BestFitColumns(); } #endregion #region 获取分组行列名 private List GetGroupRowList() { List groups = new List(); foreach (System.Windows.Forms.Control item in this.pl_groupByRow.Controls) { DragItem dragItem = item as DragItem; groups.Add(dragItem.dragItemModel.name); } return groups; } #endregion #region 获取分组列列名 private List GetGroupColList() { List groups = new List(); foreach (System.Windows.Forms.Control item in this.pl_GroupByCol.Controls) { DragItem dragItem = item as DragItem; groups.Add(dragItem.dragItemModel.name); } return groups; } #endregion #region 获取统计列数据 private List GetTargetModelList() { List targets = new List(); foreach (System.Windows.Forms.Control item in this.pl_Result.Controls) { DragItem dragItem = item as DragItem; TargetModel targetModel = new TargetModel(); targetModel.name = dragItem.dragItemModel.name; targetModel.oper = dragItem.dragItemModel.oper; targets.Add(targetModel); } return targets; } #endregion #region 根据方案类加载方案选择数据 /// /// 说明:根据方案类加载方案选择数据 /// 创建人:唐德馨 /// 创建日期:2022-10-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// private void LoadProject(GridSiftProjectModel projectModel) { try { this.BtnClear.PerformClick(); DataTable dataTable = this.leftGridControl.DataSourceTable(); if (projectModel.Groups != null && projectModel.Groups.Count > 0) { List dataRows = new List(); foreach (string group in projectModel.Groups) { DataRow dataRow = dataTable.Select().Where(n => (n["sysName"] + "").Equals(group)).FirstOrDefault(); if (dataRow != null) { dataRows.Add(dataRow); } } IDataObject data = new DataObject(); data.SetData(typeof(DataRow[]), dataRows.ToArray()); DragEventArgs e = new DragEventArgs(data, 0, 0, 0, DragDropEffects.None, DragDropEffects.None); OnDragEnter(this.pl_groupByRow, e); OnDragDrop(this.pl_groupByRow, e); //foreach (string group in projectModel.Groups) //{ // DragItem dragItem = this.DragItemList.Where(n => n.dragItemModel.name.Equals(group)).FirstOrDefault(); // if (dragItem != null) // { // //startDrag(dragItem); // IDataObject data = new DataObject(); // data.SetData(typeof(DataColumn), dragItem.Tag); // DragEventArgs e = new DragEventArgs(data, 0, 0, 0, DragDropEffects.None, DragDropEffects.None); // OnDragEnter(this.pl_groupByRow, e); // OnDragDrop(this.pl_groupByRow, e); // } //} } if (projectModel.Cols != null && projectModel.Cols.Count > 0) { List dataRows = new List(); foreach (string col in projectModel.Cols) { DataRow dataRow = dataTable.Select().Where(n => (n["sysName"] + "").Equals(col)).FirstOrDefault(); if (dataRow != null) { dataRows.Add(dataRow); } } IDataObject data = new DataObject(); data.SetData(typeof(DataRow[]), dataRows.ToArray()); DragEventArgs e = new DragEventArgs(data, 0, 0, 0, DragDropEffects.None, DragDropEffects.None); OnDragEnter(this.pl_GroupByCol, e); OnDragDrop(this.pl_GroupByCol, e); //foreach (string col in projectModel.Cols) //{ // DragItem dragItem = this.DragItemList.Where(n => n.dragItemModel.name.Equals(col)).FirstOrDefault(); // if (dragItem != null) // { // //startDrag(dragItem); // IDataObject data = new DataObject(); // data.SetData(typeof(DataColumn), dragItem.Tag); // DragEventArgs e = new DragEventArgs(data, 0, 0, 0, DragDropEffects.None, DragDropEffects.None); // OnDragEnter(this.pl_GroupByCol, e); // OnDragDrop(this.pl_GroupByCol, e); // } //} } if (projectModel.Targets != null && projectModel.Targets.Count > 0) { foreach (TargetModel targetModel in projectModel.Targets) { List dataRows = new List(); DataRow dataRow = dataTable.Select().Where(n => (n["sysName"] + "").Equals(targetModel.name)).FirstOrDefault(); if (dataRow != null) { dataRows.Add(dataRow); } IDataObject data = new DataObject(); data.SetData(typeof(DataRow[]), dataRows.ToArray()); DragEventArgs e = new DragEventArgs(data, 0, 0, 0, DragDropEffects.None, DragDropEffects.None); OnDragEnter(this.pl_Result, e); OnDragDrop(this.pl_Result, e); DragItem resuleDragItem = this.pl_Result.Controls.Cast().Where(n => n.dragItemModel.name.Equals(targetModel.name) && string.IsNullOrEmpty(n.dragItemModel.oper)).FirstOrDefault(); if (resuleDragItem != null) { this.rightClickItem = resuleDragItem; BarItemLink operItemLink = this.popupMenu.ItemLinks.Where(n => n.Item.Name.Equals(targetModel.oper)).FirstOrDefault(); ItemClickEventArgs itemClickEventArgs = new ItemClickEventArgs(operItemLink.Item, operItemLink); OnItem_ItemClick(null, itemClickEventArgs); } } //foreach (TargetModel targetModel in projectModel.Targets) //{ // DragItem dragItem = this.DragItemList.Where(n => n.dragItemModel.name.Equals(targetModel.name)).FirstOrDefault(); // if (dragItem != null) // { // //startDrag(dragItem); // IDataObject data = new DataObject(); // data.SetData(typeof(DataColumn), dragItem.Tag); // DragEventArgs e = new DragEventArgs(data, 0, 0, 0, DragDropEffects.None, DragDropEffects.None); // OnDragEnter(this.pl_Result, e); // OnDragDrop(this.pl_Result, e); // DragItem resuleDragItem = this.pl_Result.Controls.Cast().Where(n => n.dragItemModel.name.Equals(targetModel.name) && string.IsNullOrEmpty(n.dragItemModel.oper)).FirstOrDefault(); // if (resuleDragItem != null) // { // this.rightClickItem = resuleDragItem; // BarItemLink operItemLink = this.popupMenu.ItemLinks.Where(n => n.Item.Name.Equals(targetModel.oper)).FirstOrDefault(); // ItemClickEventArgs itemClickEventArgs = new ItemClickEventArgs(operItemLink.Item, operItemLink); // OnItem_ItemClick(null, itemClickEventArgs); // } // } //} } } catch (Exception ex) { MessageUtil.Show(ex.Message); } } #endregion #region 初始化方案 /// /// 说明:初始化方案下拉按钮 /// 创建人:唐德馨 /// 创建日期:2022-10-03 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// private void InitCheckProject() { try { if (!BaseImpl.HasExistsTable("p_SysModuleSchemeTab")) { string createSqlStr = @"create table p_SysModuleSchemeTab( id int primary key identity, name varchar(100), moduleId varchar(100), operatorid int, isPub int, Querys varchar(max), Cols varchar(max), Groups varchar(max), Targets varchar(max), )"; SqlHelper.ExecuteNonQuery(createSqlStr); } this.checkProject.Properties.Items.Clear(); this.projectDic.Clear(); this.checkProject.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; this.checkProject.Properties.AllowNullInput = DefaultBoolean.True; this.checkProject.Properties.NullText = "请选择方案"; ImageComboBoxItem defaultItem = new ImageComboBoxItem("默认方案"); this.checkProject.Properties.Items.Add(defaultItem); this.projectDic.Add("默认方案", 0); string sqlStr = @"select name,isPub from p_SysModuleSchemeTab where moduleId = '{0}' and operatorid = '{1}' and isPub = '0' union all select name,isPub from p_SysModuleSchemeTab where moduleId = '{0}' and isPub = '1'"; DataTable sourceTab = SqlHelper.ExecuteDataTable(string.Format(sqlStr, this.CustomColumKey, ERPInfo.Instance.UserId)); ImageCollection images = new ImageCollection(); Image lockedImag = Resources.locked; images.AddImage(lockedImag); this.checkProject.Properties.SmallImages = images; for (int i = 0; i < sourceTab.Rows.Count; i++) { DataRow item = sourceTab.Rows[i]; string isPub = item["isPub"] + ""; ImageComboBoxItem imageItem = new ImageComboBoxItem(item["name"] + ""); if (!string.IsNullOrEmpty(isPub) && !isPub.Equals("1")) { imageItem.ImageIndex = 0; } this.checkProject.Properties.Items.Add(imageItem); this.projectDic.Add(item["name"] + "", i + 1); } } catch (Exception ex) { MessageUtil.Show(ex.Message); } } #endregion #region 初始化方案选择 private void InitProjectSelect() { if (!BaseImpl.HasExistsTable("p_SysModuleSchemeLogTab")) { string createSqlStr = @"create table p_SysModuleSchemeLogTab( id int primary key identity, moduleId varchar(100), operatorid int, projectid int, )"; SqlHelper.ExecuteNonQuery(createSqlStr); } DataTable dataTable = SqlHelper.ExecuteDataTable(string.Format("select * from p_SysModuleSchemeLogTab where operatorid='{0}' and moduleId='{1}'", ERPInfo.Instance.UserId, this.CustomColumKey)); if (dataTable.Rows.Count > 0) { DataRow dataRow = dataTable.Rows[0]; string projectId = dataRow["projectid"] + ""; if (string.IsNullOrEmpty(projectId)) { this.checkProject.SelectedIndex = 0; } else { string projectName = SqlHelper.ExecuteScalar(string.Format("select name from p_SysModuleSchemeTab where id = '{0}'", projectId)) + ""; if (!string.IsNullOrEmpty(projectName)) { this.checkProject.SelectedIndex = this.projectDic[projectName]; } else { this.checkProject.SelectedIndex = 0; } } } } #endregion #region 表格第一列添加复选框 /// /// 说明:表格第一列添加复选框 /// 创建人:唐德馨 /// 创建日期:2021-07-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The grid columnFilterPopupChecke. public static void GridAddCheckBox(GridView gridview) { gridview.OptionsSelection.MultiSelect = true; gridview.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CheckBoxRowSelect; gridview.OptionsSelection.EnableAppearanceFocusedCell = false; gridview.OptionsBehavior.EditorShowMode = EditorShowMode.MouseDown; } #endregion #endregion /// /// 饼图重新赋值 /// /// /// private void CmMain_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) { try { e.LabelText = e.LegendText; } catch (Exception ex) { } } } }