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

public partial class Admin_Trade_FastPurchaseAdd :BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckRights("column", "A1");
        if (!IsPostBack)
        {
            UnitBind();
        }
    }

    private void UnitBind()
    {
        DataSet ds = new DataSet();
        ds.ReadXml(@Server.MapPath("~/xml/UnitPrice.xml"));
        dropUnit.DataSource = ds.Tables[0];
        dropUnit.DataTextField = ds.Tables[0].Columns[1].ToString();
        dropUnit.DataValueField = ds.Tables[0].Columns[0].ToString();
        dropUnit.DataBind();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            string Restr = "";
            string myValue = "";
            if (Request.Form["SortB"] != null && Request.Form["SortB"] != "")
                myValue += Request.Form["SortB"];
            if (Request.Form["SortM"] != null && Request.Form["SortM"] != "")
                myValue += "," + Request.Form["SortM"] + ",";
            if (Request.Form["SortS"] != null && Request.Form["SortS"] != "")
                myValue += "," + Request.Form["SortS"];
            int id = 0;
            TPurchase TPur = new TPurchase();
            if (Request.QueryString["UserID"] != null)
            {
                id = int.Parse(Request.QueryString["UserID"]);
            }
            TPur.UserID = id;
            TPur.IndType = myValue;
            if (txtName.Text.Trim().Equals(string.Empty))
                Restr += "产品名称，";
            else
                TPur.Name = this.txtName.Text;
            if (txtKey.Text.Trim().Equals(string.Empty))
                Restr += "关键字，";
            else
                TPur.Key = this.txtKey.Text;
            string Temp = GetRequest.RemoveHTMLForEditor(this.txtContent.Value);
            Temp = GetRequest.WipeScript(Temp);
            TPur.Info = Temp;
            TPur.Picture_1 = this.ImgUrl1.Value;
            TPur.IsUser = "1";
            if (GetRequest.isDataTime(this.txtStartDate.Text))
                TPur.StartDate = Convert.ToDateTime(this.txtStartDate.Text);
            else
                TPur.StartDate = DateTime.Now;
            if (GetRequest.isDataTime(this.txtEndDate.Text))
                TPur.EndDate = Convert.ToDateTime(this.txtEndDate.Text);
            else
                TPur.EndDate = DateTime.Now;
            TPur.Brand = this.txtBrand.Text;
            TPur.Model = this.txtModel.Text;
            TPur.Unit = dropUnit.SelectedValue;
            if (GetRequest.isNum(txtCount.Text))
                TPur.Count = int.Parse(txtCount.Text);
            else
                TPur.Count = 0;
            if (GetRequest.isProce(txtPrice.Text))
                TPur.Price = txtPrice.Text;
            else
                TPur.Price = "0";
            TPur.Verify = 1;
            IPurchase Rpur = new RPurchase();
            if (!Restr.Trim().Equals(string.Empty))
                Restr = Restr.Substring(0, Restr.Length - 1);
            if (Restr.Trim().Equals(string.Empty))
            {
                int isEmail = 0;
                Rpur.Insert(TPur, out isEmail);
                ShowMessage("恭喜您，商机发布成功！", "trade/PurchaseManage.aspx");
            }
            else
            {
                lblMessage.Visible = true;
                lblMessage.Text = Restr + "填写有误！";
            }
        }
        catch (Exception ex)
        {
            ShowMessage("商机发布失败！", "trade/PurchaseManage.aspx");
        }
    }
}
