using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
namespace ComResProSystem
{
    public partial class ProductOut:BasePage
    {
        BaseBLL bll = new BaseBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BingProName();
                Tb_ProOutPreName.Text = Session["UserName"].ToString();
            }
        }
        public void BingProName()
        {
          List<object> list=bll.SelectObject(typeof(ProIn), "ProIn", "DISTINCT  ProName", "1=1");
          Dd_ProName.DataSource = list;
          Dd_ProName.DataTextField = "ProName";
          Dd_ProName.DataValueField = "ProName";
          Dd_ProName.DataBind();
          Dd_ProName.Items.Add(new ListItem("-请选择-", "-请选择-"));
          Dd_ProName.SelectedValue = "-请选择-";
        }

        protected void Ibt_Check_Click(object sender, ImageClickEventArgs e)
        {
            System.Web.UI.ScriptManager.RegisterStartupScript(this, Page.GetType(), "ajaxjs", " var sReturn=window.showModalDialog('SelectPerson.aspx','window','dialogWidth:100px;dialogHeight:150px;help:0;scroll:1;status:no;');document.getElementById('" + this.Tb_PersonName.UniqueID + "').value=sReturn;", true);
        }

        protected void Ibt_Submit_Click(object sender, ImageClickEventArgs e)
        {
            Dictionary<string, string> dic = FindControls(this.form1);
            object obj = bll.CreateObject(typeof(ProOut), dic);
            if (bll.SaveObject(obj, "ProOut") == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('操作成功')", true);
                Dd_ProName.SelectedValue = "-请选择-";
                Tb_PersonName.Text = "";
                Tb_ProCount.Text = "";
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this,this.GetType(),"alert","alert('操作失败')",true);
            }
        }
        protected override Dictionary<string, string> FindControls(Control ct)
        {
            Dictionary<string,string>  dic=base.FindControls(ct);
            foreach (Control ctl in ct.Controls)
            {
                if (ctl is DropDownList)
                {
                    DropDownList dd = (DropDownList)ctl;
                    string Name = dd.ID.Substring(3, ctl.ID.Length - 3);
                    string value = dd.Text;
                    dic.Add(Name, value);
                }
            }
            return dic;
        }
    }
}