private void button3_Click(object sender, EventArgs e)
        {
            var error = Validate();

            if (error != string.Empty)
            {
                MessageBox.Show(error);
            }
            else
            {
                if (!cbNhieuUyQuyen.Checked)
                {
                    UyQuyen.Users.Clear();
                    var user = new ListUserCustom
                    {
                        Id          = Guid.NewGuid(),
                        DanhXung1   = cboDanhXungUQ1.Text,
                        HoVaTen1    = txtHoVaTenUQ1.Text,
                        NgaySinh1   = txtNgaySinhUQ1.Text,
                        LoaiGiayTo1 = cboLoaiGiayToUQ1.Text,
                        SoGiayTo1   = txtSoGiayToUQ1.Text,
                        NoiCap1     = cboNoiCapUQ1.Text,
                        NgayCap1    = txtNgayCapUQ1.Text,
                        CuTru1      = cboCuTruUQ1.Text,

                        DanhXung2   = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text,
                        HoVaTen2    = cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : txtHoVaTenUQ2.Text,
                        NgaySinh2   = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : txtNgaySinhUQ2.Text,
                        LoaiGiayTo2 = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : cboLoaiGiayToUQ2.Text,
                        SoGiayTo2   = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : txtSoGiayToUQ2.Text,
                        NoiCap2     = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : cboNoiCapUQ2.Text,
                        NgayCap2    = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : txtNgayCapUQ2.Text,
                        CuTru2      = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty :
                                      (cboCuTruUQ2.Text != null && cboCuTruUQ2.Text != string.Empty && cboCuTruUQ2.Text != "") ?
                                      cboCuTruUQ2.Text : cboCuTruUQ1.Text,
                        TaiSanRieng = cboDanhXungUQ2.Text == "Tài sản riêng" ? txtHoVaTenUQ2.Text : string.Empty
                    };
                    UyQuyen.Users.Add(user);

                    var users = new List <ListUserCustom> {
                        user
                    };
                    AddUser(users, true);
                }
                UyQuyen.CamKet = txtCamKet.Text;
                Main.UpdateUyQuyen2(UyQuyen, Ben);
                MessageBox.Show("Thêm thành công!");
                this.Visible = false;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            var error = Validate();

            if (error != string.Empty)
            {
                MessageBox.Show(error);
            }
            else
            {
                var user = new ListUserCustom
                {
                    Id          = Guid.NewGuid(),
                    DanhXung1   = cboDanhXungUQ1.Text,
                    HoVaTen1    = txtHoVaTenUQ1.Text,
                    NgaySinh1   = txtNgaySinhUQ1.Text,
                    LoaiGiayTo1 = cboLoaiGiayToUQ1.Text,
                    SoGiayTo1   = txtSoGiayToUQ1.Text,
                    NoiCap1     = cboNoiCapUQ1.Text,
                    NgayCap1    = txtNgayCapUQ1.Text,
                    CuTru1      = cboCuTruUQ1.Text,

                    DanhXung2   = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text,
                    HoVaTen2    = cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : txtHoVaTenUQ2.Text,
                    NgaySinh2   = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : txtNgaySinhUQ2.Text,
                    LoaiGiayTo2 = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : cboLoaiGiayToUQ2.Text,
                    SoGiayTo2   = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : txtSoGiayToUQ2.Text,
                    NoiCap2     = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : cboNoiCapUQ2.Text,
                    NgayCap2    = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty : txtNgayCapUQ2.Text,
                    CuTru2      = txtHoVaTenUQ2.Text == null || txtHoVaTenUQ2.Text == string.Empty ? string.Empty : cboDanhXungUQ2.Text == "Tài sản riêng" ? string.Empty :
                                  (cboCuTruUQ2.Text != null && cboCuTruUQ2.Text != string.Empty && cboCuTruUQ2.Text != "") ?
                                  cboCuTruUQ2.Text : cboCuTruUQ1.Text,
                    TaiSanRieng = cboDanhXungUQ2.Text == "Tài sản riêng" ? txtHoVaTenUQ2.Text : string.Empty
                };
                UyQuyen.Users.Add(user);

                var users = new List <ListUserCustom> {
                    user
                };
                AddUser(users, false);
                MessageBox.Show("Thêm thành công!");
                LoadDefaultData(true);
            }
        }
        private void txtHoVaTenUQ2_TextChanged(object sender, EventArgs e)
        {
            var newList = new List <ListUserCustom>();

            if (SelectedId != null && SelectedId != Guid.Empty)
            {
                var userList = UyQuyen.Users;
                foreach (var item in userList)
                {
                    if (item.Id != SelectedId)
                    {
                        newList.Add(item);
                    }
                    else
                    {
                        var editedItem = item;
                        editedItem.DanhXung1   = cboDanhXungUQ1.Text;
                        editedItem.HoVaTen1    = txtHoVaTenUQ1.Text;
                        editedItem.NgaySinh1   = txtNgaySinhUQ1.Text;
                        editedItem.LoaiGiayTo1 = cboLoaiGiayToUQ1.Text;
                        editedItem.SoGiayTo1   = txtSoGiayToUQ1.Text;
                        editedItem.NoiCap1     = cboNoiCapUQ1.Text;
                        editedItem.NgayCap1    = txtNgayCapUQ1.Text;
                        editedItem.CuTru1      = cboCuTruUQ1.Text;
                        editedItem.DanhXung2   = cboDanhXungUQ2.Text;
                        editedItem.HoVaTen2    = txtHoVaTenUQ2.Text;
                        editedItem.NgaySinh2   = txtNgaySinhUQ2.Text;
                        editedItem.LoaiGiayTo2 = cboLoaiGiayToUQ2.Text;
                        editedItem.SoGiayTo2   = txtSoGiayToUQ2.Text;
                        editedItem.NoiCap2     = cboNoiCapUQ2.Text;
                        editedItem.NgayCap2    = txtNgayCapUQ2.Text;
                        editedItem.CuTru2      = (cboCuTruUQ2.Text != null && cboCuTruUQ2.Text != string.Empty && cboCuTruUQ2.Text != "") ?
                                                 cboCuTruUQ2.Text : cboCuTruUQ1.Text;

                        newList.Add(editedItem);
                    }
                }
            }
            else if (UyQuyen.Users != null && UyQuyen.Users.Any(x => x.HoVaTen2 == txtHoVaTenUQ2.Text))
            {
                newList.AddRange(UyQuyen.Users);
            }
            else
            {
                newList.AddRange(UyQuyen.Users);
                var editedItem = new ListUserCustom();
                editedItem.DanhXung1   = cboDanhXungUQ1.Text;
                editedItem.HoVaTen1    = txtHoVaTenUQ1.Text;
                editedItem.NgaySinh1   = txtNgaySinhUQ1.Text;
                editedItem.LoaiGiayTo1 = cboLoaiGiayToUQ1.Text;
                editedItem.SoGiayTo1   = txtSoGiayToUQ1.Text;
                editedItem.NoiCap1     = cboNoiCapUQ1.Text;
                editedItem.NgayCap1    = txtNgayCapUQ1.Text;
                editedItem.CuTru1      = cboCuTruUQ1.Text;
                editedItem.DanhXung2   = cboDanhXungUQ2.Text;
                editedItem.HoVaTen2    = txtHoVaTenUQ2.Text;
                editedItem.NgaySinh2   = txtNgaySinhUQ2.Text;
                editedItem.LoaiGiayTo2 = cboLoaiGiayToUQ2.Text;
                editedItem.SoGiayTo2   = txtSoGiayToUQ2.Text;
                editedItem.NoiCap2     = cboNoiCapUQ2.Text;
                editedItem.NgayCap2    = txtNgayCapUQ2.Text;
                editedItem.CuTru2      = (cboCuTruUQ2.Text != null && cboCuTruUQ2.Text != string.Empty && cboCuTruUQ2.Text != "") ?
                                         cboCuTruUQ2.Text : cboCuTruUQ1.Text;

                newList.Add(editedItem);
            }

            var uq = CamketUpdate(newList);

            txtCamKet.Text = string.Format(Constants.CamKet, BenChinh == string.Empty ? "Ông ... và bà ..." : BenChinh,
                                           uq == string.Empty ? "ông ... và bà ..." : uq, "...", "...", "...", "...",
                                           uq == string.Empty ? "ông ... và bà ..." : uq);


            button4.Enabled = true;
            if (txtHoVaTenUQ2.Text != string.Empty | txtNgaySinhUQ2.Text != string.Empty ||
                txtSoGiayToUQ2.Text != string.Empty || txtNgayCapUQ2.Text != string.Empty)
            {
                button6.Enabled = true;
            }
        }