| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using HySoft.Common;
- using System.Data;
- namespace HySoft.BaseCallCenter.Web.askmanage.ajax
- {
- /// <summary>
- /// question 的摘要说明
- /// </summary>
- public class question : IHttpHandler
- {
- public void ProcessRequest(HttpContext context)
- {
- context.Response.ContentType = "text/plain";
- string action = CommonRequest.GetQueryString("action");
- switch (action)
- {
- case "getlist":
- context.Response.Write(LoadList(context));
- break;
- case "getlistbypager":
- context.Response.Write(LoadListByPager(context));
- break;
- case "getselectlist":
- context.Response.Write(LoadSelectList(context));
- break;
- case "delete":
- context.Response.Write(DeleteById(context));
- break;
- }
- }
- #region 删除试题
- private string DeleteById(HttpContext context)
- {
- string str = "error";
- try
- {
- if (new BLL.T_Ask_Question().Delete(Convert.ToInt32(context.Request.Params["id"])))
- {
- if (new BLL.T_Ask_QuestionItems().DeleteByQuestionId(Convert.ToInt32(context.Request.Params["id"])))
- {
- str = "success";
- }
- else
- {
- str = "error";
- }
- str = "success";
- }
- else
- {
- str = "error";
- }
- }
- catch (Exception ex)
- {
- }
- return str;
- }
- #endregion
- #region 获取数据
- private string LoadList(HttpContext context)
- {
- string res = "";
- DataTable dt = new DataTable();
- string sql = " ";
- try
- {
- string strpageindex = context.Request.Params["page"];
- int pageindex = 1;
- string strpagesize = context.Request.Params["pagesize"];
- int pagesize = 10;
- string categoryid = context.Request.Params["categoryid"];
- string selecttype = context.Request.Params["selecttype"];
- string key = context.Request.Params["key"];
- if (categoryid.Trim() != "")
- {
- sql += " and F_CategoryId=" + categoryid + " ";
- }
- if (selecttype.Trim() != "")
- {
- sql += " and F_Type=" + selecttype + " ";
- }
- if (key.Trim() != "")
- {
- sql += " and (F_Title like '%" + key.Trim() + "%' or F_Content like '%" + key.Trim() + "%') ";
- }
- if (strpageindex.Trim() != "")
- {
- try
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- catch
- { }
- }
- if (strpagesize.Trim() != "")
- {
- try
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- catch
- { }
- }
- int recordCount = 0;
- Model.PageData<Model.T_Ask_Question> pageModel = new Model.PageData<Model.T_Ask_Question>();
- dt = BLL.PagerBLL.GetListPager(
- "vw_Ask_Question",
- "F_QuestionId",
- "*",
- " and F_DeleteFlag=0 " + sql,
- "ORDER BY F_QuestionId desc",
- pagesize,
- pageindex,
- true,
- out recordCount);
- System.Collections.Generic.List<Model.T_Ask_Question> modelList = new BLL.T_Ask_Question().DataTableToList(dt);
- pageModel.Rows = modelList;
- pageModel.Total = recordCount;
- System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Ask_Question>));
- using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
- {
- //JSON序列化
- serializer.WriteObject(stream, pageModel);
- res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
- }
- }
- catch (Exception err)
- {
- //res = err.ToString();
- }
- finally
- {
- dt.Clear();
- dt.Dispose();
- }
- return res;
- }
- #endregion
- #region 获取数据
- private string LoadListByPager(HttpContext context)
- {
- string res = "";
- DataTable dt = new DataTable();
- string sql = " ";
- try
- {
- string pagerid = context.Request.Params["pagerid"];
- string userid = context.Request.Params["userid"];
- string strpageindex = context.Request.Params["page"];
- int pageindex = 1;
- string strpagesize = context.Request.Params["pagesize"];
- int pagesize = 10;
- string categoryid = context.Request.Params["categoryid"];
- string selecttype = context.Request.Params["selecttype"];
- string key = context.Request.Params["key"];
- if (categoryid.Trim() != "")
- {
- sql += " and F_CategoryId=" + categoryid + " ";
- }
- if (selecttype.Trim() != "")
- {
- sql += " and F_Type=" + selecttype + " ";
- }
- if (key.Trim() != "")
- {
- sql += " and (F_Title like '%" + key.Trim() + "%' or F_Content like '%" + key.Trim() + "%') ";
- }
- if (pagerid.Trim() != "")
- {
- sql += " and F_QuestionId not in (SELECT [F_QuestionId] FROM [T_Ask_PagerItems] where [F_PagerId]=" + pagerid + ") ";
- }
- else
- {
- sql += " and F_QuestionId not in (SELECT [ExpandIntField1] FROM [T_Sys_TempItems] where [F_UserId]=" + userid + " and F_TempName='T_Ask_PagerItems') ";
- }
- if (strpageindex.Trim() != "")
- {
- try
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- catch
- { }
- }
- if (strpagesize.Trim() != "")
- {
- try
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- catch
- { }
- }
- int recordCount = 0;
- Model.PageData<Model.T_Ask_Question> pageModel = new Model.PageData<Model.T_Ask_Question>();
- dt = BLL.PagerBLL.GetListPager(
- "vw_Ask_Question",
- "F_QuestionId",
- "*",
- " and F_DeleteFlag=0 " + sql,
- "ORDER BY F_QuestionId desc",
- pagesize,
- pageindex,
- true,
- out recordCount);
- System.Collections.Generic.List<Model.T_Ask_Question> modelList = new BLL.T_Ask_Question().DataTableToList(dt);
- pageModel.Rows = modelList;
- pageModel.Total = recordCount;
- System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Ask_Question>));
- using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
- {
- //JSON序列化
- serializer.WriteObject(stream, pageModel);
- res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
- }
- }
- catch (Exception err)
- {
- //res = err.ToString();
- }
- finally
- {
- dt.Clear();
- dt.Dispose();
- }
- return res;
- }
- #endregion
- #region 获取数据
- private string LoadSelectList(HttpContext context)
- {
- string res = "";
- DataTable dt = new DataTable();
- string sql = " ";
- try
- {
- string pagerid = context.Request.Params["pagerid"];
- string userid = context.Request.Params["userid"];
- string strpageindex = context.Request.Params["page"];
- int pageindex = 1;
- string strpagesize = context.Request.Params["pagesize"];
- int pagesize = 10;
- //string arrid = context.Request.Params["arrid"];
- //string categoryid = context.Request.Params["categoryid"];
- //string selecttype = context.Request.Params["selecttype"];
- //string key = context.Request.Params["key"];
- //if (categoryid.Trim() != "")
- //{
- // sql += " and F_CategoryId=" + categoryid + " ";
- //}
- //if (selecttype.Trim() != "")
- //{
- // sql += " and F_Type=" + selecttype + " ";
- //}
- //if (key.Trim() != "")
- //{
- // sql += " and (F_Title like '%" + key.Trim() + "%' or F_Content like '%" + key.Trim() + "%') ";
- //}
- //if (arrid.Trim() != "")
- //{
- // sql += " and F_QuestionId in(" + arrid + ") ";
- //}
- //else
- //{
- // sql += " and 1=0 ";
- //}
- if (strpageindex.Trim() != "")
- {
- try
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- catch
- { }
- }
- if (strpagesize.Trim() != "")
- {
- try
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- catch
- { }
- }
- int recordCount = 0;
- Model.PageData<Model.T_Ask_PagerItemsQuestion> pageModel = new Model.PageData<Model.T_Ask_PagerItemsQuestion>();
- if (pagerid.Trim() != "")
- {
- sql += " and [F_PagerId]=" + pagerid + " ";
- dt = BLL.PagerBLL.GetListPager(
- "vw_Ask_PagerQuestion",
- "F_ItemId",
- "*",
- " and F_DeleteFlag=0 " + sql,
- "ORDER BY F_Sort ",
- pagesize,
- pageindex,
- true,
- out recordCount);
- }
- else
- {
- sql += " and F_QuestionId in (SELECT [ExpandIntField1] FROM [T_Sys_TempItems] where [F_UserId]=" + userid + " and F_TempName='T_Ask_PagerItems') ";
- dt = BLL.PagerBLL.GetListPager(
- "vw_Ask_Question LEFT OUTER JOIN T_Sys_TempItems ON vw_Ask_Question.F_QuestionId = T_Sys_TempItems.ExpandIntField1",
- "F_QuestionId",
- "vw_Ask_Question.*,T_Sys_TempItems.ExpandIntField3 as F_Sort,T_Sys_TempItems.F_Id as F_ItemId",
- " and F_DeleteFlag=0 " + sql,
- "ORDER BY T_Sys_TempItems.ExpandIntField3 ",
- pagesize,
- pageindex,
- true,
- out recordCount);
- }
-
- System.Collections.Generic.List<Model.T_Ask_PagerItemsQuestion> modelList = new BLL.T_Ask_Question().DataTableToPagerItemList(dt);
- pageModel.Rows = modelList;
- pageModel.Total = recordCount;
- System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Ask_PagerItemsQuestion>));
- using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
- {
- //JSON序列化
- serializer.WriteObject(stream, pageModel);
- res = System.Text.Encoding.UTF8.GetString(stream.ToArray());
- }
- }
- catch (Exception err)
- {
- //res = err.ToString();
- }
- finally
- {
- dt.Clear();
- dt.Dispose();
- }
- return res;
- }
- #endregion
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
- }
|