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 OaUserGroupHandler : IHttpHandler { 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 = list(context); break; case "add": returnstr = add(context); break; case "update": returnstr = update(context); break; case "delete": returnstr = delete(context); break; } context.Response.Write(returnstr); } //查询 private string list(HttpContext context) { string returnstr = ""; try { string orgId = context.Request.Params["OrgId"]; string sql = ""; if (string.IsNullOrEmpty(orgId)) { return "{\"code\":\"-1\",\"msg\":\"请求异常,请联系平台管理员。\",\"error\":\"orgId参数不能为空!\",\"data\":[]}"; } else { sql = @" select * from oa_usergroup where org_Id = '" + orgId + @"' "; } returnstr += "{\"code\":0,\"data\":"; DataTable dt = FangYar.Common.MySqlHelper.QueryTable(sql); returnstr += Common.JsonHelper.ToJson(dt); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"error\":\""+e.Message+"\",\"msg\":\"error\",\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "周食谱记录操作请求", "查询异常:" + e); } return returnstr; } //添加 private string add(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = Guid.NewGuid().ToString("N"); string PID = context.Request.Params["PID"]; string NAME = context.Request.Params["NAME"]; string USERS = context.Request.Params["USERS"]; string USERS_NAME = context.Request.Params["USERS_NAME"]; string ORG_ID = context.Request.Params["ORG_ID"]; string ORG_NAME = context.Request.Params["ORG_NAME"]; string STATE = context.Request.Params["STATE"]; string IS_PRIVATE = context.Request.Params["IS_PRIVATE"]; string REMARKS = context.Request.Params["REMARKS"]; string SORT_STR = context.Request.Params["SORT"]; int SORT = 9999; if (!string.IsNullOrEmpty(SORT_STR)) { SORT = int.Parse(SORT_STR); } string sql = @" insert into oa_usergroup ( ID,PID,NAME,USERS,USERS_NAME,ORG_ID,ORG_NAME,STATE,IS_PRIVATE,REMARKS,SORT ) values ( '" + ID + @"', '" + PID + @"', '" + NAME + @"', '" + USERS + @"', '" + USERS_NAME + @"', '" + ORG_ID + @"', '" + ORG_NAME + @"', '" + STATE + @"', '" + IS_PRIVATE + @"', '" + REMARKS + @"', '" + SORT + @"' )"; if (FangYar.Common.MySqlHelper.ExecuteSql(sql)>0) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } catch { msg = "添加失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //修改 private string update(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string PID = context.Request.Params["PID"]; string NAME = context.Request.Params["NAME"]; string USERS = context.Request.Params["USERS"]; string USERS_NAME = context.Request.Params["USERS_NAME"]; string ORG_ID = context.Request.Params["ORG_ID"]; string ORG_NAME = context.Request.Params["ORG_NAME"]; string STATE = context.Request.Params["STATE"]; string IS_PRIVATE = context.Request.Params["IS_PRIVATE"]; string REMARKS = context.Request.Params["REMARKS"]; string SORT_STR = context.Request.Params["SORT"]; int SORT = 9999; if (!string.IsNullOrEmpty(SORT_STR)) { SORT = int.Parse(SORT_STR); } string sql = @" update oa_usergroup set PID = '" + PID + @"', NAME = '" + NAME + @"', USERS = '" + USERS + @"', USERS_NAME = '" + USERS_NAME + @"', ORG_ID = '" + ORG_ID + @"', ORG_NAME = '" + ORG_NAME + @"', STATE = '" + STATE + @"', IS_PRIVATE = '" + IS_PRIVATE + @"', REMARKS = '" + REMARKS + @"', SORT = '" + SORT + @"' where ID = '" + ID + @"' "; if (FangYar.Common.MySqlHelper.ExecuteSql(sql)>0) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } catch { msg = "修改失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //删除 private string delete(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string sql = @" delete from oa_usergroup where ID = '" + ID + @"'"; if (FangYar.Common.MySqlHelper.ExecuteSql(sql)>0) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除异常!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } public bool IsReusable { get { return false; } } } }