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 { //工序检验单Controller public class QC_ProcessCheckBillController : ApiController { public DBUtility.ClsPub.Enum_BillStatus BillStatus; private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); DataSet ds; SQLHelper.ClsCN oCN1 = new SQLHelper.ClsCN(); DataSet ds1; /// /// 新增单据-保存按钮 ///参数:string sql。 ///返回值:object。 /// [Route("QC_ProcessCheckBill/AddBill")] [HttpPost] public object AddBill([FromBody] JObject sMainSub) { var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); oCN.BeginTran(); //保存主表 objJsonResult = AddBillMain(msg1); 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 = "新增单据成功!"; return objJsonResult; } public json AddBillMain(string msg1) { string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); try { msg2 = "[" + msg2.ToString() + "]"; List mainList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); string BillType = "7507"; long HInterID = mainList[0].HInterID;//递入type得到的单据ID string HBillNo = mainList[0].HBillNo;//递入type得到的单据号 DateTime HDate = mainList[0].HDate;//日期 int HYear = 2021; double HPeriod = 1; long HBillStatus = mainList[0].HBillStatus; long HCheckItemNowID = mainList[0].HCheckItemNowID; long HCkeckItemNextID = mainList[0].HCheckItemNextID; long HCheckFlowID = mainList[0].HCheckFlowID; string HRemark = mainList[0].HRemark;//备注 string HBacker = mainList[0].HBacker; DateTime HBackDate = mainList[0].HBackDate; string HBackRemark = mainList[0].HBackRemark; string HChecker = mainList[0].HChecker; DateTime HCheckDate = mainList[0].HCheckDate; string HMaker = mainList[0].HMaker; DateTime HMakeDate = mainList[0].HMakeDate; string HUpDater = mainList[0].HUpDater; DateTime HUpDateDate = mainList[0].HUpDateDate; string HCloseMan = mainList[0].HCloseMan; DateTime HCloseDate = mainList[0].HCloseDate; string HCloseType = mainList[0].HCloseType; string HDeleteMan = mainList[0].HDeleteMan; DateTime HDeleteDate = mainList[0].HDeleteDate; string HMainSourceBillType = mainList[0].HMainSourceBillType; long HMainSourceInterID = mainList[0].HMainSourceInterID; long HMainSourceEntryID = mainList[0].HMainSourceEntryID; string HMainSourceBillNo = mainList[0].HMainSourceBillNo; double HPrintQty = mainList[0].HPrintQty; long HICMOInterID = mainList[0].HICMOInterID; string HICMOBillNo = mainList[0].HICMOBillNo; long HProExchInterID = mainList[0].HProcExchInterID; long HProExchEntryID = mainList[0].HProcExchEntryID; string HProExchBillNo = mainList[0].HProcExchBillNo; long HMaterID = mainList[0].HMaterID; long HProcID = mainList[0].HProcID; long HSourceID = mainList[0].HSourceID; long HEmpID = mainList[0].HEmpID; double HInStockQty = mainList[0].HInStockQty; double HCheckQty = mainList[0].HCheckQty; double HRightQty = mainList[0].HRightQty; double HBadQty = mainList[0].HBadQty; long HFirstCheckEmp = mainList[0].HFirstCheckEmp; string HCheckerResult = mainList[0].HCheckerResult; string HBarcode = mainList[0].HBarcode; string HLBatchNo = mainList[0].HLBatchNo; long HCusID = mainList[0].HCusID; string HSortBillNo = mainList[0].HSortBillNo; string HConTrctBatchNo = mainList[0].HContrctBatchNo; long HProdAreaID = mainList[0].HProdAreaID; long HProdTypeID = mainList[0].HProdTypeID; string HProdStoveNo = mainList[0].HProdStoveNo; long HRecipeID = mainList[0].HRecipeID; double HDiameter1 = mainList[0].HDiameter1; double HDiameter2 = mainList[0].HDiameter2; long HRoutingInterID = mainList[0].HRoutingInterID; long HPackTypeID = mainList[0].HPackTypeID; long HDrawingDireID = mainList[0].HDrawingDireID; //主表 oCN.RunProc("Insert Into QC_ProcessCheckBillMain " + "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" + ",HYear,HPeriod,HRemark" + ",HICMOInterID,HICMOBillNo,HProcExchInterID,HProcExchEntryID,HProcExchBillNo" + ",HMaterID,HProcID,HSourceID,HEmpID,HInStockQty" + ",HCheckQty,HRightQty,HBadQty,HFirstCheckEmp,HCheckerResult" + ",HBarCode,HLBatchNo,HCusID,HSortBillNo,HContrctBatchNo" + ",HProdAreaID,HProdTypeID,HProdStoveNo,HRecipeID,HDiameter1" + ",HDiameter2,HRoutingInterID,HDrawingDireID,HPackTypeID" + ") " + " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "','" + HBillStatus + "','" + HDate + "','" + HMaker + "','" + HDate + "'" + "," + HYear + "," + HPeriod + ",'" + HRemark + "'" + "," + HICMOInterID + "," + HICMOBillNo + "," + HProExchInterID + "," + HProExchEntryID + ",'" + HProExchBillNo + "'" + "," + HMaterID + "," + HProcID + "," + HSourceID + "," + HEmpID + "," + HInStockQty + "," + HCheckQty + "," + HRightQty + "," + HBadQty + "," + HFirstCheckEmp + ",'" + HCheckerResult + "'" + ",'" + HBarcode + "','" + HLBatchNo + "'," + HCusID + ",'" + HSortBillNo + "','" + HConTrctBatchNo + "'" + "," + HProdAreaID + "," + HProdTypeID + ",'" + HProdStoveNo + "'," + HRecipeID + ",'" + HDiameter1 + "'" + "," + HDiameter2 + "," + HRoutingInterID + "," + HDrawingDireID + "," + HPackTypeID + ") "); //子表 oCN.RunProc("Insert into QC_ProcessCheckBillSub " + " (HInterID,HBillNo_bak,HEntryID,HCloseMan" + ",HEntryCloseDate,HCloseType,HRemark,HSourceInterID" + ",HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" + ",HQCCheckClassID,HQCCheckItemID,HQCStd,HQCRelValue,HResult" + ",HProcCheckEmp,HProcCheckTime" + ") " + " values('" + HInterID + "','',0,'" + HCloseMan + "'" + ",'','','',0 " + ",0,'','',0,0" + ",0,0,'','',''"+ ",0,''" + ") "); if (objJsonResult.code == "0") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } 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; } } /// /// 工序检验单列表修改按钮方法 ///参数:string sql。 ///返回值:object。 /// [Route("QC_ProcessCheckBill/xg")] [HttpGet] public object xg(long HInterID) { try { ds = oCN.RunProcReturn("select HInterID,HBillNo,HProcExchInterID,HProcExchEntryID,HProcExchBillNo" + ",HMaterID,HProcID,HSourceID,HEmpID,HInStockQty" + ",HCheckQty,HRightQty,HBadQty,HFirstCheckEmp,HCheckerResult" + ",HBarCode,HLBatchNo,HCusID,HSortBillNo,HContrctBatchNo" + ",HProdAreaID,HProdTypeID,HProdStoveNo,HRecipeID,HDiameter1" + ",HDiameter2,HRoutingInterID,HDrawingDireID,HPackTypeID from QC_ProcessCheckBillMain where HInterID=" + HInterID, "QC_ProcessCheckBillMain"); 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 = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } /// /// 修改单据-保存按钮 ///参数:string sql。 ///返回值:object。 /// [Route("QC_ProcessCheckBill/AddBill1")] [HttpPost] public object AddBill1([FromBody] JObject oMain) { var _value = oMain["oMain"].ToString(); string msg1 = _value.ToString(); try { DAL.ClsQC_ProcessCheckBill oProcess = new DAL.ClsQC_ProcessCheckBill(); msg1 = "[" + msg1.ToString() + "]"; List mainList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg1); string BillType = "7507"; long HInterID = mainList[0].HInterID;//递入type得到的单据ID string HBillNo = mainList[0].HBillNo;//递入type得到的单据号 DateTime HDate = mainList[0].HDate;//日期 int HYear = 2021; double HPeriod = 1; long HBillStatus = mainList[0].HBillStatus; long HCheckItemNowID = mainList[0].HCheckItemNowID; long HCkeckItemNextID = mainList[0].HCheckItemNextID; long HCheckFlowID = mainList[0].HCheckFlowID; string HRemark = mainList[0].HRemark;//备注 string HBacker = mainList[0].HBacker; DateTime HBackDate = mainList[0].HBackDate; string HBackRemark = mainList[0].HBackRemark; string HChecker = mainList[0].HChecker; DateTime HCheckDate = mainList[0].HCheckDate; string HMaker = mainList[0].HMaker; DateTime HMakeDate = mainList[0].HMakeDate; string HUpDater = mainList[0].HUpDater; DateTime HUpDateDate = mainList[0].HUpDateDate; string HCloseMan = mainList[0].HCloseMan; DateTime HCloseDate = mainList[0].HCloseDate; string HCloseType = mainList[0].HCloseType; string HDeleteMan = mainList[0].HDeleteMan; DateTime HDeleteDate = mainList[0].HDeleteDate; string HMainSourceBillType = mainList[0].HMainSourceBillType; long HMainSourceInterID = mainList[0].HMainSourceInterID; long HMainSourceEntryID = mainList[0].HMainSourceEntryID; string HMainSourceBillNo = mainList[0].HMainSourceBillNo; double HPrintQty = mainList[0].HPrintQty; long HICMOInterID = mainList[0].HICMOInterID; string HICMOBillNo = mainList[0].HICMOBillNo; long HProExchInterID = mainList[0].HProcExchInterID; long HProExchEntryID = mainList[0].HProcExchEntryID; string HProExchBillNo = mainList[0].HProcExchBillNo; long HMaterID = mainList[0].HMaterID; long HProcID = mainList[0].HProcID; long HSourceID = mainList[0].HSourceID; long HEmpID = mainList[0].HEmpID; double HInStockQty = mainList[0].HInStockQty; double HCheckQty = mainList[0].HCheckQty; double HRightQty = mainList[0].HRightQty; double HBadQty = mainList[0].HBadQty; long HFirstCheckEmp = mainList[0].HFirstCheckEmp; string HCheckerResult = mainList[0].HCheckerResult; string HBarcode = mainList[0].HBarcode; string HLBatchNo = mainList[0].HLBatchNo; long HCusID = mainList[0].HCusID; string HSortBillNo = mainList[0].HSortBillNo; string HConTrctBatchNo = mainList[0].HContrctBatchNo; long HProdAreaID = mainList[0].HProdAreaID; long HProdTypeID = mainList[0].HProdTypeID; string HProdStoveNo = mainList[0].HProdStoveNo; long HRecipeID = mainList[0].HRecipeID; double HDiameter1 = mainList[0].HDiameter1; double HDiameter2 = mainList[0].HDiameter2; long HRoutingInterID = mainList[0].HRoutingInterID; long HPackTypeID = mainList[0].HPackTypeID; long HDrawingDireID = mainList[0].HDrawingDireID; //若MAINDI重复则重新获取 oCN.BeginTran(); //主表 oCN.RunProc("Update QC_ProcessCheckBillMain set " + "HMaterID=" + HMaterID + ",HSourceID=" + HSourceID + ",HEmpID=" + HEmpID + ",HInStockQty=" + HInStockQty + ",HCheckQty=" + HCheckQty + ",HRightQty=" + HRightQty + ",HBadQty=" + HBadQty + ",HCusID=" + HCusID + ",HRemark= '" + HRemark + "' Where HInterID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo); //修改子项目代码 //oCN.RunProc("exec h_p_Gy_UpdateNumber Gy_Department,'" + HNumber + ".','" + this.HOldNumber + ".'", ref DBUtility.ClsPub.sExeReturnInfo); //将上级 为非末级 //oCN.RunProc("Update Gy_Department set HEndflag=0 where HItemID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo); // oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "修改单据成功!"; //objJsonResult.data = null; return objJsonResult; } catch (Exception e) { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.Message; objJsonResult.data = null; return objJsonResult; } } /// /// 工序检验单列表删除按钮 ///参数:string sql。 ///返回值:object。 /// [Route("QC_ProcessCheckBill/Delete_Json")] [HttpGet] public object Delete_Json(long HItemID) { DAL.ClsQC_ProcessCheckBill BillOld = new DAL.ClsQC_ProcessCheckBill(); try { if (BillOld.DeleteBill(HItemID, ref ClsPub.sExeReturnInfo) != true) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "删除成功"; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "删除成功"; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } /// /// 返回工序检验单列表 ///参数:string sql。 ///返回值:object。 /// [Route("QC_ProcessCheckBill/GetProcessCheckBillList")] [HttpGet] public object GetProcessCheckBillList(string sWhere) { try { if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("select * from h_v_QC_ProcessCheckBillList " + sWhere, "h_v_QC_ProcessCheckBillList"); } else { string sql1 = "select * from h_v_QC_ProcessCheckBillList where 1 = 1 "; string sql = sql1 + sWhere; ds = oCN.RunProcReturn(sql, "h_v_QC_ProcessCheckBillList"); } if (ds == null || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "false!"; objJsonResult.data = null; return objJsonResult; } else { 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; } } // } }