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

public partial class system_Lab_labmanage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 过期和权限

        PageFunc.IfSystemLogin(this.Page);

        #endregion
        if (IsPostBack)
            return;

        BindData();
    }


    #region 实验室预约绑定
    /// <summary>
    /// 数据绑定
    /// </summary>
    private void BindData()
    {

        //计算总数的语句的头部
        string sql_CountFirst = string.Empty;
        sql_CountFirst += " select";
        sql_CountFirst += " count(*)";
        sql_CountFirst += " from NT_Lab ";
        sql_CountFirst += " where MemberId=" + Session["ID1"].ToString();

        //查询语句的头部
        string sql_SelectFirst = "select l.ID as lid,l.StartTime,l.EndTime,l.AddTime,l.Audit,m.Account,m.Name,d.Title,d.ID ";
        sql_SelectFirst += " from NT_Lab l,NT_Member m,NT_Data d ";
        sql_SelectFirst += " where l.MemberId=m.ID and l.DataId=d.ID and  l.MemberId=" + Session["ID1"].ToString();
        sql_SelectFirst += " order by l.ID desc";


        WebControlsFunc.BindToAspNetPagerAndGridView(GridView1, AspNetPager1, sql_CountFirst, sql_SelectFirst);

    }
    #endregion

    #region 分页事件
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindData();
    }
    #endregion


    //详细
    protected void btnDetails_Command(object sender, CommandEventArgs e)
    {
        JavaScriptFunc.Redirect("orderdetails.aspx?lid=" + e.CommandArgument.ToString());
    }

    //取消
    protected void btnUpdate_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "3")
        {
            JavaScriptFunc.Alert(this.Page, "已取消，不能进行再次操作");
            return;
        }

        //if (e.CommandName != "0")
        //{
        //    JavaScriptFunc.Alert(this.Page, "已审核，不能进行取消操作");
        //    return;
        //}
        string sql = "update NT_Lab set Audit=3 where ID=" + e.CommandArgument.ToString();

        DbHelperOleDb.ExecuteNonQuery(CommandType.Text, sql, null);
        BindData();
    }


    //删除
    protected void btnDelete_Command(object sender, CommandEventArgs e)
    {

        string sql = "delete * from NT_Lab where ID=" + e.CommandArgument.ToString();

        DbHelperOleDb.ExecuteNonQuery(CommandType.Text, sql, null);
        BindData();

    }

    //预约状态
    public string GetAudit(string id)
    {
        if (id == "0")
        {
            return "审核中";
        }
        else if(id=="1")
        {
            return "预约成功";
        }
        else if (id == "2")
        {
            return "预约失败";
        }
        else if (id == "3")
        {
            return "已取消";
        }
        return "";

    }
}
