| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Collections;
- using System.Runtime.Serialization;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Xml;
- using System.Data.SqlClient;
- using System.Diagnostics;
- using System.Reflection; //MISSIN
- using Infragistics.Win.UltraWinGrid;
- using Infragistics.Win;
- using Infragistics.Excel;
- using Infragistics.Win.UltraWinDataSource;
- using Infragistics.Win.UltraWinEditors;
- using Core.Mes.Client.Comm.Server;
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.Mcp.Control;
- namespace Core.StlMes.Client.PlnSaleOrd
- {
- public class PlanComm
- {
- public static double PI = 3.1415926;
- /// <summary>
- /// 管米单重计算(t/m)
- /// </summary>
- /// <param name="outdiameter">外径(mm)</param>
- /// <param name="aimwallthick">壁厚(mm)</param>
- /// <returns></returns>
- public static double WeightOfMi(double outdiameter, double aimwallthick)
- {
- double weightOfmi = 0.02466 * aimwallthick * (outdiameter - aimwallthick) / 1000;
- return weightOfmi;
- }
- /// <summary>
- /// 管坯米单重(t/m)
- /// </summary>
- /// <param name="outdiameter">管坯断面(mm)</param>
- /// <returns></returns>
- public static double GpweightOfmi(double outdiameter)
- {
- return (7.8 * PI / 4 * outdiameter * outdiameter) / 1000 / 1000;
- }
- /// <summary>
- /// 单位英尺长度转米
- /// </summary>
- /// <param name="lenth">英尺长度</param>
- /// <returns>米长度</returns>
- public static double FootoMi(double lenth)
- {
- double converate = 0.3048; //换算率
- return Math.Round((lenth * converate), 3);
- }
- /// <summary>
- /// 单位英磅转吨
- /// </summary>
- /// <param name="weight"></param>
- /// <returns></returns>
- public static double PoundtoTon(double weight)
- {
- double converate = 0.45392 / 1000; //换算率
- return Math.Round((weight * converate), 3);
- }
- /// <summary>
- /// 设置grid单元格可编辑
- /// </summary>
- /// <param name="band">grid表格</param>
- /// <param name="strs">可编辑的列头名称数组</param>
- public static void setGridActivation(UltraGridBand band, params string[] strs)
- {
- foreach (UltraGridColumn column in band.Columns)
- {
- if (!strs.Contains(column.Key))
- {
- column.CellActivation = Activation.ActivateOnly;
- }
- else
- {
- column.CellActivation = Activation.AllowEdit;
- column.CellAppearance.BackColor = Color.FromArgb(255, 255, 128);
- }
- }
- }
- /// <summary>
- /// 表格下拉框,可以有ValueList来提供,可以选择的样式
- /// </summary>
- /// <param name="table"></param>
- /// <param name="strKey"></param>
- /// <param name="strText"></param>
- /// <returns></returns>
- public static ValueList GeneralValuelist(ref System.Data.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;
- }
- /// <summary>
- /// 自定义对象深拷贝
- /// </summary>
- /// <typeparam name="T">类名</typeparam>
- /// <param name="RealObject">源对象</param>
- /// <returns></returns>
- public static T Clone<T>(T RealObject)
- {
- using (Stream objectStream = new MemoryStream())
- {
- //利用 System.Runtime.Serialization序列化与反序列化完成引用对象的复制
- IFormatter formatter = new BinaryFormatter();
- formatter.Serialize(objectStream, RealObject);
- objectStream.Seek(0, SeekOrigin.Begin);
- return (T)formatter.Deserialize(objectStream);
- }
- }
- /// <summary>
- /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中
- /// </summary>
- /// <param name="ugrid">UltraGrid</param>
- /// <param name="e"></param>
- /// <param name="strs">可以进行列名称</param>
- public static void setGridCopyActColumn(UltraGrid ugrid, KeyEventArgs e, params string[] strs)
- {
- if (e.Control && e.KeyCode == Keys.D)
- {
- if (ugrid != null && ugrid.ActiveRow != null)
- {
- UltraGridRow ugr = ugrid.ActiveRow;
- foreach (string colName in strs)
- {
- if (ugrid.ActiveCell.Column.Key.Equals(colName))
- {
- if (ugr.Cells[colName].Activation != Activation.AllowEdit)
- {
- return;
- }
- ugrid.UpdateData();
- ArrayList list = new ArrayList();
- IQueryable<UltraGridRow> checkRows = ugrid.Rows.AsQueryable().Where(" CHECK = 'True' ");
- if (checkRows.Count() == 0)
- {
- return;
- }
- foreach (UltraGridRow uRow in checkRows)
- {
- if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit)
- {
- uRow.Cells[colName].Value = ugr.Cells[colName].Value;
- }
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中
- /// </summary>
- /// <param name="ugrid">UltraGrid</param>
- /// <param name="key">选择列名(例如"CHC")</param>
- /// <param name="e"></param>
- /// <param name="strs">可以进行列名称</param>
- public static void setGridCopyActColumn(UltraGrid ugrid, string key, KeyEventArgs e, params string[] strs)
- {
- if (e.Control && e.KeyCode == Keys.D)
- {
- if (ugrid != null && ugrid.ActiveRow != null)
- {
- UltraGridRow ugr = ugrid.ActiveRow;
- foreach (string colName in strs)
- {
- if (ugrid.ActiveCell.Column.Key.Equals(colName))
- {
- if (ugr.Cells[colName].Activation != Activation.AllowEdit)
- {
- return;
- }
- ugrid.UpdateData();
- ArrayList list = new ArrayList();
- IQueryable<UltraGridRow> checkRows = ugrid.Rows.AsQueryable().Where(key + " = 'True'");
- if (checkRows.Count() == 0)
- {
- return;
- }
- foreach (UltraGridRow uRow in checkRows)
- {
- if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit)
- {
- uRow.Cells[colName].Value = ugr.Cells[colName].Value;
- }
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 返回table的column列中是否存在str
- /// </summary>
- /// <param name="dt">datable</param>
- /// <param name="column">列头名</param>
- /// <param name="str">匹配字符串</param>
- /// <returns></returns>
- public static bool isInDataTable(System.Data.DataTable dt, string column, string str)
- {
- bool isInTable = false;
- if (dt == null || column.Equals(""))
- {
- return isInTable;
- }
- if (!dt.Columns.Contains(column))
- {
- return isInTable;
- }
- foreach(DataRow dr in dt.Rows)
- {
- if (dr[column].ToString().Equals(str))
- {
- isInTable = true;
- }
- }
- return isInTable;
- }
- /// <summary>
- /// 复制DataTable到UltraDataBand
- /// </summary>
- /// <param name="src">源数据</param>
- /// <param name="dest">UltraDataBand</param>
- /// <param name="ClearExists">是否清除原数据</param>
- public static void CopyDataToDataSource(System.Data.DataTable src, UltraDataBand dest, bool ClearExists)
- {
- if (src == null || dest == null)
- {
- return;
- }
- if (ClearExists)
- {
- dest.DataSource.Rows.Clear();
- }
- for (int i = 0; i < src.Rows.Count; i++)
- {
- DataRow CurRow = src.Rows[i];
- object[] cellValues = new object[dest.Columns.Count];
- for (int j = 0; j < dest.Columns.Count; j++)
- {
- if (src.Columns.Contains(dest.Columns[j].Key))
- {
- cellValues[j] = CurRow[j];
- }
- else
- {
- cellValues[j] = null;
- }
- }
- dest.DataSource.Rows.Add(cellValues);
- }
- }
- /// <summary>
- /// 设置Grid列是数字类型,显示样式
- /// </summary>
- /// <param name="band">UltraGridBand</param>
- /// <param name="maxDigit">数字最大位数(如:99999.99,最大位数5位)</param>
- /// <param name="digit">保留小数位数(如:99999.99,保留2位小数)</param>
- /// <param name="strs">数字单元列</param>
- public static void setGridDigitalCol(UltraGridBand band, int maxDigit, int digit, params string[] strs)
- {
- if (band == null)
- {
- return;
- }
- string maskInput = "-";
- if (maxDigit > 0)
- {
- string str = "";
- for (int i = 0; i < maxDigit; i++)
- {
- if (i != 0 && (i % 3) == 0)
- {
- str = "," + str;
- }
- str = "n" + str;
- }
- maskInput = maskInput + str;
- if (digit > 0)
- {
- maskInput += ".";
- for (int i = 0; i < digit; i++)
- {
- maskInput += "n";
- }
- }
- foreach (UltraGridColumn column in band.Columns)
- {
- if (strs.Contains(column.Key))
- {
- column.MaskDisplayMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeLiterals;
- column.MaskInput = maskInput;
- column.CellAppearance.TextHAlign = HAlign.Right;
- if (digit > 0)
- {
- column.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Double;
- }
- else
- {
- column.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Integer;
- }
- }
- }
- }
- }
- /// <summary>
- /// Grid列添加求和统计,设置数字显示样式
- /// </summary>
- /// <param name="band">UltraGridBand</param>
- /// <param name="digit">保留小数位数(如:99999.99,保留2位小数)</param>
- /// <param name="strs">添加统计的列头名</param>
- public static void setGridSummarySet(UltraGrid grid, int digit, params string[] strs)
- {
- grid.DisplayLayout.Override.AllowRowSummaries = Infragistics.Win.UltraWinGrid.AllowRowSummaries.Default;
- grid.DisplayLayout.Override.AllowRowSummaries = Infragistics.Win.UltraWinGrid.AllowRowSummaries.BasedOnDataType;
- for (int i = 0; i < strs.Count(); i++)
- {
- string columnKey = strs[i];
- UltraGridBand band = grid.DisplayLayout.Bands[0];
- if (band == null)
- {
- return;
- }
- if (!band.Columns.Exists(columnKey))
- {
- continue;
- }
- if (band.Summaries.Exists(columnKey))
- {
- continue;
- }
- SummarySettings sumColumn = band.Summaries.Add(columnKey, SummaryType.Sum,
- band.Columns[columnKey], SummaryPosition.UseSummaryPositionColumn);
- sumColumn.DisplayFormat = "{0:N" + digit + "}";
- sumColumn.Appearance.TextHAlign = HAlign.Right;
- }
- grid.DisplayLayout.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
- }
-
- /// <summary>
- /// 等待窗口
- /// </summary>
- public static void WaitFromOpen(Cursor cursor)
- {
- cursor = Cursors.WaitCursor; //控制鼠标的样式为等待
- if (Constant.WaitingForm == null)
- {
- Constant.WaitingForm = new WaitingForm();
- }
- Constant.WaitingForm.ShowToUser = true;
- Constant.WaitingForm.Show();
- Constant.WaitingForm.Update();
- }
- /// <summary>
- /// 关闭等待
- /// </summary>
- public static void WaitFromColse(Cursor cursor)
- {
- cursor = Cursors.Default;
- Constant.WaitingForm.ShowToUser = false;
- Constant.WaitingForm.Close();
- Constant.WaitingForm = null;
- }
- /// <summary>
- //byWenCheng 设置grid的band的列名和描述(列名和描述来自数据库的列名和描述)
- /// </summary>
- /// <param name="band">需要设置的grid的band</param>
- /// <param name="tablename">与band对应的表名</param>
- /// <param name="ob">OpenBase对象</param>
- public static void SetColandCaption(Infragistics.Win.UltraWinGrid.UltraGridBand band, string tablename,CoreFS.CA06.OpeBase ob)
- {
- if (band == null)
- {
- return;
- }
- System.Data.DataTable dt = GetDataBySql(string.Format(@"select column_name,comments from user_col_comments where table_name = '{0}'", tablename),ob);
- if (dt.Rows.Count > 0)
- {
- foreach (DataRow row in dt.Rows)
- {
- band.Columns.Add(row[0].ToString(), row[1].ToString());
- }
- }
- }
- /// <summary>
- ///byWenCheng 执行sql语句
- /// </summary>
- /// <param name="sqlString"></param>
- /// <param name="_ob"></param>
- /// <returns></returns>
- public static System.Data.DataTable GetDataBySql(string sqlString,CoreFS.CA06.OpeBase _ob)
- {
- return Core.Mes.Client.Comm.Server.ServerHelper.GetData("com.steering.pss.plnsaleord.ordAmCal.OrderDemo.getDataBySql", new Object[] { sqlString }, _ob);
- }
- /// <summary>
- ///byWenCheng 设置某band的所有列不可编辑,除了ignoreColums里包含的列
- /// </summary>
- /// <param name="band">需要设置的band</param>
- /// <param name="ignoreColums">需要忽略的列</param>
- public static void SetGridColNoEdit(Infragistics.Win.UltraWinGrid.UltraGridBand band, string[] ignoreColums)
- {
- foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn col in band.Columns)
- {
- if (ignoreColums.Length > 0 && !string.IsNullOrEmpty(ignoreColums.FirstOrDefault(c => c == col.Key)))
- {
- col.CellAppearance.BackColor = System.Drawing.Color.Yellow;
- continue;
- }
- col.CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
- }
- }
- /// <summary>
- /// byWenCheng,复制数据到数据表,暂未测试速率,目前发现在查询数据时比较耗时,2000条数据2-3s
- /// </summary>
- /// <param name="srcDt"></param>
- /// <param name="desDt"></param>
- /// <param name="ClearExsit"></param>
- public static void CopyDatabyDatatable(System.Data.DataTable srcDt,System.Data.DataTable desDt, bool ClearExsit)
- {
- if (srcDt.Rows.Count <= 0)
- {
- return;
- }
- if (ClearExsit)
- {
- desDt.Rows.Clear();
- }
- foreach (DataRow row in srcDt.Rows)
- {
- desDt.LoadDataRow(row.ItemArray, false);
- }
- }
- /// <summary>
- ///byWenCheng 设置列宽根据内容自适应方法1
- /// </summary>
- /// <param name="band">需要设置的band</param>
- public static void SetColumnAutoFitSize1(UltraGridBand band)
- {
- if (band != null)
- {
- band.PerformAutoResizeColumns(true, PerformAutoSizeType.VisibleRows);
- }
- }
- /// <summary>
- ///byWenCheng 设置列宽根据内容自适应方法2
- /// </summary>
- /// <param name="band">需要设置的band</param>
- public static void SetColumnAutoFitSize2(UltraGridBand band)
- {
- if (band != null)
- {
- foreach (UltraGridColumn col in band.Columns)
- {
- col.PerformAutoResize();
- }
- }
- }
- /// <summary>
- ///byWenCheng 设置行高根据内容自适应
- /// </summary>
- /// <param name="grid"></param>
- public static void SetRowAutoFitSize(UltraGrid grid)
- {
- if(grid != null)
- {
- grid.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
- }
- }
- /// <summary>
- ///byWenCheng 获取grid的激活的行,如果该行有对应的父行,则取其父行。和selected选择的行有区别的是,selectedrow是可以有多行,activedrow只能是一行,而且一般是最后选择的那一行
- /// </summary>
- /// <param name="grid"></param>
- /// <returns></returns>
- public static UltraGridRow GetActiveRow(UltraGrid grid)
- {
- if (grid == null || grid.ActiveRow == null)
- {
- return null;
- }
- UltraGridRow ugr = grid.ActiveRow;
- if (ugr.HasParent())
- {
- ugr = ugr.ParentRow;
- }
- return ugr;
- }
- /// <summary>
- /// byWencheng,获取小数点后指定位数的double值
- /// </summary>
- /// <param name="dsrc">源double</param>
- /// <param name="nBit">指定小数点后的位数</param>
- /// <returns>结果值</returns>
- public static double GetSpecDecimalBit(double dsrc,int nBit)
- {
- return Convert.ToDouble(dsrc.ToString(string.Format("f{0}",nBit)));
- }
- }
- }
|