| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using CoreFS.CA06;
- using System.Data;
- using System.Collections;
- using Core.Mes.Client.Common;
- using Core.LgMes.Client.lgClassModel.LgChem;
- using Core.LgMes.Client.lgClassModel.SqModel;
- using Core.LgMes.Client.lgServiceMgt;
- using System.Text.RegularExpressions;
- namespace Core.LgMes.Client.lgBll.LgChemeLementMgt
- {
- public class LgChemeLementMgt
- {
- private static Core.LgMes.Client.lgServiceMgt.SqMesService.Tbb01FacIngrService tbb01FacIngrService
- = new Core.LgMes.Client.lgServiceMgt.SqMesService.Tbb01FacIngrService();
- private static Core.LgMes.Client.lgServiceMgt.LgChemeLementService.LgChemeLementService chemservice
- = new Core.LgMes.Client.lgServiceMgt.LgChemeLementService.LgChemeLementService();
- private static Core.LgMes.Client.lgServiceMgt.SqMesService.Tbb01SeqIngrService seqingrservice
- = new Core.LgMes.Client.lgServiceMgt.SqMesService.Tbb01SeqIngrService();
- /// <summary>
- /// 从三期获取成分标准,按2.5级限定格式
- /// 2.5级中的成分标准也是从三期下来的,带炉号信息
- /// 导致如果一炉的牌号后续如果判定变化,现有的方式不能支持显示变化后的牌号成分信息
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- public static DataSet ReturnChemStandInfo(ClientParamWithSqlConditionAndOpenBase param)
- {
- return tbb01FacIngrService.ReturStandSteelChemeBySteelCode(param);
- }
- /// <summary>
- /// 获取成分修约数据
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- public static List<TBB01_SEQ_INGR> GetTbb01SeqIngrAll(ClientParamWithSqlConditionAndOpenBase param)
- {
- return TBB01_SEQ_INGR.GetTbb01SeqIngrByDataSet(seqingrservice.ReturnDsTbb01SeqIngr(param));
- }
- /// <summary>
- /// 通过成分名称从修约中查找
- /// </summary>
- /// <param name="list"></param>
- /// <param name="chemCd"></param>
- /// <returns></returns>
- public static TBB01_SEQ_INGR GetTbb01SeqIngrByChecmCd(List<TBB01_SEQ_INGR> list, string chemCd)
- {
- TBB01_SEQ_INGR igr = null;
- if(list == null || list.Count == 0)
- {
- return igr;
- }
- foreach(TBB01_SEQ_INGR ingr in list)
- {
- if(ingr.CHEM_CD.ToUpper() == chemCd.ToUpper())
- {
- igr = ingr;
- break;
- }
- }
- return igr;
- }
- /// <summary>
- /// 炼钢放行标准
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- public static List<TBB01_TAFAC_INGR> GetTbb01TafacIngrBySteelName(ClientParamWithSqlConditionAndOpenBase param)
- {
- return TBB01_TAFAC_INGR.GetTbb01TafacIngrByDataSet(tbb01FacIngrService.ReturnDsTbb01TaFacIngr(param));
- }
- /// <summary>
- /// 炼钢放行标准 ,自定义查询条件
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- public static List<TBB01_TAFAC_INGR> GetTbb01TafacIngrBySteelCodeList(ClientParamWithSqlConditionAndOpenBase param)
- {
- ArrayList listSteelcode = param.param[0] as ArrayList;
- string sqlConditon = "";
- foreach(string s in listSteelcode)
- {
- sqlConditon += string.Format(" tafac_stl_grd = '{0}' or ", s);
- }
- sqlConditon = " and (" + sqlConditon + " 1 = 2" + ")";
- ClientParamWithSqlConditionAndOpenBase param01 = new ClientParamWithSqlConditionAndOpenBase(sqlConditon, param.ob);
- return TBB01_TAFAC_INGR.GetTbb01TafacIngrByDataSet(tbb01FacIngrService.ReturnDsTbb01TaFacIngrWithConditon(param01));
- }
- public static DataSet GetCeqChem(ClientParamWithSqlConditionAndOpenBase param)
- {
- return chemservice.ReturnDsOfChemeCeq(param);
- }
- /// <summary>
- /// 根据炉号和化验时间找到其对应的复合元素,并组合成hashtable返回
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- public static Hashtable ReturnCeqChemByHeatNoAndAssDate(ClientParamWithSqlConditionAndOpenBase param)
- {
- Hashtable hashreturn = null;
- try
- {
- Hashtable hsCeq = null;
- hashreturn = new Hashtable();
- // 获取复合元素集合
- DataTable dt = param.param[2] as DataTable;
- if(dt != null && dt.Rows.Count > 0)
- {
- hsCeq = new Hashtable();
- // 将复合元素存入hash
- foreach(DataRow dr in dt.Rows)
- {
- try
- {
- hsCeq.Add(dr["CHEM_CD"].ToString(), dr["CHEM_VALUE"].ToString());
- }
- catch
- {
- }
- }
- // 将结果返回
- hashreturn.Add(param.param[0].ToString() + param.param[1].ToString(), hsCeq);
- }
- }
- catch
- {
- }
- return hashreturn;
- }
- /// <summary>
- /// 将形如格式=C+Si/30+Mn/20+Cu/20+Ni/60+Cr/20+Mo/15+V/10+5*B 分解复合要求的串,并放到数据库执行
- /// </summary>
- /// <param name="strin"></param>
- /// <param name="listIngr"></param>
- /// <returns></returns>
- private static string ConvertCalChemToMathRound(string strin, string chem_cd, List<TBB01_SEQ_INGR> listIngr)
- {
- //=C+Si/30+Mn/20+Cu/20+Ni/60+Cr/20+Mo/15+V/10+5*B
- string partten = @"[^A-Za-z0-9]"; // 替换所有非字符
- ArrayList list = new ArrayList();
- char[] strinTemp = strin.Replace("=", "").ToCharArray();
- string temp = "";
- int idxLeft = 0;
- int idxRight = 0;
- for(int i = 0; i < strinTemp.Length; i = i + idxRight)
- {
- // 非字符,直接填写
- temp = strinTemp[i].ToString();
- idxLeft = i;
- idxRight = 1;
- if(Regex.Replace(strinTemp[i].ToString(), partten, "").Length != strinTemp[i].ToString().Length)
- {
- list.Add(temp);
- }
- else
- {
- // 如果是Cu 等,往后找最多10位,并标记步长
- // 单一元素不考虑数字的
- for(int j = idxLeft + 1; j < idxLeft + 10; j++)
- {
- try
- {
- if(Regex.Replace(strinTemp[j].ToString(), partten, "").Length == strinTemp[j].ToString().Length)
- {
- // 如果都是字符
- temp = temp + strinTemp[j].ToString();
- idxRight++;
- }
- else
- break;
- }
- catch
- {
- }
- }
- try
- {
- // 应用数据库函数round_math
- if(Regex.Replace(temp, @"[^A-Za-z]", "").Length == temp.Length)
- {
- list.Add("round_math" + "(" + temp + "," + "'" + 1 / Convert.ToDouble(GetTbb01SeqIngrByChecmCd(listIngr, temp).DISPLAY_LEN) + "'" + ")");
- }
- else
- list.Add(temp);
- }
- catch
- {
- }
- }
- }
- // 组合成一个串
- string ret = "";
- foreach(string s in list)
- {
- ret += s;
- }
- // 对复合元素也要应用修约
- ret = "round_math(substr(" + ret + ",1,6" + ")" + "," + "'" + 1 / Convert.ToDouble(GetTbb01SeqIngrByChecmCd(listIngr, chem_cd).DISPLAY_LEN) + "'" + ")";
- return ret;
- }
- /// <summary>
- /// 获取所有的复和成分元素列表
- /// </summary>
- /// <returns></returns>
- public static ArrayList GetAllCeqChemByUpperChar(ClientParamWithSqlConditionAndOpenBase param)
- {
- ArrayList list = new ArrayList();
- List<TBB01_SEQ_INGR> listSeq = GetTbb01SeqIngrAll(param);
- if(listSeq == null && listSeq.Count == 0)
- return null;
- foreach(TBB01_SEQ_INGR ingr in listSeq)
- {
- if(ingr.COMP_YN == "Y")
- list.Add(ingr.CHEM_CD.ToUpper());
- }
- return list;
- }
- /// <summary>
- /// 获取修约的复合成分元素以及计算方法,并组合成hashtable
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- public static Hashtable GetAllCeqChemAndValueByUpperChar(ClientParamWithSqlConditionAndOpenBase param)
- {
- Hashtable hs = new Hashtable();
- List<TBB01_SEQ_INGR> listSeq = GetTbb01SeqIngrAll(param);
- if(listSeq == null && listSeq.Count == 0)
- return null;
- foreach(TBB01_SEQ_INGR ingr in listSeq)
- {
- if(ingr.COMP_YN == "Y")
- hs.Add(ingr.CHEM_CD.ToUpper(), ingr.COMP_CAL);
- }
- return hs;
- }
- /// <summary>
- /// 获取一个牌号对应的复合成分
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- public static ArrayList GetCeqBySteelCode(ClientParamWithSqlConditionAndOpenBase param)
- {
- ArrayList listCeq = new ArrayList();
- try
- {
- string steelCode = param.sqlCondition;
- List<TBB01_TAFAC_INGR> listTafac = GetTbb01TafacIngrBySteelName(new ClientParamWithSqlConditionAndOpenBase(steelCode, param.ob));
- if(listTafac != null && listTafac.Count > 0)
- {
- foreach(TBB01_TAFAC_INGR tbbt in listTafac)
- {
- if(tbbt.COMP_YN == "Y")
- listCeq.Add(tbbt.CHEM_CD);
- }
- }
- }
- catch
- {
- }
- return listCeq;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- public static ArrayList GetCeqBySteelCode(string steelCode, List<TBB01_TAFAC_INGR> listTafac)
- {
- ArrayList listCeq = new ArrayList();
- try
- {
- if(listTafac != null && listTafac.Count > 0)
- {
- foreach(TBB01_TAFAC_INGR tbbt in listTafac)
- {
- if(tbbt.TAFAC_STL_GRD == steelCode)
- {
- if(tbbt.COMP_YN == "Y")
- listCeq.Add(tbbt.CHEM_CD);
- }
- }
- }
- }
- catch
- {
- }
- return listCeq;
- }
- /// <summary>
- /// 扫描每天成分数据,并计算复合成分,写入表stl_chemelement_ceq
- /// </summary>
- /// <param name="param"></param>
- public static void Insert_StlChemelementCeq(ClientParamWithSqlConditionAndOpenBase param)
- {
- // 获取所有复合成分元素
- try
- {
- string steelCode = "";
- ClientParamWithSqlConditionAndOpenBase param01 = null;
- List<TBB01_SEQ_INGR> listSeq = GetTbb01SeqIngrAll(param);
- Hashtable hsChemList = GetAllCeqChemAndValueByUpperChar(param);
- List<TBB01_TAFAC_INGR> listTafac = null;
- ArrayList listsel = null;
- ArrayList listselCode = new ArrayList();
- string startDate = string.Format(" and assaydate >= to_date('{0}','yyyy-mm-dd hh24:mi:ss') - 1 ", param.param[0].ToString());
- string endDate = string.Format(" and assaydate < to_date('{0}','yyyy-mm-dd hh24:mi:ss') + 1 ", param.param[1].ToString());
- ClientParamWithSqlConditionAndOpenBase param02 = new ClientParamWithSqlConditionAndOpenBase();
- param02.param = new object[] { string.Format(" to_date('{0}','yyyy-mm-dd hh24:mi:ss') - 1",param.param[0].ToString()),
- string.Format(" to_date('{0}','yyyy-mm-dd hh24:mi:ss') +1",param.param[1].ToString()) };
- param02.ob = param.ob;
- // 需查找一个牌号对应的复合元素,否则会有计算错误
- DataSet dsSteelCode = chemservice.ReturnDsOfChemeByAssayDate(param02);
- foreach(DataRow dr in dsSteelCode.Tables[0].Rows)
- {
- steelCode = dr["STEELNAME"].ToString();
- if(steelCode.Length == 0)
- continue;
- if(listselCode.Contains(steelCode))
- {
- continue;
- }
- listselCode.Add(steelCode);
- }
- if(listselCode.Count > 0)
- {
- listTafac = GetTbb01TafacIngrBySteelCodeList(new ClientParamWithSqlConditionAndOpenBase(new object[] { listselCode }, param.ob));
- foreach(string steelCodes in listselCode)
- {
- listsel = GetCeqBySteelCode(steelCodes, listTafac);
- foreach(string strCeq in listsel)
- {
- try
- {
- param01 = new ClientParamWithSqlConditionAndOpenBase();
- param01.param = new object[] { strCeq, ConvertCalChemToMathRound(hsChemList[strCeq.ToUpper()].ToString(), strCeq, listSeq), steelCodes, startDate + endDate };
- param01.ob = param.ob;
- chemservice.StlChemelementCeqByAssaydate_Insert(param01);
- }
- catch(Exception ex)
- {
- }
- }
- }
- }
- }
- catch(Exception ex)
- {
- }
- }
- }
- }
|