LgChemeLementMgt.cs.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using CoreFS.CA06;
  6. using System.Data;
  7. using System.Collections;
  8. using Core.Mes.Client.Common;
  9. using Core.LgMes.Client.lgClassModel.LgChem;
  10. using Core.LgMes.Client.lgClassModel.SqModel;
  11. using Core.LgMes.Client.lgServiceMgt;
  12. using System.Text.RegularExpressions;
  13. namespace Core.LgMes.Client.lgBll.LgChemeLementMgt
  14. {
  15. public class LgChemeLementMgt
  16. {
  17. private static Core.LgMes.Client.lgServiceMgt.SqMesService.Tbb01FacIngrService tbb01FacIngrService
  18. = new Core.LgMes.Client.lgServiceMgt.SqMesService.Tbb01FacIngrService();
  19. private static Core.LgMes.Client.lgServiceMgt.LgChemeLementService.LgChemeLementService chemservice
  20. = new Core.LgMes.Client.lgServiceMgt.LgChemeLementService.LgChemeLementService();
  21. private static Core.LgMes.Client.lgServiceMgt.SqMesService.Tbb01SeqIngrService seqingrservice
  22. = new Core.LgMes.Client.lgServiceMgt.SqMesService.Tbb01SeqIngrService();
  23. /// <summary>
  24. /// 从三期获取成分标准,按2.5级限定格式
  25. /// 2.5级中的成分标准也是从三期下来的,带炉号信息
  26. /// 导致如果一炉的牌号后续如果判定变化,现有的方式不能支持显示变化后的牌号成分信息
  27. /// </summary>
  28. /// <param name="param"></param>
  29. /// <returns></returns>
  30. public static DataSet ReturnChemStandInfo(ClientParamWithSqlConditionAndOpenBase param)
  31. {
  32. return tbb01FacIngrService.ReturStandSteelChemeBySteelCode(param);
  33. }
  34. /// <summary>
  35. /// 获取成分修约数据
  36. /// </summary>
  37. /// <param name="param"></param>
  38. /// <returns></returns>
  39. public static List<TBB01_SEQ_INGR> GetTbb01SeqIngrAll(ClientParamWithSqlConditionAndOpenBase param)
  40. {
  41. return TBB01_SEQ_INGR.GetTbb01SeqIngrByDataSet(seqingrservice.ReturnDsTbb01SeqIngr(param));
  42. }
  43. /// <summary>
  44. /// 通过成分名称从修约中查找
  45. /// </summary>
  46. /// <param name="list"></param>
  47. /// <param name="chemCd"></param>
  48. /// <returns></returns>
  49. public static TBB01_SEQ_INGR GetTbb01SeqIngrByChecmCd(List<TBB01_SEQ_INGR> list, string chemCd)
  50. {
  51. TBB01_SEQ_INGR igr = null;
  52. if(list == null || list.Count == 0)
  53. {
  54. return igr;
  55. }
  56. foreach(TBB01_SEQ_INGR ingr in list)
  57. {
  58. if(ingr.CHEM_CD.ToUpper() == chemCd.ToUpper())
  59. {
  60. igr = ingr;
  61. break;
  62. }
  63. }
  64. return igr;
  65. }
  66. /// <summary>
  67. /// 炼钢放行标准
  68. /// </summary>
  69. /// <param name="param"></param>
  70. /// <returns></returns>
  71. public static List<TBB01_TAFAC_INGR> GetTbb01TafacIngrBySteelName(ClientParamWithSqlConditionAndOpenBase param)
  72. {
  73. return TBB01_TAFAC_INGR.GetTbb01TafacIngrByDataSet(tbb01FacIngrService.ReturnDsTbb01TaFacIngr(param));
  74. }
  75. /// <summary>
  76. /// 炼钢放行标准 ,自定义查询条件
  77. /// </summary>
  78. /// <param name="param"></param>
  79. /// <returns></returns>
  80. public static List<TBB01_TAFAC_INGR> GetTbb01TafacIngrBySteelCodeList(ClientParamWithSqlConditionAndOpenBase param)
  81. {
  82. ArrayList listSteelcode = param.param[0] as ArrayList;
  83. string sqlConditon = "";
  84. foreach(string s in listSteelcode)
  85. {
  86. sqlConditon += string.Format(" tafac_stl_grd = '{0}' or ", s);
  87. }
  88. sqlConditon = " and (" + sqlConditon + " 1 = 2" + ")";
  89. ClientParamWithSqlConditionAndOpenBase param01 = new ClientParamWithSqlConditionAndOpenBase(sqlConditon, param.ob);
  90. return TBB01_TAFAC_INGR.GetTbb01TafacIngrByDataSet(tbb01FacIngrService.ReturnDsTbb01TaFacIngrWithConditon(param01));
  91. }
  92. public static DataSet GetCeqChem(ClientParamWithSqlConditionAndOpenBase param)
  93. {
  94. return chemservice.ReturnDsOfChemeCeq(param);
  95. }
  96. /// <summary>
  97. /// 根据炉号和化验时间找到其对应的复合元素,并组合成hashtable返回
  98. /// </summary>
  99. /// <param name="param"></param>
  100. /// <returns></returns>
  101. public static Hashtable ReturnCeqChemByHeatNoAndAssDate(ClientParamWithSqlConditionAndOpenBase param)
  102. {
  103. Hashtable hashreturn = null;
  104. try
  105. {
  106. Hashtable hsCeq = null;
  107. hashreturn = new Hashtable();
  108. // 获取复合元素集合
  109. DataTable dt = param.param[2] as DataTable;
  110. if(dt != null && dt.Rows.Count > 0)
  111. {
  112. hsCeq = new Hashtable();
  113. // 将复合元素存入hash
  114. foreach(DataRow dr in dt.Rows)
  115. {
  116. try
  117. {
  118. hsCeq.Add(dr["CHEM_CD"].ToString(), dr["CHEM_VALUE"].ToString());
  119. }
  120. catch
  121. {
  122. }
  123. }
  124. // 将结果返回
  125. hashreturn.Add(param.param[0].ToString() + param.param[1].ToString(), hsCeq);
  126. }
  127. }
  128. catch
  129. {
  130. }
  131. return hashreturn;
  132. }
  133. /// <summary>
  134. /// 将形如格式=C+Si/30+Mn/20+Cu/20+Ni/60+Cr/20+Mo/15+V/10+5*B 分解复合要求的串,并放到数据库执行
  135. /// </summary>
  136. /// <param name="strin"></param>
  137. /// <param name="listIngr"></param>
  138. /// <returns></returns>
  139. private static string ConvertCalChemToMathRound(string strin, string chem_cd, List<TBB01_SEQ_INGR> listIngr)
  140. {
  141. //=C+Si/30+Mn/20+Cu/20+Ni/60+Cr/20+Mo/15+V/10+5*B
  142. string partten = @"[^A-Za-z0-9]"; // 替换所有非字符
  143. ArrayList list = new ArrayList();
  144. char[] strinTemp = strin.Replace("=", "").ToCharArray();
  145. string temp = "";
  146. int idxLeft = 0;
  147. int idxRight = 0;
  148. for(int i = 0; i < strinTemp.Length; i = i + idxRight)
  149. {
  150. // 非字符,直接填写
  151. temp = strinTemp[i].ToString();
  152. idxLeft = i;
  153. idxRight = 1;
  154. if(Regex.Replace(strinTemp[i].ToString(), partten, "").Length != strinTemp[i].ToString().Length)
  155. {
  156. list.Add(temp);
  157. }
  158. else
  159. {
  160. // 如果是Cu 等,往后找最多10位,并标记步长
  161. // 单一元素不考虑数字的
  162. for(int j = idxLeft + 1; j < idxLeft + 10; j++)
  163. {
  164. try
  165. {
  166. if(Regex.Replace(strinTemp[j].ToString(), partten, "").Length == strinTemp[j].ToString().Length)
  167. {
  168. // 如果都是字符
  169. temp = temp + strinTemp[j].ToString();
  170. idxRight++;
  171. }
  172. else
  173. break;
  174. }
  175. catch
  176. {
  177. }
  178. }
  179. try
  180. {
  181. // 应用数据库函数round_math
  182. if(Regex.Replace(temp, @"[^A-Za-z]", "").Length == temp.Length)
  183. {
  184. list.Add("round_math" + "(" + temp + "," + "'" + 1 / Convert.ToDouble(GetTbb01SeqIngrByChecmCd(listIngr, temp).DISPLAY_LEN) + "'" + ")");
  185. }
  186. else
  187. list.Add(temp);
  188. }
  189. catch
  190. {
  191. }
  192. }
  193. }
  194. // 组合成一个串
  195. string ret = "";
  196. foreach(string s in list)
  197. {
  198. ret += s;
  199. }
  200. // 对复合元素也要应用修约
  201. ret = "round_math(substr(" + ret + ",1,6" + ")" + "," + "'" + 1 / Convert.ToDouble(GetTbb01SeqIngrByChecmCd(listIngr, chem_cd).DISPLAY_LEN) + "'" + ")";
  202. return ret;
  203. }
  204. /// <summary>
  205. /// 获取所有的复和成分元素列表
  206. /// </summary>
  207. /// <returns></returns>
  208. public static ArrayList GetAllCeqChemByUpperChar(ClientParamWithSqlConditionAndOpenBase param)
  209. {
  210. ArrayList list = new ArrayList();
  211. List<TBB01_SEQ_INGR> listSeq = GetTbb01SeqIngrAll(param);
  212. if(listSeq == null && listSeq.Count == 0)
  213. return null;
  214. foreach(TBB01_SEQ_INGR ingr in listSeq)
  215. {
  216. if(ingr.COMP_YN == "Y")
  217. list.Add(ingr.CHEM_CD.ToUpper());
  218. }
  219. return list;
  220. }
  221. /// <summary>
  222. /// 获取修约的复合成分元素以及计算方法,并组合成hashtable
  223. /// </summary>
  224. /// <param name="param"></param>
  225. /// <returns></returns>
  226. public static Hashtable GetAllCeqChemAndValueByUpperChar(ClientParamWithSqlConditionAndOpenBase param)
  227. {
  228. Hashtable hs = new Hashtable();
  229. List<TBB01_SEQ_INGR> listSeq = GetTbb01SeqIngrAll(param);
  230. if(listSeq == null && listSeq.Count == 0)
  231. return null;
  232. foreach(TBB01_SEQ_INGR ingr in listSeq)
  233. {
  234. if(ingr.COMP_YN == "Y")
  235. hs.Add(ingr.CHEM_CD.ToUpper(), ingr.COMP_CAL);
  236. }
  237. return hs;
  238. }
  239. /// <summary>
  240. /// 获取一个牌号对应的复合成分
  241. /// </summary>
  242. /// <param name="param"></param>
  243. /// <returns></returns>
  244. public static ArrayList GetCeqBySteelCode(ClientParamWithSqlConditionAndOpenBase param)
  245. {
  246. ArrayList listCeq = new ArrayList();
  247. try
  248. {
  249. string steelCode = param.sqlCondition;
  250. List<TBB01_TAFAC_INGR> listTafac = GetTbb01TafacIngrBySteelName(new ClientParamWithSqlConditionAndOpenBase(steelCode, param.ob));
  251. if(listTafac != null && listTafac.Count > 0)
  252. {
  253. foreach(TBB01_TAFAC_INGR tbbt in listTafac)
  254. {
  255. if(tbbt.COMP_YN == "Y")
  256. listCeq.Add(tbbt.CHEM_CD);
  257. }
  258. }
  259. }
  260. catch
  261. {
  262. }
  263. return listCeq;
  264. }
  265. /// <summary>
  266. ///
  267. /// </summary>
  268. /// <param name="param"></param>
  269. /// <returns></returns>
  270. public static ArrayList GetCeqBySteelCode(string steelCode, List<TBB01_TAFAC_INGR> listTafac)
  271. {
  272. ArrayList listCeq = new ArrayList();
  273. try
  274. {
  275. if(listTafac != null && listTafac.Count > 0)
  276. {
  277. foreach(TBB01_TAFAC_INGR tbbt in listTafac)
  278. {
  279. if(tbbt.TAFAC_STL_GRD == steelCode)
  280. {
  281. if(tbbt.COMP_YN == "Y")
  282. listCeq.Add(tbbt.CHEM_CD);
  283. }
  284. }
  285. }
  286. }
  287. catch
  288. {
  289. }
  290. return listCeq;
  291. }
  292. /// <summary>
  293. /// 扫描每天成分数据,并计算复合成分,写入表stl_chemelement_ceq
  294. /// </summary>
  295. /// <param name="param"></param>
  296. public static void Insert_StlChemelementCeq(ClientParamWithSqlConditionAndOpenBase param)
  297. {
  298. // 获取所有复合成分元素
  299. try
  300. {
  301. string steelCode = "";
  302. ClientParamWithSqlConditionAndOpenBase param01 = null;
  303. List<TBB01_SEQ_INGR> listSeq = GetTbb01SeqIngrAll(param);
  304. Hashtable hsChemList = GetAllCeqChemAndValueByUpperChar(param);
  305. List<TBB01_TAFAC_INGR> listTafac = null;
  306. ArrayList listsel = null;
  307. ArrayList listselCode = new ArrayList();
  308. string startDate = string.Format(" and assaydate >= to_date('{0}','yyyy-mm-dd hh24:mi:ss') - 1 ", param.param[0].ToString());
  309. string endDate = string.Format(" and assaydate < to_date('{0}','yyyy-mm-dd hh24:mi:ss') + 1 ", param.param[1].ToString());
  310. ClientParamWithSqlConditionAndOpenBase param02 = new ClientParamWithSqlConditionAndOpenBase();
  311. param02.param = new object[] { string.Format(" to_date('{0}','yyyy-mm-dd hh24:mi:ss') - 1",param.param[0].ToString()),
  312. string.Format(" to_date('{0}','yyyy-mm-dd hh24:mi:ss') +1",param.param[1].ToString()) };
  313. param02.ob = param.ob;
  314. // 需查找一个牌号对应的复合元素,否则会有计算错误
  315. DataSet dsSteelCode = chemservice.ReturnDsOfChemeByAssayDate(param02);
  316. foreach(DataRow dr in dsSteelCode.Tables[0].Rows)
  317. {
  318. steelCode = dr["STEELNAME"].ToString();
  319. if(steelCode.Length == 0)
  320. continue;
  321. if(listselCode.Contains(steelCode))
  322. {
  323. continue;
  324. }
  325. listselCode.Add(steelCode);
  326. }
  327. if(listselCode.Count > 0)
  328. {
  329. listTafac = GetTbb01TafacIngrBySteelCodeList(new ClientParamWithSqlConditionAndOpenBase(new object[] { listselCode }, param.ob));
  330. foreach(string steelCodes in listselCode)
  331. {
  332. listsel = GetCeqBySteelCode(steelCodes, listTafac);
  333. foreach(string strCeq in listsel)
  334. {
  335. try
  336. {
  337. param01 = new ClientParamWithSqlConditionAndOpenBase();
  338. param01.param = new object[] { strCeq, ConvertCalChemToMathRound(hsChemList[strCeq.ToUpper()].ToString(), strCeq, listSeq), steelCodes, startDate + endDate };
  339. param01.ob = param.ob;
  340. chemservice.StlChemelementCeqByAssaydate_Insert(param01);
  341. }
  342. catch(Exception ex)
  343. {
  344. }
  345. }
  346. }
  347. }
  348. }
  349. catch(Exception ex)
  350. {
  351. }
  352. }
  353. }
  354. }