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 Sc_ProcExchWWSendWorkBillController : ApiController { public DBUtility.ClsPub.Enum_BillStatus BillStatus; private json objJsonResult = new json(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill(); DataSet ds; #region 工序委外派工单列表 [Route("WW_EntrustWorkOrderBill/WW_EntrustWorkOrderBillList")] [HttpGet] public object WW_EntrustWorkOrderBillList(string sWhere, string user) { try { List columnNameList = new List(); string sql1 = "select * from h_v_WW_EntrustWorkOrderBill where 1 = 1 "; string sql = sql1 + sWhere + " order by hmainid desc"; ds = oCN.RunProcReturn(sql, "h_v_WW_EntrustWorkOrderBill"); //添加列名 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.list = columnNameList; 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("WW_EntrustWorkOrderBill/SaveEntrustWorkOrderBill")] [HttpPost] public object SaveProcessSendWork([FromBody] JObject msg) { var _value = msg["msg"].ToString(); string msg1 = _value.ToString(); string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); string msg3 = sArray[1].ToString(); string msg4 = sArray[2].ToString(); string UserName = ""; ListModels oListModels = new ListModels(); try { DAL.ClsWW_EntrustWorkOrderBill oBill = new DAL.ClsWW_EntrustWorkOrderBill(); List lsmain = new List(); msg2 = msg2.Replace("\\", ""); msg2 = msg2.Replace("\n", ""); //\n lsmain = oListModels.getObjectByJson_ClsWW_EntrustWorkOrderBillMain(msg2); foreach (Model.ClsWW_EntrustWorkOrderBillMain oItem in lsmain) { //oItem.HMaker = ""; UserName = oItem.HMaker; //制单人 oItem.HBillType = "3740"; oItem.HBillSubType = "3740"; oItem.HBillStatus = 1; DBUtility.ClsPub.CurUserName = UserName; oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year); if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!没有单据日期,无法保存!"; objJsonResult.data = 1; return objJsonResult; } oBill.omodel = oItem; } //表体数据 //按 },{来拆分数组 //去掉【和】 msg3 = msg3.Substring(1, msg3.Length - 2); msg3 = msg3.Replace("\\", ""); msg3 = msg3.Replace("\n", ""); //\n //msg2 = msg2.Replace("'", "’"); List ls = new List(); ls = oListModels.getObjectByJson_ClsWW_EntrustWorkOrderBillSub(msg3); int i = 0; foreach (Model.ClsWW_EntrustWorkOrderBillSub oItemSub in ls) { i++; oItemSub.HEntryID = i; //oItemSub.HCloseMan = ""; //行关闭 oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now); oItemSub.HCloseType = false; //关闭类型 //oItemSub.HRemark = ""; //备注 oItemSub.HSourceInterID = oItemSub.HSourceInterID; // 源单主内码 oItemSub.HSourceEntryID = oItemSub.HSourceEntryID; //源单子内码 oItemSub.HSourceBillNo = oItemSub.HSourceBillNo; //源单单号 oItemSub.HSourceBillType = oItemSub.HSourceBillType; //源单类型 oItemSub.HRelationQty = 0; //关联数量 oBill.DetailColl.Add(oItemSub); } //保存 //保存完毕后处理 bool bResult; if (oBill.omodel.HInterID == 0) { // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); } else { bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo); } if (bResult) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "保存成功!"; objJsonResult.data = 1; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = 1; return objJsonResult; } } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + e.ToString(); objJsonResult.data = 1; return objJsonResult; } } #endregion //#region 工序委外派工单 删除 [Route("WW_EntrustWorkOrderBill/DelEntrustWorkOrder")] [HttpGet] public object DelEntrustWorkOrder(string HInterID, string user) { Int64 lngBillKey = 0; lngBillKey = DBUtility.ClsPub.isLong(HInterID); if (lngBillKey == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据ID为空!"; objJsonResult.data = null; return objJsonResult; } DAL.ClsWW_EntrustWorkOrderBill oBill = new DAL.ClsWW_EntrustWorkOrderBill(); if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) { ds = oCN.RunProcReturn("select * from WW_EntrustWorkOrderBillMain where HInterID=" + lngBillKey, "WW_EntrustWorkOrderBillMain"); if (int.Parse(ds.Tables[0].Rows[0]["HBillStatus"].ToString()) > 1) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据当前处于不能删除状态,不能删除!"; objJsonResult.data = null; return objJsonResult; } if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已经审核,不能删除!"; objJsonResult.data = null; return objJsonResult; } bool IsDete = oBill.DeleteBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo); if (IsDete) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据未找到"; objJsonResult.data = null; return objJsonResult; } } //#endregion } }