protected void btnLuu_Click(object sender, EventArgs e)
    {
        try
        {
            if (Common.LoaiNguoiDungID() == 3)
            {
                NhomSanPham nhomsanpham = new NhomSanPham();
                if (Request.QueryString["subid"] == null)
                {
                    nhomsanpham.InsertFields(txtTenNhomCon.Text, null, Convert.ToInt32(Request.QueryString["id"]), false,
                                             Convert.ToInt32(txtThuTu.Text), null, null, null, null, null, null);
                }
                else
                {
                    nhomsanpham.UpdateFields(Convert.ToInt32(Request.QueryString["subid"]), txtTenNhomCon.Text, null,
                                             Convert.ToInt32(Request.QueryString["id"]), null,
                                             Convert.ToInt32(txtThuTu.Text), null, null, null, null, null, null);
                }
            }
            else if (Common.LoaiNguoiDungID()==2)
            {
                NhomSanPhamCuaHang nhomsanpham = new NhomSanPhamCuaHang();
                CuaHangNhomSanPham chnsp = new CuaHangNhomSanPham();
                if (Request.QueryString["id"] == null)
                {
                    int chnspid = chnsp.InsertFields(int.Parse(CuaHangID), int.Parse(ddlNhomSanPham.SelectedValue), null);
                    nhomsanpham.InsertFields(Convert.ToInt32(Request.QueryString["pid"]), int.Parse(ddlNhomSanPham.SelectedValue)
                        , Convert.ToInt32(txtThuTu.Text), int.Parse(CuaHangID), txtTenNhomCon.Text, chnspid);

                }
                else
                {
                    NhomSanPhamCuaHang nsp = new NhomSanPhamCuaHang();
                    DataSet ds = nsp.SelectByID(int.Parse(Request["id"]));
                    int chnspid = int.Parse("0" + ds.Tables[0].Rows[0]["CuaHangNhomSanPhamID"].ToString());
                    //chnsp.UpdateFields();
                    nhomsanpham.UpdateFields(Convert.ToInt32(Request.QueryString["id"]),
                                             null, int.Parse(ddlNhomSanPham.SelectedValue),
                                             Convert.ToInt32(txtThuTu.Text), null, txtTenNhomCon.Text,null);
                    chnsp.UpdateFields(chnspid,int.Parse(CuaHangID),int.Parse(ddlNhomSanPham.SelectedValue),null);
                }
            }
            string strScript = "<script language='JavaScript'>" + "window.parent.RefreshCat();</script>";
            ClientScript.RegisterStartupScript(GetType(), "Refresh", strScript);
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     //int firstCatId = 0;
     foreach (UltraGridRow row in grdCat.Rows)
     {
         //int id = int.Parse(row.Cells.FromKey("NhomSanPhamID").Value.ToString());
         int NhomSanPhamID = 0;
         CuaHangNhomSanPham chnsp = new CuaHangNhomSanPham();
         if (row.Cells.FromKey("Selected").Value != null)
         {
             if (bool.Parse(row.Cells.FromKey("Selected").Value.ToString()))
             {
                 NhomSanPhamID = int.Parse(row.Cells.FromKey("NhomSanPhamID").Value.ToString());
                 chnsp.InsertFields(CuaHangID, NhomSanPhamID, null);
             }
         }
     }
     string strScript = "<script language='JavaScript'>" + "window.parent.Refresh();</script>";
     ClientScript.RegisterStartupScript(GetType(), "Refresh", strScript);
 }