using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.ComponentModel; using System.Windows.Forms; using System.Reflection; using System.IO; using CoreFS.CA06; using System.Collections; using Core.Mes.Client.Comm.Server; using Infragistics.Win.UltraWinEditors; namespace Core.StlMes.Client.SaleOrder { /// /// 合同公共方法 /// public static class OrderFunction { /// /// (成品接箍)单个重 /// /// 单个重(吨) /// 产品码 /// 标准号 /// 标准类别 /// 钢级代码 /// 规格代码 /// 扣型代码 public static void GetWgt_JG(ref double dubWeight, string strProduc_code, string strStd_code, string strStd_style, string strSteelcode, string strSpec_code, string strModel_code, OpeBase ob) { double dubTempWeight= 0; DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderLine.getJG_Weight", new object[] { strProduc_code, strStd_code, strStd_style, strSteelcode, strSpec_code, strModel_code }, ob); if (dt != null && dt.Rows.Count > 0) { dubTempWeight = Convert.ToDouble(dt.Rows[0][0].ToString()); } else { dubTempWeight = 0.003; } dubWeight = dubTempWeight; } /// /// 估算重量公式 /// /// 计算后的订货重量 /// 订货量 /// 订货单位 /// WebService /// 产品规格编码 public static void GetPrdctWgt(ref double dhweight, double ordernum, string orderunit, string psc, OpeBase ob) { double orderwgt = 0; //米单重 ArrayList parm = new ArrayList(); //代表 米单重(数据来源于COM_BASE_SPEC表,通过产品规格编码获取,需要除以1000,将“公斤”转换成“吨”) //2015-06-17修改 基础数据维护公式计算,已将数据单位 米/吨。 if (orderunit == "米" || orderunit == "毫米" || orderunit == "英尺") { //查询数据库 DataTable dataWgt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.GetWeiGht", new Object[] { psc }, ob); if (dataWgt.Rows.Count > 0) { string di = dataWgt.Rows[0][0].ToString(); //外径 string he = dataWgt.Rows[0][1].ToString(); //壁厚 string ty = dataWgt.Rows[0][2].ToString(); //类型(A钢管(必须要填外径壁厚)、B管坯(只允许填外径) string fomula = ""; //公式 DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getBaseCode4052", null, ob); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i][1].ToString().Equals(ty)) { fomula = dt.Rows[i][0].ToString(); break; } } if (!fomula.Equals("")) { fomula = fomula.Replace("外径", di); fomula = fomula.Replace("壁厚", he); decimal? result = fomula.CompileFormula(); if (result != null) orderwgt = (double)result; else { MessageBox.Show("质量管理-基础信息维护的米单重公式不合法!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } //orderwgt = Convert.ToDouble(dataWgt.Rows[0][0]); } if (orderunit == "吨") { dhweight = ordernum; } else if (orderunit == "英镑") { dhweight = Convert.ToDouble(ordernum * 0.45359237); } else if (orderunit == "米") { if (orderwgt == 0) orderwgt = 1; dhweight = (ordernum * orderwgt); } else if (orderunit == "毫米") { if (orderwgt == 0) orderwgt = 1; dhweight = (ordernum * orderwgt) / 1000; } else if (orderunit == "英尺") { if (orderwgt == 0) orderwgt = 1; dhweight = Convert.ToDouble(ordernum * 0.3048 * Convert.ToDouble(orderwgt)); } else if (orderunit == "支") { dhweight = ordernum; } else if (orderunit == "个") { dhweight = ordernum; } } /// /// 实体类间相同字段的值复制 /// 将fromEntity赋给toEntity /// /// public static void copyValue(object fromEntity, object toEntity) { foreach (PropertyInfo info in fromEntity.GetType().GetProperties()) { if (info.CanRead) { object o = info.GetValue(fromEntity, null); PropertyInfo column = toEntity.GetType().GetProperty(info.Name); if (column != null && column.CanWrite) column.SetValue(toEntity, o, null); } } } /// /// 将DataTable转换成对应的List集合 /// /// /// /// public static List ConvertToList(this DataTable table) where T : new() { Type t = typeof(T); //Create a list of the entities we want to return List returnObject = new List(); //Iterate through the DataTable's rows foreach (DataRow dr in table.Rows) { //Convert each row into an entity object and add to the list T newRow = dr.ConvertToEntity(); returnObject.Add(newRow); } //Return the finished list return returnObject; } /// /// 将DataRow转换成对应的Entity集合 /// /// /// /// public static T ConvertToEntity(this DataRow tableRow) where T : new() { //Create a new type of the entity I want Type t = typeof(T); T returnObject = new T(); foreach (DataColumn col in tableRow.Table.Columns) { string colName = col.ColumnName; //Look for the object's property with the columns name, ignore case PropertyInfo pInfo = t.GetProperty(colName.ToLower(), BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); //did we find the property ? if (pInfo != null) { object val = tableRow[colName]; //is this a Nullable<> type bool IsNullable = (Nullable.GetUnderlyingType(pInfo.PropertyType) != null); if (IsNullable) { if (val is System.DBNull) { val = null; } else { // Convert the db type into the T we have in our Nullable type val = Convert.ChangeType(val, Nullable.GetUnderlyingType(pInfo.PropertyType)); } } else { if (pInfo.PropertyType.FullName == "System.Byte[]") { if (val is System.DBNull) { val = null; } } else { //Convert the db type into the type of the property in our entity val = Convert.ChangeType(val, pInfo.PropertyType); } } //Set the value of the property with the value from the db pInfo.SetValue(returnObject, val, null); } } // return the entity object with values return returnObject; } /// /// 将List类型转换为DataTable /// /// /// public static DataTable ToDataTable(IList list) { DataTable dt = new DataTable(); dt.TableName = "table1"; // 通过使用反射来获取列表中队形的属性 BindingFlags bf = BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty; PropertyInfo[] props = list.GetType().GetGenericArguments()[0].GetProperties(); //PropertyInfo[] props = list[0].GetType().GetProperties(); foreach (PropertyInfo pi in props) { if (!pi.PropertyType.Name.Equals(typeof(Nullable<>).Name)) { dt.Columns.Add(pi.Name, Type.GetType(pi.PropertyType.FullName)); } else { dt.Columns.Add(pi.Name, Type.GetType(pi.PropertyType.GetGenericArguments()[0].FullName)); } } if (list != null && list.Count > 0) { foreach (object obj in list) { DataRow dr = dt.NewRow(); foreach (PropertyInfo pi in props) { object result = obj.GetType().InvokeMember(pi.Name, bf, null, obj, null); // d.Add(result); if (result != null) { dr[pi.Name] = result; } else { dr[pi.Name] = DBNull.Value; } } dt.Rows.Add(dr); } } return dt; } /// /// 过滤查询条件表 /// /// /// /// public static DataTable FilterDataTable(DataTable dt, string[] arr) { for (int i = 0; i < dt.Rows.Count; i++) { if (!arr.Contains(dt.Rows[i][1].ToString())) { DataRow dr = dt.Rows[i]; dt.Rows.Remove(dr); i--; } } return dt; } /// /// 计算估算重量 /// /// /// /// /// /// public static decimal GetPrdctWgtNew(decimal ordernum, string orderunit, string psc, OpeBase ob) { decimal orderwgt = 0; //米单重 decimal dhweight = 0; ArrayList parm = new ArrayList(); //代表 米单重(数据来源于COM_BASE_SPEC表,通过产品规格编码获取,需要除以1000,将“公斤”转换成“吨”) //2015-06-17修改 基础数据维护公式计算,已将数据单位 米/吨。 if (orderunit == "米" || orderunit == "毫米" || orderunit == "英尺") { //查询数据库 DataTable dataWgt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.GetWeiGht", new Object[] { psc }, ob); if (dataWgt.Rows.Count > 0) { string di = dataWgt.Rows[0][0].ToString(); //外径 string he = dataWgt.Rows[0][1].ToString(); //壁厚 string ty = dataWgt.Rows[0][2].ToString(); //类型(A钢管(必须要填外径壁厚)、B管坯(只允许填外径) string fomula = ""; //公式 DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getBaseCode4052", null, ob); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i][1].ToString().Equals(ty)) { fomula = dt.Rows[i][0].ToString(); break; } } if (!fomula.Equals("")) { fomula = fomula.Replace("外径", di); fomula = fomula.Replace("壁厚", he); decimal? result = fomula.CompileFormula(); if (result != null) orderwgt = (decimal)result; else { MessageBox.Show("质量管理-基础信息维护的米单重公式不合法!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return 0; } } } //orderwgt = Convert.ToDouble(dataWgt.Rows[0][0]); } if (orderunit == "吨") { dhweight = ordernum; } else if (orderunit == "英镑") { dhweight = Convert.ToDecimal(ordernum * Convert.ToDecimal(0.45359237)); } else if (orderunit == "米") { dhweight = (ordernum * orderwgt); } else if (orderunit == "毫米") { dhweight = (ordernum * orderwgt) / 1000; } else if (orderunit == "英尺") { dhweight = Convert.ToDecimal(ordernum * Convert.ToDecimal(0.3048) * Convert.ToDecimal(orderwgt)); } else if (orderunit == "支") { dhweight = ordernum; } else if (orderunit == "个") { dhweight = ordernum; } return dhweight; } /// /// 新增 修改 合同变更合同附加要求项 /// /// /// /// /// /// public static string IsSameAddAsk(string addAskNo, string addAskDesc, OpeBase ob, string ordLnPk) { string errMsg = ""; if (addAskNo == "") return errMsg; if (ordLnPk == null || ordLnPk == "") ordLnPk = "1"; DataTable validDt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getValidAddAskNo", new object[] { addAskNo }, ob); if (validDt != null && validDt.Rows.Count > 0) { //addAskNo 有效 } else { errMsg = "附加要求码" + addAskNo + "已经被作废,请重新选择附加要求!"; return errMsg; } DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getOrderAddAskDesc", new object[] { addAskNo, ordLnPk }, ob); if (dt != null && dt.Rows.Count > 0) { if (dt.Rows.Count >= 2) { string[] addAskDescs = dt.Rows[0]["ORDER_ADD_DESC"].ToString().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); Array.Sort(addAskDescs); for (int i = 1; i < dt.Rows.Count; i++) { string[] addAskDescs2 = dt.Rows[i]["ORDER_ADD_DESC"].ToString().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); Array.Sort(addAskDescs2); if (string.Join("", addAskDescs) != string.Join("", addAskDescs2)) { errMsg = addAskNo + "在数据库中存在" + dt.Rows.Count + "套不同的附加要求描述"; return errMsg; } } return errMsg; } else { //dt.Rows[0][0].ToString().Replace('\r', '\u0000').Replace('\n', '\u0000') string[] addAskDescs = addAskDesc.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); Array.Sort(addAskDescs); string[] ordLnAddAskDescs = dt.Rows[0][0].ToString().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); Array.Sort(ordLnAddAskDescs); bool isSame = true; for (int i = 0; i < addAskDescs.Length; i++) { if (addAskDescs[i] != ordLnAddAskDescs[i]) { isSame = false; break; } } if (isSame) { return errMsg; } else { errMsg = "您所选择的附加要求描述已改变,请重新选择!"; return errMsg; } //if (addAskDesc.Replace("\n", "").Replace("\r", "") == dt.Rows[0][0].ToString().Replace("\n", "").Replace("\r", "")) //{ // return errMsg; //} //else //{ // errMsg = "您所选择的附加要求描述已改变,请重新选择!"; // return errMsg; //} } } else { return errMsg; } } /// /// 判断是否有效的技术要求 /// /// 产品技术要求码 /// /// public static string IsValidSpecialCode(string special, OpeBase ob) { string errMsg = ""; if (special == "") return errMsg; DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getValidSpecial", new object[] { special }, ob); if (dt != null && dt.Rows.Count > 0) { //技术要求有效可以保存 } else { errMsg = "技术要求" + special + "已经被作废,请重新选择技术要求"; return errMsg; } return errMsg; } /// /// 初始化下拉框 /// /// 下拉框 /// 请求的服务 /// 值成员 /// ob对象 /// 是否有空行 public static void InitComboEditor(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty) { DataTable dt = ServerHelper.GetData(methodId, null, 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; ClsBaseInfo.SetComboItemHeight(uce); } } /// /// 初始化下拉框 --带参数的 /// /// /// /// 值成员 /// 显示成员 /// /// /// public static void InitComboEditorWithParm(UltraComboEditor uce, string methodId, string valueMember,string displayMember, 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[] { "", "" }; DataRow dr = dt.NewRow(); dr.ItemArray = obj; dt.Rows.InsertAt(dr, 0); } uce.DataSource = dt; uce.ValueMember = valueMember; uce.DisplayMember = displayMember; ClsBaseInfo.SetComboItemHeight(uce); } } } }