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;
using System.Data;
namespace ComResProSystem
{
    public partial class Stock_taking:BasePage
    {
        BaseBLL bll = new BaseBLL();
        UserBll ubll = new UserBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BingProName();
                DataTable dt = ubll.Stocktaking("1=1");
                Gv_Total.DataSource = dt;
                Gv_Total.DataBind();
                Gv_Total.Visible = true;
                Gv_ProOut.Visible = false;
                Gv_ProIn.Visible = false;
            }
        }
        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 Dd_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Dd_ProName.Text == "库存盘点")
            {
                Tb_Begin.Enabled = false;

                Tb_End.Enabled = false;
            }
            else
            {
                Tb_Begin.Enabled = true;
                Tb_End.Enabled = true;
            }
        }

        protected void Ibt_Submit_Click(object sender, ImageClickEventArgs e)
        {
            if (Dd_Type.Text == "库存盘点")
            {
                if (Dd_ProName.Text != "-请选择-")
                {
                    DataTable dt = ubll.Stocktaking("ProName='" + Dd_ProName.Text + "'");
                    Gv_Total.DataSource = dt;
                    Gv_Total.DataBind();
                    Gv_Total.Visible = true;
                    Gv_ProOut.Visible = false;
                    Gv_ProIn.Visible = false;
                }
                else
                {
                    DataTable dt = ubll.Stocktaking("1=1");
                    Gv_Total.DataSource = dt;
                    Gv_Total.DataBind();
                    Gv_Total.Visible = true;
                    Gv_ProOut.Visible = false;
                    Gv_ProIn.Visible = false;
                }
            }
            if (Dd_Type.Text == "入库记录")
            {
                if (Dd_ProName.Text == "-请选择-")
                {
                   List<object> list=bll.SelectObject(typeof(ProIn), "ProIn", "ProName,ProCount,ProPerName,ProPerInName,ProInTime", "ProInTime BETWEEN '"+Tb_Begin.Text+"' AND '"+Tb_End.Text+"'");
                   Gv_ProIn.DataSource = list;
                   Gv_ProIn.DataBind();
                   Gv_Total.Visible = false;
                   Gv_ProOut.Visible = false;
                   Gv_ProIn.Visible = true;
                }
                else
                {
                    List<object> list = bll.SelectObject(typeof(ProIn), "ProIn", "ProName,ProCount,ProPerName,ProPerInName,ProInTime", "ProInTime BETWEEN '" + Tb_Begin.Text + "' AND '" + Tb_End.Text + "' and ProName='"+Dd_ProName.Text+"'");
                    Gv_ProIn.DataSource = list;
                    Gv_ProIn.DataBind();
                    Gv_Total.Visible = false;
                    Gv_ProOut.Visible = false;
                    Gv_ProIn.Visible = true;
                }
            }
            if (Dd_Type.Text == "出库记录")
            {
                if (Dd_ProName.Text == "-请选择-")
                {
                    List<object> list = bll.SelectObject(typeof(ProOut), "ProOut", "ProName,ProCount,PersonName,ProOutPreName,ProOutTime", "ProOutTime BETWEEN '" + Tb_Begin.Text + "' AND '" + Tb_End.Text + "'");
                    Gv_ProOut.DataSource = list;
                    Gv_ProOut.DataBind();
                    Gv_Total.Visible = false;
                    Gv_ProOut.Visible = true;
                    Gv_ProIn.Visible = false;
                }
                else
                {
                    List<object> list = bll.SelectObject(typeof(ProOut), "ProOut", "ProName,ProCount,PersonName,ProOutPreName,ProOutTime", "ProOutTime BETWEEN '" + Tb_Begin.Text + "' AND '" + Tb_End.Text + "' and ProName='" + Dd_ProName.Text + "'");
                    Gv_ProOut.DataSource = list;
                    Gv_ProOut.DataBind();
                    Gv_Total.Visible = false;
                    Gv_ProOut.Visible = true;
                    Gv_ProIn.Visible = false;
                }
            }
            
        }
    }
}