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 #region 工序委外派工单审核/反审核功能 [Route("WW_EntrustWorkOrderBill/CheckSWW_EntrustWorkOrderBill")] [HttpGet] public object CheckSWW_EntrustWorkOrderBill(string HInterID, int Type, string user) { try { //判断是否有删除权限 委外工序派工单_审核 if (!DBUtility.ClsPub.Security_Log("WW_EntrustProcSendWorkBill_Check", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限审核!"; objJsonResult.data = null; return objJsonResult; } if (string.IsNullOrWhiteSpace(HInterID)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID为空!"; objJsonResult.data = null; return objJsonResult; } ClsPub.CurUserName = user; BillOld.MvarItemKey = "WW_EntrustWorkOrderBillMain"; oCN.BeginTran();//开始事务 //Type 1 审核 2 反审核 if (Type == 1) { //判断单据是否已经审核 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HChecker"] != null && ds.Tables[0].Rows[0]["HChecker"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核!不需要再审核!"; objJsonResult.data = null; return objJsonResult; } } //审核前控制 string HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString(); sql = "exec h_p_WW_EntrustWorkOrderBill_BeforeCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'"; ds = oCN.RunProcReturn(sql, "h_p_WW_EntrustWorkOrderBill_BeforeCheckCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:审核前判断失败,请与网络管理人员联系"; objJsonResult.data = null; return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; return objJsonResult; } //审核单据 if (!BillOld.CheckBill(Int64.Parse(HInterID), HBillNo, "h_p_WW_EntrustWorkOrderBill_AfterCheckCtrl", user, ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { //判断单据是否已经反审核 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HChecker"] == null || ds.Tables[0].Rows[0]["HChecker"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已反审核!不需要再反审核!"; objJsonResult.data = null; return objJsonResult; } } //反审核前控制 string HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString(); sql = "exec h_p_WW_EntrustWorkOrderBill_BeforeUnCheckCtrl " + int.Parse(HInterID) + ",'" + HBillNo + "','" + user + "'"; ds = oCN.RunProcReturn(sql, "h_p_WW_EntrustWorkOrderBill_BeforeUnCheckCtrl"); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反审核失败!原因:反审核前判断失败,请与网络管理人员联系"; objJsonResult.data = null; return objJsonResult; } if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0") { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ; objJsonResult.data = null; return objJsonResult; } //反审核单据 if (BillOld.AbandonCheck(Int64.Parse(HInterID), HBillNo, "h_p_WW_EntrustWorkOrderBill_AfterUnCheckCtrl", user, ref ClsPub.sExeReturnInfo)) { } else { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } oCN.Commit();//提交事务 objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "执行成功!"; objJsonResult.data = null; return objJsonResult; ; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "执行失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工序委外派工单 关闭/反关闭功能 [Route("WW_EntrustWorkOrderBill/CloseWW_EntrustWorkOrderBill")] [HttpGet] public object CloseWW_EntrustWorkOrderBill(string HInterID, int Type, string user) { try { //判断是否有删除权限 委外工序派工单_关闭 if (!DBUtility.ClsPub.Security_Log("WW_EntrustProcSendWorkBill_Close", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限关闭!"; objJsonResult.data = null; return objJsonResult; } if (string.IsNullOrWhiteSpace(HInterID)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID为空!"; objJsonResult.data = null; return objJsonResult; } ClsPub.CurUserName = user; BillOld.MvarItemKey = "WW_EntrustWorkOrderBillMain"; oCN.BeginTran();//开始事务 //Type 1 关闭 2 反关闭 if (Type == 1) { //判断单据是否已经关闭 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HCloseMan"] != null && ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已关闭!不需要再关闭!"; objJsonResult.data = null; return objJsonResult; } } //关闭单据 if (!BillOld.CloseBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { //判断单据是否已经反关闭 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HCloseMan"] == null || ds.Tables[0].Rows[0]["HCloseMan"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已反关闭!不需要再反关闭!"; objJsonResult.data = null; return objJsonResult; } } //反关闭单据 if (!BillOld.CancelClose(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } oCN.Commit();//提交事务 objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "执行成功!"; objJsonResult.data = null; return objJsonResult; ; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "执行失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工序委外派工单 作废/反作废 /// /// /// 单据ID /// 作废(0),反作废(1) /// 作废人 /// [Route("WW_EntrustWorkOrderBill/DropWW_EntrustWorkOrderBill")] [HttpGet] public object DropWW_EntrustWorkOrderBill(int HInterID, int IsAudit, string CurUserName) { string ModRightNameCheck = "WW_EntrustProcSendWorkBill_Drop"; //委外工序派工单_作废 DBUtility.ClsPub.CurUserName = CurUserName; try { //检查权限 if (!DBUtility.ClsPub.Security_Log_second(ModRightNameCheck, 1, false, CurUserName)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "作废失败!无权限!"; objJsonResult.data = null; return objJsonResult; } //HInterID数据判断 if (HInterID <= 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID小于0!"; objJsonResult.data = null; return objJsonResult; } ds = oCN.RunProcReturn("select * from WW_EntrustWorkOrderBillMain", "WW_EntrustWorkOrderBillMain"); //针对需要进行的操作,检验当前单据的状态是否支持需要进行的操作 if (ds.Tables[0].Rows.Count>0) //根据HInterID获取该单据的数据 { if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核!不能进行作废!"; objJsonResult.data = null; return objJsonResult; } if (IsAudit == 0) //作废判断 { if (ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已作废!不能再作废!"; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反作废判断 { if (ds.Tables[0].Rows[0]["HDeleteMan"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据未作废!不需要反作废!"; objJsonResult.data = null; return objJsonResult; } } } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } //进行需要进行的作废/反作废操作 if (IsAudit == 0) //作废提交 { //作废提交 if (Cancelltion(HInterID, ref DBUtility.ClsPub.sExeReturnInfo) == true) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "作废成功"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "作废失败!原因:" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反关闭提交 { //反关闭提交 if (AbandonCancelltion(HInterID, ref DBUtility.ClsPub.sExeReturnInfo) == true) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "反作废成功"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "反作废失败!原因:" + DBUtility.ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "作废失败或者反作废失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } //作废 public bool Cancelltion(Int64 lngBillKey, ref string sReturn) { try { string HDeleteMan = ClsPub.CurUserName; string HDeleteDate = ClsPub.GetServerDate(-1); oCN.RunProc(" Update WW_EntrustWorkOrderBillMain set HDeleteMan='" + HDeleteMan + "',HDeleteDate='" + HDeleteDate + "',HBillStatus=4 Where HInterID=" + lngBillKey.ToString()); sReturn = ""; return true; } catch (Exception e) { sReturn = e.Message; throw (e); } } //反作废 public bool AbandonCancelltion(Int64 lngBillKey, ref string sReturn) { try { DataSet ds = oCN.RunProcReturn("select * from WW_EntrustWorkOrderBillMain where HInterID=" + lngBillKey.ToString(), "WW_EntrustWorkOrderBillMain"); if (ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "") { oCN.RunProc(" Update WW_EntrustWorkOrderBillMain set HDeleteMan='',HDeleteDate=null,HBillStatus=3 Where HInterID=" + lngBillKey.ToString()); } else if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "") { oCN.RunProc(" Update WW_EntrustWorkOrderBillMain set HDeleteMan='',HDeleteDate=null,HBillStatus=2 Where HInterID=" + lngBillKey.ToString()); } else { oCN.RunProc(" Update WW_EntrustWorkOrderBillMain set HDeleteMan='',HDeleteDate=null,HBillStatus=1 Where HInterID=" + lngBillKey.ToString()); } sReturn = ""; return true; } catch (Exception e) { sReturn = e.Message; throw (e); } } #endregion } }