| | |
| | | using Dapper; |
| | | using Newtonsoft.Json.Linq; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | |
| | | //获取最大单据号 |
| | | if (i == 1) //首单获取工单号 |
| | | { |
| | | sql = @"select isnull(max(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code))),0)+1 as worknumb from TK_Wrk_Man where m_po=@erpordercode"; |
| | | sql = @"select isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0)+1 as worknumb |
| | | from TK_Wrk_Man where m_po=@erpordercode"; |
| | | dynamicParams.Add("@erpordercode", erpordercode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | num = Convert.ToInt32(data.Rows[0]["WORKNUMB"].ToString()); |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[MES工单新增、获取工单号] |
| | | public static ToMessage AddMesOrderCodeSearch() |
| | | { |
| | | string sql = ""; |
| | | string wo_code = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //获取单据号 |
| | | sql = @"SELECT 'SGPO'+CONVERT(varchar(12) , getdate(), 112 )+'_'+cast(isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0)+1 as varchar) as numct |
| | | FROM TK_Wrk_Man where wo_code like '%SGPO%'"; |
| | | var data = DapperHelper.selecttable(sql); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data.Rows[0]["numct"].ToString(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工,工序检验扫码获取任务信息] |
| | | public static ToMessage MesOrderStepCheckSearch(string orderstepqrcode) |
| | | |
| | | #region[工序检验扫码获取任务信息] |
| | | public static ToMessage MesOrderStepCheckSearch(string orderstepqrcode, string checktype) |
| | | { |
| | | var sql = ""; |
| | | string ordercode = ""; |
| | | string stepcode = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | Dictionary<string, object> list = new Dictionary<string, object>(); |
| | | try |
| | | { |
| | | if (orderstepqrcode != "" && orderstepqrcode != null) |
| | |
| | | stepcode = arra[1]; //获取指定字符串前面的字符 |
| | | } |
| | | //通过扫描二维码信息查找任务信息 |
| | | sql = @"select A.wo_code,M.partcode,M.partname,M.partspec,S.stepcode,S.stepname |
| | | sql = @"select A.wo_code,A.good_qty,M.partcode,M.partname,M.partspec,M.stocktype_code,S.stepcode,S.stepname |
| | | from TK_Wrk_Step A |
| | | inner join TK_Wrk_Man P on A.wo_code=P.wo_code |
| | | left join TMateriel_Info M on P.materiel_code=M.partcode |
| | |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | return mes; |
| | | if (decimal.Parse(data.Rows[0]["good_qty"].ToString()) > 0) |
| | | { |
| | | //获取绑定的质检方案、抽样方式、样本数 |
| | | sql = @"select code as checkstandcode,name as checkstandname,sampmethod,sampscare |
| | | from TStepCheckStandard |
| | | where (PATINDEX('%,' + RTRIM(@partcode) + ',%',',' + suitpart + ',')>0 or PATINDEX('%,' + RTRIM(@stocktype_code) + ',%',',' + suitpart + ',')>0) |
| | | and checktype=@checktype and stepcode=@stepcode "; |
| | | dynamicParams.Add("@partcode", data.Rows[0]["partcode"].ToString());//物料编码 |
| | | dynamicParams.Add("@stepcode", stepcode);//工序编码 |
| | | dynamicParams.Add("@stocktype_code", data.Rows[0]["stocktype_code"].ToString());//存货类型编码 |
| | | dynamicParams.Add("@checktype", checktype);//检验类型 |
| | | var data1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data1.Rows.Count > 0) |
| | | { |
| | | list.Add("labcont", data); |
| | | list.Add("chekstand", data1); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = list; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前产品【" + data.Rows[0]["partname"].ToString() + "】,对应工序【" + data.Rows[0]["stepname"].ToString() + "】,未指定质检方案!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前工序任务无报工产出!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工,工序检验获取检验标准下拉框数据] |
| | | public static ToMessage MesOrderStepCheckSelect() |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //获取工序检验标准 |
| | | sql = @"select code,name from TStepCheckStandard where is_delete<>'1'"; |
| | | var data = DapperHelper.selecttable(sql); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工,工序检验根据检验标准获取检验项目列表] |
| | | #region[工序检验根据选择的检验方案查找检验项目] |
| | | public static ToMessage MesOrderStepCheckItemList(string checkstandcode) |
| | | { |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | //根据检验标准编码获取工序检验项目 |
| | | sql = @"select B.code,B.name,A.stepcheckitem_desc,A.stepcheckitem_seq from TStepCheckStandardSub A |
| | | //质检方案编码获取检验项 |
| | | sql = @"select A.stepcheckitem_seq, B.code,B.name,A.required,A.numberjudge,A.unit,A.decimalnum, |
| | | A.standvalue,A.uppervalue,A.lowervalue,A.stepcheckitem_desc |
| | | from TStepCheckStandardSub A |
| | | left join TStepCheckItem B on A.stepcheckitem_code=B.code |
| | | where B.is_delete<>'1' and A.stepstaned_code=@checkstandcode"; |
| | | dynamicParams.Add("@checkstandcode", checkstandcode); |
| | | where A.stepstaned_code=@checkstandcode |
| | | order by A.stepcheckitem_seq"; |
| | | dynamicParams.Add("@checkstandcode", checkstandcode);//质检方案编码 |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | mes.code = "200"; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "查询成功!"; |
| | | mes.data = data; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "当前质检方案无检验项!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[生产开报工,工序检验提交保存] |
| | | public static ToMessage SaveMesOrderStepCheckItem(string mesordercode, string partcode, string stepcode, string checkstanedcode, string checkusercode, string checktypecode, string checkresult, string checkdescr, string checkqty, string username, List<StepCheck> json) |
| | | #region[工序检验,提交] |
| | | public static ToMessage SaveMesOrderStepCheckItem(string wocode, string partcode, string stepcode, string checkstandcode, string check_type, string sampmethod, string qualitystatus, string labqty, string sampleqty, string goodqty, string ngqty, string checkitemcont, string username) |
| | | { |
| | | var sql = ""; |
| | | string[] arra = new string[] { }; |
| | | string[] arra1 = new string[] { }; |
| | | List<object> list = new List<object>(); |
| | | string checktypename = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | string date = DateTime.Now.ToString(); //获取系统时间 |
| | | |
| | | string datetime = DateTime.Now.ToString(); //获取系统时间 |
| | | //获取检验项目信息 |
| | | JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(checkitemcont); |
| | | list.Clear(); |
| | | switch (checktypecode) |
| | | |
| | | //写入检验记录主表 |
| | | sql = @"insert into TStepCheckRecord(wo_code,partcode,step_code,checkstaned_code,check_user,check_type,check_typename,sampmethod,check_result,check_qty,good_qty,ng_qty,lm_user,lm_date) |
| | | values(@wo_code,@partcode,@step_code,@checkstaned_code,@check_user,@check_type,@check_typename,@sampmethod,@check_result,@check_qty,@good_qty,@ng_qty,@lm_user,@lm_date)"; |
| | | switch (check_type) |
| | | { |
| | | case "FirstCheck": |
| | | checktypename = "首检"; |
| | |
| | | default: |
| | | break; |
| | | } |
| | | //写入工序检验记录主表 |
| | | sql = @"insert into TStepCheckRecord(wo_code,partcode,step_code,checkstaned_code,check_user,check_type,check_typename,check_result,check_descr,check_qty,lm_user,lm_date) |
| | | values(@mesordercode,@partcode,@stepcode,@checkstanedcode,@checkusercode,@checktypecode,@checktypename,@checkresult,@checkdescr,@check_qty,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { mesordercode = mesordercode, partcode = partcode, stepcode = stepcode, checkstanedcode = checkstanedcode, checkusercode = checkusercode, checktypecode = checktypecode, checktypename = checktypename, checkresult = checkresult, checkdescr = checkdescr, check_qty = checkqty, lm_user = username, lm_date = date } }); |
| | | //写入工序检验记录子表 |
| | | //获取主表最大ID |
| | | sql = @"select ISNULL(IDENT_CURRENT('TStepCheckRecord')+1,1) as id"; |
| | | var dt = DapperHelper.selecttable(sql); |
| | | for (int i = 0; i < json.Count; i++) |
| | | list.Add(new |
| | | { |
| | | sql = @"insert into TStepCheckRecordSub(m_id,checkitem_seq,checkitem_code,checkitem_name,checkitem_descr,check_result,lm_user,lm_date) |
| | | values(@m_id,@checkiem_seq,@checkitem_code,@checkitem_name,@checkitem_descr,@check_result,@lm_user,@lm_date)"; |
| | | list.Add(new { str = sql, parm = new { m_id = int.Parse(dt.Rows[0]["ID"].ToString()), checkiem_seq = int.Parse(json[i].seq), checkitem_code = json[i].code, checkitem_name = json[i].name, checkitem_descr = json[i].descr, check_result = json[i].checkresult, lm_user = username, lm_date = date } }); |
| | | |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | wo_code = wocode, |
| | | partcode = partcode, |
| | | step_code = stepcode, |
| | | checkstaned_code = checkstandcode, |
| | | check_user = username, |
| | | check_type = check_type, |
| | | check_typename = checktypename, |
| | | sampmethod = sampmethod, |
| | | check_result = qualitystatus, |
| | | check_qty = decimal.Parse(sampleqty), |
| | | good_qty = decimal.Parse(goodqty), |
| | | ng_qty = decimal.Parse(ngqty), |
| | | lm_user = username, |
| | | lm_date = datetime |
| | | } |
| | | }); |
| | | //写入检验记录子表 |
| | | for (int j = 0; j < arra.Count; j++) |
| | | { |
| | | sql = @"insert into TStepCheckRecordSub(m_id,checknum,checkitem_seq,checkitem_code,checkitem_name,checkitem_descr,check_value,check_result,lm_user,lm_date) |
| | | values(CONVERT(INT,IDENT_CURRENT('TStepCheckRecord')),@checknum,@checkiem_seq,@checkitem_code,@checkitem_name,@checkitem_descr,@check_value,@check_result,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | checknum = arra[j]["checknum"].ToString(), |
| | | checkiem_seq = arra[j]["checkiem_seq"].ToString(), |
| | | checkitem_code = arra[j]["checkitem_code"].ToString(), |
| | | checkitem_name = arra[j]["checkitem_name"].ToString(), |
| | | checkitem_descr = arra[j]["checkitem_descr"].ToString(), |
| | | check_value = arra[j]["check_value"].ToString(), |
| | | check_result = arra[j]["check_result"].ToString(), |
| | | lm_user = username, |
| | | lm_date = datetime |
| | | } |
| | | }); |
| | | } |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | |
| | | { |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "检验成功!"; |
| | | mes.Message = "操作成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.Message = "检验失败!"; |
| | | mes.Message = "操作失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |