| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- <%@ WebHandler Language="C#" Class="setting" %>
- using System;
- using System.Web;
- using System.Web.SessionState;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Data;
- using Curtain.DataAccess;
- using DK.XuWei.WebMes;
- /// <summary>
- /// TP_WEB_SETTING
- /// xuwei create 2021-03-03
- /// </summary>
- public class setting : IHttpHandler, IReadOnlySessionState
- {
- public void ProcessRequest(HttpContext context)
- {
- context.Response.ContentType = "text/plain";
- if (mes.LoginCheck() && context.Request["m"] is object)
- {
- Button b = new Button();
- if(mes.RightCheck(""))
- {
- b.btnIndex = true;
- b.btnInsert = true;
- b.btnInsertBatch = false;
- b.btnCopy = true;
- b.btnUpdate = true;
- b.btnDelete = false;
- b.btnCancel = false;
- b.btnSearch = false;
- b.btnDetail = true;
- b.btnCheckbox = true;
- b.btnExport = false;
- b.btnReload = true;
- }
- switch (context.Request["m"].ToString().ToLower())
- {
- case "b":
- {
- //按钮
- context.Response.Write(new JsonResult(b).ToJson());
- break;
- }
- case "a":
- {
- //添加
- if (b.btnDetail && context.Request["id"] is object)
- context.Response.Write(detail());
- else
- {
- List<xRecord> list = new List<xRecord>();
- xRecord r = new xRecord();
- list.Add(r);
- context.Response.Write(new JsonResult(list).ToJson());
- }
- break;
- }
- case "s":
- {
- //搜索
- if (b.btnIndex)
- context.Response.Write(search(context.Request.Form));
- else
- context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
- break;
- }
- case "t":
- {
- //详细
- if (b.btnDetail)
- context.Response.Write(detail());
- else
- context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
- break;
- }
- case "i":
- {
- //插入
- if (b.btnInsert)
- context.Response.Write(insert(context.Request.Form));
- else
- context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
- break;
- }
- case "u":
- {
- //修改
- if (b.btnUpdate)
- context.Response.Write(update(context.Request.Form));
- else
- context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
- break;
- }
- case "d":
- {
- //删除
- if (b.btnDelete)
- context.Response.Write(delete());
- else
- context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
- break;
- }
- case "e":
- {
- //导出
- if (b.btnExport)
- {
- context.Response.Write(export());
- }
- else
- {
- context.Response.Write(new JsonResult(JsonStatus.rightError).ToJson());
- }
- break;
- }
- default:
- {
- break;
- }
- }
- }
- else
- {
- context.Response.Write(new JsonResult(JsonStatus.loginError).ToJson());
- }
- }
- /// <summary>
- /// TP_WEB_SETTING 查询
- /// </summary>
- /// <returns>json</returns>
- private string search(NameValueCollection form)
- {
- using(IDataAccess conn=DataAccess.Create())
- {
- int page = HttpContext.Current.Request["page"] is object ? Convert.ToInt32(HttpContext.Current.Request["page"]) : 1;
- int rows = HttpContext.Current.Request["rows"] is object ? Convert.ToInt32(HttpContext.Current.Request["rows"]) : 10;
- string sort = HttpContext.Current.Request["sort"] is object ? HttpContext.Current.Request["sort"] : "";
- string order = HttpContext.Current.Request["order"] is object ? HttpContext.Current.Request["order"] : "";
- string sqlStr = @"
- SELECT
- m.ID,
- m.NAME,
- m.VALUE,
- m.MEMO,
- m.ID AS SID
- FROM
- TP_WEB_SETTING m
- WHERE
- 1 = 1
- ";
- List<CDAParameter> sqlPara = new List<CDAParameter>();
- if(!string.IsNullOrEmpty(form["ID"]))
- {
- sqlStr += " AND m.ID = @ID@ ";
- sqlPara.Add(new CDAParameter("ID", form["ID"]));
- }
- if(!string.IsNullOrEmpty(form["NAME"]))
- {
- sqlStr += " AND INSTR( m.NAME, @NAME@ ) > 0 ";
- sqlPara.Add(new CDAParameter("NAME", form["NAME"]));
- }
- if(!string.IsNullOrEmpty(form["VALUE"]))
- {
- sqlStr += " AND INSTR( m.VALUE, @VALUE@ ) > 0 ";
- sqlPara.Add(new CDAParameter("VALUE", form["VALUE"]));
- }
- if(!string.IsNullOrEmpty(form["MEMO"]))
- {
- sqlStr += " AND INSTR( m.MEMO, @MEMO@ ) > 0 ";
- sqlPara.Add(new CDAParameter("MEMO", form["MEMO"]));
- }
- if(sort != "")
- {
- sqlStr += " ORDER BY " + sort + " " + order;
- }
- int total = 0;
- DataTable dt = conn.SelectPages(page, rows,out total, sqlStr, sqlPara.ToArray());
- return new JsonResult(dt) { total = total}.ToJson();
- }
- }
- /// <summary>
- /// 详细 TP_WEB_SETTING
- /// </summary>
- /// <returns>json</returns>
- private string detail()
- {
- using(IDataAccess conn= DataAccess.Create())
- {
- DataTable dt = conn.ExecuteDatatable(@"
- SELECT
- m.NAME,
- m.VALUE,
- m.MEMO,
- m.ID
- FROM
- TP_WEB_SETTING m
- WHERE
- m.ID = @ID@
- ",
- new CDAParameter("ID",HttpContext.Current.Request["id"])
- );
- return new JsonResult(dt).ToJson();
- }
- }
- /// <summary>
- /// 插入 TP_WEB_SETTING
- /// </summary>
- /// <returns>json</returns>
- private string insert(NameValueCollection form)
- {
- using(IDataAccess conn= DataAccess.Create())
- {
- int result = conn.ExecuteNonQuery(@"
- INSERT INTO TP_WEB_SETTING (
- NAME,
- VALUE,
- MEMO
- ) VALUES (
- @NAME@,
- @VALUE@,
- @MEMO@
- )
- ",
- new CDAParameter("NAME",form["NAME"]),
- new CDAParameter("VALUE",form["VALUE"]),
- new CDAParameter("MEMO",form["MEMO"])
- );
- return new JsonResult(JsonStatus.success).ToJson();
- }
- }
- /// <summary>
- /// 更新 TP_WEB_SETTING
- /// </summary>
- /// <returns>json</returns>
- private string update(NameValueCollection form)
- {
- using(IDataAccess conn=DataAccess.Create())
- {
- int result = conn.ExecuteNonQuery(@"
- UPDATE TP_WEB_SETTING
- SET
- NAME = @NAME@,
- VALUE = @VALUE@,
- MEMO = @MEMO@
- WHERE
- ID = @ID@
- ",
- new CDAParameter("NAME",form["NAME"]),
- new CDAParameter("VALUE",form["VALUE"]),
- new CDAParameter("MEMO",form["MEMO"]),
- new CDAParameter("ID",HttpContext.Current.Request["id"])
- );
- return new JsonResult(JsonStatus.success).ToJson();
- }
- }
- /// <summary>
- /// 删除 TP_WEB_SETTING
- /// </summary>
- /// <returns>json</returns>
- private string delete()
- {
- using(IDataAccess conn= DataAccess.Create())
- {
- if (HttpContext.Current.Request["id"] is object)
- {
- int result = conn.ExecuteNonQuery(@"
- DELETE
- TP_WEB_SETTING
- WHERE
- INSTR(',' || @ID@ || ',' , ',' || ID || ',') > 0
- ",
- new CDAParameter("ID", HttpContext.Current.Request["id"])
- );
- return new JsonResult(JsonStatus.success).ToJson();
- }
- else
- {
- return new JsonResult(JsonStatus.otherError).ToJson();
- }
- }
- }
- /// <summary>
- /// 导出 TP_WEB_SETTING
- /// </summary>
- /// <returns>json</returns>
- private string export()
- {
- return search(new NameValueCollection());
- }
- private class Button
- {
- public bool btnIndex = false;
- public bool btnInsert = false;
- public bool btnInsertBatch = false;
- public bool btnCopy = false;
- public bool btnUpdate = false;
- public bool btnDelete = false;
- public bool btnCancel = false;
- public bool btnSearch = false;
- public bool btnDetail = false;
- public bool btnCheckbox = false;
- public bool btnExport = false;
- public bool btnReload = false;
- }
- private class xRecord
- {
- public string sid { get; set; }
- public string NAME { get; set; }
- public string VALUE { get; set; }
- public string MEMO { get; set; }
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
|