| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350 | 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<GridCellDoubleClickEventArgs>(this.SCGrid_CellDoubleClick);            this.SCGrid.CellMouseDown += new System.EventHandler<GridCellMouseEventArgs>(this.SCGrid_CellMouseDown);            this.SCGrid.CellValueChanged += new System.EventHandler<GridCellValueChangedEventArgs>(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<GridColumn> _GCList = new List<GridColumn>();//表格列表        List<LayoutControlItem> _LCItemList = new List<LayoutControlItem>();// 查询控件        bool _IsMultiSelect = true;//单/多选标记        OpaqueLayer OpaqueLayerItem = null;//遮罩层        object CellStr = null;//单元格数据        bool IsChange = true;//单元格单击变量        string _GroupName = "";        #region [ 遮罩层 ]        /// <summary>        /// 显示遮罩层        /// </summary>        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            {            }        }        /// <summary>        /// 隐藏遮罩层        /// </summary>        public void HideOpaqueLayer()        {            try            {                if (OpaqueLayerItem != null)                {                    this.OpaqueLayerItem.Visible = false;                    this.OpaqueLayerItem.Enabled = false;                }            }            catch            {                //MessageBox.Show(ex.Message);            }        }        #endregion        /// <summary>        /// 初始化分页查询        /// </summary>        /// <param name="LC_Height">查询面板高度</param>        /// <param name="IsMultiSelect">是否启用多选</param>        /// <param name="IsExport">是否启用导出</param>        /// <param name="GCList">表格列列表</param>        /// <param name="LCItemList">查询面板控件</param>        /// <param name="QueryPageDataMethods">获取数据集方法</param>        /// <param name="ChkValueChangeMethods">单/多选改变方法</param>        /// <param name="GridDoubleClickMethods">表格双击方法</param>        /// <param name="RefreshRoleMethods">刷新权限方法</param>        public void Init_QueryPage(int LC_Height, bool IsMultiSelect, bool IsExport, string GroupName, List<GridColumn> GCList, List<LayoutControlItem> 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<string> GetQueryWhere()        {            return LCWhereUtil.GetWhereText(_LCItemList);        }        /// <summary>        ///   获取LayoutControlItem列表        /// </summary>        /// <returns></returns>        public void ClearLCItemValue()        {            LCItemUtil.ClearValue_LCItem(_LCItemList);        }        /// <summary>        ///   获取LayoutControlItem列表        /// </summary>        /// <returns></returns>        public LayoutControlItem GetLCItem(string LCName)        {            return _LCItemList.Find(a => a.Name == LCName);        }        /// <summary>        /// 分页查询        /// </summary>        /// <param name="QPageIndex">页码</param>        /// <param name="QPageSize">分页尺寸</param>        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);            }        }        /// <summary>        /// 切换单/多选        /// </summary>        /// <param name="IsCheckBoxes">true,多选|false单选</param>        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);            }        }        /// <summary>        /// 获取选中项数量        /// </summary>        /// <returns>选中数量</returns>        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;            }        }        /// <summary>        /// 获取选中数据        /// </summary>        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<DataRow> 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<GridCell> 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;        }        /// <summary>        /// 获取选中数据        /// </summary>        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<DataRow> 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;        }        /// <summary>        /// 分页查询        /// </summary>        /// <param name="QPageIndex">页码</param>        /// <param name="QPageSize">分页尺寸</param>        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));        //}        /// <summary>        /// Creates a new GridRow        /// </summary>        /// <returns></returns>        //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            //}        }    }}
 |