using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Web; using System.Web.Script.Services; using System.Web.Services; using MESClassLibrary; using MESClassLibrary.BLL.BasicInfo; using MESClassLibrary.BLL.Injection; using MESClassLibrary.EFModel; using Newtonsoft.Json; using Webservice; using WebService.Model; using JSONTools = Tools.JSONTools; namespace WebService { /// /// APSWebService 的摘要说明 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService] public class APSWebService : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethodAttribute] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public string UpdatePlan(string str) { LogHelper.WriteSysLogBase("[增加或修改计划]" + str, MethodBase.GetCurrentMethod().Name); string res = ""; string errorReason = ""; string stationID = "",stockNo=""; tb_InjectionPlan md1=new tb_InjectionPlan(); InjectionPlanBLL bll = new InjectionPlanBLL(); StationBLL sbll=new StationBLL(); ProductBLL pbll=new ProductBLL(); JsonModel model=new JsonModel(); model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = errorReason; model.DataList = null; //str = "{\"dataList\":[{\"beginTime\":\"2022-06-13 11:04:44\",\"commandType\":\"1\",\"endTime\":\"2022-06-13 19:07:54\",\"partNo\":\"A2138851203-P\",\"planCount\":446,\"stationNo\":\"IM01\"}]}"; //str = "{\"dataList\":[{\"beginTime\":\"2022-05-27 08:58:31\",\"commandType\":\"2\",\"endTime\":\"2022-05-15 15:07:00\",\"partNo\":\"A2058850838-P\",\"planCount\":444,\"stationNo\":\"IM01\",\"u_EndTime\":\"2022-04-24 13:49:00\"}]}"; InjectionUpdatePlanModel md = JsonConvert.DeserializeObject(str); foreach (var item in md.datalist) { #region 校验工位是否存在 DataTable dt1 = sbll.SearchInfoByNo(item.StationNo); if (dt1 != null && dt1.Rows.Count > 0) { stationID=dt1.Rows[0]["StationID"].ToString(); md1.StationID = dt1.Rows[0]["StationID"].ToString(); } else { model.Result = "0"; model.ErrReason = "工位号:" + item.StationNo + "不存在!"; res = JSONTools.ScriptSerialize>(model); return res; } #endregion #region 校验零件号是否存在 DataTable dt2 = pbll.SearchInfoByPartNo(item.PartNo); if (dt2 != null && dt2.Rows.Count > 0) { md1.StockNo = dt2.Rows[0]["StockNo"].ToString(); stockNo = md1.StockNo; } else { model.ErrReason = "零件号:" + item.PartNo + "不存在!"; res = JSONTools.ScriptSerialize>(model); return res; } #endregion #region 校验开始时间是否小于结束时间 if (string.IsNullOrEmpty(item.U_EndTime)) { if (Convert.ToDateTime(item.BeginTime) >= Convert.ToDateTime(item.EndTime)) { model.ErrReason = "开始时间不能大于结束时间!"; res = JSONTools.ScriptSerialize>(model); return res; } } else { if (Convert.ToDateTime(item.BeginTime) >= Convert.ToDateTime(item.U_EndTime)) { model.ErrReason = "开始时间不能大于结束时间!"; res = JSONTools.ScriptSerialize>(model); return res; } } #endregion md1.BeginTime = item.BeginTime; md1.PlanCount = item.PlanCount; md1.PartNo = item.PartNo; if (item.CommandType == "1") //添加 { md1.InjectionPlanID = Guid.NewGuid().ToString(); md1.EndTime = item.EndTime; if (!bll.AddInfo(md1)) { model.ErrReason = "添加计划失败!"; res = JSONTools.ScriptSerialize>(model); return res; } } else if (item.CommandType == "2") //修改 { #region 校验计划是否存在 var list = bll.isExit(item.BeginTime, item.EndTime, stationID, stockNo); if (list.Count ==0) { model.ErrReason = "计划不存在!"; res = JSONTools.ScriptSerialize>(model); return res; } else { DataTable dt5 = Tool.ListToDataTable(list); if (dt5 != null && dt5.Rows.Count > 0) { md1.InjectionPlanID = dt5.Rows[0]["InjectionPlanID"].ToString(); } } #endregion md1.EndTime = item.U_EndTime; if (!bll.UpdateInfo(md1)) { model.ErrReason = "编辑计划失败!"; res = JSONTools.ScriptSerialize>(model); return res; } } } model.Result = "1"; res = JSONTools.ScriptSerialize>(model); LogHelper.WriteSysLogBase("[编辑计划入参]" + str + ";出参" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); return res; } [WebMethodAttribute] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public string DelPlan(string str) { LogHelper.WriteSysLogBase("[删除计划]" + str, MethodBase.GetCurrentMethod().Name); string res = ""; string errorReason = ""; string stationID = "",planID="",stockNo=""; tb_InjectionPlan md1 = new tb_InjectionPlan(); InjectionPlanBLL bll = new InjectionPlanBLL(); InjectionRecordBLL rbll = new InjectionRecordBLL(); StationBLL sbll = new StationBLL(); ProductBLL pbll = new ProductBLL(); JsonModel model = new JsonModel(); model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = errorReason; model.DataList = null; //str = "{\"dataList\":[{\"beginTime\":\"2022-04-24 11:49:00\",\"endTime\":\"2022-04-24 13:49:00\",\"partNo\":\"A2058850838-P\",\"stationNo\":\"IM01\"}]}"; InjectionDelPlanModel md = JsonConvert.DeserializeObject(str); foreach (var item in md.datalist) { #region 校验工位是否存在 DataTable dt1 = sbll.SearchInfoByNo(item.StationNo); if (dt1 != null && dt1.Rows.Count > 0) { stationID = dt1.Rows[0]["StationID"].ToString(); md1.StationID = dt1.Rows[0]["StationID"].ToString(); } else { model.Result = "0"; model.ErrReason = "工位号:" + item.StationNo + "不存在!"; res = JSONTools.ScriptSerialize>(model); return res; } #endregion #region 校验零件号是否存在 DataTable dt2 = pbll.SearchInfoByPartNo(item.PartNo); if (dt2 != null && dt2.Rows.Count > 0) { md1.StockNo = dt2.Rows[0]["StockNo"].ToString(); stockNo = md1.StockNo; } else { model.ErrReason = "零件号:" + item.PartNo + "不存在!"; res = JSONTools.ScriptSerialize>(model); return res; } #endregion #region 校验计划是否存在 var list = bll.isExit(item.BeginTime, item.EndTime, stationID, stockNo); if (list.Count == 0) { model.ErrReason = "计划不存在!"; res = JSONTools.ScriptSerialize>(model); return res; } #endregion #region 校验计划是否已经生产 DataTable dt = Tool.ListToDataTable(list); if (dt != null && dt.Rows.Count > 0) { if (dt.Rows[0]["IsFinish"].ToString() == "1") { model.ErrReason = "工位:"+ item.StationNo +"的计划删除失败,该计划已完成!"; res = JSONTools.ScriptSerialize>(model); return res; } planID = dt.Rows[0]["InjectionPlanID"].ToString(); DataTable dt3 = rbll.SearchInfoByPlanID(planID); if (dt3 != null && dt3.Rows.Count > 0) { model.ErrReason = "工位:" + item.StationNo + "的计划删除失败,该计划生产中!"; res = JSONTools.ScriptSerialize>(model); return res; } } #endregion #region 删除计划 md1.InjectionPlanID = planID; if (!bll.DeleteInfo(md1)) { model.ErrReason = "工位:" + item.StationNo + "的计划删除失败!"; res = JSONTools.ScriptSerialize>(model); return res; } #endregion } model.Result = "1"; res = JSONTools.ScriptSerialize>(model); LogHelper.WriteSysLogBase("[删除计划入参]" + str + ";出参" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); return res; } //[WebMethodAttribute] //[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] //public string GetState(string str) //{ // LogHelper.WriteSysLogBase("[返回计划状态]" + str, MethodBase.GetCurrentMethod().Name); // string res = ""; // string errorReason = ""; // string stationID = "", planID = ""; // tb_InjectionPlan md1 = new tb_InjectionPlan(); // InjectionPlanBLL bll = new InjectionPlanBLL(); // InjectionRecordBLL rbll = new InjectionRecordBLL(); // StationBLL sbll = new StationBLL(); // ProductBLL pbll = new ProductBLL(); // JsonModel model = new JsonModel(); // model.Result = "0"; // model.ResultType = "Result"; // model.ResultRowsCount = "0"; // model.ErrReason = errorReason; // model.DataList = null; // InjectionUpdatePlanModel md = JsonConvert.DeserializeObject(str); // foreach (var item in md.datalist) // { // #region 校验工位是否存在 // DataTable dt1 = sbll.SearchInfoByNo(item.StationNo); // if (dt1 != null && dt1.Rows.Count > 0) // { // stationID = dt1.Rows[0]["StationID"].ToString(); // md1.StationID = dt1.Rows[0]["StationID"].ToString(); // } // else // { // model.Result = "0"; // model.ErrReason = "工位号:" + item.StationNo + "不存在!"; // res = JSONTools.ScriptSerialize>(model); // return res; // } // #endregion // #region 校验零件号是否存在 // DataTable dt2 = pbll.SearchInfoByPartNo(item.PartNo); // if (dt2 != null && dt2.Rows.Count > 0) // { // md1.StockNo = dt2.Rows[0]["StockNo"].ToString(); // } // else // { // model.ErrReason = "零件号:" + item.PartNo + "不存在!"; // res = JSONTools.ScriptSerialize>(model); // return res; // } // #endregion // #region 校验计划是否存在 // var list = bll.isExit(item.BeginTime, item.EndTime, stationID, item.PartNo); // if (list == null) // { // model.ErrReason = "计划不存在!"; // res = JSONTools.ScriptSerialize>(model); // return res; // } // else // { // planID = Tool.ListToDataTable(list).Rows[0]["InjectionPlanID"].ToString(); // } // #endregion // } // return res; //} } }