protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
 {
     GridView1.EditIndex = -1;
     Class1 ob = new Class1();
     GridView1.DataSource = ob.zShowGridView(eBophan.Text, eChonngay.Text);
     GridView1.DataBind();
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            Label3.Style["Text-align"] = "left";
            Label4.Style["Text-align"] = "left";
            Class1 ob = new Class1();
            if (ob.zConnect())
            {
                DropDownList2.Enabled = true;
                ddNgayDau.Enabled = true;
                if (!IsPostBack)
                {
                    int id = UserInfo.UserID;
                    //eBophan.Text = ob.zBoPhan(id);
                    eBophan.Text = ob.zUyQuyen(id);
                    if ((eBophan.Text == "2") || (eBophan.Text == "3"))
                    {
                        DropDownList1.Enabled = true;
                        string st = "SELECT * FROM BoPhan";
                        DataSet ds = ob.zSelect(st);
                        DropDownList1.DataSource = ds.Tables[0];
                        DropDownList1.DataTextField = "TenBP";
                        DropDownList1.DataValueField = "MaBP";
                        DropDownList1.DataBind();
                        if (eBophan.Text == "3") DropDownList1.SelectedIndex = 1;
                    }
                    else
                    {
                        string st = "SELECT * FROM BoPhan where MaBP=" + eBophan.Text; ;
                        DataSet ds = ob.zSelect(st);
                        DropDownList1.DataSource = ds.Tables[0];
                        DropDownList1.DataTextField = "TenBP";
                        DropDownList1.DataValueField = "MaBP";
                        DropDownList1.DataBind();
                    }
                    int selectedIndex;
                    DropDownList2.DataSource = ob.zDistinctNgay(0, "1/1/1900", out selectedIndex);
                    DropDownList2.DataTextField = "NgayThu";
                    DropDownList2.DataValueField = "Ngay";
                    DropDownList2.DataBind();
                    DropDownList2.SelectedIndex = selectedIndex;
                    ddNgayDau.DataSource = ob.zDistinctNgay(1, "1/1/1900", out selectedIndex);
                    ddNgayDau.DataTextField = "NgayThu";
                    ddNgayDau.DataValueField = "Ngay";
                    ddNgayDau.DataBind();
                    ddNgayDau.SelectedIndex = selectedIndex;
                    eChonngay.Text = Convert.ToDateTime(DropDownList2.SelectedValue).ToString("MM/dd/yyyy");
                    lbChamCong.Text = "In bảng chấm công tháng " + DateTime.Today.AddMonths(-1).ToString("MM/yyyy");
                    GridView1.DataSource = ob.zShowGridView(eBophan.Text, eChonngay.Text);
                    GridView1.DataBind();
                }
            }

            this_Month();
        }
 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
 {
     if (GridView1.Rows[e.NewEditIndex].Cells[6].Text != " ")
     {
         GridView1.EditIndex = e.NewEditIndex;
         if ((UserInfo.UserID == 119) && (eBophan.Text != "3")) GridView1.EditIndex = -1;
         if (UserInfo.UserID == 116) GridView1.EditIndex = -1;
     }
     else GridView1.EditIndex = -1;
     Class1 ob = new Class1();
     GridView1.DataSource = ob.zShowGridView(eBophan.Text, eChonngay.Text);
     GridView1.DataBind();
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     ClientScript.RegisterStartupScript(this.GetType(), "title", "<script>document.title='-'</script>");
     Label3.Style["Text-align"] = "left";
     string maBP = Request.QueryString[0].ToString();
     string ngayDau = Request.QueryString[1].ToString();
     string ngayCuoi = Request.QueryString[2].ToString();
     lbNgay.Text = "Từ ngày " + ngayDau + " đến ngày " + ngayCuoi;
     string[] split = ngayDau.Split(new Char[] { '/' });
     ngayDau = split[1].ToString() + "/" + split[0].ToString() + "/" + split[2].ToString();
     split = ngayCuoi.Split(new Char[] { '/' });
     ngayCuoi = split[1].ToString() + "/" + split[0].ToString() + "/" + split[2].ToString();
     Class1 ob = new Class1();
     GridView2.DataSource = ob.zShowThongKe(maBP, ngayDau, ngayCuoi);
     GridView2.DataBind();
     string st = "select * from Bophan where MaBP=" + maBP;            
     DataSet ds = ob.zSelect(st);
     lbBoPhan.Text = "Đơn vị : " + ds.Tables[0].Rows[0][1].ToString();
     lbHaNoi.Text = "Hà Nội, ngày " + DateTime.Today.Day + " tháng " + DateTime.Today.Month + " năm " + DateTime.Today.Year;
     maBP = "<script>window.print();</script>";
     ClientScript.RegisterStartupScript(this.GetType(), "windowKey", maBP);
 }
 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
     string lyDo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text;
     string id = GridView1.Rows[e.RowIndex].Cells[1].Text;
     string user = UserInfo.Username;
     string st = string.Format("SELECT COUNT(*) FROM zRecordData WHERE zIDCard='{0}' AND DATEDIFF(DD, zThoiGian, '{1}')=0", id, eChonngay.Text);
     Class1 ob = new Class1();
     if (ob.zSelect(st).Tables[0].Rows[0][0].ToString() == "0")
     {
         st = string.Format("INSERT INTO zRecordData (zIDCard, zThoiGian, zReson, zUser, zWrite) VALUES ('{0}', '{1}', N'{2}', '{3}', getdate())", id, eChonngay.Text, lyDo, user);
         ob.zInsert(st);
     }
     else
     {
         st = string.Format("UPDATE zRecordData SET zReson=N'{0}', zUser='******', zWrite=GETDATE() WHERE zIDCard='{2}' AND DATEDIFF(DD, zThoiGian, '{3}')=0", lyDo, user, id, eChonngay.Text);
         ob.zInsert(st);
     }
     GridView1.EditIndex = -1;
     GridView1.DataSource = ob.zShowGridView(eBophan.Text, eChonngay.Text);
     GridView1.DataBind();
 }
 protected void ddNgayCuoi_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!ddNgayCuoi.SelectedValue.StartsWith("1/1/1900"))
     {
         Class1 ob = new Class1();
         DataSet ds = ob.zShowThongKe(eBophan.Text, ddNgayDau.SelectedValue, ddNgayCuoi.SelectedValue);
         GridView2.DataSource = ds;
         GridView2.DataBind();
         GridView1.Visible = false;
         GridView2.Visible = true;
         lbThongKe.Visible = true;
     }
 }
 protected void ddNgayDau_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!ddNgayDau.SelectedValue.StartsWith("1/1/1900"))
     {
         Class1 ob = new Class1();
         int selectedIndex;
         ddNgayCuoi.DataSource = ob.zDistinctNgay(2, ddNgayDau.SelectedValue, out selectedIndex);
         ddNgayCuoi.DataTextField = "NgayThu";
         ddNgayCuoi.DataValueField = "Ngay";
         ddNgayCuoi.DataBind();
         ddNgayCuoi.SelectedIndex = selectedIndex;
         ddNgayCuoi.Enabled = true;
     }
 }
 protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!DropDownList2.SelectedValue.StartsWith("1/1/1900"))
     {
         Class1 ob = new Class1();
         eChonngay.Text = Convert.ToDateTime(DropDownList2.SelectedValue).ToString("MM/dd/yyyy");
         GridView1.DataSource = ob.zShowGridView(eBophan.Text, eChonngay.Text);
         GridView1.DataBind();
         GridView1.EditIndex = -1;
         GridView1.Visible = true;
         GridView2.Visible = false;
         lbThongKe.Visible = false;
     }
 }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            eBophan.Text = DropDownList1.SelectedValue;
            Class1 ob = new Class1();
            if (GridView1.Visible == false)
            {
                if (!ddNgayCuoi.SelectedValue.StartsWith("1/1/1900"))
                {
                    GridView2.DataSource = ob.zShowThongKe(eBophan.Text, ddNgayDau.SelectedValue, ddNgayCuoi.SelectedValue);
                    GridView2.DataBind();
                }
            }
            else
            {
                if (!DropDownList1.SelectedValue.StartsWith("0"))
                {
                    GridView1.DataSource = ob.zShowGridView(eBophan.Text, eChonngay.Text);
                    GridView1.DataBind();
                    GridView1.EditIndex = -1;
                }
            }

            this_Month();
        }