protected void lbtChangeAdvance_Click(object sender, EventArgs e)
    {
        try
        {
            RoleDetailBUS rdBus = new RoleDetailBUS();
            PanelAdvance.Visible = false;
            int departmentId = int.Parse(hdfDepartmentId.Value);
            int limitSendMail = int.Parse(txtLimitMailSend.Text);
            string toDate = txtToDate.Text;
            int limitCreateCustomer = int.Parse(txtLimitCreateCustomer.Text);

            if (chkAdvance.Checked)
            {
                // Cap nhat voi hang ngach gui mail, tao khach hang.
                RoleDetailDTO rdDto = new RoleDetailDTO();
                rdDto.roleId = -1;
                rdDto.departmentId = departmentId;
                rdDto.limitSendMail = limitSendMail;
                rdDto.limitCreateCustomer = limitCreateCustomer;
                rdDto.toDate = convertStringToDate(toDate);
                ConnectionData.OpenMyConnection();
                int rsUpdate = rdBus.tblRoleDetail_Update(rdDto);
                ConnectionData.CloseMyConnection();
                if (rsUpdate <= 0)
                {
                    // Them voi hang ngach gui mail, tao khach hang.
                    ConnectionData.OpenMyConnection();
                    rdBus.tblRoleDetail_insert(rdDto);
                    ConnectionData.CloseMyConnection();
                }

                // Reset thong tin so luong da gui mail cua tat ca user trong group.
                UserLoginBUS ulBus = new UserLoginBUS();
                ConnectionData.OpenMyConnection();
                ulBus.tblUserLogin_UpdateByDepartmentId(departmentId, 0);
                ConnectionData.CloseMyConnection();
            }
            else
            {
                // Xóa phân quyền nâng cao.
                ConnectionData.OpenMyConnection();
                rdBus.tblRoleDetail_Delete(-1, departmentId);
                ConnectionData.CloseMyConnection();
            }

            PanelAdvanceSuccess.Visible = true;
            lblAdvanceSuccess.Text = "Cập nhập thành công !";

        }
        catch (Exception)
        {
            PanelAdvanceSuccess.Visible = false;
            PanelAdvance.Visible = true;
            lblAdvanceError.Text = "Kiểm tra lại dữ liệu nhập !";
        }
    }