| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using System.Text;
- using System.Data;
- using System.Drawing;
- using System.Diagnostics;
- using System.IO;
- using Infragistics.Win;
- using Infragistics.Win.UltraWinGrid;
- using Infragistics.Win.UltraWinEditors;
- using Infragistics.Win.UltraWinGrid.ExcelExport;
- using Core.Mes.Client.Comm;
- using CoreFS.CA06;
- using Core.Mes.Client.Comm.Server;
- using System.Text.RegularExpressions;
- using Infragistics.Win.UltraWinMaskedEdit;
- using Core.StlMes.Client.YdmBcPipeManage;
- namespace Core.StlMes.Client.YdmBcPipeManage
- {
- public enum CodeName
- {
- Code,
- Name
- }
- public class CheckedListBoxItems
- {
- private string _strKey = "";
- private string _strText = "";
- private object _tag = null;
- private bool _checked = false;
- public string strKey
- {
- get
- {
- return _strKey;
- }
- set
- {
- if (_strKey != value)
- _strKey = value;
- }
- }
- public string strText
- {
- get
- {
- return _strText;
- }
- set
- {
- if (_strText != value)
- _strText = value;
- }
- }
- public object Tag
- {
- get
- {
- return _tag;
- }
- set
- {
- _tag = value;
- }
- }
- public bool Checked
- {
- get
- {
- return _checked;
- }
- set
- {
- if (_checked != value)
- _checked = value;
- }
- }
- public void Check()
- {
- if (!_checked)
- {
- this._checked = true;
- }
- }
- public CheckedListBoxItems(string strKey, string strText)
- {
- this._strKey = strKey;
- this._strText = strText;
- }
- public CheckedListBoxItems(string strKey, string strText, bool Checked)
- {
- this._strKey = strKey;
- this._strText = strText;
- this._checked = Checked;
- }
- public override string ToString()
- {
- return this._strText;
- }
- }
- public class CommonMethod
- {
- public static ValueList InitValueListComparisonOperator()
- {
- ValueList vlist_ComparisonOperator = new ValueList();
- vlist_ComparisonOperator.ValueListItems.Add(" = ", "等于");
- vlist_ComparisonOperator.ValueListItems.Add(" > ", "大于");
- vlist_ComparisonOperator.ValueListItems.Add(" >= ", "大于等于");
- vlist_ComparisonOperator.ValueListItems.Add(" < ", "小于");
- vlist_ComparisonOperator.ValueListItems.Add(" <= ", "小于等于");
- vlist_ComparisonOperator.ValueListItems.Add(" <> ", "不等于");
- return vlist_ComparisonOperator;
- }
- public static ValueList InitValueListLgic()
- {
- ValueList vlist_Logic = new ValueList();
- vlist_Logic.ValueListItems.Add("1", "是");
- vlist_Logic.ValueListItems.Add("0", "否");
- return vlist_Logic;
- }
- public static ValueList InitValueListBanCi()
- {
- ValueList vlist_BanCi = new ValueList();
- vlist_BanCi.ValueListItems.Add("1", "夜班");
- vlist_BanCi.ValueListItems.Add("2", "日班");
- return vlist_BanCi;
- }
- public static ValueList InitValueListBanZu()
- {
- ValueList vlist_BanZu = new ValueList();
- vlist_BanZu.ValueListItems.Add("1", "甲班");
- vlist_BanZu.ValueListItems.Add("2", "乙班");
- vlist_BanZu.ValueListItems.Add("3", "丙班");
- vlist_BanZu.ValueListItems.Add("4", "丁班");
- return vlist_BanZu;
- }
- public static void GetMonthPeriod(DateTime dtToday, out DateTime dtFrom, out DateTime dtTo)
- {
- try
- {
- dtTo = dtToday;
- if (dtToday.Month == 1)
- {
- if (dtToday.Day >= 26)
- {
- dtFrom = dtToday.AddDays(-dtToday.Day).AddDays(26);
- }
- else
- {
- dtFrom = new DateTime(dtToday.Year, dtToday.Month, 1);
- }
- }
- else if (dtToday.Month == 12)
- {
- dtFrom = dtToday.AddDays(-dtToday.Day).AddDays(26).AddMonths(-1);
- }
- else
- {
- if (dtToday.Day >= 26)
- {
- dtFrom = dtToday.AddDays(-dtToday.Day).AddDays(26);
- }
- else
- {
- dtFrom = dtToday.AddDays(-dtToday.Day).AddDays(26).AddMonths(-1);
- }
- }
- }
- catch
- {
- dtFrom = dtTo = dtToday;
- }
- }
- public static void GeneralCheckedListboxItems(ref MyCheckedListBox listBox, ref DataTable table, ArrayList alistBesides, ArrayList alistChecked)
- {
- try
- {
- listBox.Controls.Clear();
- int iMaxWidth = 0;
- SizeF size = new SizeF(0, 0);
- Graphics g = listBox.CreateGraphics();
- Font font = listBox.Font;
- CheckBox item;
- for (int i = 0; i < table.Columns.Count; i++)
- {
- try
- {
- if (alistBesides != null && !alistBesides.Contains(table.Columns[i].ColumnName))
- {
- try
- {
- size = g.MeasureString(table.Columns[i].Caption + "测 量", font);
- if (Convert.ToUInt16(Math.Ceiling(size.Width)) > iMaxWidth)
- {
- iMaxWidth = Convert.ToUInt16(Math.Ceiling(size.Width));
- }
- }
- catch { }
- //table.Columns[i].ColumnName, table.Columns[i].Caption, ();
- item = new CheckBox();
- item.Text = table.Columns[i].Caption;
- item.Name = table.Columns[i].ColumnName;
- item.Checked = alistChecked == null ? true : (alistChecked.Contains(table.Columns[i].ColumnName) ? true : false);
- listBox.Controls.Add(item);
- }
- }
- catch { }
- }
- //listBox.ColumnWidth = iMaxWidth;
- g.Dispose();
- }
- catch { }
- }
- public static void GeneralCheckedListboxItems(ref MyCheckedListBox listBox, ref UltraGrid ultraGrid1, ArrayList alistBesides, ArrayList alistChecked)
- {
- try
- {
- listBox.Controls.Clear();
- int iMaxWidth = 0;
- SizeF size = new SizeF(0, 0);
- Graphics g = listBox.CreateGraphics();
- Font font = listBox.Font;
- CheckBox item;
- for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
- {
- try
- {
- if (!ultraGrid1.DisplayLayout.Bands[0].Columns[i].Hidden && alistBesides != null && !alistBesides.Contains(ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key))
- {
- try
- {
- size = g.MeasureString(ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption + "测 量", font);
- if (Convert.ToUInt16(Math.Ceiling(size.Width)) > iMaxWidth)
- {
- iMaxWidth = Convert.ToUInt16(Math.Ceiling(size.Width));
- }
- }
- catch { }
- item = new CheckBox();
- item.Text = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption;
- item.Name = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
- item.Checked = (alistChecked == null ? true : (alistChecked.Contains(ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key) ? true : false));
- item.Margin = new Padding(0);
- item.Width = 74;
- listBox.Controls.Add(item);
- }
- }
- catch { }
- }
- //listBox.ColumnWidth = iMaxWidth;
- g.Dispose();
- }
- catch { }
- }
- public static void SetColumnsVisible(ref UltraGrid ultraGrid1, ArrayList alistColumns)
- {
- try
- {
- if (ultraGrid1 == null || alistColumns == null || alistColumns.Count == 0)
- {
- return;
- }
- for (int i = 0; i < alistColumns.Count; i++)
- {
- for (int j = 0; j < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; j++)
- {
- try
- {
- if (alistColumns[i].ToString().Equals(ultraGrid1.DisplayLayout.Bands[0].Columns[j].Key) && ultraGrid1.DisplayLayout.Bands[0].Columns[j].Hidden)
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[j].Hidden = false;
- break;
- }
- }
- catch { }
- }
- }
- }
- catch { }
- }
- public static void SetColumnsHidden(ref UltraGrid ultraGrid1, ArrayList alistColumns)
- {
- try
- {
- if (ultraGrid1 == null || alistColumns == null || alistColumns.Count == 0)
- {
- return;
- }
- for (int i = 0; i < alistColumns.Count; i++)
- {
- for (int j = 0; j < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; j++)
- {
- try
- {
- if (alistColumns[i].ToString().Equals(ultraGrid1.DisplayLayout.Bands[0].Columns[j].Key) && !ultraGrid1.DisplayLayout.Bands[0].Columns[j].Hidden)
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[j].Hidden = true;
- break;
- }
- }
- catch { }
- }
- }
- }
- catch { }
- }
- public static string GetProduceLine(string strManagementno, string strStorageattr)
- {
- string strProduceLine = "";
- if ((strManagementno.Equals("500101") || strManagementno.Equals("500103")) && strStorageattr.Equals("500205"))
- {
- strProduceLine = "1011BC1";
- }
- else if ((strManagementno.Equals("500101") || strManagementno.Equals("500104")) && strStorageattr.Equals("500206"))
- {
- strProduceLine = "1011XC1";
- }
- return strProduceLine;
- }
-
- public static DataRow[] GetRows(ref DataTable table, string strFilter, string strSort)
- {
- if (table == null)
- {
- return null;
- }
- try
- {
- return table.Select(strFilter, strSort);
- }
- catch { }
- return null;
- }
- public static void AddItems(ref ArrayList alist, ref Hashtable hs, ref DataRow[] rows, string strKey, string strValue)
- {
- if (alist == null)
- {
- alist = new ArrayList();
- }
- else
- {
- alist.Clear();
- }
- if (hs == null)
- {
- hs = new Hashtable();
- }
- else
- {
- hs.Clear();
- }
- if (rows.Length > 0)
- {
- DataTable table = rows[0].Table;
- if (table == null || !table.Columns.Contains(strKey) || !table.Columns.Contains(strValue))
- return;
- for (int i = 0; i < rows.Length; i++)
- {
- try
- {
- if (!hs.Contains(Convert.ToString(rows[i][strKey])))
- {
- alist.Add(Convert.ToString(rows[i][strKey]));
- hs.Add(Convert.ToString(rows[i][strKey]), Convert.ToString(rows[i][strValue]));
- }
- }
- catch { }
- }
- }
- }
- public static ValueList GeneralValuelist(ref DataTable table, string strKey, string strText)
- {
- if (table == null || !table.Columns.Contains(strKey) || !table.Columns.Contains(strText))
- {
- return null;
- }
- ArrayList alist = new ArrayList();
- ValueList vlist = new ValueList();
- for (int i = 0; i < table.Rows.Count; i++)
- {
- try
- {
- if (!alist.Contains(table.Rows[i][strKey]))
- {
- alist.Add(table.Rows[i][strKey]);
- vlist.ValueListItems.Add(table.Rows[i][strKey], Convert.ToString(table.Rows[i][strText]));
- }
- }
- catch { }
- }
- return vlist;
- }
- public static ValueList GeneralValuelist(ref ArrayList alist, ref Hashtable hs)
- {
- if (alist == null || hs == null)
- {
- return null;
- }
- ValueList vlist = new ValueList();
- for (int i = 0; i < alist.Count; i++)
- {
- try
- {
- if (hs.Contains(alist[i]))
- {
- vlist.ValueListItems.Add(alist[i], Convert.ToString(hs[alist[i]]));
- }
- }
- catch { }
- }
- return vlist;
- }
- public static void CopyDataToDatatable(ref DataTable table, DataRow row, bool ClearExists)
- {
- if (table == null || row == null)
- {
- return;
- }
- if (ClearExists)
- {
- table.Rows.Clear();
- }
- try
- {
- DataRow NewRow = table.NewRow();
- for (int i = 0; i < row.Table.Columns.Count; i++)
- {
- try
- {
- if (table.Columns.Contains(row.Table.Columns[i].ColumnName))
- {
- NewRow[row.Table.Columns[i].ColumnName] = row[i];
- }
- }
- catch { }
- }
- table.Rows.Add(NewRow);
- }
- catch { }
- }
- public static void CopyDataToDatatable(ref DataTable src, ref DataTable dest, bool ClearExists, ArrayList alistColumns, ArrayList alistValue)
- {
- if (src == null || dest == null)
- {
- return;
- }
- if (ClearExists)
- {
- dest.Rows.Clear();
- }
- DataRow CurRow, NewRow;
- for (int i = 0; i < src.Rows.Count; i++)
- {
- CurRow = src.Rows[i];
- NewRow = dest.NewRow();
- for (int j = 0; j < src.Columns.Count; j++)
- {
- try
- {
- if (dest.Columns.Contains(src.Columns[j].ColumnName))
- {
- NewRow[src.Columns[j].ColumnName] = CurRow[j];
- }
- }
- catch { }
- }
- if (alistColumns != null && alistValue != null)
- {
- for (int idx = 0; idx < alistColumns.Count; idx++)
- {
- try
- {
- if (dest.Columns.Contains(alistColumns[idx].ToString()))
- {
- NewRow[alistColumns[idx].ToString()] = alistValue[idx];
- }
- }
- catch { }
- }
- }
- dest.Rows.Add(NewRow);
- }
- }
- public static void CopyDataToDatatable(ref DataTable src, ref DataTable dest, bool ClearExists)
- {
- if (src == null || dest == null)
- {
- return;
- }
- if (ClearExists)
- {
- dest.Rows.Clear();
- }
- DataRow CurRow, NewRow;
- for (int i = 0; i < src.Rows.Count; i++)
- {
- CurRow = src.Rows[i];
- NewRow = dest.NewRow();
- for (int j = 0; j < src.Columns.Count; j++)
- {
- try
- {
- if (dest.Columns.Contains(src.Columns[j].ColumnName))
- {
- NewRow[src.Columns[j].ColumnName] = CurRow[j];
- }
- }
- catch { }
- }
- dest.Rows.Add(NewRow);
- }
- }
- public static DataRow GetDatatableRow(ref DataTable table, string strColumn, object value)
- {
- if (table == null || !table.Columns.Contains(strColumn))
- {
- return null;
- }
- DataRow row;
- for (int i = 0; i < table.Rows.Count; i++)
- {
- row = table.Rows[i];
- try
- {
- if (row[strColumn].Equals(value))
- {
- return row;
- }
- }
- catch { }
- }
- return null;
- }
- public static bool DataChanged(ref UltraGrid myGrid, ref DataTable dataSource, ref DataTable tblChanged)
- {
- if (myGrid == null)
- {
- return false;
- }
- myGrid.UpdateData();
- return DataChanged(ref dataSource, ref tblChanged);
- }
- public static bool DataChanged(ref DataTable dataSource, ref DataTable tblChanged)
- {
- if (dataSource == null)
- {
- return false;
- }
- tblChanged = dataSource.GetChanges(DataRowState.Modified);
- if (tblChanged != null && tblChanged.Rows.Count > 0)
- {
- return true;
- }
- return false;
- }
- public static void ResetArrayList(ref ArrayList alist)
- {
- if (alist == null)
- {
- alist = new ArrayList();
- }
- else
- {
- alist.Clear();
- }
- }
- public static bool GridContainsColumn(ref UltraGrid grid, string strColumn)
- {
- for (int i = 0; i < grid.DisplayLayout.Bands[0].Columns.Count; i++)
- {
- if (grid.DisplayLayout.Bands[0].Columns[i].Key.Equals(strColumn))
- return true;
- }
- return false;
- }
- public static bool GridContainsColumn(ref UltraGrid grid, int BandIndex, string strColumn)
- {
- if (BandIndex <= grid.DisplayLayout.Bands.Count - 1)
- {
- for (int i = 0; i < grid.DisplayLayout.Bands[BandIndex].Columns.Count; i++)
- {
- if (grid.DisplayLayout.Bands[BandIndex].Columns[i].Key.Equals(strColumn))
- return true;
- }
- }
- return false;
- }
- public static void SetGridValuelist(ref UltraGrid myGrid, string strColumn, ref ValueList vlist)
- {
- try
- {
- if (GridContainsColumn(ref myGrid, strColumn))
- {
- myGrid.DisplayLayout.Bands[0].Columns[strColumn].ValueList = vlist;
- }
- }
- catch { }
- }
- public static void SetGridValuelist(ref UltraGrid myGrid, int BandIndex, string strColumn, ref ValueList vlist)
- {
- try
- {
- if (GridContainsColumn(ref myGrid, BandIndex, strColumn))
- {
- myGrid.DisplayLayout.Bands[BandIndex].Columns[strColumn].ValueList = vlist;
- }
- }
- catch { }
- }
- public static string Substring(string strSrc, int startIndex, int length)
- {
- try
- {
- return strSrc.Substring(startIndex, length);
- }
- catch { }
- return strSrc;
- }
- public static void SetValueToDatatableColumn(ref DataTable tbl, string strColumnName, object value)
- {
- if (tbl == null || !tbl.Columns.Contains(strColumnName))
- {
- return;
- }
- for (int i = 0; i < tbl.Rows.Count; i++)
- {
- try
- {
- if (tbl.Rows[i][strColumnName] != value)
- tbl.Rows[i][strColumnName] = value;
- }
- catch { }
- }
- }
- public static string[] proc_GeneralItemList(ref ArrayList alist)
- {
- try
- {
- if (alist == null || alist.Count == 0)
- return new string[] { "''" };
- int iCount = alist.Count / 1000 + 1;
- string[] strList = new string[iCount];
- int iDiv = 0, index = 0;
- for (int i = 0; i < alist.Count; i++, index++)
- {
- iDiv = i / 1000;
- if (i % 1000 == 0)
- {
- index = 0;
- }
- strList[iDiv] += (index == 0 ? "" : ",") + Convert.ToString(alist[i]);
- }
- for (int i = 0; i < strList.Length; i++)
- {
- strList[i] = "'" + strList[i].Replace(",", "','") + "'";
- }
- return strList;
- }
- catch (Exception ex)
- {
- Debug.WriteLine(ex.Message);
- }
- return new string[] { "''" };
- }
- public static string[] proc_GeneralItemList(ref Hashtable hs)
- {
- try
- {
- if (hs == null || hs.Count == 0)
- return new string[] { "''" };
- ArrayList alist = new ArrayList(hs.Keys);
- int iCount = alist.Count / 1000 + 1;
- string[] strList = new string[iCount];
- int iDiv = 0, index = 0;
- for (int i = 0; i < alist.Count; i++, index++)
- {
- iDiv = i / 1000;
- if (i % 1000 == 0)
- {
- index = 0;
- }
- strList[iDiv] += (index == 0 ? "" : ",") + Convert.ToString(alist[i]);
- }
- for (int i = 0; i < strList.Length; i++)
- {
- strList[i] = "'" + strList[i].Replace(",", "','") + "'";
- }
- return strList;
- }
- catch (Exception ex)
- {
- Debug.WriteLine(ex.Message);
- }
- return new string[] { "''" };
- }
- public static UltraGridRow RetrieveRowByKey(ref UltraGrid grid, string strColumn, string strKey)
- {
- if (grid == null || !GridContainsColumn(ref grid, strColumn))
- {
- return null;
- }
- for (int i = 0; i < grid.Rows.Count; i++)
- {
- if (Convert.ToString(grid.Rows[i].Cells[strColumn].Value).Equals(strKey))
- {
- return grid.Rows[i];
- }
- }
- return null;
- }
- public static void LocateMyGridByKey(ref UltraGrid myGrid1, string strKey, string strValue, bool NullThenLast)
- {
- if (myGrid1 == null)
- {
- return;
- }
- if (string.IsNullOrEmpty(strKey))
- {
- if (myGrid1.Rows.Count > 0 && NullThenLast)
- {
- myGrid1.ActiveRow = myGrid1.Rows[myGrid1.Rows.Count - 1];
- }
- }
- else
- {
- UltraGridRow row = RetrieveRowByKey(ref myGrid1, strKey, strValue);
- if (row != null)
- {
- myGrid1.ActiveRow = row;
- }
- }
- }
- public static Color GetInvertColor(Color src)
- {
- return Color.FromArgb((int)(src.R ^ 255), (int)(src.R ^ 255), (int)(src.R ^ 255));
- }
-
-
-
-
- public static void SetGridGroupBy(ref UltraGrid myGrid1, bool bAllowGroupBy)
- {
- try
- {
- if (!bAllowGroupBy)
- {
- for (int i = 0; i < myGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
- {
- try
- {
- if (myGrid1.DisplayLayout.Bands[0].Columns[i].IsGroupByColumn)
- myGrid1.DisplayLayout.Bands[0].Columns[i].ResetIsGroupByColumn();
- }
- catch { }
- }
- }
- myGrid1.DisplayLayout.GroupByBox.Hidden = !bAllowGroupBy;
- }
- catch { }
- }
- public static void SetGridRowFilter(ref UltraGrid myGrid1, bool bAllowFilter)
- {
- try
- {
- if (bAllowFilter)
- {
- if (myGrid1.DisplayLayout.Override.FilterUIType != FilterUIType.FilterRow)
- myGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow;
- for (int i = 0; i < myGrid1.DisplayLayout.Bands.Count; i++)
- {
- for (int j = 0; j < myGrid1.DisplayLayout.Bands[i].Columns.Count; j++)
- {
- try
- {
- if (!myGrid1.DisplayLayout.Bands[i].Columns[j].Hidden &&
- myGrid1.DisplayLayout.Bands[i].Columns[j].RowLayoutColumnInfo.LabelPosition != LabelPosition.LabelOnly)
- myGrid1.DisplayLayout.Bands[i].Columns[j].AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
- }
- catch { }
- }
- }
- }
- else
- {
- if (myGrid1.DisplayLayout.Override.FilterUIType != FilterUIType.HeaderIcons)
- myGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.HeaderIcons;
- for (int i = 0; i < myGrid1.DisplayLayout.Bands.Count; i++)
- {
- try
- {
- myGrid1.DisplayLayout.Bands[i].ColumnFilters.ClearAllFilters();
- }
- catch { }
- for (int j = 0; j < myGrid1.DisplayLayout.Bands[i].Columns.Count; j++)
- {
- try
- {
- myGrid1.DisplayLayout.Bands[i].Columns[j].AllowRowFiltering = Infragistics.Win.DefaultableBoolean.False;
- }
- catch { }
- }
- }
- }
- }
- catch { }
- }
- public static void SetGridRowSort(ref UltraGrid myGrid1, bool bAllowSort)
- {
- try
- {
- if (bAllowSort)
- {
- myGrid1.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.SortMulti;
- }
- else
- {
- for (int i = 0; i < myGrid1.DisplayLayout.Bands.Count; i++)
- {
- try
- {
- for (int j = 0; j < myGrid1.DisplayLayout.Bands[i].Columns.Count; j++)
- {
- myGrid1.DisplayLayout.Bands[i].Columns[j].SortIndicator = SortIndicator.None;
- }
- }
- catch { }
- }
- myGrid1.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default;
- }
- }
- catch { }
- }
- public static void SetStaticsInfoFormula(ref UltraGrid myGrid1, ArrayList alistColumns, ArrayList alistFormulas, bool clearExists)
- {
- try
- {
- UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
- if (clearExists)
- band.Summaries.Clear();
- band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
- for (int i = 0; i < alistColumns.Count; i++)
- {
- try
- {
- SummarySettings summary = band.Summaries.Add(alistFormulas[i].ToString(), SummaryPosition.UseSummaryPositionColumn, band.Columns[alistColumns[i].ToString()]);
- summary.SummaryType = SummaryType.Formula;
- summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
- summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
- summary.DisplayFormat = "{0}";
- summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
- summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
- summary.Appearance.FontData.Bold = DefaultableBoolean.True;
- }
- catch { }
- }
- }
- catch { }
- }
- public static void SetStaticsInfoSum(ref UltraGrid myGrid1, ArrayList alistColumns, bool clearExists)
- {
- try
- {
- UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
- if (clearExists)
- band.Summaries.Clear();
- band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
- for (int i = 0; i < alistColumns.Count; i++)
- {
- try
- {
- SummarySettings summary = band.Summaries.Add(SummaryType.Sum, band.Columns[alistColumns[i].ToString()]);
- summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
- summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
- if (alistColumns[i].ToString().Contains("Count") || alistColumns[i].ToString().Contains("COUNT"))
- {
- summary.DisplayFormat = "{0:N0}";
- }
- else
- {
- summary.DisplayFormat = "{0:N3}";
- }
- summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
- summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
- summary.Appearance.FontData.Bold = DefaultableBoolean.True;
- summary.Lines = 3;
- }
- catch { }
- }
- }
- catch { }
- }
- public static void SetStaticsInfoSumA(ref UltraGrid myGrid1, ArrayList alistColumns, bool clearExists)
- {
- try
- {
- UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
- if (clearExists)
- band.Summaries.Clear();
- band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
- for (int i = 0; i < alistColumns.Count; i++)
- {
- try
- {
- SummarySettings summary = band.Summaries.Add(SummaryType.Sum, band.Columns[alistColumns[i].ToString()]);
- summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
- summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
- if (alistColumns[i].ToString().Contains("COUNT"))
- {
- summary.DisplayFormat = "{0:N0}";
- }
- else
- {
- summary.DisplayFormat = "{0:N4}";
- }
- summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
- summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
- summary.Appearance.FontData.Bold = DefaultableBoolean.True;
- summary.Lines = 3;
- }
- catch { }
- }
- }
- catch { }
- }
- public static void SetGridSumArea(Infragistics.Win.UltraWinGrid.UltraGridBase Grid)
- {
- try
- {
- //Grid.DisplayLayout.GroupByBox.Hidden
- if (Grid.Rows.Count == 0)
- {
- foreach (Infragistics.Win.UltraWinGrid.UltraGridBand band in Grid.DisplayLayout.Bands)
- {
- foreach (Infragistics.Win.UltraWinGrid.SummarySettings sum in band.Summaries)
- {
- sum.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.None;
- }
- }
- }
- else
- {
- foreach (Infragistics.Win.UltraWinGrid.UltraGridBand band in Grid.DisplayLayout.Bands)
- {
- foreach (Infragistics.Win.UltraWinGrid.SummarySettings sum in band.Summaries)
- {
- if (Grid.DisplayLayout.GroupByBox.Hidden)
- {
- sum.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.Top;
- }
- else
- {
- sum.SummaryDisplayArea = ((Infragistics.Win.UltraWinGrid.SummaryDisplayAreas)((Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.Top | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.InGroupByRows | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.GroupByRowsFooter)));
- }
- }
- }
- }
- }
- catch (System.Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
- public static void SetStaticsInfoCount(ref UltraGrid myGrid1, ArrayList alistColumns, bool clearExists)
- {
- try
- {
- UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
- if (clearExists)
- band.Summaries.Clear();
- band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
- for (int i = 0; i < alistColumns.Count; i++)
- {
- try
- {
- SummarySettings summary = band.Summaries.Add(SummaryType.Count, band.Columns[alistColumns[i].ToString()]);
- //summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
- summary.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.BottomFixed | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.InGroupByRows | Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.GroupByRowsFooter;
-
- summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
- summary.DisplayFormat = "{0:0,0}";
- summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
- summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
- summary.Appearance.FontData.Bold = DefaultableBoolean.True;
- }
- catch { }
- }
- }
- catch { }
- }
- public static Point SetChildWindowLocation(Size ChildWindowSize)
- {
- int width = Cursor.Position.X + ChildWindowSize.Width - Screen.PrimaryScreen.Bounds.Width;
- int height = Cursor.Position.Y + ChildWindowSize.Height - Screen.PrimaryScreen.Bounds.Height + 30;
- width = (width > 0) ? (Cursor.Position.X - width) : Cursor.Position.X; // X坐标
- height = (height > 0) ? (Cursor.Position.Y - height + 10) : (Cursor.Position.Y + 10); // Y坐标
- return new Point(width, height);
- }
- private static UltraGridExcelExporter ultraGridExcelExporter1 = new UltraGridExcelExporter();
- public static void ExportDataWithSaveDialog(ref UltraGrid myGrid1, string strFileName)
- {
- try
- {
- if (myGrid1.Rows.Count == 0) return;
- if (strFileName.Length == 0)
- strFileName = "未命名";
- SaveFileDialog dlg = new SaveFileDialog();
- dlg.Title = "保存";
- dlg.OverwritePrompt = true;
- dlg.Filter = "Excel文件(*.xls)|*.xls";
- dlg.AddExtension = true;
- dlg.FileName = strFileName;
- if (dlg.ShowDialog() == DialogResult.OK)
- {
- strFileName = dlg.FileName;
- ultraGridExcelExporter1.Export(myGrid1, strFileName);
- if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- ProcessStartInfo p = new ProcessStartInfo(strFileName);
- p.WorkingDirectory = Path.GetDirectoryName(strFileName);
- Process.Start(p);
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- public static bool HasCheckedRows(ref UltraGrid ultraGrid, string strColumnCondition, object value, string strOutColumn, out ArrayList alistValue, out string strMsg)
- {
- strMsg = "";
- alistValue = new ArrayList();
- try
- {
- if (ultraGrid == null || ultraGrid.Rows.Count == 0)
- {
- return false;
- }
- if (!string.IsNullOrEmpty(strColumnCondition))
- {
- if (!CommonMethod.GridContainsColumn(ref ultraGrid, 0, strColumnCondition))
- {
- strMsg = "不存在条件字段【" + strColumnCondition + "】!";
- return false;
- }
- }
- if (string.IsNullOrEmpty(strOutColumn))
- {
- strMsg = "未指定输出字段【" + strOutColumn + "】!";
- return false;
- }
- if (!CommonMethod.GridContainsColumn(ref ultraGrid, 0, strOutColumn))
- {
- strMsg = "不存在输出字段【" + strOutColumn + "】!";
- return false;
- }
- for (int i = 0; i < ultraGrid.Rows.Count; i++)
- {
- if (!string.IsNullOrEmpty(strColumnCondition))
- {
- if (ultraGrid.Rows[i].Cells[strColumnCondition].Value.Equals(value))
- {
- alistValue.Add(ultraGrid.Rows[i].Cells[strOutColumn].Value);
- }
- }
- else
- {
- alistValue.Add(ultraGrid.Rows[i].Cells[strOutColumn].Value);
- }
- }
- return true;
- }
- catch (Exception ex)
- {
- strMsg = ex.Message;
- alistValue = null;
- }
- return false;
- }
- public static Hashtable GetHashtableFromDatatable(ref DataTable table, string strColumnKey, string strColumnValue)
- {
- Hashtable htbl = new Hashtable();
- if (table == null || table.Rows.Count == 0)
- {
- return htbl;
- }
- if (!table.Columns.Contains(strColumnKey) || !table.Columns.Contains(strColumnValue))
- {
- return htbl;
- }
- object Key = null, Value = null;
- for (int i = 0; i < table.Rows.Count; i++)
- {
- try
- {
- Key = table.Rows[i][strColumnKey];
- if (!htbl.Contains(Key))
- {
- Value = table.Rows[i][strColumnValue];
- htbl.Add(Key, Value);
- }
- }
- catch { }
- }
- return htbl;
- }
- /// <summary>
- /// 对目标对象进行字符串的转换
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public static string CheckNullStr(object obj)
- {
- if (obj == null || obj.GetType() == typeof(System.DBNull))
- {
- return "";
- }
- else
- {
- return Convert.ToString(obj).Trim();
- }
- }
- /// <summary>
- /// 初始化UltraCombo数据
- /// </summary>
- /// <param name="ulcme">ultraComboEditor控件</param>
- /// <param name="dset">DataSet数据源</param>
- public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset)
- {
- if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
- {
- for (int i = 0; i < dset.Tables[0].Rows.Count; i++)
- ulcme.Items.Add(dset.Tables[0].Rows[i][0].ToString(), dset.Tables[0].Rows[i][1].ToString());
- }
- }
- /// <summary>
- /// 初始化下拉框 --带参数的
- /// </summary>
- /// <param name="uce"></param>
- /// <param name="methodId"></param>
- /// <param name="valueMember"></param>
- /// <param name="ob"></param>
- /// <param name="isEmpty"></param>
- /// <param name="obj"></param>
- public static void InitComboEditorWithParm(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty, Object[] parm)
- {
- DataTable dt = ServerHelper.GetData(methodId, parm, ob);
- if (dt != null && dt.Rows.Count > 0)
- {
- if (isEmpty)
- {
- Object[] obj = new Object[] { "", "" };
- dt.Rows.Add(obj);
- }
- uce.DataSource = dt;
- uce.ValueMember = valueMember;
- SetComboItemHeight(uce);
- }
- }
- /// <summary>
- /// 设置UltraComboEditor中的中文和非中文统一高度。
- /// </summary>
- /// <param name="cmb"></param>
- public static void SetComboItemHeight(UltraComboEditor cmb)
- {
- foreach (ValueListItem item in cmb.Items)
- {
- if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
- {
- item.Appearance.FontData.SizeInPoints = 9.0F;
- }
- else
- {
- item.Appearance.FontData.SizeInPoints = 10.5F;
- }
- }
- }
- /// <summary>
- /// 设置列显示位数
- /// </summary>
- /// <param name="ug"></param>
- /// <param name="arr"></param>
- //public static void setUltraGridColumnMaxInput(UltraGrid ug, string[] arr)
- //{
- // if (ug == null || arr == null || arr.Length == 0)
- // {
- // return;
- // }
- // arr;
- // foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
- // {
- // if (arr.Contains(ugc.Key.ToString()))
- // {
- // ugc.MaskDisplayMode = MaskMode.IncludeLiterals;
- // ugc.MaskInput = "{LOC}nn,nnn,nnn.nnn";
- // }
- // }
- //}
- }
- }
|