| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using Core.Mes.Client.Comm.Server;
- using CoreFS.CA06;
- using Infragistics.Win;
- using Infragistics.Win.UltraWinEditors;
- using Infragistics.Win.UltraWinGrid;
- using System.Text.RegularExpressions;
- using Core.Mes.Client.Comm.Tool;
- using System.Reflection;
- using System.Windows.Forms;
- namespace Core.StlMes.Client.PlnSaleOrd.炼钢计划
- {
- public class SteelHelper
- {
- /// <summary>
- /// 初始化产线下拉框
- /// </summary>
- /// <param name="uce">下拉框</param>
- /// <param name="processCode">工序</param>
- /// <param name="ob">OpeBase</param>
- public static void InitPline(UltraComboEditor uce, string processCode, OpeBase ob)
- {
- DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.steelMarkingPlan.SteelHelper.initPline",
- new object[] {processCode}, ob);
- uce.DropDownListWidth = -1;
- //uce.DropDownStyle = DropDownStyle.DropDownList;
- uce.DataSource = dt;
- uce.DisplayMember = "PLINE_NAME";
- uce.ValueMember = "PLINE_CODE";
- uce.SelectedIndex = 0;
- }
- /// <summary>
- /// 初始化产线下拉框
- /// </summary>
- /// <param name="uce">下拉框</param>
- /// <param name="processCode">工序</param>
- /// <param name="ob">OpeBase</param>
- public static void InitPline2(UltraComboEditor uce, string processCode, OpeBase ob)
- {
- DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.steelMarkingPlan.SteelHelper.initPline", new object[] { processCode }, ob);
- DataRow dr = dt.NewRow();
- dr[0] = "";
- dr[1] = "离线库";
- dt.Rows.Add(dr);
- uce.DropDownListWidth = -1;
- //uce.DropDownStyle = DropDownStyle.DropDownList;
- uce.DataSource = dt;
- uce.DisplayMember = "PLINE_NAME";
- uce.ValueMember = "PLINE_CODE";
- uce.SelectedIndex = 0;
- }
- /// <summary>
- /// 初始化工序下拉框
- /// </summary>
- /// <param name="uce">下拉框</param>
- /// <param name="processCode">工序</param>
- /// <param name="ob">OpeBase</param>
- public static void InitProcess(UltraComboEditor uce, string processCode,OpeBase ob)
- {
- DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.steelMarkingPlan.SteelHelper.initProcess", new object[] { processCode }, ob);
- uce.DropDownListWidth = -1;
- uce.DropDownStyle = DropDownStyle.DropDownList;
- uce.DataSource = dt;
- uce.DisplayMember = "PROCESS_DESC";
- uce.ValueMember = "PROCESS_CODE";
- uce.SelectedIndex = 0;
- }
- /// <summary>
- /// 初始化余材类型
- /// </summary>
- /// <param name="uce"></param>
- public static void InitSurplusType(UltraComboEditor uce)
- {
- //余材类型(1生产超量2开浇加量3尾炉加量45)
- DataTable dt = new DataTable();
- dt.Columns.Add("SURPLUS_TYPE_NAME");
- dt.Columns.Add("SURPLUS_TYPE_CODE");
- DataRow dr1 = dt.NewRow();
- dr1["SURPLUS_TYPE_NAME"] = "生产超量";
- dr1["SURPLUS_TYPE_CODE"] = "1";
- dt.Rows.Add(dr1);
- DataRow dr2 = dt.NewRow();
- dr2["SURPLUS_TYPE_NAME"] = "开浇加量";
- dr2["SURPLUS_TYPE_CODE"] = "2";
- dt.Rows.Add(dr2);
- DataRow dr3 = dt.NewRow();
- dr3["SURPLUS_TYPE_NAME"] = "尾炉加量";
- dr3["SURPLUS_TYPE_CODE"] = "3";
- dt.Rows.Add(dr3);
- DataRow dr4 = dt.NewRow();
- dr4["SURPLUS_TYPE_NAME"] = "连浇前炉加量";
- dr4["SURPLUS_TYPE_CODE"] = "4";
- dt.Rows.Add(dr4);
- DataRow dr5 = dt.NewRow();
- dr5["SURPLUS_TYPE_NAME"] = "连浇后炉加量";
- dr5["SURPLUS_TYPE_CODE"] = "5";
- dt.Rows.Add(dr5);
- uce.DataSource = dt;
- uce.DisplayMember = "SURPLUS_TYPE_NAME";
- uce.ValueMember = "SURPLUS_TYPE_CODE";
- }
- /// <summary>
- /// (删除修改新增)涉及事务处理方法
- /// </summary>
- /// <param name="methodId">方法ID</param>
- /// <param name="param">参数</param>
- /// <param name="ob">OpeBase</param>
- /// <returns>string[] 第一个参数 true/false 第二个参数 返回提示信息</returns>
- public static string[] SetData(string methodId, object[] param, OpeBase ob)
- {
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
- ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
- ccp.ServerParams = param;
- ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode == -1)
- {
- return null;
- }
- else
- {
- string[] strArray = new string[2];
- strArray[0] = ccp.ReturnObject.ToString();
- strArray[1] = ccp.ReturnInfo;
- return strArray;
- }
- }
- /// <summary>
- /// (删除修改新增)涉及事务处理方法
- /// </summary>
- /// <param name="methodId">方法ID</param>
- /// <param name="param">参数</param>
- /// <param name="ob">OpeBase</param>
- /// <returns>string[] 第一个参数 true/false 第二个参数 返回提示信息</returns>
- public static object[] SetDataReturnData(string methodId, object[] param, OpeBase ob)
- {
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
- ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
- ccp.ServerParams = param;
- ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode == -1)
- {
- return null;
- }
- else
- {
- object[] strArray = new object[2];
- strArray[0] = ccp.ReturnObject;
- strArray[1] = ccp.ReturnInfo;
- return strArray;
- }
- }
- /// <summary>
- /// 验证字符串是否是数字
- /// </summary>
- /// <param name="str">字符串</param>
- /// <returns>bool</returns>
- public static bool IsNum(string str)
- {
- try
- {
- double a = Convert.ToDouble(str);
- }
- catch (Exception e)
- {
- return false;
- }
- return true;
- }
- /// 初始化钢种
- /// </summary>
- /// <param name="uce">下拉框</param>
- /// <param name="ob">OpeBase</param>
- public static void InitGrade(UltraComboEditor uce, OpeBase ob)
- {
- DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.steelMarkingPlan.SteelHelper.initGrade", new object[] { }, ob);
- uce.DropDownListWidth = -1;
- uce.DataSource = dt;
- uce.DisplayMember = "GRADENAME";
- uce.ValueMember = "GRADECODE";
- }
- /// <summary>
- /// 从服务端查询数据(query)
- /// </summary>
- /// <param name="methodId">服务端MethodId</param>
- /// <param name="param">参数数组,需与服务端方法参数一致</param>
- /// <param name="ob">界面OB对象</param>
- /// <exception cref="MESException">自定义异常</exception>
- /// <returns>查询数据集</returns>
- public static object GetData(string methodId, object[] param, OpeBase ob)
- {
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = methodId.Substring(0, methodId.LastIndexOf("."));
- ccp.MethodName = methodId.Substring(methodId.LastIndexOf(".") + 1);
- ccp.ServerParams = param;
- ccp = ob.ExecuteSortResultByQueryToDataTable(ccp, CoreInvokeType.Internal);
- if (ccp == null)
- {
- throw null;
- }
- return ccp.ReturnObject;
- }
- /// <summary>
- /// 初始化状态
- /// </summary>
- /// <param name="uce"></param>
- public static void InitStatus(UltraComboEditor uce)
- {
- //状态(0=组炉,1=组浇,2=下发,3生产中,4生产完成)
- DataTable dt = new DataTable();
- dt.Columns.Add("STATUS");
- dt.Columns.Add("STATUS_CODE");
- DataRow dr1 = dt.NewRow();
- dr1["STATUS"] = "组炉";
- dr1["STATUS_CODE"] = "0";
- dt.Rows.Add(dr1);
- DataRow dr2 = dt.NewRow();
- dr2["STATUS"] = "组浇";
- dr2["STATUS_CODE"] = "1";
- dt.Rows.Add(dr2);
- DataRow dr3 = dt.NewRow();
- dr3["STATUS"] = "下发";
- dr3["STATUS_CODE"] = "2";
- dt.Rows.Add(dr3);
- DataRow dr4 = dt.NewRow();
- dr4["STATUS"] = "生产中";
- dr4["STATUS_CODE"] = "3";
- dt.Rows.Add(dr4);
- DataRow dr5 = dt.NewRow();
- dr5["STATUS"] = "生产完成";
- dr5["STATUS_CODE"] = "4";
- dt.Rows.Add(dr5);
- uce.DataSource = dt;
- uce.DisplayMember = "STATUS";
- uce.ValueMember = "STATUS_CODE";
- }
- /// <summary>
- /// 初始化下拉框
- /// </summary>
- /// <param name="uce">下拉框</param>
- /// <param name="methodId">请求的服务</param>
- /// <param name="valueMember">值成员</param>
- /// <param name="ob">ob对象</param>
- /// <param name="isEmpty">是否有空行</param>
- public static void InitComboEditor(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty)
- {
- DataTable dt = ServerHelper.GetData(methodId, new object[]{""}, ob);
- if (dt != null && dt.Rows.Count > 0)
- {
- if (isEmpty)
- {
- Object[] obj = new Object[] { "", "" };
- DataRow dr = dt.NewRow();
- dr.ItemArray = obj;
- dt.Rows.InsertAt(dr, 0);
- }
- uce.DataSource = dt;
- uce.ValueMember = valueMember;
- SetComboItemHeight(uce);
- }
- }
- /// <summary>
- /// 将下拉框绑定到GRID列
- /// </summary>
- /// <param name="uce">下拉框(已经初始化完成)</param>
- /// <param name="ColumnName">列名</param>
- /// <param name="con">空间集合(每次只需填入this.Controls)</param>
- /// <param name="ug">GRID</param>
- /// <param name="i">GRID的第几层结构</param>
- public static void BindColumn(UltraComboEditor uce, string ColumnName, System.Windows.Forms.Control.ControlCollection con, UltraGrid ug, int i)
- {
- con.Add(uce);
- uce.Visible = false;
- ug.DisplayLayout.Bands[i].Columns[ColumnName].EditorComponent = uce;
- ug.DisplayLayout.Bands[i].Columns[ColumnName].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDown;
- 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;
- }
- }
- }
- public static DataSourceList<T> GetModelByDt<T>(DataTable dt) where T : new()
- {
- var modelList = new DataSourceList<T>();
-
- //List<string> columns = dt.Columns.Cast<DataColumn>().Select(p => p.ColumnName.Replace("_", "").ToUpper()).ToList();
- foreach (DataRow dr in dt.Rows)
- {
- T model = new T();
- foreach (var propertyInfo in typeof(T).GetProperties().AsParallel())
- {
- if (dt.Columns.Contains(propertyInfo.Name.ToUpper()) &&
- (dr[propertyInfo.Name] != DBNull.Value))
- //SetPropertyValue(propertyInfo, model, dr[propertyInfo.Name]);
- propertyInfo.SetValue(model,
- ConvertDataType(propertyInfo.PropertyType, dr[propertyInfo.Name]), null);
- }
- modelList.Add(model);
- }
- return modelList;
- }
- private static object ConvertDataType(Type type, object objValue)
- {
- if (type == typeof(bool) || type == typeof(bool?))
- {
- return bool.Parse(objValue == null ? "False" : objValue.ToString());
- }
- else if (type == typeof(int?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return int.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(long?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return long.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(short?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return short.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(float?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return float.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(double?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return double.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(decimal?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return decimal.Parse(objValue.ToString());
- }
- }
- else if (type == typeof(DateTime?))
- {
- if (objValue == null)
- {
- return null;
- }
- else
- {
- return DateTime.Parse(objValue.ToString());
- }
- }
- else
- {
- return objValue == null ? "" : objValue.ToString();
- }
- }
- private static void SetPropertyValue<T>(PropertyInfo propertyInfo, T model, object data)
- {
- try
- {
- if (data == null) return;
- propertyInfo.SetValue(model,
- propertyInfo.PropertyType == data.GetType()
- ? data
- : Convert.ChangeType(data, propertyInfo.PropertyType), null);
- }
- catch (Exception)
- {
- // ignored
- }
- }
- public static DataSourceList<T> TableToEntity<T>(DataTable dt) where T : class,new()
- {
- Type type = typeof(T);
- DataSourceList<T> list = new DataSourceList<T>();
- foreach (DataRow row in dt.Rows)
- {
- PropertyInfo[] pArray = type.GetProperties();
- T entity = new T();
- foreach (PropertyInfo p in pArray)
- {
- if (row[p.Name] is Int64)
- {
- p.SetValue(entity, Convert.ToInt32(row[p.Name]), null);
- continue;
- }
- p.SetValue(entity, row[p.Name], null);
- }
- list.Add(entity);
- }
- return list;
- }
- /// 执行DataTable中的查询返回新的DataTable
- /// </summary>
- /// <param name="dt">源数据DataTable</param>
- /// <param name="condition">查询条件</param>
- /// <returns></returns>
- public static DataTable GetNewDataTable(DataTable dt, string condition, string sortstr)
- {
- DataTable newdt = new DataTable();
- newdt = dt.Clone();
- DataRow[] dr = dt.Select(condition, sortstr);
- for (int i = 0; i < dr.Length; i++)
- {
- newdt.ImportRow((DataRow)dr[i]);
- }
- return newdt;//返回的查询结果
- }
- /// datatable去重
- /// </summary>
- /// <param name="dtSource">需要去重的datatable</param>
- /// <param name="columnNames">依据哪些列去重</param>
- /// <returns></returns>
- public static DataTable GetDistinctTable(DataTable dtSource, params string[] columnNames)
- {
- DataTable distinctTable = dtSource.Clone();
- try
- {
- if (dtSource != null && dtSource.Rows.Count > 0)
- {
- DataView dv = new DataView(dtSource);
- distinctTable = dv.ToTable(true, columnNames);
- }
- }
- catch (Exception ee)
- {
- MessageBox.Show(ee.ToString());
- }
- return distinctTable;
- }
- /// <summary>
- /// 主从表禁止排序
- /// </summary>
- /// <param name="ugr"></param>
- public static void ForbidSort(UltraGrid ugr)
- {
- foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
- {
- ugc.SortIndicator = SortIndicator.Disabled;
-
- }
- foreach (UltraGridColumn ug1 in ugr.DisplayLayout.Bands[1].Columns)
- {
- ug1.SortIndicator = SortIndicator.Disabled;
- }
- }
- }
- }
|