|  |  | 
 |  |  | using Newtonsoft.Json.Linq; | 
 |  |  | using Newtonsoft.Json; | 
 |  |  | using Newtonsoft.Json.Linq; | 
 |  |  | using Pub_Class; | 
 |  |  | using System; | 
 |  |  | using System.Collections; | 
 |  |  | 
 |  |  |     { | 
 |  |  |         public DBUtility.ClsPub.Enum_BillStatus BillStatus; | 
 |  |  |         Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); | 
 |  |  |  | 
 |  |  |         public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill(); | 
 |  |  |         private json objJsonResult = new json(); | 
 |  |  |         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
 |  |  |         DataSet ds; | 
 |  |  | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 List<object> columnNameList = new List<object>(); | 
 |  |  |                 //判断是否有查询权限 | 
 |  |  |                 if (!DBUtility.ClsPub.Security_Log("MES_StationEntrustOutBill_Query", 1, false, user)) | 
 |  |  |                 { | 
 |  |  | 
 |  |  |  | 
 |  |  |                 if (sWhere == null || sWhere.Equals("")) | 
 |  |  |                 { | 
 |  |  |                     ds = oCN.RunProcReturn("select * from h_v_MES_StationEntrustOutBillList " + sWhere+ " order by 接收时间 desc", "h_v_MES_StationEntrustOutBillList"); | 
 |  |  |                     ds = oCN.RunProcReturn("select * from h_v_MES_StationEntrustOutBillList ", "h_v_MES_StationEntrustOutBillList"); | 
 |  |  |                     //order by hmainid desc 排序丢到数据库里进行处理 | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     string sql1 = "select * from h_v_MES_StationEntrustOutBillList where 1 = 1 "; | 
 |  |  |                     string sql = sql1 + sWhere; | 
 |  |  |                     string sql = sql1 + sWhere+ " order by hmainid desc"; | 
 |  |  |                     ds = oCN.RunProcReturn(sql, "h_v_MES_StationEntrustOutBillList"); | 
 |  |  |                 } | 
 |  |  |                 if (ds == null || ds.Tables[0].Rows.Count == 0) | 
 |  |  |  | 
 |  |  |                 //添加列名 | 
 |  |  |                 foreach (DataColumn col in ds.Tables[0].Columns) | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = "false!"; | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                     Type dataType = col.DataType; | 
 |  |  |                     string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; | 
 |  |  |                     columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "1"; | 
 |  |  |                     objJsonResult.count = 1; | 
 |  |  |                     objJsonResult.Message = "Sucess!"; | 
 |  |  |                     objJsonResult.data = ds.Tables[0]; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 //if (ds.Tables[0].Rows.Count != 0 || ds != null) | 
 |  |  |                 //{ | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "Sucess!"; | 
 |  |  |                 objJsonResult.list = columnNameList; | 
 |  |  |                 objJsonResult.data = ds.Tables[0]; | 
 |  |  |                 return objJsonResult; | 
 |  |  |                 //} | 
 |  |  |                 //else | 
 |  |  |                 //{ | 
 |  |  |                 //objJsonResult.code = "0"; | 
 |  |  |                 //objJsonResult.count = 0; | 
 |  |  |                 //objJsonResult.Message = "无数据"; | 
 |  |  |                 //objJsonResult.data = null; | 
 |  |  |                 //return objJsonResult; | 
 |  |  |                 //} | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  | 
 |  |  |                 double HMoney = list[0].HMoney;//金额 | 
 |  |  |                 string HRemark = list[0].HRemark;//备注 | 
 |  |  |                 double HTaxRate = list[0].HTaxRate;//税率 | 
 |  |  |                 long HProcNo = list[0].HProcNo;//流水号 | 
 |  |  |                 string HProcNo = list[0].HProcNo;//流水号 | 
 |  |  |                 string HOrderProcNO = list[0].HOrderProcNO;//订单跟踪号 | 
 |  |  |                 int HWWWorkOrderInterID = 0;//委外工单号子内码 | 
 |  |  |                 int HWWWorkOrderEntryID = 0;//委外工单号主内吗 | 
 |  |  | 
 |  |  |                 double HMainSourceInterID = 0; | 
 |  |  |                 string HMainSourceBillNo = ""; | 
 |  |  |                 string HMainSourceBillType = "3792"; | 
 |  |  |                 long HPRDOrgID = list[0].HPRDOrgID;//组织ID | 
 |  |  |                 if (HProcExchInterID <= 0) | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |                 if (HProcNo <= 0) | 
 |  |  |                 if (HProcNo == "") | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  | 
 |  |  |                     ",HICMOInterID,HICMOBillNo,HProcPlanInterID,HProcPlanEntryID,HProcPlanBillNo,HProcExchInterID,HProcExchEntryID" + | 
 |  |  |                     ",HProcExchBillNo,HMaterID,HProcID,HICMOQty,HPlanQty,HStationOutTime,HSourceID" + | 
 |  |  |                     ",HGroupID,HDeptID,HEmpID,HBarCode,HAddr,HBarCodeMaker,HBarCodeMakeDate" + | 
 |  |  |                     ",HSupID,HTaxRate,HQty,HPrice,HMoney,HPrice_BHS,HMoney_BHS,HBadCount" + | 
 |  |  |                     ",HMainSourceInterID,HMainSourceBillNo,HMainSourceBillType,HProcNo,HOrderProcNO,HLastSubProc,HWWWorkOrderBillNo,HWWWorkOrderInterID,HWWWorkOrderEntryID,HMainInterID" + | 
 |  |  |                     ",HSupID,HTaxRate,HQty,HPrice,HMoney,HPrice_BHS,HMoney_BHS,HBadCount" +               ",HMainSourceInterID,HMainSourceBillNo,HMainSourceBillType,HProcNo,HOrderProcNO,HLastSubProc,HWWWorkOrderBillNo,HWWWorkOrderInterID,HWWWorkOrderEntryID,HMainInterID,HPRDOrgID" + | 
 |  |  |                     ") " + | 
 |  |  |                     " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",getdate(),'" + HMaker + "',getdate()" + | 
 |  |  |                     "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HInnerBillNo + "','" + HSourceName + "'," + HPieceQty + "," + HWasterQty + "," + HPlanPieceQty + "," + HBadPNL + | 
 |  |  | 
 |  |  |                     ",'" + HProcExchBillNo + "'," + HMaterID + "," + HProcID + "," + HICMOQty + "," + HPlanQty + ",getdate()," + HSourceID + | 
 |  |  |                     "," + HGroupID + "," + HDeptID + "," + HEmpID + ",'" + HBarCode + "','" + HAddr + "','" + HBarCodeMaker + "',getdate()" + | 
 |  |  |                     "," + HSupID + "," + HTaxRate + "," + HQty + "," + HPrice + "," + HMoney + "," + HPrice_BHS + "," + HMoney_BHS + "," + HBadCount + | 
 |  |  |                     "," + HMainSourceInterID + ",'" + HMainSourceBillNo + "','" + HMainSourceBillType + "'," + HProcNo + ",'" + HOrderProcNO + "'," + Convert.ToString(HLastSubProc ? 1 : 0) + ",'" + HWWWorkOrderBillNo + "'," + HWWWorkOrderInterID + "," + HWWWorkOrderEntryID + "," + HMainInterID + | 
 |  |  |                     "," + HMainSourceInterID + ",'" + HMainSourceBillNo + "','" + HMainSourceBillType + "'," + HProcNo + ",'" + HOrderProcNO + "'," + Convert.ToString(HLastSubProc ? 1 : 0) + ",'" + HWWWorkOrderBillNo + "'," + HWWWorkOrderInterID + "," + HWWWorkOrderEntryID + "," + HMainInterID + "," + HPRDOrgID + | 
 |  |  |                     ") "); | 
 |  |  |                 } | 
 |  |  |                 else if ("Modify".Equals(eventType)) | 
 |  |  | 
 |  |  |                     ",HUpDater='" + HMaker + "'" + | 
 |  |  |                     ",HUpDateDate=getdate()" + | 
 |  |  |                     ",HInnerBillNo='" + HInnerBillNo + "'" + | 
 |  |  |                     ",HWWWorkOrderBillNo='" + HWWWorkOrderBillNo + "'" + | 
 |  |  |                     ",HSupID=" + HSupID + | 
 |  |  |                     ",HEmpID=" + HEmpID + | 
 |  |  |                     ",HQty=" + HQty + | 
 |  |  |                     ",HPieceQty=" + HPieceQty + | 
 |  |  |                     ",HPrice=" + HPrice + | 
 |  |  | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |                 //if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "2") | 
 |  |  |                 //{ | 
 |  |  |                 //    oCN.RollBack(); | 
 |  |  |                 //    objJsonResult.code = "0"; | 
 |  |  |                 //    objJsonResult.count = 0; | 
 |  |  |                 //    objJsonResult.Message = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]); | 
 |  |  |                 //    objJsonResult.data = null; | 
 |  |  |                 //    return objJsonResult; | 
 |  |  |                 //} | 
 |  |  |                 if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "2") | 
 |  |  |                 { | 
 |  |  |                     oCN.RollBack(); | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]); | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |                 oCN.RunProc("exec h_p_Mes_ProcessExchangeRelationQty_Out " + HInterID.ToString() + ",1"); | 
 |  |  |                 oCN.RunProc("exec h_p_WW_EntrustWorkOrderRelationQty_Out " + HInterID.ToString() + ",1"); | 
 |  |  |                 oCN.Commit(); | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         #region 工序委外接收单关闭/反关闭功能 | 
 |  |  |         [Route("Cj_StationEntrustOutBill/CloseCj_StationEntrustOutBill")] | 
 |  |  |         [HttpGet] | 
 |  |  |         public object CloseCj_StationEntrustOutBill(string HInterID, int Type, string user) | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 //判断是否有删除权限 | 
 |  |  |                 if (!DBUtility.ClsPub.Security_Log("MES_StationEntrustOutBill_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 = "Sc_StationOutBillMain"; | 
 |  |  |                 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 | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         //是否被关联 | 
 |  |  |         public bool Cj_StationEntrustOutBillisUse(Int64 lngBillKey, ref string sReturn) | 
 |  |  |         { |