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

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

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Request.ContentEncoding = System.Text.Encoding.UTF8;

            string action = context.Request.Params["action"];
            switch (action)
            {
                case "getseatlist":
                    getseatlist(context);
                    break;
                case "getseatnewlist":
                    getseatnewlist(context);
                    break;
                default:
                    break;
            }
        }

        private void getseatlist(HttpContext context)
        {
            string strHtml = "";

            DataTable dt = new DataTable();
            try
            {
                BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
                dt = bll.GetList(" f_seatflag=1 order by f_userid desc ").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        strHtml += "<div style=\"float:left; width:120px; height:120px; text-align:center; padding:8px;\">";
                        strHtml += "<div style=\"height: 90px; border: 1px solid #CCCCCC; padding: 3px; text-align: center;\" onmouseover=\"this.style.border='1px solid #3A8BDC'\"";
                        strHtml += "onmouseout=\"this.style.border='1px solid #CCCCCC'\">";
                        strHtml += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"";
                        strHtml += "width=\"100%\" height=\"100%\" style=\" text-align:center;\" onclick=\"GetOneState('" + dt.Rows[i]["F_WorkNumber"].ToString() + "','" + dt.Rows[i]["F_UserName"].ToString() + "')\">";
                        strHtml += "<tr><td><input type=\"text\" id=\"" + dt.Rows[i]["F_WorkNumber"].ToString() + "\" name=\"forcount\" style=\"display:none\" />";
                        strHtml += "<span id=\"span_zxtimes_" + dt.Rows[i]["F_WorkNumber"].ToString() + "\" style=\"color: #00000;\">" + dt.Rows[i]["F_UserName"].ToString() + "</span></td></tr>";
                        strHtml += "<tr><td><img id=\"img_zxstate_" + dt.Rows[i]["F_WorkNumber"].ToString() + "\"  src=\"../images/seatimgs/weiqianru.jpg\" /></td></tr>";
                        strHtml += "<tr><td><span id=\"span_zxstate_" + dt.Rows[i]["F_WorkNumber"].ToString() + "\" style=\"color: #cccccc;\">未签入</span></td></tr></table></div></div>";
                    }

                }
            }
            catch
            {
            }
            finally
            {
                dt.Clear();
                dt.Dispose();
            }


            context.Response.Write(strHtml);
            context.Response.End();
        }

        private void getseatnewlist(HttpContext context)
        {
            string strHtml = "";
            string strList = "";

            DataTable dt = new DataTable();
            try
            {
                BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
                dt = bll.GetList(" f_seatflag=1 order by f_userid desc ").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        strList += dt.Rows[i]["F_WorkNumber"] + ",";
                        strHtml += "<div id=\"div_" + dt.Rows[i]["F_WorkNumber"] + "\"  style='float: left; width: 120px; height: 120px; text-align: center; padding: 8px;cursor:pointer'>";
                        strHtml += "<div style='height: 90px; border: 1px solid #CCCCCC; padding: 3px; text-align: center;cursor:pointer'";
                        strHtml += "onmouseover=\"this.style.border='1px solid #3A8BDC'\" onmouseout=\"this.style.border='1px solid #CCCCCC'\">";
                        strHtml += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100%\" style=\"text-align: center;cursor:pointer\" ";
                        strHtml += "  onclick=\"GetOneState('" + dt.Rows[i]["F_WorkNumber"] + "','" + dt.Rows[i]["F_UserName"] + "')\">";
                        strHtml += " <tr><td><input type=\"text\" id=\"" + dt.Rows[i]["F_WorkNumber"] + "\" style=\"display: none\" /><input type=\"text\" id=\"txtSeatState_" + dt.Rows[i]["F_WorkNumber"] + "\" value=\"0\" style=\"display: none\" />";
                        strHtml += "   <span id=\"span_" + dt.Rows[i]["F_WorkNumber"] + "\" style=\"color: #000000;\">";
                        strHtml += dt.Rows[i]["F_WorkNumber"] + "(" + dt.Rows[i]["F_UserName"] + ")</span>";
                        strHtml += "</td></tr> <tr> <td><img id=\"img_" + dt.Rows[i]["F_WorkNumber"] + "\" src=\"../images/seatimgs/weiqianru.jpg\" />";
                        strHtml += "</td></tr><tr><td><span id=\"span_state_" + dt.Rows[i]["F_WorkNumber"] + "\" style=\"color: #cccccc;\">未签入</span>";
                        strHtml += " </td></tr></table></div></div>";
                    }

                }
                strList += "!@#";
                strList = strList.Replace(",!@#", "").Replace("!@#", "");
            }
            catch
            {
            }
            finally
            {
                dt.Clear();
                dt.Dispose();
            }


            context.Response.Write(strList+"~"+strHtml);
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}