using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using xabaraCOM;

public partial class webXabara_study_onlineorder : System.Web.UI.Page
{
    sqlServer sql = new sqlServer();
    classify c = new classify();
    admin a = new admin();
    webPublic wp = new webPublic();
    javasrcipt js = new javasrcipt();

    protected void Page_Load(object sender, EventArgs e)
    {
        a.check("|study|");

        if (!IsPostBack)
        {
            string ts = Request.QueryString["ts"];
            string strSql = string.Empty;
            if (ts.Equals("t"))
            {
                strSql = "select * from onlineorder left join (select xabaraUser.userName,xabaraUser.userTel,xabaraUser.userMobile,xabaraUser.userQQ,xabaraUser.userEmail,teacherInfo.tID from xabarauser left join teacherinfo on XabaraUser.userCardID=teacherinfo.uID) as newTeacher on onlineorder.relatingID=newTeacher.tID where onlineorder.ts='s' order by onlineorder.flagID asc,onlineorder.id DESC";
            }
            else
            {
                strSql = "select * from onlineorder left join (select xabaraUser.userName,xabaraUser.userTel,xabaraUser.userMobile,xabaraUser.userQQ,xabaraUser.userEmail,studentinfo.sID from xabarauser left join studentinfo on XabaraUser.userCardID=studentinfo.uID) as newStudent on onlineorder.relatingID=newStudent.sID where onlineorder.ts='t' order by onlineorder.flagID asc,onlineorder.id DESC";
            }
            //Response.Write(strSql);
            //Response.End();

            lblCurrentPage.Text = sql.RepeaterDB(sList, strSql, "&ts=" + ts, 10, "page", "center", true);
            if (this.sList.Items.Count < 1)
            {
                errInfo.Text = "目前暂没有任何信息！";
                errDiv.Visible = true;
                checkDiv.Visible = false;
            }
            else
            {
                errDiv.Visible = false;
            }
        }
    }

    public string adminStr(string flagID, string uID, string data)
    {
        string str = "<span style='color:red;'>待确认</span>";

        if (Convert.ToInt16(flagID) > 0)
        {
            str = uID + "于 " + Convert.ToDateTime(data).ToString("yy-MM-dd HH:mm") + " 处理";
        }

        return str;
    }

    public string getQQHtm(string qqStr)
    {
        return xabara.QQ(qqStr, "46");
    }

    public string pca(string p, string cc, string a)
    {
        if (string.IsNullOrEmpty(p as string))
        {
            return "";
        }
        else
        {
            return c.cityName(p, cc, a);
        }
    }

    public string ids(string id)
    {
        return wp.IDsTreeName(id, ",");
    }

    protected void batDelete_Click(object sender, EventArgs e)
    {
        a.check("|orderExe|");

        string requestID = xabara.safeSql(Request["batDel"]);
        if (string.IsNullOrEmpty(requestID as string))
        {
            js.div(false, "", "text", "请选择选项后再点击删除按钮！", 350, 150, Server.UrlDecode(url.before), "goto");
        }
        else
        {
            string returnValue = sql.del("onlineorder", "id", requestID, string.Empty, false, string.Empty);

            sql.log(a.uid, "admin", "删除预约信息");
            js.div(false, "", "text", returnValue, 350, 150, Server.UrlDecode(url.currently), "goto");
        }
    }

    protected void batOK_Click(object sender, EventArgs e)
    {
        a.check("|orderExe|");

        string requestID = xabara.safeSql(Request["batDel"]);
        if (string.IsNullOrEmpty(requestID as string))
        {
            js.div(false, "", "text", "请选择选项后再点击确认按钮！", 350, 150, Server.UrlDecode(url.before), "goto");
        }
        else
        {
            string strDim = "@flagID,@adminIP,@adminDate,@adminID";
            string[] strValue = new string[4];
            strValue[0] = "1";
            strValue[1] = new ipAddress().address();
            strValue[2] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            strValue[3] = a.uid;

            string[] ids = requestID.Split(new char[] { ',' });
            for (int i = 0; i <= ids.GetUpperBound(0); i++)
            {
                sql.update("onlineorder", strDim, strValue, "id=" + ids[i] + " and flagID<1");
            }

            js.div(false, "", "text", "操作完成！", 350, 150, Server.UrlDecode(url.before), "goto");
        }
    }

    public string viewHttp(string relatingID, string ts)
    {
        string htm = "<span style='color:red;'>直接预约客户</span>";

        if (xabara.isNum(relatingID) > 0)
        {
            if (ts.Equals("s"))
            {
                htm = "<a href=\"/teacher/view/" + relatingID + ".htm\" target=\"_blank\"><strong>查看详情</strong></a>";
            }
            else
            {
                htm = "<a href=\"/student/view/" + relatingID + ".htm\" target=\"_blank\"><strong>查看详情</strong></a>";
            }
        }

        return htm;
    }
}