using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Pub_Class; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Web.Http; using WebAPI.Models; namespace WebAPI.Controllers.CJGL { public class Cj_SingleStationController : ApiController { private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; #region 工序单品不良采集 用户查询关联字段 [Route("Cj_SingleStation/Cj_CollectionOfSingleProductDefectsUserList")] [HttpGet] public object Cj_CollectionOfSingleProductDefectsUserList(string sWhere, string user) { try { if (sWhere == null || sWhere.Equals("")) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = new DataTable(); return objJsonResult; } ds = oCN.RunProcReturn("select * from h_v_Cj_UserAssociationList where 1=1 "+sWhere, "h_v_Cj_UserAssociationList"); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工序单品不良采集 扫码查询 [Route("Cj_SingleStation/HBardCodeList")] [HttpGet] public object HBardCodeList(string HBarCode, string user) { try { ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBillHICOMProcessExchange where 条码='" + HBarCode + "'", "h_v_Gy_BarCodeBillHICOMProcessExchange"); if (ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "条码查无数据!"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = ""; objJsonResult.data = ds.Tables[0]; } return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "没有返回任何记录!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工序单品不良采集 保存 [Route("Cj_SingleStation/ProcessBLSave")] [HttpPost] public object ProcessBLSave([FromBody] JObject sMainSub) { var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); //主表数据 string HResult = sArray[1].ToString(); string user = sArray[2].ToString(); try { var msg3 = msg2.ToString(); msg2 = "[" + msg2.ToString() + "]"; List mainList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); long HInterID = mainList[0].HInterID;//递入type得到的单据ID string HBillNo = mainList[0].HBillNo;//递入type得到的单据号 DateTime HDate = DateTime.Now;//日期 string HRemark = mainList[0].HRemark;//备注 long HEmpID = mainList[0].HEmpID;//质检员 long HGroupID = mainList[0].HGroupID;//班组 long HDeptID = mainList[0].HDeptID;//车间 string HMaker = user;//制单人 ds = oCN.RunProcReturn("select * from Sc_QualityReportBillMain where HInterID=" + HInterID + " and HBillNo='" + HBillNo + "'", "Sc_QualityReportBillMain"); if (ds.Tables[0].Rows.Count != 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已存在!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran(); if (ds.Tables[0].Rows.Count == 0)//新增 { //主表 oCN.RunProc(@"Insert Into Sc_QualityReportBillMain (HBillType,HBillSubType,HBillStatus,HInterID,HBillNo,HDate ,HYear,HPeriod,HRemark,HMaker,HMakeDate ,HEmpID,HGroupID,HDeptID) values('3717','3717',1," + HInterID + ",'" + HBillNo + "','" + HDate + "'" + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" + ",'" + HEmpID + "'," + HGroupID + "," + HDeptID + ") "); } //保存子表 objJsonResult = AddBillSub_NoTable(msg3, HInterID, HResult); if (objJsonResult.code == "0") { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } public json AddBillSub_NoTable(string msg3, long HInterID, string HResult) { Model.ClsSc_QualityReportBillSub oSub = Newtonsoft.Json.JsonConvert.DeserializeObject(msg3); if (oSub.HMaterID == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "物料不能为空"; objJsonResult.data = null; return objJsonResult; } oCN.RunProc($@"Insert into Sc_QualityReportBillSub (HInterID,HENTRYID,HBillNo_bak,HEmpID,HBarCode,HBadReasonID,HAddr,HMaker,HMakeDate ,HMaterID,HUnitID,HRemark,HSourceID,HICMOInterID,HICMOEntryID,HICMOBillNo,HReportType ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney ,HQty,HResult,HProcExchInterID,HProcExchEntryID,HProcExchBillNo) values({HInterID},1,'{oSub.HBillNo_bak}',{oSub.HEmpID},'{oSub.HBarCode}',{oSub.HBadReasonID},'','{oSub.HMaker}','{oSub.HMakeDate}' ,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HICMOInterID},{oSub.HICMOEntryID},'{oSub.HICMOBillNo}',{oSub.HReportType} ,0,0,'','',0,0 ,0,'{HResult}',{oSub.HProcExchInterID},{oSub.HProcExchEntryID},'{oSub.HProcExchBillNo}')"); //修改条码表的状态 oCN.RunProc("update Gy_BarCodeBill set HStatus='"+ HResult + "' where HBarCode='"+ oSub.HBarCode + "'"); //修改出站单的 不良 报废数量 if (HResult == "不良") { oCN.RunProc("update Sc_StationOutBillMain set HBadCount+=1 where HProcExchBillNo='" + oSub.HProcExchBillNo + "' and HProcID=" + oSub.HProcID); } else if (HResult == "报废") { oCN.RunProc("update Sc_StationOutBillMain set HWasterQty+=1 where HProcExchBillNo='" + oSub.HProcExchBillNo + "' and HProcID=" + oSub.HProcID); } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } #endregion #region 工序单品过站 流转卡查询关键件清单 [Route("Cj_SingleStation/HBardCodeBomList")] [HttpGet] public object HBardCodeBomList(string HBarCode, string user) { try { ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBillHICOMProcessExchange where 条码='" + HBarCode + "'", "h_v_Gy_BarCodeBillHICOMProcessExchange"); if (ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "条码查无数据!"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = ""; objJsonResult.data = ds.Tables[0]; } return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "没有返回任何记录!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工序单品返修台 获取表格数据 [Route("Cj_SingleStation/ProcessItemRepair")] [HttpGet] public object ProcessItemRepair( string sWhere, string user) { try { List columnNameList = new List(); string sql = @"select * from h_v_Cj_BarCodeProcessItemRepair where 1=1 " + sWhere + " order by 日期 desc, HInterID desc, HEntryID desc"; ds = oCN.RunProcReturn(sql, "h_v_Cj_BarCodeProcessItemRepair"); //添加列名 foreach (DataColumn col in ds.Tables[0].Columns) { Type dataType = col.DataType; string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = columnNameList; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工序单品返修台--配件更换 查询更换记录 [Route("Cj_SingleStation/Sc_SourceLineRepairBillSub_MaterList")] [HttpGet] public object Sc_SourceLineRepairBillSub_MaterList(string sWhere, string user) { try { List columnNameList = new List(); string sql = @"select * from Sc_SourceLineRepairBillSub_Mater where 1=1 " + sWhere + " order by HInterID asc, HEntryID asc"; ds = oCN.RunProcReturn(sql, "Sc_SourceLineRepairBillSub_Mater"); //添加列名 foreach (DataColumn col in ds.Tables[0].Columns) { Type dataType = col.DataType; string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = columnNameList; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion } }