using Newtonsoft.Json; using SyntacticSugar.constant; 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.SCGL { public class Sc_MESProductReportStepBillController : ApiController { private json objJsonResult = new json(); public DataSet ds = new DataSet(); public WebServer webserver = new WebServer(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); private WebS.WebService1 oWebs = new WebS.WebService1(); #region 产量汇报列表 [Route("Sc_MESProductReportStepBill/Get_Sc_MESProductReportBillListxxxx")] [HttpGet] public object Get_Sc_MESProductReportBillListxxxx(string sWhere) { try { if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillProcessWorkQty_Tmp " + sWhere+ "order by 单据号 desc", "h_v_IF_ICMOBillProcessWorkQty_Tmp"); } else { string sql1 = "select * from h_v_IF_ICMOBillProcessWorkQty_Tmp where 1 = 1 "; string sql = sql1 + sWhere+ " order by 单据号 desc"; ds = oCN.RunProcReturn(sql, "h_v_IF_ICMOBillProcessWorkQty_Tmp"); } 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; } } #endregion #region 产量汇报编辑获取数据 [Route("Sc_MESProductReportStepBill/Get_Sc_MESProductReportEditBillListxxxx")] [HttpGet] public object Get_Sc_MESProductReportEditBillListxxxx(string linterid, string HICMOInID, string HICMOEnID) { try { //根据选择资源ID获取当前生产工单、责任人 ds=oCN.RunProcReturn("select * from h_v_IF_ICMOBillProcessWorkQty_Tmp where HInterID='" + linterid + "' and HICMOInterID='" + HICMOInID + "' and HICMOEntryID='" + HICMOEnID + "'", "h_v_IF_ICMOBillProcessWorkQty_Tmp"); if (ds.Tables[0].Rows.Count > 0) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "获取资源绑定数据成功!"; objJsonResult.data = ds; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "暂无资源绑定!"; objJsonResult.data = null; return objJsonResult; } } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = e.Message.ToString(); objJsonResult.data = null; } return objJsonResult; } #endregion #region 产量汇报列表新 [Route("Sc_MESProductReportStepBill/Get_Sc_MESProductReportBillList")] [HttpGet] public object Get_Sc_MESProductReportBillList(string sWhere, string user) { try { List a = new List(); //判断是否有查询权限 if (!DBUtility.ClsPub.Security_Log("MES_ProcExchReport_Query", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限查询!"; objJsonResult.data = null; return objJsonResult; } if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillWorkQtyStatus_Tmp order by HInterID desc", "h_v_IF_ICMOBillWorkQtyStatus_Tmp"); } else { string sql1 = "select * from h_v_IF_ICMOBillWorkQtyStatus_Tmp where 1 = 1 "; string sql = sql1 + sWhere + " order by HInterID desc"; ds = oCN.RunProcReturn(sql, "h_v_IF_ICMOBillWorkQtyStatus_Tmp"); } foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用 { Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接 // 将列名和数据类型信息拼接成一个JSON格式的字符串 a.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "查询数据成功!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = a; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 产量汇报单 分页列表 [Route("Sc_MESProductReportStepBill/Get_Sc_MESProductReportBillPage")] [HttpGet] public json Get_Sc_MESProductReportBillPage(string sWhere, string user, int page, int size) { DataSet ds; json res = new json(); try { List columnNameList = new List(); //判断权限 if (!DBUtility.ClsPub.Security_Log("Sc_ICMOReportBillList", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限查询!"; objJsonResult.data = null; return objJsonResult; } sWhere = sWhere.Replace("'", "''"); if (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("exec h_p_Sc_ICMOStepBillWorkQtyStatusList " + page + "," + size + ",''", "h_p_Sc_ICMOStepBillWorkQtyStatusList"); } else { ds = oCN.RunProcReturn("exec h_p_Sc_ICMOStepBillWorkQtyStatusList " + page + "," + size + ",'" + sWhere + "'", "h_p_Sc_ICMOStepBillWorkQtyStatusList"); } //添加列名 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列对象的列名 } res.code = CodeConstant.SUCCEED; res.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString()); res.Message = "Sucess!"; res.list = columnNameList; res.data = ds.Tables[0]; return res; } catch (Exception e) { res.code = CodeConstant.FAIL; res.count = CountConstant.FAIL; res.Message = "Exception!" + e.ToString(); res.data = null; return res; } } #endregion #region 产量汇报编辑获取数据新 [Route("Sc_MESProductReportStepBill/Get_Sc_MESProductReportEditBillList")] [HttpGet] public object Get_Sc_MESProductReportEditBillList(string linterid, string HICMOInID, string HICMOEnID) { try { //根据选择资源ID获取当前生产工单、责任人 ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillWorkQtyStatus_Edit where HInterID='" + linterid + "' and HICMOInterID='" + HICMOInID + "' and HICMOEntryID='" + HICMOEnID + "'", "h_v_IF_ICMOBillWorkQtyStatus_Edit"); if (ds.Tables[0].Rows.Count > 0) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "获取资源绑定数据成功!"; objJsonResult.data = ds; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "暂无资源绑定!"; objJsonResult.data = null; return objJsonResult; } } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = e.Message.ToString(); objJsonResult.data = null; } return objJsonResult; } #endregion #region 产量汇报单 关闭/反关闭 /// /// /// 单据ID /// 关闭(0),反关闭(1) /// 关闭人 /// [Route("Sc_MESProductReportStepBill/CloseSc_ICMOBillWorkQtyStatus")] [HttpGet] public object CloseSc_ICMOBillWorkQtyStatus(int HInterID, int IsAudit, string CurUserName) { string ModRightNameCheck = "Sc_ICMOReportBill_Close"; 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; } Int64 lngBillKey = 0; lngBillKey = DBUtility.ClsPub.isLong(HInterID); //对HInterID进行类型的转换 DLL.ClsSc_ICMOStepBillWorkQtyStatus_Tmp oBill = new DLL.ClsSc_ICMOStepBillWorkQtyStatus_Tmp(); //实例化单据操作类,用于进行相关操作 //针对需要进行的操作,检验当前单据的状态是否支持需要进行的操作 if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) //根据HInterID获取该单据的数据 { if (oBill.omodel.HDeleteMan.Trim() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已作废!不能进行关闭!"; objJsonResult.data = null; return objJsonResult; } if (oBill.omodel.HChecker.Trim() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据未审核!不能进行关闭!"; objJsonResult.data = null; return objJsonResult; } if (IsAudit == 0) //关闭判断 { if (oBill.omodel.HCloseMan.Trim() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已关闭!不能再次关闭!"; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反关闭判断 { if (oBill.omodel.HCloseMan.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) //关闭提交 { //关闭前控制========================================= string sql1 = "exec h_p_Sc_ICMOStepBillWorkQtyStatus_BeforeCloseCtrl " + oBill.omodel.HInterID + ",'" + oBill.omodel.HBillNo + "','" + CurUserName + "'"; ds = oCN.RunProcReturn(sql1, "h_p_Sc_ICMOStepBillWorkQtyStatus_BeforeCloseCtrl"); 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 (oBill.CloseBill(lngBillKey, oBill.omodel.HBillNo, "h_p_Sc_ICMOStepBillWorkQtyStatus_AfterCloseCtrl", CurUserName, 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) //反关闭提交 { //反关闭前控制========================================= string sql1 = "exec h_p_Sc_ICMOStepBillWorkQtyStatus_BeforeUnCloseCtrl " + oBill.omodel.HInterID + ",'" + oBill.omodel.HBillNo + "','" + CurUserName + "'"; ds = oCN.RunProcReturn(sql1, "h_p_Sc_ICMOStepBillWorkQtyStatus_BeforeUnCloseCtrl"); 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 (oBill.CancelClose(lngBillKey, oBill.omodel.HBillNo, "h_p_Sc_ICMOStepBillWorkQtyStatus_AfterUnCloseCtrl", CurUserName, 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 产量汇报单 作废/反作废 /// /// /// 单据ID /// 作废(0),反作废(1) /// 作废人 /// [Route("Sc_MESProductReportStepBill/DeleteSc_ICMOStepBillWorkQtyStatus")] [HttpGet] public object DeleteSc_ICMOStepBillWorkQtyStatus(int HInterID, int IsAudit, string CurUserName) { string ModRightNameCheck = "Sc_ICMOReportBill_Delete"; 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; } Int64 lngBillKey = 0; lngBillKey = DBUtility.ClsPub.isLong(HInterID); //对HInterID进行类型的转换 DLL.ClsSc_ICMOStepBillWorkQtyStatus_Tmp oBill = new DLL.ClsSc_ICMOStepBillWorkQtyStatus_Tmp(); //实例化单据操作类,用于进行相关操作 //针对需要进行的操作,检验当前单据的状态是否支持需要进行的操作 if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) //根据HInterID获取该单据的数据 { if (oBill.omodel.HChecker.Trim() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核!不能进行作废!"; objJsonResult.data = null; return objJsonResult; } if (IsAudit == 0) //作废判断 { if (oBill.omodel.HDeleteMan.Trim() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已作废!不能再作废!"; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反作废判断 { if (oBill.omodel.HDeleteMan.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.Cancelltion(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) //反关闭提交 { //反关闭提交 if (oBill.AbandonCancelltion(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 } }