using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HySoft.Common;
using System.Data;

namespace HySoft.BaseCallCenter.Web.workordermanage.ajax
{
    /// <summary>
    /// workorderstatelist 的摘要说明
    /// </summary>
    public class workorderstatelist : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = CommonRequest.GetQueryString("action");
            switch (action)
            {
                case "getYCLlist":
                    context.Response.Write(GetYCLList(context));
                    break;
                case "getYWJlist":
                    context.Response.Write(GetYWJList(context));
                    break;
                case "getallstatelist":
                    context.Response.Write(GetGDZHCXList(context));
                    break;
                case "getstateinfo":
                    context.Response.Write(GetStateInfo(context));
                    break;
            }
        }
        private string GetYCLList(HttpContext context)
        {
            string res = "";
            DataTable dt = new DataTable();
            string sql = " ";

            try
            {
                string customername = HttpUtility.UrlDecode(CommonRequest.GetQueryString("customername"));
                string time = HttpUtility.UrlDecode(CommonRequest.GetQueryString("createdate"));
                string repairmanname = HttpUtility.UrlDecode(CommonRequest.GetQueryString("repairmanname"));
                string userid = (CommonRequest.GetQueryString("userid") == null || CommonRequest.GetQueryString("userid") == "") ? "-1" : CommonRequest.GetQueryString("userid");
                //string stateid = (CommonRequest.GetQueryString("stateid") == null || CommonRequest.GetQueryString("stateid") == "") ? "-1" : CommonRequest.GetQueryString("stateid");

                string F_Name = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_Name"));
                string F_TypeName = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_TypeName"));
                string F_USERNAME = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_USERNAME"));
                string F_CODE = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_CODE"));
                string F_REPAIRMANPHONE = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_REPAIRMANPHONE"));
                string F_CustomerNature = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_CustomerNature"));
                string F_SystemType = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_SystemType"));
                string F_ServiceDept = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_ServiceDept"));
                string F_QualityGuaranteeEndTime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_QualityGuaranteeEndTime"));
                string strpageindex = context.Request.Params["page"];
                int pageindex = 1;
                string strpagesize = context.Request.Params["pagesize"];
                int pagesize = 10;
                if (strpageindex.Trim() != "")
                {
                    try
                    {
                        pageindex = Convert.ToInt32(strpageindex);
                    }
                    catch
                    { }
                }

                if (strpagesize.Trim() != "")
                {
                    try
                    {
                        pagesize = Convert.ToInt32(strpagesize);
                    }
                    catch
                    { }
                }
                sql += CommonRequest.GetQueryString("whereSql");
                //sql += " and F_WORKORDERSTATEID=7";
                sql += " and F_INSTANCEID IN (SELECT F_INSTANCEID FROM T_Wo_WorkOrderTask WHERE F_LOSEFLAG=1 AND F_OWNERID='" + userid + "')";
                if (customername.Trim() != "")
                {
                    sql += " and F_CUSTOMERNAME like '%" + customername.Trim() + "%' ";
                }
                if (repairmanname.Trim() != "")
                {
                    sql += " and F_REPAIRMANNAME like '%" + repairmanname.Trim() + "%' ";
                }
                if (time.Trim() != "")
                {
                    sql += " and CONVERT(varchar , F_CREATEDATE, 120)>=CONVERT(varchar , '" + time.Trim() + " 00:00:01', 120) and CONVERT(varchar , F_CREATEDATE, 120)<=CONVERT(varchar , '" + time.Trim() + " 23:59:59', 120) ";

                }
                if (F_Name.Trim() != "")
                {
                    sql += " and F_Name='" + F_Name.Trim() + "' ";
                }
                if (F_TypeName.Trim() != "")
                {
                    sql += " and F_TypeName='" + F_TypeName.Trim() + "' ";
                }
                if (F_USERNAME.Trim() != "")
                {
                    sql += " and F_USERNAME like '%" + F_USERNAME.Trim() + "%' ";
                }
                if (F_CODE.Trim() != "")
                {
                    sql += " and F_CODE like '%" + F_CODE.Trim() + "%' ";
                }
                if (F_REPAIRMANPHONE.Trim() != "")
                {
                    sql += " and F_REPAIRMANPHONE like '%" + F_REPAIRMANPHONE.Trim() + "%' ";
                }
                if (F_CustomerNature.Trim() != "")
                {
                    sql += " and F_CustomerNature like '%" + F_CustomerNature.Trim() + "%' ";
                }
                if (F_SystemType.Trim() != "")
                {
                    sql += " and F_SystemType like '%" + F_SystemType.Trim() + "%' ";
                }
                if (F_ServiceDept.Trim() != "")
                {
                    sql += " and F_ServiceDept like '%" + F_ServiceDept.Trim() + "%' ";
                }
                if (F_QualityGuaranteeEndTime.Trim() != "")
                {
                    sql += " and CONVERT(varchar , F_QualityGuaranteeEndTime, 120)>=CONVERT(varchar , '" + F_QualityGuaranteeEndTime.Trim() + " 00:00:01', 120) and CONVERT(varchar , F_QualityGuaranteeEndTime, 120)<=CONVERT(varchar , '" + F_QualityGuaranteeEndTime.Trim() + " 23:59:59', 120) ";
                }
                int recordCount = 0;

                Model.PageData<Model.T_Wo_WorkOrderBase> pageModel = new Model.PageData<Model.T_Wo_WorkOrderBase>();

                dt = BLL.PagerBLL.GetListPager(
                    "V_WorkOrderBase",
                    "F_WORKORDERID",
                    "*",
                    sql,
                    "ORDER BY F_WORKORDERID desc",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);

                System.Collections.Generic.List<Model.T_Wo_WorkOrderBase> modelList = new BLL.T_Wo_WorkOrderBase().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_Wo_WorkOrderBase>));

                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;
        }
        private string GetYWJList(HttpContext context)
        {
            string res = "";
            DataTable dt = new DataTable();
            string sql = " ";

            try
            {
                string customername = HttpUtility.UrlDecode(CommonRequest.GetQueryString("customername"));
                string time = HttpUtility.UrlDecode(CommonRequest.GetQueryString("createdate"));
                string repairmanname = HttpUtility.UrlDecode(CommonRequest.GetQueryString("repairmanname"));
                string F_Name = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_Name"));
                string F_TypeName = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_TypeName"));
                string F_USERNAME = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_USERNAME"));
                string F_CODE = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_CODE"));
                string F_REPAIRMANPHONE = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_REPAIRMANPHONE"));
                string F_CustomerNature = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_CustomerNature"));
                string F_SystemType = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_SystemType"));
                string F_ServiceDept = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_ServiceDept"));
                string F_QualityGuaranteeEndTime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_QualityGuaranteeEndTime"));
                //string stateid = (CommonRequest.GetQueryString("stateid") == null || CommonRequest.GetQueryString("stateid") == "") ? "-1" : CommonRequest.GetQueryString("stateid");
                string userid = (CommonRequest.GetQueryString("userid") == null || CommonRequest.GetQueryString("userid") == "") ? "-1" : CommonRequest.GetQueryString("userid");
                string strpageindex = context.Request.Params["page"];
                int pageindex = 1;
                string strpagesize = context.Request.Params["pagesize"];
                int pagesize = 10;
                if (strpageindex.Trim() != "")
                {
                    try
                    {
                        pageindex = Convert.ToInt32(strpageindex);
                    }
                    catch
                    { }
                }

                if (strpagesize.Trim() != "")
                {
                    try
                    {
                        pagesize = Convert.ToInt32(strpagesize);
                    }
                    catch
                    { }
                }
                sql += CommonRequest.GetQueryString("whereSql");
                sql += " and F_WORKORDERSTATEID=0";
                if (customername.Trim() != "")
                {
                    sql += " and F_CUSTOMERNAME like '%" + customername.Trim() + "%' ";
                }
                if (repairmanname.Trim() != "")
                {
                    sql += " and F_REPAIRMANNAME like '%" + repairmanname.Trim() + "%' ";
                }
                if (time.Trim() != "")
                {
                    sql += " and CONVERT(varchar , F_CREATEDATE, 120)>=CONVERT(varchar , '" + time.Trim() + " 00:00:01', 120) and CONVERT(varchar , F_CREATEDATE, 120)<=CONVERT(varchar , '" + time.Trim() + " 23:59:59', 120) ";
                }
                if (F_Name.Trim() != "")
                {
                    sql += " and F_Name='" + F_Name.Trim() + "' ";
                }
                if (F_TypeName.Trim() != "")
                {
                    sql += " and F_TypeName='" + F_TypeName.Trim() + "' ";
                }
                if (F_USERNAME.Trim() != "")
                {
                    sql += " and F_USERNAME like '%" + F_USERNAME.Trim() + "%' ";
                }
                if (F_CODE.Trim() != "")
                {
                    sql += " and F_CODE like '%" + F_CODE.Trim() + "%' ";
                }
                if (F_REPAIRMANPHONE.Trim() != "")
                {
                    sql += " and F_REPAIRMANPHONE like '%" + F_REPAIRMANPHONE.Trim() + "%' ";
                }
                if (F_CustomerNature.Trim() != "")
                {
                    sql += " and F_CustomerNature like '%" + F_CustomerNature.Trim() + "%' ";
                }
                if (F_SystemType.Trim() != "")
                {
                    sql += " and F_SystemType like '%" + F_SystemType.Trim() + "%' ";
                }
                if (F_ServiceDept.Trim() != "")
                {
                    sql += " and F_ServiceDept like '%" + F_ServiceDept.Trim() + "%' ";
                }
                if (F_QualityGuaranteeEndTime.Trim() != "")
                {
                    sql += " and CONVERT(varchar , F_QualityGuaranteeEndTime, 120)>=CONVERT(varchar , '" + F_QualityGuaranteeEndTime.Trim() + " 00:00:01', 120) and CONVERT(varchar , F_QualityGuaranteeEndTime, 120)<=CONVERT(varchar , '" + F_QualityGuaranteeEndTime.Trim() + " 23:59:59', 120) ";
                }
                int recordCount = 0;

                Model.PageData<Model.T_Wo_WorkOrderBase> pageModel = new Model.PageData<Model.T_Wo_WorkOrderBase>();

                dt = BLL.PagerBLL.GetListPager(
                    "V_WorkOrderBase",
                    "F_WORKORDERID",
                    "*",
                    sql,
                    "ORDER BY F_WORKORDERID desc",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);

                System.Collections.Generic.List<Model.T_Wo_WorkOrderBase> modelList = new BLL.T_Wo_WorkOrderBase().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_Wo_WorkOrderBase>));

                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;
        }
        private string GetGDZHCXList(HttpContext context)
        {
            string res = "";
            DataTable dt = new DataTable();
            string sql = " ";

            try
            {
                string userid = HttpUtility.UrlDecode(CommonRequest.GetQueryString("userid"));
                string customername = HttpUtility.UrlDecode(CommonRequest.GetQueryString("customername"));
                string time = HttpUtility.UrlDecode(CommonRequest.GetQueryString("createdate"));
                string repairmanname = HttpUtility.UrlDecode(CommonRequest.GetQueryString("repairmanname"));
                string F_Name = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_Name"));
                string F_TypeName = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_TypeName"));
                string F_USERNAME = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_USERNAME"));
                string F_CODE = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_CODE"));
                string F_REPAIRMANPHONE = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_REPAIRMANPHONE"));
                string F_CustomerNature = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_CustomerNature"));
                string F_SystemType = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_SystemType"));
                string F_ServiceDept = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_ServiceDept"));
                string F_QualityGuaranteeEndTime = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_QualityGuaranteeEndTime"));
                string F_KNOWLEDGE = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_KNOWLEDGE"));
                string F_ALREADYKNOWLEDGE = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_ALREADYKNOWLEDGE"));
                string F_CONTENT = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_CONTENT"));
                string F_RoleName = HttpUtility.UrlDecode(CommonRequest.GetQueryString("F_RoleName"));

                string ownerid = HttpUtility.UrlDecode(CommonRequest.GetQueryString("ownerid"));
                string gdtype = HttpUtility.UrlDecode(CommonRequest.GetQueryString("gdtype"));
                string strpageindex = context.Request.Params["page"];
                int pageindex = 1;
                string strpagesize = context.Request.Params["pagesize"];
                int pagesize = 10;
                if (strpageindex.Trim() != "")
                {
                    try
                    {
                        pageindex = Convert.ToInt32(strpageindex);
                    }
                    catch
                    { }
                }

                if (strpagesize.Trim() != "")
                {
                    try
                    {
                        pagesize = Convert.ToInt32(strpagesize);
                    }
                    catch
                    { }
                }
                sql += CommonRequest.GetQueryString("whereSql");
                if (userid.Trim() != "" && userid != "undefined")
                {
                    sql += " and F_INSTANCEID in(select F_INSTANCEID from T_Wo_WorkOrderTask where  F_LOSEFLAG=0 and F_OWNERID=" + userid + ") and F_WORKORDERSTATEID!=0";
                }
                if (customername.Trim() != "")
                {
                    sql += " and F_CUSTOMERNAME like '%" + customername.Trim() + "%' ";
                }
                if (repairmanname.Trim() != "")
                {
                    sql += " and F_REPAIRMANNAME like '%" + repairmanname.Trim() + "%' ";
                }
                if (time.Trim() != "")
                {
                    sql += " and CONVERT(varchar , F_CREATEDATE, 120)>=CONVERT(varchar , '" + time.Trim() + " 00:00:01', 120) and CONVERT(varchar , F_CREATEDATE, 120)<=CONVERT(varchar , '" + time.Trim() + " 23:59:59', 120) ";
                }
                if (F_Name.Trim() != "")
                {
                    sql += " and F_Name='" + F_Name.Trim() + "' ";
                }
                if (F_TypeName.Trim() != "")
                {
                    sql += " and F_TypeName='" + F_TypeName.Trim() + "' ";
                }
                if (F_USERNAME.Trim() != "")
                {
                    sql += " and F_USERNAME like '%" + F_USERNAME.Trim() + "%' ";
                }
                if (F_CODE.Trim() != "")
                {
                    sql += " and F_CODE like '%" + F_CODE.Trim() + "%' ";
                }
                if (F_REPAIRMANPHONE.Trim() != "")
                {
                    sql += " and F_REPAIRMANPHONE like '%" + F_REPAIRMANPHONE.Trim() + "%' ";
                }
                if (F_CustomerNature.Trim() != "")
                {
                    sql += " and F_CustomerNature like '%" + F_CustomerNature.Trim() + "%' ";
                }
                if (F_SystemType.Trim() != "")
                {
                    sql += " and F_SystemType like '%" + F_SystemType.Trim() + "%' ";
                }
                if (F_ServiceDept.Trim() != "")
                {
                    sql += " and F_ServiceDept like '%" + F_ServiceDept.Trim() + "%' ";
                }
                if (F_CONTENT.Trim() != "")
                {
                    sql += " and F_CONTENT like '%" + F_CONTENT.Trim() + "%' ";
                }
                if (F_QualityGuaranteeEndTime.Trim() != "")
                {
                    sql += " and CONVERT(varchar , F_QualityGuaranteeEndTime, 120)>=CONVERT(varchar , '" + F_QualityGuaranteeEndTime.Trim() + " 00:00:01', 120) and CONVERT(varchar , F_QualityGuaranteeEndTime, 120)<=CONVERT(varchar , '" + F_QualityGuaranteeEndTime.Trim() + " 23:59:59', 120) ";
                }
                if (F_RoleName.Trim() != "")
                {
                    sql += " and F_INSTANCEID in (select distinct F_INSTANCEID from T_Wo_WorkOrderTask where F_OWNERID in (select F_UserId from T_Sys_UserAccount where F_RoleId = (select F_RoleId from T_Sys_RoleInfo where F_RoleName='" + F_RoleName + "')))";
                }
                if (ownerid.Trim() != "" && gdtype.Trim() != "")
                {
                    switch (gdtype)
                    {
                        case "1":
                            string sqlwhere1 = string.Format(" and F_INSTANCEID in (select distinct F_INSTANCEID FROM [XKP_CallCenter].[dbo].[T_Wo_WorkOrderTask] WHERE F_OWNERID={0} and F_WORKORDERSTATEID=13 and F_LOSEFLAG=0)", ownerid);
                            sql += sqlwhere1;
                            break;
                        case "2":
                            string sqlwhere2 = string.Format(" and F_INSTANCEID in (select distinct F_INSTANCEID from [XKP_CallCenter].[dbo].[T_Wo_WorkOrderTask] where F_INSTANCEID in(select distinct F_INSTANCEID from [XKP_CallCenter].[dbo].[T_Wo_WorkOrderTask] where F_OWNERID={0} and F_WORKORDERSTATEID=13) and F_WORKORDERSTATEID=6 and F_LOSEFLAG=0)", ownerid);
                            sql += sqlwhere2;
                            break;
                        case "3":
                            string sqlwhere3 = string.Format(" and F_INSTANCEID in (select distinct F_INSTANCEID from [XKP_CallCenter].[dbo].[T_Wo_WorkOrderTask] where F_INSTANCEID in(select distinct F_INSTANCEID from [XKP_CallCenter].[dbo].[T_Wo_WorkOrderTask] where F_OWNERID={0} and F_WORKORDERSTATEID=13) and F_WORKORDERSTATEID=7 and F_LOSEFLAG=0)", ownerid);
                            sql += sqlwhere3;
                            break;
                    }
                }
                int recordCount = 0;

                Model.PageData<Model.T_Wo_WorkOrderBase> pageModel = new Model.PageData<Model.T_Wo_WorkOrderBase>();

                dt = BLL.PagerBLL.GetListPager(
                    "V_WorkOrderBase",
                    "F_WORKORDERID",
                    "*",
                    sql,
                    "ORDER BY F_WORKORDERID desc",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);

                System.Collections.Generic.List<Model.T_Wo_WorkOrderBase> modelList = new BLL.T_Wo_WorkOrderBase().DataTableToList(dt);
                if (F_ALREADYKNOWLEDGE.Trim() != "")
                {
                    string knowsql = "F_ALREADYKNOWLEDGE is not null order by ID desc";
                    //除了是否形成知识、是否已经形成知识以外条件的数据
                    DataTable tt = DBUtility.DbHelperSQL.Query("select * from V_WorkOrderBase where 1=1 " + sql).Tables[0];
                    System.Collections.Generic.List<Model.T_Wo_WorkOrderBase> newmodelList = new BLL.T_Wo_WorkOrderBase().DataTableToList(tt);
                    //是否形成知识或是否已经形成知识
                    List<int?> hisinfolist1 = new List<int?>();
                    List<int?> hisinfolist2= new List<int?>();
                    foreach (Model.T_Wo_WorkOrderBase wbase in newmodelList)
                    {
                        var hisinfomodel = new BLL.T_Wo_WorkOrderHistoryInfo().GetModelList("F_INSTANCEID='" + wbase.F_INSTANCEID + "' and " + knowsql).FirstOrDefault();
                        if (hisinfomodel != null)
                        {
                            if (hisinfomodel.F_ALREADYKNOWLEDGE == 0)
                                hisinfolist1.Add(hisinfomodel.F_INSTANCEID);
                            else hisinfolist2.Add(hisinfomodel.F_INSTANCEID);
                        }
                    }
                    string strjiaoji = "";
                    if (F_ALREADYKNOWLEDGE == "0") strjiaoji = string.Join(",", hisinfolist1);
                    else strjiaoji = string.Join(",", hisinfolist2);
                    if (strjiaoji == "") strjiaoji = "-1";
                    DataTable dd = BLL.PagerBLL.GetListPager("V_WorkOrderBase",
                                    "F_WORKORDERID",
                                    "*",
                                    " and F_INSTANCEID in (" + strjiaoji + ")",
                                    "ORDER BY F_WORKORDERID desc",
                                    pagesize,
                                    pageindex,
                                    true,
                                    out recordCount);
                    System.Collections.Generic.List<Model.T_Wo_WorkOrderBase> tw = new BLL.T_Wo_WorkOrderBase().DataTableToList(dd);

                    pageModel.Rows = tw;
                    pageModel.Total = recordCount;
                }
                else if (F_KNOWLEDGE.Trim() != "")
                {
                    string knowsql = "F_KNOWLEDGE is not null order by ID desc";
                    //除了是否形成知识、是否已经形成知识以外条件的数据
                    DataTable tt = DBUtility.DbHelperSQL.Query("select * from V_WorkOrderBase where 1=1 " + sql).Tables[0];
                    System.Collections.Generic.List<Model.T_Wo_WorkOrderBase> newmodelList = new BLL.T_Wo_WorkOrderBase().DataTableToList(tt);
                    //是否形成知识或是否已经形成知识
                    List<int?> hisinfolist1 = new List<int?>();
                    List<int?> hisinfolist2 = new List<int?>();
                    foreach (Model.T_Wo_WorkOrderBase wbase in newmodelList)
                    {
                        var hisinfomodel = new BLL.T_Wo_WorkOrderHistoryInfo().GetModelList("F_INSTANCEID='" + wbase.F_INSTANCEID + "' and " + knowsql).FirstOrDefault();
                        if (hisinfomodel != null)
                        {
                            if (hisinfomodel.F_KNOWLEDGE == 0)
                                hisinfolist1.Add(hisinfomodel.F_INSTANCEID);
                            else hisinfolist2.Add(hisinfomodel.F_INSTANCEID);
                        }
                    }
                    string strjiaoji = "";
                    if (F_KNOWLEDGE == "0") strjiaoji = string.Join(",", hisinfolist1);
                    else strjiaoji = string.Join(",", hisinfolist2);
                    if (strjiaoji == "") strjiaoji = "-1";
                    DataTable dd = BLL.PagerBLL.GetListPager("V_WorkOrderBase",
                                    "F_WORKORDERID",
                                    "*",
                                    " and F_INSTANCEID in (" + strjiaoji + ")",
                                    "ORDER BY F_WORKORDERID desc",
                                    pagesize,
                                    pageindex,
                                    true,
                                    out recordCount);
                    System.Collections.Generic.List<Model.T_Wo_WorkOrderBase> tw = new BLL.T_Wo_WorkOrderBase().DataTableToList(dd);

                    pageModel.Rows = tw;
                    pageModel.Total = recordCount;
                }
                else
                {
                    pageModel.Rows = modelList;
                    pageModel.Total = recordCount;
                }
                System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Model.PageData<Model.T_Wo_WorkOrderBase>));

                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;
        }
        private string GetStateInfo(HttpContext context)
        {
            string res = "";
            if (context.Request.QueryString["type"] != null && context.Request.QueryString["id"] != null)
            {
                int id = Convert.ToInt32(context.Request.QueryString["id"]);
                string type = context.Request.QueryString["type"];
                if (type == "knowledge")
                {
                    var hisinfomodel = new BLL.T_Wo_WorkOrderHistoryInfo().GetModelList("F_INSTANCEID='" + id + "' and F_KNOWLEDGE is not null order by ID desc").FirstOrDefault();
                    if (hisinfomodel != null)
                    {
                        if (hisinfomodel.F_KNOWLEDGE == 0)
                            res = "是";
                        else res = "否";
                    }
                }
                if (type == "alreadyknowledge")
                {
                    var hisinfomodel = new BLL.T_Wo_WorkOrderHistoryInfo().GetModelList("F_INSTANCEID='" + id + "' and F_ALREADYKNOWLEDGE is not null order by ID desc").FirstOrDefault();
                    if (hisinfomodel != null)
                        if (hisinfomodel.F_ALREADYKNOWLEDGE == 0)
                            res = "是";
                        else res = "否";
                }
            }
            return res;
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}