| using Newtonsoft.Json; | 
| using Newtonsoft.Json.Converters; | 
| using Pub_Class; | 
| using System; | 
| using System.Collections.Generic; | 
| using System.Data; | 
| using System.Linq; | 
| using System.Net; | 
| using System.Net.Http; | 
| using System.Web.Http; | 
| using WebAPI.Models; | 
|   | 
| namespace WebAPI.Controllers | 
| { | 
|     public class Sc_ProcessReportController : ApiController | 
|     { | 
|         public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更) | 
|         private json objJsonResult = new json(); | 
|         private JsonResult jsonresult = new JsonResult(); | 
|         public DataSet ds = new DataSet(); | 
|         public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); | 
|   | 
|         #region 工序汇报单列表 | 
|         [Route("Sc_ProcessReport/MES_Sc_ProcessReportList_Json")] | 
|         [HttpGet] | 
|         public object MES_Sc_ProcessReportList_Json(int page, int limit, string sWhere) | 
|         { | 
|             try | 
|             { | 
|                 int count = 0; | 
|                 int pageNum = page; | 
|                 int pageSize = limit; | 
|                 if (sWhere == null || sWhere.Equals("")) | 
|                 { | 
|                     sWhere = " where 1=1"; | 
|                 } | 
|                 else | 
|                 { | 
|                     sWhere = " where 1=1" + sWhere; | 
|                 } | 
|   | 
|                 DataSet ds0 = oCn.RunProcReturn("select count(*) CountNum from h_v_Sc_ProcessReportList " + sWhere + "", "h_v_Sc_ProcessReportList"); | 
|                 count = int.Parse(ds0.Tables[0].Rows[0]["CountNum"].ToString()); | 
|                 //string sql = string.Format(@"select top " + pageSize + " hmainid,日期,单据号,箱号条形码,净重,毛重,皮重,生产组织,部门,操作员,客户标签号,物料代码,物料名称,计量单位代码,计量单位名称,数量,制单人,制单日期 from(select row_number() over (order by hmainid desc) as RowNumber,hmainid,日期,单据号,箱号条形码,净重,毛重,皮重,生产组织,部门,操作员,客户标签号,物料代码,物料名称,计量单位代码,计量单位名称,数量,制单人,制单日期 from h_v_PackUnionBillList " + sWhere + ")   as A where RowNumber >" + pageSize + " *(" + pageNum + "-1)"); | 
|                 string sql = string.Format(@"select * from h_v_Sc_ProcessReportList " + sWhere + "  order by hmainid desc  offset ((" + pageNum + "-1)*" + pageSize + ") rows fetch next " + pageSize + " rows only"); | 
|                 ds = new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_Sc_ProcessReportList"); | 
|                 string aa = ds.Tables[0].Columns[0].ToString(); | 
|   | 
|                 if (ds.Tables[0].Rows.Count > 0) | 
|                 { | 
|                     jsonresult.code = "1"; | 
|                     jsonresult.count = count; | 
|                     jsonresult.Message = "返回记录成功!"; | 
|                     jsonresult.data = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(ds.Tables[0], new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }));  //序列化DataSet中的时间格式,然后再反序列化回来 | 
|                     return jsonresult; | 
|                 } | 
|                 else | 
|                 { | 
|                     jsonresult.code = "0"; | 
|                     jsonresult.count = 0; | 
|                     jsonresult.Message = "暂无记录!"; | 
|                     jsonresult.data = null; | 
|                     return jsonresult; | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 jsonresult.code = "0"; | 
|                 jsonresult.count = 0; | 
|                 jsonresult.Message = "没有返回任何记录!" + ex.ToString(); | 
|                 jsonresult.data = null; | 
|                 return jsonresult; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|         #region 工序汇报单审核、反审核 | 
|         /// <summary> | 
|         ///  | 
|         /// </summary> | 
|         /// <param name="HInterID">单据ID</param> | 
|         /// <param name="IsAudit">审核(0),反审核(1)</param> | 
|         /// <param name="CurUserName">审核人</param> | 
|         /// <returns></returns> | 
|         [Route("Sc_ProcessReport/MES_Sc_ProcessReportCheck")] | 
|         [HttpGet] | 
|         public object MES_Sc_ProcessReportCheck(int HInterID, int IsAudit, string CurUserName) | 
|         { | 
|             string ModRightNameCheck = "MES_ProductReport_Check"; | 
|             DBUtility.ClsPub.CurUserName = CurUserName; | 
|             try | 
|             { | 
|                 string StrMessage = ""; | 
|                 //审核权限 | 
|                 if (!WebClsPub.Security_Log(ModRightNameCheck, 1, false, CurUserName, ref StrMessage)) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = StrMessage; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 if (HInterID <= 0) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "HInterID小于0!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 Int64 lngBillKey = 0; | 
|                 lngBillKey = DBUtility.ClsPub.isLong(HInterID); | 
|                 DLL.ClsSc_ProcessReport oBill = new DLL.ClsSc_ProcessReport(); | 
|                 //查看是否已审核,关闭,作废 | 
|                 if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) | 
|                 { | 
|                     if (oBill.omodel.HCloseMan.Trim() != "") | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "单据已关闭!不能再次审核!"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                     if (oBill.omodel.HDeleteMan.Trim() != "") | 
|                     { | 
|                         objJsonResult.code = "0"; | 
|                         objJsonResult.count = 0; | 
|                         objJsonResult.Message = "单据已作废!不能再次审核!"; | 
|                         objJsonResult.data = null; | 
|                         return objJsonResult; | 
|                     } | 
|                     if (IsAudit == 0)  //审核判断 | 
|                     { | 
|                         if (oBill.omodel.HChecker.Trim() != "") | 
|                         { | 
|                             objJsonResult.code = "0"; | 
|                             objJsonResult.count = 0; | 
|                             objJsonResult.Message = "单据已审核!不能再次审核!"; | 
|                             objJsonResult.data = null; | 
|                             return objJsonResult; | 
|                         } | 
|                     } | 
|                     if (IsAudit == 1) //反审核判断 | 
|                     { | 
|                         if (oBill.omodel.HChecker.Trim() == "") | 
|                         { | 
|                             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 (oBill.CheckBill(lngBillKey, 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) //反审核提交 | 
|                 { | 
|                     //反审核提交AbandonCheck | 
|                     if (oBill.AbandonCheck(lngBillKey, 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; | 
|             } | 
|         } | 
|         #endregion | 
|   | 
|         #region [工序汇报单删除功能] | 
|         /// <summary> | 
|         /// 开工单删除功能 | 
|         /// </summary> | 
|         /// <returns></returns> | 
|         [Route("Sc_ProcessReport/DeltetMESProcessReport")] | 
|         [HttpGet] | 
|         public object DeltetMESProcessReport(string HInterID, string UserName) | 
|         { | 
|             DBUtility.ClsPub.CurUserName = UserName; | 
|             //编辑权限 | 
|             //if (!DBUtility.ClsPub.Security_Log_second("MES_Sc_ProcessReporBill_Delete", 1, false, DBUtility.ClsPub.CurUserName)) | 
|             //{ | 
|             //    objJsonResult.code = "0"; | 
|             //    objJsonResult.count = 0; | 
|             //    objJsonResult.Message = "无删除权限!"; | 
|             //    objJsonResult.data = null; | 
|             //    return objJsonResult; | 
|             //} | 
|   | 
|             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; | 
|             } | 
|             DLL.ClsSc_ProcessReport oBill = new DLL.ClsSc_ProcessReport(); | 
|             if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) | 
|             { | 
|                 if (oBill.omodel.HBillStatus > 1) | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "单据当前处于不能删除状态,不能删除!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|                 if (oBill.omodel.HChecker != "") | 
|                 { | 
|                     objJsonResult.code = "0"; | 
|                     objJsonResult.count = 0; | 
|                     objJsonResult.Message = "单据已经审核,不能删除!"; | 
|                     objJsonResult.data = null; | 
|                     return objJsonResult; | 
|                 } | 
|   | 
|                 bool IsDete = oBill.DeleteBill(oBill.omodel.HInterID, 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 | 
|     } | 
| } |