| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239 |
- 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;
- namespace Core.StlMes.Client.ZGMil
- {
- 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 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"))
- {
- 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 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";
- // }
- // }
- //}
- }
- }
|