OrderFunction.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.ComponentModel;
  7. using System.Windows.Forms;
  8. using System.Reflection;
  9. using System.IO;
  10. using CoreFS.CA06;
  11. using System.Collections;
  12. using Core.Mes.Client.Comm.Server;
  13. using Infragistics.Win.UltraWinEditors;
  14. namespace Core.StlMes.Client.SaleOrder
  15. {
  16. /// <summary>
  17. /// 合同公共方法
  18. /// </summary>
  19. public static class OrderFunction
  20. {
  21. /// <summary>
  22. /// (成品接箍)单个重
  23. /// </summary>
  24. /// <param name="dubWeight">单个重(吨)</param>
  25. /// <param name="strProduc_code">产品码</param>
  26. /// <param name="strStd_code">标准号</param>
  27. /// <param name="strStd_style">标准类别</param>
  28. /// <param name="strSteelcode">钢级代码</param>
  29. /// <param name="strSpec_code">规格代码</param>
  30. /// <param name="strModel_code">扣型代码</param>
  31. 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)
  32. {
  33. double dubTempWeight= 0;
  34. 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);
  35. if (dt != null && dt.Rows.Count > 0)
  36. {
  37. dubTempWeight = Convert.ToDouble(dt.Rows[0][0].ToString());
  38. }
  39. else
  40. {
  41. dubTempWeight = 0.003;
  42. }
  43. dubWeight = dubTempWeight;
  44. }
  45. /// <summary>
  46. /// 估算重量公式
  47. /// </summary>
  48. /// <param name="dhweight">计算后的订货重量</param>
  49. /// <param name="ordernum">订货量</param>
  50. /// <param name="orderunit">订货单位</param>
  51. /// <param name="ob">WebService</param>
  52. /// <param name="ob">产品规格编码</param>
  53. public static void GetPrdctWgt(ref double dhweight, double ordernum, string orderunit, string psc, OpeBase ob)
  54. {
  55. double orderwgt = 0; //米单重
  56. ArrayList parm = new ArrayList();
  57. //代表 米单重(数据来源于COM_BASE_SPEC表,通过产品规格编码获取,需要除以1000,将“公斤”转换成“吨”)
  58. //2015-06-17修改 基础数据维护公式计算,已将数据单位 米/吨。
  59. if (orderunit == "米" || orderunit == "毫米" || orderunit == "英尺")
  60. {
  61. //查询数据库
  62. DataTable dataWgt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.GetWeiGht", new Object[] { psc }, ob);
  63. if (dataWgt.Rows.Count > 0)
  64. {
  65. string di = dataWgt.Rows[0][0].ToString(); //外径
  66. string he = dataWgt.Rows[0][1].ToString(); //壁厚
  67. string ty = dataWgt.Rows[0][2].ToString(); //类型(A钢管(必须要填外径壁厚)、B管坯(只允许填外径)
  68. string fomula = ""; //公式
  69. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getBaseCode4052", null, ob);
  70. for (int i = 0; i < dt.Rows.Count; i++)
  71. {
  72. if (dt.Rows[i][1].ToString().Equals(ty))
  73. {
  74. fomula = dt.Rows[i][0].ToString();
  75. break;
  76. }
  77. }
  78. if (!fomula.Equals(""))
  79. {
  80. fomula = fomula.Replace("外径", di);
  81. fomula = fomula.Replace("壁厚", he);
  82. decimal? result = fomula.CompileFormula();
  83. if (result != null)
  84. orderwgt = (double)result;
  85. else
  86. {
  87. MessageBox.Show("质量管理-基础信息维护的米单重公式不合法!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  88. return;
  89. }
  90. }
  91. }
  92. //orderwgt = Convert.ToDouble(dataWgt.Rows[0][0]);
  93. }
  94. if (orderunit == "吨")
  95. {
  96. dhweight = ordernum;
  97. }
  98. else if (orderunit == "英镑")
  99. {
  100. dhweight = Convert.ToDouble(ordernum * 0.45359237);
  101. }
  102. else if (orderunit == "米")
  103. {
  104. if (orderwgt == 0)
  105. orderwgt = 1;
  106. dhweight = (ordernum * orderwgt);
  107. }
  108. else if (orderunit == "毫米")
  109. {
  110. if (orderwgt == 0)
  111. orderwgt = 1;
  112. dhweight = (ordernum * orderwgt) / 1000;
  113. }
  114. else if (orderunit == "英尺")
  115. {
  116. if (orderwgt == 0)
  117. orderwgt = 1;
  118. dhweight = Convert.ToDouble(ordernum * 0.3048 * Convert.ToDouble(orderwgt));
  119. }
  120. else if (orderunit == "支")
  121. {
  122. dhweight = ordernum;
  123. }
  124. else if (orderunit == "个")
  125. {
  126. dhweight = ordernum;
  127. }
  128. }
  129. /// <summary>
  130. /// 实体类间相同字段的值复制
  131. /// </summary>将fromEntity赋给toEntity
  132. /// <param name="fromTable"></param>
  133. /// <param name="toTable"></param>
  134. public static void copyValue(object fromEntity, object toEntity)
  135. {
  136. foreach (PropertyInfo info in fromEntity.GetType().GetProperties())
  137. {
  138. if (info.CanRead)
  139. {
  140. object o = info.GetValue(fromEntity, null);
  141. PropertyInfo column = toEntity.GetType().GetProperty(info.Name);
  142. if (column != null && column.CanWrite)
  143. column.SetValue(toEntity, o, null);
  144. }
  145. }
  146. }
  147. /// <summary>
  148. /// 将DataTable转换成对应的List集合
  149. /// </summary>
  150. /// <typeparam name="T"></typeparam>
  151. /// <param name="table"></param>
  152. /// <returns></returns>
  153. public static List<T> ConvertToList<T>(this DataTable table) where T : new()
  154. {
  155. Type t = typeof(T);
  156. //Create a list of the entities we want to return
  157. List<T> returnObject = new List<T>();
  158. //Iterate through the DataTable's rows
  159. foreach (DataRow dr in table.Rows)
  160. {
  161. //Convert each row into an entity object and add to the list
  162. T newRow = dr.ConvertToEntity<T>();
  163. returnObject.Add(newRow);
  164. }
  165. //Return the finished list
  166. return returnObject;
  167. }
  168. /// <summary>
  169. /// 将DataRow转换成对应的Entity集合
  170. /// </summary>
  171. /// <typeparam name="T"></typeparam>
  172. /// <param name="tableRow"></param>
  173. /// <returns></returns>
  174. public static T ConvertToEntity<T>(this DataRow tableRow) where T : new()
  175. {
  176. //Create a new type of the entity I want
  177. Type t = typeof(T);
  178. T returnObject = new T();
  179. foreach (DataColumn col in tableRow.Table.Columns)
  180. {
  181. string colName = col.ColumnName;
  182. //Look for the object's property with the columns name, ignore case
  183. PropertyInfo pInfo = t.GetProperty(colName.ToLower(), BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
  184. //did we find the property ?
  185. if (pInfo != null)
  186. {
  187. object val = tableRow[colName];
  188. //is this a Nullable<> type
  189. bool IsNullable = (Nullable.GetUnderlyingType(pInfo.PropertyType) != null);
  190. if (IsNullable)
  191. {
  192. if (val is System.DBNull)
  193. {
  194. val = null;
  195. }
  196. else
  197. {
  198. // Convert the db type into the T we have in our Nullable<T> type
  199. val = Convert.ChangeType(val, Nullable.GetUnderlyingType(pInfo.PropertyType));
  200. }
  201. }
  202. else
  203. {
  204. if (pInfo.PropertyType.FullName == "System.Byte[]")
  205. {
  206. if (val is System.DBNull)
  207. {
  208. val = null;
  209. }
  210. }
  211. else
  212. {
  213. //Convert the db type into the type of the property in our entity
  214. val = Convert.ChangeType(val, pInfo.PropertyType);
  215. }
  216. }
  217. //Set the value of the property with the value from the db
  218. pInfo.SetValue(returnObject, val, null);
  219. }
  220. }
  221. // return the entity object with values
  222. return returnObject;
  223. }
  224. /// <summary>
  225. /// 将List<T>类型转换为DataTable
  226. /// </summary>
  227. /// <param name="data"></param>
  228. /// <returns></returns>
  229. public static DataTable ToDataTable<T>(IList<T> list)
  230. {
  231. DataTable dt = new DataTable();
  232. dt.TableName = "table1";
  233. // 通过使用反射来获取列表中队形的属性
  234. BindingFlags bf = BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty;
  235. PropertyInfo[] props = list.GetType().GetGenericArguments()[0].GetProperties();
  236. //PropertyInfo[] props = list[0].GetType().GetProperties();
  237. foreach (PropertyInfo pi in props)
  238. {
  239. if (!pi.PropertyType.Name.Equals(typeof(Nullable<>).Name))
  240. {
  241. dt.Columns.Add(pi.Name, Type.GetType(pi.PropertyType.FullName));
  242. }
  243. else
  244. {
  245. dt.Columns.Add(pi.Name, Type.GetType(pi.PropertyType.GetGenericArguments()[0].FullName));
  246. }
  247. }
  248. if (list != null && list.Count > 0)
  249. {
  250. foreach (object obj in list)
  251. {
  252. DataRow dr = dt.NewRow();
  253. foreach (PropertyInfo pi in props)
  254. {
  255. object result = obj.GetType().InvokeMember(pi.Name, bf, null, obj, null);
  256. // d.Add(result);
  257. if (result != null)
  258. {
  259. dr[pi.Name] = result;
  260. }
  261. else
  262. {
  263. dr[pi.Name] = DBNull.Value;
  264. }
  265. }
  266. dt.Rows.Add(dr);
  267. }
  268. }
  269. return dt;
  270. }
  271. /// <summary>
  272. /// 过滤查询条件表
  273. /// </summary>
  274. /// <param name="dt"></param>
  275. /// <param name="arr"></param>
  276. /// <returns></returns>
  277. public static DataTable FilterDataTable(DataTable dt, string[] arr)
  278. {
  279. for (int i = 0; i < dt.Rows.Count; i++)
  280. {
  281. if (!arr.Contains(dt.Rows[i][1].ToString()))
  282. {
  283. DataRow dr = dt.Rows[i];
  284. dt.Rows.Remove(dr);
  285. i--;
  286. }
  287. }
  288. return dt;
  289. }
  290. /// <summary>
  291. /// 计算估算重量
  292. /// </summary>
  293. /// <param name="ordernum"></param>
  294. /// <param name="orderunit"></param>
  295. /// <param name="psc"></param>
  296. /// <param name="ob"></param>
  297. /// <returns></returns>
  298. public static decimal GetPrdctWgtNew(decimal ordernum, string orderunit, string psc, OpeBase ob)
  299. {
  300. decimal orderwgt = 0; //米单重
  301. decimal dhweight = 0;
  302. ArrayList parm = new ArrayList();
  303. //代表 米单重(数据来源于COM_BASE_SPEC表,通过产品规格编码获取,需要除以1000,将“公斤”转换成“吨”)
  304. //2015-06-17修改 基础数据维护公式计算,已将数据单位 米/吨。
  305. if (orderunit == "米" || orderunit == "毫米" || orderunit == "英尺")
  306. {
  307. //查询数据库
  308. DataTable dataWgt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.GetWeiGht", new Object[] { psc }, ob);
  309. if (dataWgt.Rows.Count > 0)
  310. {
  311. string di = dataWgt.Rows[0][0].ToString(); //外径
  312. string he = dataWgt.Rows[0][1].ToString(); //壁厚
  313. string ty = dataWgt.Rows[0][2].ToString(); //类型(A钢管(必须要填外径壁厚)、B管坯(只允许填外径)
  314. string fomula = ""; //公式
  315. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getBaseCode4052", null, ob);
  316. for (int i = 0; i < dt.Rows.Count; i++)
  317. {
  318. if (dt.Rows[i][1].ToString().Equals(ty))
  319. {
  320. fomula = dt.Rows[i][0].ToString();
  321. break;
  322. }
  323. }
  324. if (!fomula.Equals(""))
  325. {
  326. fomula = fomula.Replace("外径", di);
  327. fomula = fomula.Replace("壁厚", he);
  328. decimal? result = fomula.CompileFormula();
  329. if (result != null)
  330. orderwgt = (decimal)result;
  331. else
  332. {
  333. MessageBox.Show("质量管理-基础信息维护的米单重公式不合法!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  334. return 0;
  335. }
  336. }
  337. }
  338. //orderwgt = Convert.ToDouble(dataWgt.Rows[0][0]);
  339. }
  340. if (orderunit == "吨")
  341. {
  342. dhweight = ordernum;
  343. }
  344. else if (orderunit == "英镑")
  345. {
  346. dhweight = Convert.ToDecimal(ordernum * Convert.ToDecimal(0.45359237));
  347. }
  348. else if (orderunit == "米")
  349. {
  350. dhweight = (ordernum * orderwgt);
  351. }
  352. else if (orderunit == "毫米")
  353. {
  354. dhweight = (ordernum * orderwgt) / 1000;
  355. }
  356. else if (orderunit == "英尺")
  357. {
  358. dhweight = Convert.ToDecimal(ordernum * Convert.ToDecimal(0.3048) * Convert.ToDecimal(orderwgt));
  359. }
  360. else if (orderunit == "支")
  361. {
  362. dhweight = ordernum;
  363. }
  364. else if (orderunit == "个")
  365. {
  366. dhweight = ordernum;
  367. }
  368. return dhweight;
  369. }
  370. /// <summary>
  371. /// 新增 修改 合同变更合同附加要求项
  372. /// </summary>
  373. /// <param name="addAskNo"></param>
  374. /// <param name="addAskDesc"></param>
  375. /// <param name="ob"></param>
  376. /// <param name="ordLnPk"></param>
  377. /// <returns></returns>
  378. public static string IsSameAddAsk(string addAskNo, string addAskDesc, OpeBase ob, string ordLnPk)
  379. {
  380. string errMsg = "";
  381. if (addAskNo == "")
  382. return errMsg;
  383. if (ordLnPk == null || ordLnPk == "")
  384. ordLnPk = "1";
  385. DataTable validDt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getValidAddAskNo", new object[] { addAskNo }, ob);
  386. if (validDt != null && validDt.Rows.Count > 0)
  387. {
  388. //addAskNo 有效
  389. }
  390. else
  391. {
  392. errMsg = "附加要求码" + addAskNo + "已经被作废,请重新选择附加要求!";
  393. return errMsg;
  394. }
  395. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getOrderAddAskDesc", new object[] { addAskNo, ordLnPk }, ob);
  396. if (dt != null && dt.Rows.Count > 0)
  397. {
  398. if (dt.Rows.Count >= 2)
  399. {
  400. string[] addAskDescs = dt.Rows[0]["ORDER_ADD_DESC"].ToString().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
  401. Array.Sort(addAskDescs);
  402. for (int i = 1; i < dt.Rows.Count; i++)
  403. {
  404. string[] addAskDescs2 = dt.Rows[i]["ORDER_ADD_DESC"].ToString().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
  405. Array.Sort(addAskDescs2);
  406. if (string.Join("", addAskDescs) != string.Join("", addAskDescs2))
  407. {
  408. errMsg = addAskNo + "在数据库中存在" + dt.Rows.Count + "套不同的附加要求描述";
  409. return errMsg;
  410. }
  411. }
  412. return errMsg;
  413. }
  414. else
  415. {
  416. //dt.Rows[0][0].ToString().Replace('\r', '\u0000').Replace('\n', '\u0000')
  417. string[] addAskDescs = addAskDesc.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
  418. Array.Sort(addAskDescs);
  419. string[] ordLnAddAskDescs = dt.Rows[0][0].ToString().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
  420. Array.Sort(ordLnAddAskDescs);
  421. bool isSame = true;
  422. for (int i = 0; i < addAskDescs.Length; i++)
  423. {
  424. if (addAskDescs[i] != ordLnAddAskDescs[i])
  425. {
  426. isSame = false;
  427. break;
  428. }
  429. }
  430. if (isSame)
  431. {
  432. return errMsg;
  433. }
  434. else
  435. {
  436. errMsg = "您所选择的附加要求描述已改变,请重新选择!";
  437. return errMsg;
  438. }
  439. //if (addAskDesc.Replace("\n", "").Replace("\r", "") == dt.Rows[0][0].ToString().Replace("\n", "").Replace("\r", ""))
  440. //{
  441. // return errMsg;
  442. //}
  443. //else
  444. //{
  445. // errMsg = "您所选择的附加要求描述已改变,请重新选择!";
  446. // return errMsg;
  447. //}
  448. }
  449. }
  450. else
  451. {
  452. return errMsg;
  453. }
  454. }
  455. /// <summary>
  456. /// 判断是否有效的技术要求
  457. /// </summary>
  458. /// <param name="special">产品技术要求码</param>
  459. /// <param name="ob"></param>
  460. /// <returns></returns>
  461. public static string IsValidSpecialCode(string special, OpeBase ob)
  462. {
  463. string errMsg = "";
  464. if (special == "")
  465. return errMsg;
  466. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderManager.getValidSpecial", new object[] { special }, ob);
  467. if (dt != null && dt.Rows.Count > 0)
  468. {
  469. //技术要求有效可以保存
  470. }
  471. else
  472. {
  473. errMsg = "技术要求" + special + "已经被作废,请重新选择技术要求";
  474. return errMsg;
  475. }
  476. return errMsg;
  477. }
  478. /// <summary>
  479. /// 初始化下拉框
  480. /// </summary>
  481. /// <param name="uce">下拉框</param>
  482. /// <param name="methodId">请求的服务</param>
  483. /// <param name="valueMember">值成员</param>
  484. /// <param name="ob">ob对象</param>
  485. /// <param name="isEmpty">是否有空行</param>
  486. public static void InitComboEditor(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty)
  487. {
  488. DataTable dt = ServerHelper.GetData(methodId, null, ob);
  489. if (dt != null && dt.Rows.Count > 0)
  490. {
  491. if (isEmpty)
  492. {
  493. Object[] obj = new Object[] { "", "" };
  494. DataRow dr = dt.NewRow();
  495. dr.ItemArray = obj;
  496. dt.Rows.InsertAt(dr, 0);
  497. }
  498. uce.DataSource = dt;
  499. uce.ValueMember = valueMember;
  500. ClsBaseInfo.SetComboItemHeight(uce);
  501. }
  502. }
  503. /// <summary>
  504. /// 初始化下拉框 --带参数的
  505. /// </summary>
  506. /// <param name="uce"></param>
  507. /// <param name="methodId"></param>
  508. /// <param name="valueMember">值成员</param>
  509. /// <param name="displayMember">显示成员</param>
  510. /// <param name="ob"></param>
  511. /// <param name="isEmpty"></param>
  512. /// <param name="obj"></param>
  513. public static void InitComboEditorWithParm(UltraComboEditor uce, string methodId, string valueMember,string displayMember, OpeBase ob, bool isEmpty, Object[] parm)
  514. {
  515. DataTable dt = ServerHelper.GetData(methodId, parm, ob);
  516. if (dt != null && dt.Rows.Count > 0)
  517. {
  518. if (isEmpty)
  519. {
  520. Object[] obj = new Object[] { "", "" };
  521. DataRow dr = dt.NewRow();
  522. dr.ItemArray = obj;
  523. dt.Rows.InsertAt(dr, 0);
  524. }
  525. uce.DataSource = dt;
  526. uce.ValueMember = valueMember;
  527. uce.DisplayMember = displayMember;
  528. ClsBaseInfo.SetComboItemHeight(uce);
  529. }
  530. }
  531. }
  532. }