using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace JuSNS.Web.system.sys
{
    public partial class spaceedit : JuSNS.UI.Page.ManagePage
    {
        JuSNS.Home.Space sp = new JuSNS.Home.Space();
        protected string sort = "sys";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string r = Request.QueryString["r"];
                if (r == "edit")
                {
                    IDataReader dr = sp.getSpaceTemplateInfo(Convert.ToInt32(Request.QueryString["id"]));
                    if (dr.Read())
                    {
                        this.TName.Text = dr["TName"].ToString();
                        this.TPath.Text = dr["TPath"].ToString();
                        this.uppic.Value = dr["TPicture"].ToString();
                        this.IPoint.Text = dr["IPoint"].ToString();
                        this.GPoint.Text = dr["GPoint"].ToString();
                        this.UserNumber.Text = dr["UserNumber"].ToString();
                        this.ID.Value = dr["id"].ToString();
                    }
                    dr.Close();
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int ID = Convert.ToInt32(this.ID.Value);
                string TName = this.TName.Text;
                string TPath = this.TPath.Text;
                DateTime CreatTime = DateTime.Now;
                string Picture = this.uppic.Value;
                string filename = string.Empty;
                string s_savepath = "uploads/template/user";
                if (this.supfile.HasFile)
                {
                    JuSNS.Common.Input.UploadFile(this.supfile.PostedFile, true, s_savepath, out filename);
                    Picture = filename;
                }
                int IPoint = Convert.ToInt32(this.IPoint.Text);
                int GPoint = Convert.ToInt32(this.GPoint.Text);
                int UserNumber = Convert.ToInt32(this.UserNumber.Text);
                sp.USpaceTemplate(ID, TName, TPath, Picture, CreatTime, 0, IPoint, GPoint, 0, 0, UserNumber);
                Response.Redirect("index.aspx");
            }
        }
    }
}
