using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Text; using System.Collections; using System.Reflection; using System.Web.Script.Serialization; using FangYar.Model; using FangYar.BLL; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using FangYar.Model.OA; namespace FangYar.WebUI.ashx { /// /// OaLeaveHandler 的摘要说明 /// public class OaRecipePlanHandler : IHttpHandler { private FangYar.BLL.OA.OA_RECIPE_PLAN bll = new FangYar.BLL.OA.OA_RECIPE_PLAN(); private FangYar.BLL.OA.BLL_OA_SIMPLERECIPE_RECORD simpleRecipeRecord = new FangYar.BLL.OA.BLL_OA_SIMPLERECIPE_RECORD(); public void ProcessRequest(HttpContext context) { // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "食谱计划操作请求", ""); context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "List": returnstr = GetList(context); break; case "PastRecipes": returnstr = GetPastRecipes(context); break; case "Add": returnstr = AddRecipePlan(context); break; case "Edit": returnstr = EditRecipePlan(context); break; case "GetWeekRecipes": returnstr = GetWeekRecipes(context); break; case "SimpleRecipeAdd": returnstr = SimpleRecipeAdd(context); break; case "SimpleRecipeUpdate": returnstr = SimpleRecipeUpdate(context); break; case "SimpleWeekRecipeList": returnstr = GetSimpleWeekRecipe(context); break; } context.Response.Write(returnstr); } //查询 private string GetList(HttpContext context) { string returnstr = ""; try { string ORG_ID = context.Request.Params["OrgId"]; string keyword = context.Request.Params["keywords"]; string page = context.Request.Params["page"]; string limit = context.Request.Params["limit"]; int pageIndex = 1; int pageSize = 10; int startIndex = 0; int endIndex = 10; if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } startIndex = (pageIndex - 1) * pageSize; endIndex = pageSize; string where = ""; if (!string.IsNullOrEmpty(ORG_ID)) { where += " ORG_ID = '" + ORG_ID + "' "; } else { return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } if (!string.IsNullOrEmpty(keyword)) { where += " and NAME like '%" + keyword + "%' "; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { DataTable dt = bll.GetListByPage(where, "STATE , NAME ", startIndex, endIndex).Tables[0]; returnstr += FangYar.Common.JsonHelper.ToJson(dt); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱计划操作请求", "查询异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "食谱计划操作请求", "查询"); return returnstr; } //查询往期食谱 private string GetPastRecipes(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; returnstr += "{\"code\":200,\"data\":"; DataTable dt = bll.GetPastRecipes(OrgId); returnstr += FangYar.Common.JsonHelper.ToJson(dt); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱计划操作请求", "查询往期食谱异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "食谱计划操作请求", "查询往期食谱"); return returnstr; } private string AddRecipePlan(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string Id = Guid.NewGuid().ToString("N"); string NAME = context.Request.Params["NAME"]; string U_ID = context.Request.Params["U_ID"]; string U_NAME = context.Request.Params["U_NAME"]; string STATE = context.Request.Params["STATE"]; string ORG_ID = context.Request.Params["ORG_ID"]; string recipeRecordArr = context.Request.Params["recipeRecordArr"]; if (bll.ExistsNAME(NAME, ORG_ID)) { return "{\"msg\":\"该营区【" + NAME + "】食谱,已存在!\",\"code\":" + code + "}"; } //周食谱计划表 Model.OA.OA_RECIPE_PLAN model = new Model.OA.OA_RECIPE_PLAN(); model.ID = Id; model.NAME = NAME; model.U_ID = U_ID; model.U_NAME = U_NAME; model.STATE = STATE; model.ORG_ID = ORG_ID; List ht = new List(); BLL.OA.OA_RECIPE_RECORD record_bll = new BLL.OA.OA_RECIPE_RECORD(); List record_data = JsonConvert.DeserializeObject>(context.Request.Params["recipeRecordArr"]); for (int i = 0; i < record_data.Count; i++) { record_data[i].ID = Guid.NewGuid().ToString("N"); record_data[i].U_ID = U_ID; record_data[i].U_NAME = U_NAME; record_data[i].ORG_ID = ORG_ID; record_data[i].PLAN_ID = model.ID; Model.OA.CommonSql record_sql = record_bll.getInsertRecordSql(record_data[i]); ht.Add(record_sql); } CommonSql plan_sql = bll.getInsertPlanSql(model); ht.Add(plan_sql); if (FangYar.Common.MySqlHelper.ExecuteSqlTranBool(ht)) { code = 1; msg = "添加成功"; } else { code = 0; msg = "添加失败"; } } catch (Exception e) { msg = "添加失败:" + e.Message; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱计划操作请求", "添加异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "食谱计划操作请求", "添加"); return returnstr; } //修改 private string EditRecipePlan(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string PLANID = context.Request.Params["PLAN_ID"]; string NAME = context.Request.Params["NAME"]; string U_ID = context.Request.Params["U_ID"]; string U_NAME = context.Request.Params["U_NAME"]; string STATE = context.Request.Params["STATE"]; string ORG_ID = context.Request.Params["ORG_ID"]; string recipeRecordArr = context.Request.Params["recipeRecordArr"]; if (!bll.Exists(PLANID)) { return "{\"msg\":\"未查询到【" + NAME + "】食谱,无法修改!\",\"code\":" + code + "}"; } //周食谱计划表 FangYar.Model.OA.OA_RECIPE_PLAN model = new Model.OA.OA_RECIPE_PLAN(); model.ID = PLANID; model.NAME = NAME; model.U_ID = U_ID; model.U_NAME = U_NAME; model.STATE = STATE; model.ORG_ID = ORG_ID; List ht = new List(); FangYar.BLL.OA.OA_RECIPE_RECORD record_bll = new FangYar.BLL.OA.OA_RECIPE_RECORD(); List record_data = JsonConvert.DeserializeObject>(recipeRecordArr); for (int i = 0; i < record_data.Count; i++) { record_data[i].U_ID = U_ID; record_data[i].U_NAME = U_NAME; record_data[i].ORG_ID = ORG_ID; record_data[i].PLAN_ID = model.ID; FangYar.Model.OA.CommonSql record_sql = record_bll.getUpdateRecordSql(record_data[i]); ht.Add(record_sql); } FangYar.Model.OA.CommonSql plan_sql = bll.getUpdatePlanSql(model); ht.Add(plan_sql); if (FangYar.Common.MySqlHelper.ExecuteSqlTranBool(ht)) { code = 1; msg = "修改成功"; } else { code = 0; msg = "修改失败"; } } catch (Exception e) { msg = "修改失败:" + e.Message; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱计划操作请求", "修改异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "食谱计划操作请求", "修改"); return returnstr; } //获取一周食谱 private string GetWeekRecipes(HttpContext context) { string returnstr = ""; try { string year = context.Request.Params["year"]; string week = context.Request.Params["week"]; string ORG_ID = context.Request.Params["ORG_ID"]; string STATE = context.Request.Params["STATE"]; returnstr += "{\"code\":0,\"data\":"; string whereStr = " ORG_ID='" + ORG_ID + "' and NAME = '" + year + " " + "第" + week + "周'"; if (!string.IsNullOrEmpty(STATE)) { whereStr += " and STATE = '" + STATE + "' "; } DataTable dt = bll.GetList(whereStr).Tables[0]; returnstr += FangYar.Common.JsonHelper.ToJson(dt); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":-1,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱计划操作请求", "获取一周食谱异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "食谱计划操作请求", "获取一周食谱"); return returnstr; } #region 一周食谱 private string GetSimpleWeekRecipe(HttpContext context) { string returnstr = ""; try { //string Name = context.Request.Params["Name"].Trim(); string OrgId = context.Request.Params["OrgId"]; string Year = context.Request.Params["Year"]; string Week = context.Request.Params["Week"]; //string STATE = context.Request.Params["STATE"]; string Page = context.Request.Params["Page"]?.Trim(); string Limit = context.Request.Params["Limit"]?.Trim(); if (string.IsNullOrEmpty(OrgId)) { return "{\"code\":-1,\"msg\":\"请求异常,请联系平台管理员。\",\"error\":\"OrgId参数不能为空!\",\"count\":0,\"data\":[]}"; } if (string.IsNullOrEmpty(Year)) { return "{\"code\":-1,\"msg\":\"请求异常,请联系平台管理员。\",\"error\":\"Year参数不能为空!\",\"count\":0,\"data\":[]}"; } if (string.IsNullOrEmpty(Week)) { return "{\"code\":-1,\"msg\":\"请求异常,请联系平台管理员。\",\"error\":\"Week参数不能为空!\",\"count\":0,\"data\":[]}"; } string where = " OrgId='" + OrgId + "' and Year = '" + Year + "' and Week = '" + Week + "'"; //if (!string.IsNullOrEmpty(Name)) //{ // where += " and Name = '" + Name + "'"; //} where += " and State ='1' "; var RecordDt = simpleRecipeRecord.GetList(where).Tables[0]; returnstr += "{\"code\":1,\"count\":" + RecordDt.Rows.Count + ",\"data\":"; returnstr += Common.JsonHelper.ToJson(RecordDt); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱计划操作请求", "获取一周食谱异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "食谱计划操作请求", "获取一周食谱"); return returnstr; } /// ///一周食谱 /// /// /// private string SimpleRecipeAdd(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string Id = Guid.NewGuid().ToString("N"); string RecipeName = context.Request.Params["RecipeName"]?.Trim(); string UserId = context.Request.Params["UserId"]?.Trim(); string UserName = context.Request.Params["UserName"]?.Trim(); //string State = context.Request.Params["State"]; string OrgId = context.Request.Params["OrgId"]?.Trim(); string Remarks = context.Request.Params["Remarks"]?.Trim(); string YEAR = context.Request.Params["YEAR"]; string WEEK = context.Request.Params["WEEK"]; OA_SIMPLERECIPE_RECORD model = new OA_SIMPLERECIPE_RECORD(); model.Id = Id; model.Name = RecipeName; model.CreateBy = UserId; model.Creator = UserName; model.CreateDateTime = DateTime.Now.ToString("G"); model.State = "1"; model.OrgId = OrgId; model.AttachmentURL = UploadFile("SimpleRecipe", context, Guid.NewGuid().ToString("N")); model.Remarks = Remarks; model.YEAR = YEAR; model.WEEK = WEEK; CommonSql simpleRecipleSql = simpleRecipeRecord.getInsertRecordSql(model); List ht = new List(); ht.Add(simpleRecipleSql); if (FangYar.Common.MySqlHelper.ExecuteSqlTranBool(ht)) { code = 1; msg = "添加成功"; } else { code = 0; msg = "添加失败"; } } catch (Exception e) { msg = "添加失败:" + e.Message; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱计划操作请求", "添加异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "食谱计划操作请求", "添加"); return returnstr; } private string SimpleRecipeUpdate(HttpContext context) { int code = -1; string msg = String.Empty; try { string Id = context.Request.Params["Id"]?.Trim(); string RecipeName = context.Request.Params["RecipeName"]?.Trim(); string UserId = context.Request.Params["UserId"]?.Trim(); string UserName = context.Request.Params["UserName"]?.Trim(); //string State = context.Request.Params["State"]; string OrgId = context.Request.Params["OrgId"]?.Trim(); string Remarks = context.Request.Params["Remarks"]?.Trim(); string YEAR = context.Request.Params["YEAR"]; string WEEK = context.Request.Params["WEEK"]; //周食谱计划表 OA_SIMPLERECIPE_RECORD model = new OA_SIMPLERECIPE_RECORD(); model.Id = Id; model.Name = RecipeName; model.UpdateBy = UserId; model.Updater = UserName; model.UpdateDateTime = DateTime.Now.ToString("G"); model.State = "1"; model.OrgId = OrgId; model.AttachmentURL = UploadFile("SimpleRecipe", context, Guid.NewGuid().ToString("N")); model.Remarks = Remarks; model.YEAR = YEAR; model.WEEK = WEEK; List ht = new List(); Model.OA.CommonSql plan_sql = simpleRecipeRecord.getUpdateRecordSql(model); ht.Add(plan_sql); if (FangYar.Common.MySqlHelper.ExecuteSqlTranBool(ht)) { code = 1; msg = "修改成功"; } else { code = 0; msg = "修改失败"; } } catch (Exception e) { msg = "修改失败:" + e.Message; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱计划操作请求", "修改异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "食谱计划操作请求", "修改"); return "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; } #endregion /// /// 上传多张图片 /// /// /// /// /// private static string UploadFile(string url, HttpContext context, string CONNMOD_ID) { string result = ""; if (context.Request.Files.Count > 0) { string ImageFilePath = "/Upload/" + url + "/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString(); if (System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(ImageFilePath)) == false)//如果不存在就创建文件夹 { System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(ImageFilePath)); } for (int i = 0; i < context.Request.Files.Count; i++) { HttpPostedFile item = context.Request.Files[i]; string fileName = CONNMOD_ID + i + ".png"; try { string rootPath = AppDomain.CurrentDomain.BaseDirectory + ImageFilePath; item.SaveAs(rootPath + fileName); result += ImageFilePath + fileName + ","; } catch (Exception r) { result += ""; } } result = result.Substring(0, result.Length - 1); } return result; } public bool IsReusable { get { return false; } } } }