public void addlistview_docgia(Docgia b)
 {
     lvi = lv_ds_doc_gia.Items.Add(b.Madocgia);
     lvi.SubItems.Add(b.Tendocgia);
     lvi.SubItems.Add(b.Gioitinh == true ? "Nu" : "Nam");
     lvi.SubItems.Add(b.Diachi);
 }
 private void loadata(Docgia b)
 {
     tbMa_doc_gia.Text     = b.Madocgia;
     tbHo_ten_doc_gia.Text = b.Tendocgia;
     rbtNam.Checked        = b.Gioitinh == true ? false :  true;
     rbtNu.Checked         = b.Gioitinh == false ? false : true;
     tbDia_chi.Text        = b.Diachi;
 }
        public void napdulieu()
        {
            var query = from docgia in a.DOCGIAs
                        orderby docgia.MADOCGIA ascending
                        select docgia;

            foreach (var b in query)
            {
                Docgia c = new Docgia(b.MADOCGIA.ToString(), b.HOTEN.ToString(), Convert.ToBoolean(b.GIOITINH), b.DIACHI.ToString());
                ds.add(c);
            }
        }
        private void btLuu_Click(object sender, EventArgs e)
        {
            if (tbHo_ten_doc_gia.Text.Length == 0 || Char.IsNumber(tbHo_ten_doc_gia.Text[tbHo_ten_doc_gia.Text.Length - 1]) ||
                (rbtNam.Checked == false && rbtNu.Checked == false) ||
                tbDia_chi.Text.Length == 0)
            {
                if (tbHo_ten_doc_gia.Text.Length == 0 || Char.IsNumber(tbHo_ten_doc_gia.Text[tbHo_ten_doc_gia.Text.Length - 1]))
                {
                    this.errorProvider1.SetError(tbHo_ten_doc_gia, "Ho ten khong duoc de trong va khong bao gom so");
                }
                if ((rbtNam.Checked == false && rbtNu.Checked == false))
                {
                    this.errorProvider1.SetError(rbtNam, "Phai chon gioi tinh");
                }
                if (tbDia_chi.Text.Length == 0)
                {
                    this.errorProvider1.SetError(tbDia_chi, "Phai dien dia chi");
                }
            }
            else
            {
                this.errorProvider1.Clear();
                Docgia tmp  = new Docgia(tbMa_doc_gia.Text, tbHo_ten_doc_gia.Text, rbtNam.Checked == true ? false : true, tbDia_chi.Text);
                DOCGIA tmp1 = new DOCGIA();
                tmp1.MADOCGIA = tbMa_doc_gia.Text;
                tmp1.HOTEN    = tbHo_ten_doc_gia.Text;
                tmp1.GIOITINH = rbtNam.Checked == true ? 0 : 1;
                tmp1.DIACHI   = tbDia_chi.Text;
                if (kiemtra == 0)
                {
                    lvi = lv_ds_doc_gia.SelectedItems[0];
                    ds.delete(ds.search_docgia(lvi.Text).Madocgia);
                    cleardata();
                    DOCGIA b = a.DOCGIAs.Where(s => s.MADOCGIA == lvi.Text).Single();
                    a.DOCGIAs.DeleteOnSubmit(b);
                    a.DOCGIAs.InsertOnSubmit(tmp1);
                    a.SubmitChanges();
                    ds.add(tmp);

                    load_list_docgia();
                    MessageBox.Show("Sua thanh cong");
                }
                if (kiemtra == 1)
                {
                    a.DOCGIAs.InsertOnSubmit(tmp1);
                    a.SubmitChanges();
                    ds.add(tmp);
                    load_list_docgia();
                    MessageBox.Show("Them thanh cong");
                }
                enable_control(false);
            }
        }
 public void add(Docgia a)
 {
     ds.Add(a);
 }