protected void m_grid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                string commandName = e.CommandName;
                GridViewRow row = m_grid.FooterRow;
                if (commandName == "Insert")
                {
                    clsThanhPham objThanhPham = new clsThanhPham();

                    string TenThanhPham = ((TextBox)row.FindControl("txtITenThanhPham")).Text;
                    string AliasName = ((TextBox)row.FindControl("txtIAliasName")).Text;
                    string DienGiai = ((TextBox)row.FindControl("txtIDienGiai")).Text;
                    string DonVi = ((DropDownList)row.FindControl("txtIDonVi")).Text;

                    objThanhPham.TenThanhPham = TenThanhPham;
                    objThanhPham.AliasName = AliasName;
                    objThanhPham.DienGiai =DienGiai;
                    objThanhPham.DonVi_Id = DonVi;

                    int _result = objThanhPham.Insert();
                    if (_result >= 1)
                    {
                        ltlAnnouncement.Text = "Thêm mới thành phẩm '" + TenThanhPham + "' thành công!";
                    }
                    if (_result == -1)
                    {
                        ltlAnnouncement.Text = "Thành phẩm '" + TenThanhPham + "' đã tồn tại, bạn nên kiểm tra lại!";
                    }
                    if (_result == 0)
                    {
                        ltlAnnouncement.Text = "Có lỗi trong quá trình thêm mới!";
                    }
                    bindData(-1);
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Khong them moi duoc du lieu. Vui long lien he voi quan tri<br>" + ex.Message;
            }
        }
        protected void m_grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                int id = e.RowIndex;
                m_grid.EditIndex = id;
                GridViewRow row = m_grid.Rows[id];
                string ThietBi_id = "";
                string ThanhPham_id = "";
                string ThietBi = ((TextBox)row.FindControl("txtUTenThietBi")).Text;
                string ThanhPham = ((TextBox)row.FindControl("txtUTenThanhPham")).Text;
                Int32 SoLuong = Convert.ToInt32(((TextBox)row.FindControl("txtUSoLuong")).Text);
                DataTable tblTemp = new DataTable();
                clsThanhPham oThanhPham = new clsThanhPham();
                clsThietBi oThietBi = new clsThietBi();

                if (ThietBi != "")
                {
                    tblTemp = oThietBi.Select();
                    int i;
                    for (i = 0; i < tblTemp.Rows.Count; i++)
                    {
                        if (tblTemp.Rows[i]["TenThietBi"].ToString().Trim() == ThietBi.Trim())
                        {
                            ThietBi_id = tblTemp.Rows[i]["ThietBi_Id"].ToString();
                        }
                    }
                }
                if (ThanhPham != "")
                {
                    tblTemp = oThanhPham.Select();
                    int i;
                    for (i = 0; i < tblTemp.Rows.Count; i++)
                    {
                        if (tblTemp.Rows[i]["TenThanhPham"].ToString().Trim() == ThanhPham.Trim())
                        {
                            ThanhPham_id = tblTemp.Rows[i]["ThanhPham_Id"].ToString();
                        }
                    }
                }
                if (m_grid.DataKeys[id].Value.ToString() != "")
                {
                    clsKeHoachNhapXuat objKeHoachNhapXuat = new clsKeHoachNhapXuat();

                    objKeHoachNhapXuat.KeHoachNhapXuat_Id = sKey;
                    objKeHoachNhapXuat.ThietBi_Id = ThietBi_id;
                    objKeHoachNhapXuat.ThanhPham_Id = ThanhPham_id;
                    objKeHoachNhapXuat.So_Luong = SoLuong;
                    int _result = objKeHoachNhapXuat.UpdateChiTiet();
                    if (_result == 1)
                    {
                        ltlAnnouncement.Text = "Sửa kế hoạch nhập xuất chi tiết '" + m_grid.DataKeys[e.RowIndex].Value.ToString() + "' thành công!";
                    }
                    if (_result < 0)
                    {
                        ltlAnnouncement.Text = "Có lỗi trong quá trình sửa dữ liệu!";
                    }
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Khong cap nhat duoc du lieu. Vui long lien he voi quan tri<br>" + ex.Message;
            }

            bindData(-1);
        }
        protected void m_grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                int id = e.RowIndex;
                m_grid.EditIndex = id;

                Guid delId = new Guid(m_grid.DataKeys[e.RowIndex].Value.ToString());
                if (m_grid.DataKeys[e.RowIndex].Value.ToString() != "")
                {
                    clsThanhPham objThanhPham = new clsThanhPham();
                    objThanhPham.ThanhPham_Id = m_grid.DataKeys[e.RowIndex].Value.ToString();
                    int status_Delete = objThanhPham.Delete();
                    if (status_Delete == 1)
                    {
                        ltlAnnouncement.Text = "Xóa thành công thành phẩm!";
                    }
                    if (status_Delete <= 0)
                    {
                        ltlAnnouncement.Text = "Không xóa được thành phẩm đã chọn.";
                    }
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Lỗi trong quá trình xóa nhóm người dùng: " + ex.ToString();
            }
            bindData(-1);
        }
        private void bindData(int index)
        {
            try
            {
                //LAY DANH SACH CAC QUOC GIA RA

                clsThanhPham objThanhPham = new clsThanhPham();
                dsGroup = objThanhPham.Select();
                objThanhPham.ThanhPham_Id= "0";

                m_grid.EditIndex = index;
                m_grid.DataSource = dsGroup;
                bool add = false;
                if (dsGroup.Rows.Count <= 0)
                {
                    dsGroup.Rows.Add(dsGroup.NewRow());
                    add = true;

                }
              //
                m_grid.DataBind();
                if(add)
                    m_grid.Rows[0].Visible = false;
                if (m_grid.Rows.Count > 0)
                {
                    string confirm = "return confirm('Bạn thật sự muốn xóa row này?')";

                    for (int i = 0; i < m_grid.Rows.Count; i++)
                    {
                        GridViewRow row = m_grid.Rows[i];
                        LinkButton lbutton1 = (LinkButton)row.FindControl("cmdDelete");
                        if (lbutton1 != null)
                        {
                            lbutton1.Visible = D_Option;
                            lbutton1.Attributes.Add("onclick", confirm);
                            //lbutton1.Enabled = D_Option;
                        }

                        LinkButton lbutton2 = (LinkButton)row.FindControl("cmdEdit");
                        if (lbutton2 != null)
                            lbutton2.Visible = U_Option;
                    }
                }

                //XET QUYETN CHO CHUC NANG INSERT
                GridViewRow row1 = m_grid.FooterRow;
                if (row1 != null)
                {
                    row1.Visible = I_Option;
                }
            }
            catch (Exception ex)
            {
            }
        }
        protected void m_grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                int id = e.RowIndex;
                m_grid.EditIndex = id;
                GridViewRow row = m_grid.Rows[id];

               string TenThanhPham = ((TextBox)row.FindControl("txtUTenThanhPham")).Text;
               string AliasName = ((TextBox)row.FindControl("txtUAliasName")).Text;
               string DienGiai = ((TextBox)row.FindControl("txtUDienGiai")).Text;
               string DonVi = ((DropDownList)row.FindControl("txtUDonVi")).Text;

              //  short updateId = Int16.Parse(m_grid.DataKeys[id].Value.ToString());
                if (m_grid.DataKeys[id].Value.ToString()!= "")
                {
                    clsThanhPham objThanhPham = new clsThanhPham();

                    objThanhPham.ThanhPham_Id = m_grid.DataKeys[id].Value.ToString();
                    objThanhPham.TenThanhPham = TenThanhPham;
                    objThanhPham.AliasName = AliasName;
                    objThanhPham.DienGiai = DienGiai;
                    objThanhPham.DonVi_Id = DonVi;

                    int _result = objThanhPham.Update();
                    if (_result == 1)
                    {
                        ltlAnnouncement.Text = "Sửa thành phẩm '" + TenThanhPham + "' thành công!";
                    }
                    if (_result < 0)
                    {
                        ltlAnnouncement.Text = "Có lỗi trong quá trình sửa dữ liệu!";
                    }
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Khong cap nhat duoc du lieu. Vui long lien he voi quan tri<br>" + ex.Message;
            }

            bindData(-1);
        }