using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using Microsoft.Win32;
using System.IO;
using System.Diagnostics;
using System.Data;
using xabaraCOM;

public partial class WebXabara_Main : System.Web.UI.Page
{
    admin a = new admin();
    xabara x = new xabara();
    sqlServer sql = new sqlServer();
    pcServer pc = new pcServer();
    javasrcipt js = new javasrcipt();

    protected void Page_Load(object sender, EventArgs e)
    {
        a.check(string.Empty);

        if (!Page.IsPostBack)
        {
            //自动升级
            if (xabara.isNum(Request.QueryString["update"]) > 0)
            {
                js.div(true, "在线自动升级---请不要关闭窗口", "iframe", a.adminFolder + "frame/update.aspx", 600, 0, a.adminFolder, "top");
            }

            //检查版本
            string oldVer = "v1.13.0925";
            xml.save("webVer", oldVer); //自动更新版本号

            string newVer = xabara.remoteHttp("http://api.etaocms.com/ver/?id=" + x.softName(), "utf-8", "", "");
            if (string.IsNullOrEmpty(newVer as string))
            {
                ver.Text = "当前版本：" + oldVer;
            }
            else
            {
                if (xabara.isNum(oldVer.Substring(1).Replace(".", "").Replace("beta", "").Trim()) >= xabara.isNum(newVer.Substring(1).Replace(".", "").Replace("beta", "").Trim()))
                {
                    ver.Text = "当前版本：" + oldVer + "<br />您已经是最新版本！";
                }
                else
                {
                    ver.Text = "当前版本：" + oldVer + "<br />最新版本：<span style=\"color:#b60202; font-weight:bold;\">" + newVer + "</span> 【<a href=\"http://api.etaocms.com/down/?id=" + x.softName() + "&ver=" + Server.UrlEncode(oldVer) + "\" target=\"_blank\" style=\"font-weight:bold;\">手工升级</a>】【<a href=\"main.aspx?update=1\" style=\"font-weight:bold;\">在线升级</a>】";
                }
            }
            buyLink.NavigateUrl = "http://api.etaocms.com/authorization/?id=" + x.softName();

            adminLog.DataSource = sql.getDataTable("select top 6 logLogin.userID,logLogin.loginDate,logLogin.loginIP,AdminUser.UserName from logLogin left join AdminUser on logLogin.UserId=AdminUser.UserId where logLogin.userType='admin' and logLogin.exeTitle='管理员登录' order by logLogin.id desc");
            adminLog.DataBind();
            adminLog.Dispose();

            serverIP.Text = Request.ServerVariables["LOCAL_ADDR"] + ":" + Request.ServerVariables["Server_Port"].ToString();
            ServerOS.Text = Environment.OSVersion.ToString();
            ServerOSVer.Text = pc.os;
            ServerSoft.Text = Request.ServerVariables["SERVER_SOFTWARE"];
            netVer.Text = Environment.Version.ToString();
            ServerPath.Text = Request.ServerVariables["PATH_TRANSLATED"];
            serverTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            sqlVer.Text = sql.ver(false);

            string infoTxt = "";
            infoTxt += "<li style=\"line-height:200%; padding:2px 0px 2px 5px;\">统计离上次登录网站信息情况</li><li style=\"line-height:200%; background-color:#e9f8fc; padding:2px 0px 2px 5px;\">共有 ";
            DataTable dt;
            DateTime d = Convert.ToDateTime(Request.Cookies["XabaraAdmin"]["AdminLgDate"].Trim());
            dt = sql.getDataTable("select count(Uid) as newReg from xabaraUser where postDate>'" + d.ToString() + "'");
            infoTxt += dt.Rows[0]["newReg"].ToString().Trim() + " 位 <a href='/webXabara/user/?level=-1' target='mainFrame' style='font-weight:bold;'>新会员注册</a></li><li style=\"line-height:200%; padding:2px 0px 2px 5px;\">共有 ";
            dt.Dispose();

            dt = sql.getDataTable("select count(tID) as newReg from teacherinfo where workFlag=0");
            infoTxt += dt.Rows[0]["newReg"].ToString().Trim() + " 条 <a href='/webXabara/study/' target='mainFrame' style='font-weight:bold;'>新教员审核</a></li><li style=\"line-height:200%; background-color:#e9f8fc; padding:2px 0px 2px 5px;\">共有 ";
            dt.Dispose();

            dt = sql.getDataTable("select count(sID) as newReg from studentinfo where workFlag=0");
            infoTxt += dt.Rows[0]["newReg"].ToString().Trim() + " 条 <a href='/webXabara/study/student.aspx' target='mainFrame' style='font-weight:bold;'>新学员审核</a></li><li style=\"line-height:200%; padding:2px 0px 2px 5px;\">共有 ";
            dt.Dispose();

            dt = sql.getDataTable("select count(ID) as newReg from onlineorder where adminID is null and ts='t'");
            infoTxt += dt.Rows[0]["newReg"].ToString().Trim() + " 条 <a href='/webXabara/study/onlineorder.aspx?ts=s' target='mainFrame' style='font-weight:bold;'>新教员预约</a></li><li style=\"line-height:200%; background-color:#e9f8fc; padding:2px 0px 2px 5px;\">共有 ";
            dt.Dispose();

            dt = sql.getDataTable("select count(ID) as newReg from onlineorder where adminID is null and ts='s'");
            infoTxt += dt.Rows[0]["newReg"].ToString().Trim() + " 条 <a href='/webXabara/study/onlineorder.aspx?ts=t' target='mainFrame' style='font-weight:bold;'>新学员预约</a></li><li style=\"line-height:200%; padding:2px 0px 2px 5px;\">共有 ";
            dt.Dispose();

            dt = sql.getDataTable("select count(ID) as newReg from cerPic where flagID=0");
            infoTxt += dt.Rows[0]["newReg"].ToString().Trim() + " 条 <a href='/webXabara/study/cer.aspx' target='mainFrame' style='font-weight:bold;'>新证件需审核</a></li><li style=\"line-height:200%; background-color:#e9f8fc; padding:2px 0px 2px 5px;\">共有 ";
            dt.Dispose();

            dt = sql.getDataTable("select count(rID) as newReg from moneyBankRemit where adminPass=0");
            infoTxt += dt.Rows[0]["newReg"].ToString().Trim() + " 条 <a href='/webXabara/money/?pass=0' target='mainFrame' style='font-weight:bold;'>汇款单需审核</a></li>";
            dt.Dispose();

            infoLJ.Text = infoTxt;
        }
    }

    public string ip(string ipstr)
    {
        ipAddress i = new ipAddress();
        return i.addressCN(ipstr);
    }

    string chkObj(string obj) //自检查
    {
        try
        {
            object meobj = Server.CreateObject(obj);
            return "支持";
        }
        catch (Exception objexe)
        {

            return objexe.Message.ToString();
        }
    }
}