| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567 |
- 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
- {
- /// <summary>
- /// 合同公共方法
- /// </summary>
- public static class OrderFunction
- {
- /// <summary>
- /// (成品接箍)单个重
- /// </summary>
- /// <param name="dubWeight">单个重(吨)</param>
- /// <param name="strProduc_code">产品码</param>
- /// <param name="strStd_code">标准号</param>
- /// <param name="strStd_style">标准类别</param>
- /// <param name="strSteelcode">钢级代码</param>
- /// <param name="strSpec_code">规格代码</param>
- /// <param name="strModel_code">扣型代码</param>
- 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;
- }
- /// <summary>
- /// 估算重量公式
- /// </summary>
- /// <param name="dhweight">计算后的订货重量</param>
- /// <param name="ordernum">订货量</param>
- /// <param name="orderunit">订货单位</param>
- /// <param name="ob">WebService</param>
- /// <param name="ob">产品规格编码</param>
- 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;
- }
- }
- /// <summary>
- /// 实体类间相同字段的值复制
- /// </summary>将fromEntity赋给toEntity
- /// <param name="fromTable"></param>
- /// <param name="toTable"></param>
- 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);
- }
- }
- }
- /// <summary>
- /// 将DataTable转换成对应的List集合
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="table"></param>
- /// <returns></returns>
- public static List<T> ConvertToList<T>(this DataTable table) where T : new()
- {
- Type t = typeof(T);
- //Create a list of the entities we want to return
- List<T> returnObject = new List<T>();
- //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<T>();
- returnObject.Add(newRow);
- }
- //Return the finished list
- return returnObject;
- }
- /// <summary>
- /// 将DataRow转换成对应的Entity集合
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="tableRow"></param>
- /// <returns></returns>
- public static T ConvertToEntity<T>(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<T> 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;
- }
- /// <summary>
- /// 将List<T>类型转换为DataTable
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public static DataTable ToDataTable<T>(IList<T> 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;
- }
- /// <summary>
- /// 过滤查询条件表
- /// </summary>
- /// <param name="dt"></param>
- /// <param name="arr"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 计算估算重量
- /// </summary>
- /// <param name="ordernum"></param>
- /// <param name="orderunit"></param>
- /// <param name="psc"></param>
- /// <param name="ob"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 新增 修改 合同变更合同附加要求项
- /// </summary>
- /// <param name="addAskNo"></param>
- /// <param name="addAskDesc"></param>
- /// <param name="ob"></param>
- /// <param name="ordLnPk"></param>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 判断是否有效的技术要求
- /// </summary>
- /// <param name="special">产品技术要求码</param>
- /// <param name="ob"></param>
- /// <returns></returns>
- 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;
- }
- /// <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, 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);
- }
- }
- /// <summary>
- /// 初始化下拉框 --带参数的
- /// </summary>
- /// <param name="uce"></param>
- /// <param name="methodId"></param>
- /// <param name="valueMember">值成员</param>
- /// <param name="displayMember">显示成员</param>
- /// <param name="ob"></param>
- /// <param name="isEmpty"></param>
- /// <param name="obj"></param>
- 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);
- }
- }
- }
- }
|