using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.IO;
using HySoft.Common;

namespace HySoft.BaseCallCenter.Web.askmanage.ajax
{
    public partial class pagerview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //取得处事类型
            string action = CommonRequest.GetQueryString("action");
            switch (action)
            {
                case "getviewlist":
                    Response.Write(LoadViewList());
                    break;
            }
        }
        #region 加载试卷
        private string LoadViewList()
        {
            StringBuilder res = new StringBuilder();
            DataTable dt = new DataTable();
            string sql = " ";
            string itemtable = "T_Sys_TempItems";
            string questionidname = "ExpandIntField1";
            string sortname = "ExpandIntField3";
            string itemidname = "F_Id";
            string key = "vw_Ask_Question.F_QuestionId";
            try
            {
                string pagerid = Request.QueryString["pagerid"];
                string userid = Request.QueryString["userid"];
                if (pagerid.Trim() != "")
                {
                    itemtable = "T_Ask_PagerItems";
                    questionidname = "F_QuestionId";
                    sortname = "F_Sort";
                    itemidname = "F_ItemId";
                    key = "T_Ask_PagerItems.F_ItemId";
                    sql += " and [T_Ask_PagerItems].[F_PagerId]=" + pagerid + " ";
                }
                else
                {
                    sql += " and F_QuestionId in (SELECT [ExpandIntField1] FROM [T_Sys_TempItems] where [F_UserId]=" + userid + " and F_TempName='T_Ask_PagerItems') ";
                }
                int recordCount = 0;
                dt = BLL.PagerBLL.GetListPager(
                    "vw_Ask_Question LEFT OUTER JOIN " + itemtable + " ON vw_Ask_Question.F_QuestionId = " + itemtable + "." + questionidname + " ",
                    key,
                    "vw_Ask_Question.*, '' as TelId," + itemtable + "." + sortname + " as F_Sort," + itemtable + "." + itemidname + " as F_ItemId",
                    " and F_DeleteFlag=0 " + sql,
                    "ORDER BY " + itemtable + "." + sortname + " ",
                    100,
                    1,
                    true,
                    out recordCount);

                if (dt != null)
                {
                    string ctrl = "~/askmanage/_controls/ctl_pagerview.ascx";

                    Control uc_rep = LoadControl(ctrl);
                    Repeater rptItems = (Repeater)uc_rep.FindControl("rptitems");
                    rptItems.DataSource = dt;
                    rptItems.DataBind();
                    StringWriter sw = new StringWriter(res);
                    HtmlTextWriter htw = new HtmlTextWriter(sw);

                    rptItems.RenderControl(htw);
                }
            }
            catch (Exception err)
            {
                //res = err.ToString(); 
            }
            finally
            {
                dt.Clear();
                dt.Dispose();
            }
            return res.ToString();
        }
        #endregion
    }
}