| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- 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 Microsoft.Office.Interop.Excel; //APP
- using System.Xml;
- using System.Data.SqlClient;
- using System.Diagnostics;
- using System.Reflection; //MISSIN
- using Infragistics.Win.UltraWinGrid;
- using Infragistics.Win;
- using Infragistics.Win.UltraWinGrid.ExcelExport;
- using Infragistics.Excel;
- namespace Core.StlMes.Client.Plan.Order
- {
- 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), 2);
- }
- /// <summary>
- /// 导出
- /// </summary>
- public static void Export(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;
- using (UltraGridExcelExporter ultraGridExcelExporter1 = new UltraGridExcelExporter())
- {
- ultraGridExcelExporter1.Export(myGrid1, strFileName);
- }
- if (MessageBox.Show("数据导出成功!\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);
- }
- }
- /// <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>
- /// 设置数字类型列千分位显示,小数点保留位数
- /// </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 setGridDigitalColMaxInput(UltraGridBand band, int maxDigit, int digit, params string[] strs)
- {
- if (band == null)
- {
- return;
- }
- string maskInput = "{LOC}";
- 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;
- }
- }
- }
- }
- /// <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 = "{LOC}";
- 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>
- /// 等待窗口
- /// </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;
- }
- }
- }
|