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

public partial class setup_step02 : System.Web.UI.Page
{
    javasrcipt js = new javasrcipt();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pcServer pc = new pcServer();
            ServerOS.Text = Environment.OSVersion.ToString();
            ServerOSVer.Text = pc.os;
            ServerSoft.Text = Request.ServerVariables["SERVER_SOFTWARE"];
            netVer.Text = Environment.Version.ToString();

            //版本检查
            xabara x = new xabara();
            string newVer = xabara.remoteHttp("http://api.etaocms.com/ver/?id=" + x.softName(), "utf-8", "", "");
            if (!string.IsNullOrEmpty(newVer as string))
            {
                if (xabara.isNum(xml.read("xabara.config","webVer",0).Substring(1).Replace(".", "").Replace("beta", "").Trim()) < xabara.isNum(newVer.Substring(1).Replace(".", "").Replace("beta", "").Trim()))
                {
                    js.div(true, "发现新版本", "text", "官网有新版本，请重新下载后再安装！", 350, 0, "http://api.etaocms.com/down/?id=" + x.softName(), "top");
                }
            }
        }

        cache.clear();
    }

    protected void step_Click(object sender, EventArgs e)
    {
        
        
        string connXml = xml.read("xabara.config", "conn", 0);
        if (!string.IsNullOrEmpty(connXml as string))
        {
            Response.Redirect("step03.aspx", true);
        }
        else
        {
            string ipPort = string.Empty;
            long port = xabara.isNum(sqlPort.Text);
            if (port != 1433)
            {
                ipPort = "," + ipPort.ToString();
            }
            string connStr = "Data Source='" + IP.Text.Trim() + ipPort + "';Initial Catalog=" + sqlName.Text.Trim() + ";User ID=" + UserID.Text.Trim() + ";Password=" + passWord.Text.Trim();

            SqlConnection conn = new SqlConnection(connStr);

            try
            {
                conn.Open();
                xml.save("conn", connStr);
                conn.Close();
                Response.Redirect("step03.aspx", true);
            }
            catch
            {
                js.div(true, "数据库连接", "text", "连接失败！", 350, 0, "", "");
            }
        }
    }
}