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;
using Product;
using Base;

public partial class admin_Trade_Supply : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckRights("column", "A1");

        if (!IsPostBack)
        {
            Bind();
        }
    }
    private void Bind()
    {
        int id = int.Parse(Request.QueryString["ID"].ToString());
        if (Request.QueryString["UserID"] != null)
            this.HiddUserID.Value = Request.QueryString["UserID"].ToString();
        ISupply RSupp = new RSupply();
        TSupply TSupp = RSupp.GateItem(id);
        this.txtName.Text = TSupp.Name;
        this.txtKey.Text = TSupp.Key;
        if (TSupp.Picture_1 == "")
        {
            this.ImgUrl1.Value = "../../Images/System/wutu.gif";
            this.ImgUrl.Src = "../../Images/System/wutu.gif";
        }
        else
        {
            this.ImgUrl1.Value = TSupp.Picture_1;
            this.ImgUrl.Src = TSupp.Picture_1;
        }
        this.txtProType.Text = TSupp.ProType.ToString();
        this.txtPlace.Text = TSupp.Place;
        this.txtBrand.Text = TSupp.Brand;
        this.txtModel.Text = TSupp.Model;
        this.txtPrice.Text = TSupp.Price.ToString();
        this.txtQuantity.Text = TSupp.Quantity.ToString();
        this.txtUnits.Text = TSupp.Units;
        this.txtMinimum.Text = TSupp.Minimum.ToString();
        this.radlDeadline.SelectedValue = TSupp.Deadline.ToString();
        this.txtContent.Value = TSupp.Info;
        this.txtStartDate.Text = TSupp.StartDate.ToShortDateString();
        this.txtEndDate.Text = TSupp.EndDate.ToShortDateString();
        this.txtRemark.Text = TSupp.Remark;
        this.txtDocument.Text = TSupp.Document;



        if (TSupp.IndType != null)
        {
            string[] str = TSupp.IndType.Split(new char[] { ',' });
            for (int i = 0; i < str.Length; i++)
            {
                if (i == 0)
                    this.txtSortB.Value = str[i];
                else if (i == 1)
                    this.txtSortM.Value = str[i];
                else
                    this.txtSortS.Value = str[i];
            }
        }

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            string myValue = "";
            myValue += Request.Form["SortB"];
            myValue += ',' + Request.Form["SortM"];
            myValue += ',' + Request.Form["SortS"];
            int id = int.Parse(Request.QueryString["ID"].ToString());
            TSupply TSup = new TSupply();
            TSup.ID = id;
            TSup.Name = this.txtName.Text;
            TSup.Key = this.txtKey.Text;
            TSup.IndType = myValue;
            TSup.Picture_1 = this.ImgUrl1.Value;
            TSup.Thumbnail = this.ImgUrl1.Value;
            TSup.ProType = int.Parse(this.txtProType.Text);
            TSup.Place = this.txtPlace.Text;
            TSup.Brand = this.txtBrand.Text;
            TSup.Model = this.txtModel.Text;
            if (txtPrice.Text != string.Empty)
            {
                if (GetRequest.isProce(this.txtPrice.Text))
                    TSup.Price = Convert.ToDecimal(this.txtPrice.Text);
                else
                    TSup.Price = 0;
            }
            else
                TSup.Price = 0;
            if (txtQuantity.Text != string.Empty)
            {
                if (GetRequest.isNum(this.txtQuantity.Text))
                    TSup.Quantity = int.Parse(this.txtQuantity.Text);
                else
                    TSup.Quantity = 0;
            }
            else
                TSup.Quantity = 0;
            TSup.Units = this.txtUnits.Text;
            if (GetRequest.isNum(this.txtMinimum.Text))
                TSup.Minimum = int.Parse(this.txtMinimum.Text);
            else
                TSup.Minimum = 0;
            TSup.Minimum = int.Parse(this.txtMinimum.Text);
            TSup.Deadline = int.Parse(this.radlDeadline.SelectedValue);
            string Temp = GetRequest.RemoveHTMLForEditor(this.txtContent.Value);
            Temp = GetRequest.WipeScript(Temp);
            TSup.Info = Temp;
            TSup.Remark = this.txtRemark.Text;
            TSup.Document = this.txtDocument.Text;
            if (this.txtStartDate.Text != "")
            {
                if (GetRequest.isDataTime(this.txtStartDate.Text))
                    TSup.StartDate = Convert.ToDateTime(this.txtStartDate.Text);
                else
                    TSup.StartDate = DateTime.Now;
            }
            else
                TSup.StartDate = DateTime.Now;
            if (this.txtEndDate.Text != "")
            {
                if (GetRequest.isDataTime(this.txtEndDate.Text))
                    TSup.EndDate = Convert.ToDateTime(this.txtEndDate.Text);
                else
                    TSup.EndDate = DateTime.Now;
            }
            else
                TSup.EndDate = DateTime.Now;
            ISupply RSup = new RSupply();
            RSup.Update(TSup);
           Base.BasePage.ShowMessage("恭喜您，商机修改成功！", "trade/SupplyManage.aspx");
        }
        catch (Exception ex)
        {
            ShowMessage("商机修改失败！", "trade/SupplyManage.aspx");
        }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("SupplyManage.aspx");
    }
}
