using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace BeginScreen
{
    public partial class SchedulingPlan : System.Web.UI.Page
    {
        string RoomType = "";
        string DeptType = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                GetdData();

                //ddlList.Items.Clear();
                //var dt = PublicMethod.GetOperationRoom(); // 获取数据自己写
                //if (dt != null && dt.Rows.Count > 0)
                //{
                //    ddlList.DataSource = dt;
                //    ddlList.DataTextField = "Name"; // DeptName:dt中列名
                //    ddlList.DataValueField = "Name";// DeptCode中列名
                //    ddlList.DataBind();
                //}

                RoomType = Request.QueryString["RoomType"];
                DeptType = Request.QueryString["DeptType"];
                tbJxrq2.Value = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
                ddlDep.SelectedValue = DeptType;
                //if (RoomType == null || RoomType == "") RoomType = "院本部手术室";
                //ddlList.Items.FindByText(RoomType).Selected = true;
                Button1_Click(null, null);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                //if (DateTime.Parse(tbJxrq2.Text).Day > DateTime.Now.Day && DateTime.Now.Hour < 12)
                //{
                //    tishji.Text = "排程未结束 请于12点之后查看！";
                //    this.GridView1.DataSource = null; //可以绑定到Gridview 、datalist等数据控件上，此处为Gridview
                //    this.GridView1.DataBind();
                //    return;
                //}
                //else
                //{
                string wheresql = "OrderOperationTime>='" + DateTime.Parse(tbJxrq2.Value).ToString("yyyy-MM-dd 00:00:00") + "' and OrderOperationTime<='" + DateTime.Parse(tbJxrq2.Value).ToString("yyyy-MM-dd 23:59:59") + "' and  StateId >3   ";
                if (ddlDep.SelectedValue.Trim() != "") wheresql += " and ( ApplyDepName like '%" + ddlDep.SelectedValue.Trim() + "%' ) "; 
                if (ddlPeo.SelectedValue.Trim() != "") wheresql += " and ( OperationDoctor like '%" + ddlPeo.SelectedValue.Trim() + "%') ";
                //if (ddlList.SelectedValue != "") wheresql += " and ( dtp.name='" + ddlList.Text + "') ";
                DataTable operationApplys = PublicMethod.SelectPlanedOpeByRoom(wheresql);
                this.GridView1.DataSource = operationApplys; //可以绑定到Gridview 、datalist等数据控件上，此处为Gridview
                this.GridView1.DataBind();
                tishji.Text = DateTime.Parse(tbJxrq2.Value).ToString("yyyy-MM-dd") + " 共(" + operationApplys.Rows.Count + ")台手术";
                tbJxrq2.Value = DateTime.Parse(tbJxrq2.Value).ToString("yyyy-MM-dd");
                //}
            }
            catch (Exception)
            {
                return;
            }
        }

        private void GetdData()
        {
            DataTable dtDep = PublicMethod.GetDepartments();
            DataRow drDep;
            drDep = dtDep.NewRow();
            drDep["Id"] = "0";
            drDep["Name"] = "";
            drDep["NameHCode"] = "全部(QB)";
            dtDep.Rows.InsertAt(drDep, 0);

            this.ddlDep.DataValueField = "Name";
            this.ddlDep.DataTextField = "NameHCode";
            this.ddlDep.DataSource = dtDep;
            this.ddlDep.DataBind();

            DataTable dtPeo = PublicMethod.GetWorkers();
            DataRow drPeo;
            drPeo = dtPeo.NewRow();
            drPeo["Id"] = "0";
            drPeo["Name"] = "";
            drPeo["NameHCode"] = "全部(QB)";
            dtPeo.Rows.InsertAt(drPeo, 0);

            this.ddlPeo.DataValueField = "Name";
            this.ddlPeo.DataTextField = "NameHCode";
            this.ddlPeo.DataSource = dtPeo;
            this.ddlPeo.DataBind();

            //DataTable dtArea = PublicMethod.GetEArea();
            //DataRow drArea;
            //drArea = dtArea.NewRow();
            //drArea["EArea"] = "";
            //drArea["NameHCode"] = "全部(QB)";
            //dtArea.Rows.InsertAt(drArea, 0);

            //this.ddlEArea.DataValueField = "EArea";
            //this.ddlEArea.DataTextField = "NameHCode";
            //this.ddlEArea.DataSource = dtArea;
            //this.ddlEArea.DataBind();
        }
    }
}