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; namespace FangYar.WebUI.ashx { /// /// OaLeaveHandler 的摘要说明 /// public class OaRecipeDicdetailHandler : IHttpHandler { private FangYar.BLL.OA.OA_RECIPE_DICDETAIL bll = new FangYar.BLL.OA.OA_RECIPE_DICDETAIL(); 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 "GetDicdetail": returnstr = GetDicdetail(context); break; case "Add": returnstr = AddRollcallTask(context); break; case "Edit": returnstr = EditRollcallTask(context); break; case "Del": returnstr = Del(context); break; case "AppAdd": returnstr = AppAddRollcallTask(context); break; case "AppEdit": returnstr = AppEditRollcallTask(context); break; case "GetRecipeDicdetailSingle": returnstr = GetRecipeDicdetailSingle(context); break; } context.Response.Write(returnstr); } //查询(分页) private string GetList(HttpContext context) { string returnstr = ""; try { string ORG_ID = context.Request.Params["OrgId"]; string page = context.Request.Params["page"]; string limit = context.Request.Params["limit"]; string keywords = context.Request.Params["keywords"] + ""; 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(keywords)) { where += " and ( NAME like '%" + keywords + "%' or DES like '%" + keywords + "%') "; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { DataTable dt = bll.GetListByPage(where, "ISDISABLE , 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 GetDicdetail(HttpContext context) { string returnstr = ""; try { string ORG_ID = context.Request.Params["OrgId"]; string where = ""; if (!string.IsNullOrEmpty(ORG_ID)) { where += " ORG_ID = '" + ORG_ID + "' and ISDISABLE = '0'"; } else { return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { where += " ORDER BY ISDISABLE , NAME "; List list = bll.GetModelList(where); returnstr += FangYar.Common.JsonHelper.ToJson(list); } 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 AddRollcallTask(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string NAME = context.Request.Params["NAME"]; string ID = Guid.NewGuid().ToString("N"); string DES = context.Request.Params["DES"]; string PIC = context.Request.Params["PIC"]; string ISDISABLE = context.Request.Params["ISDISABLE"]; string ORG_ID = context.Request.Params["ORG_ID"]; // FangYar.Model.OA.OA_RECIPE_DICDETAIL model = new Model.OA.OA_RECIPE_DICDETAIL(); model.ID = ID; model.NAME = NAME; model.DES = DES; model.PIC = PIC; model.ISDISABLE = ISDISABLE; model.ORG_ID = ORG_ID; if (bll.ExistsNAME(NAME, ORG_ID)) { msg = "添加失败,菜品名称有重复!"; } else { if (bll.Add(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } } catch (Exception e) { msg = "添加失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱字典项操作请求", "添加异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "食谱字典项操作请求", "添加"); return returnstr; } //修改 private string EditRollcallTask(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string NAME = context.Request.Params["NAME"]; string DES = context.Request.Params["DES"]; string PIC = context.Request.Params["PIC"]; string ISDISABLE = context.Request.Params["ISDISABLE"]; string ORG_ID = context.Request.Params["ORG_ID"]; //点名任务表 FangYar.Model.OA.OA_RECIPE_DICDETAIL model = new Model.OA.OA_RECIPE_DICDETAIL(); model.ID = ID; model.NAME = NAME; model.DES = DES; model.PIC = PIC; model.ISDISABLE = ISDISABLE; model.ORG_ID = ORG_ID; if (bll.Update(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } catch (Exception e) { msg = "修改失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱字典项操作请求", "修改异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "食谱字典项操作请求", "修改"); return returnstr; } //删除 private string Del(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string id = context.Request.Params["id"]; if (bll.Delete(id)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch (Exception e) { msg = "删除失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱字典项操作请求", "删除异常:" + e); } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "食谱字典项操作请求", "删除"); return returnstr; } //添加 private string AppAddRollcallTask(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string NAME = context.Request.Params["NAME"]; string ID = Guid.NewGuid().ToString("N"); string DES = context.Request.Params["DES"]; string ISDISABLE = context.Request.Params["ISDISABLE"]; string ORG_ID = context.Request.Params["ORG_ID"]; //点名 FangYar.Model.OA.OA_RECIPE_DICDETAIL model = new Model.OA.OA_RECIPE_DICDETAIL(); model.ID = ID; model.NAME = NAME; model.DES = DES; model.PIC = UploadFile("RecipeDicdetail", context, ID); model.ISDISABLE = ISDISABLE; model.ORG_ID = ORG_ID; if (bll.Add(model)) { msg = "添加成功!"; code = 1; } else { 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 AppEditRollcallTask(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string NAME = context.Request.Params["NAME"]; string DES = context.Request.Params["DES"]; string ISDISABLE = context.Request.Params["ISDISABLE"]; string ORG_ID = context.Request.Params["ORG_ID"]; string PIC = context.Request.Params["PIC"]; // FangYar.Model.OA.OA_RECIPE_DICDETAIL model = new Model.OA.OA_RECIPE_DICDETAIL(); model.ID = ID; model.NAME = NAME; model.DES = DES; model.PIC = UploadFile("RecipeDicdetail", context, ID); if (model.PIC == "" && !string.IsNullOrEmpty(PIC)) { model.PIC = PIC; } model.ISDISABLE = ISDISABLE; model.ORG_ID = ORG_ID; if (bll.Update(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } catch (Exception e) { msg = "修改失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱字典项操作请求", "修改异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "食谱字典项操作请求", "修改"); return returnstr; } //查询 private string GetRecipeDicdetailSingle(HttpContext context) { string returnstr = ""; try { string id = context.Request.Params["id"]; //string where = ""; if (!string.IsNullOrEmpty(id)) { } else { return "{\"code\":-1,\"msg\":\"error\",\"data\":[]}"; } returnstr = "{\"code\":0,\"msg\":\"\",\"data\":"; FangYar.Model.OA.OA_RECIPE_DICDETAIL model = bll.GetModel(id); returnstr += FangYar.Common.JsonHelper.ToJson(model); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "食谱字典项操作请求", "查询异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "食谱字典项操作请求", "查询"); return returnstr; } /// /// 上传多张图片 /// /// /// /// /// 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 = System.AppDomain.CurrentDomain.BaseDirectory + ImageFilePath; item.SaveAs(rootPath + fileName); result += ImageFilePath + fileName + ","; } catch { result += ""; } } result = result.Substring(0, result.Length - 1); } return result; } public bool IsReusable { get { return false; } } } }