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);
            }
        }
 private void btXoa_Click(object sender, EventArgs e)
 {
     if (tbMa_doc_gia.Text != "")
     {
         lvi = lv_ds_doc_gia.SelectedItems[0];
         DOCGIA b      = a.DOCGIAs.Where(s => s.MADOCGIA == lvi.Text).Single();
         var    pm_xoa = from pm in a.PHIEUMUONs
                         where pm.MADOCGIA == lvi.Text
                         select pm;
         var ctpm_xoa = from ctpm in a.CTPMs
                        join pm in a.PHIEUMUONs on ctpm.MAPHIEUMUON equals pm.MAPHIEUMUON
                        where pm.MADOCGIA == lvi.Text
                        select ctpm;
         var pt_xoa = from pt in a.PHIEUTRAs
                      join bb in a.PHIEUMUONs on pt.MAPHIEUMUON equals bb.MAPHIEUMUON
                      where bb.MADOCGIA == lvi.Text
                      select pt;
         foreach (var tmp_pm in pm_xoa)
         {
             a.PHIEUMUONs.DeleteOnSubmit(tmp_pm);
             a.SubmitChanges();
         }
         foreach (var tmp_pm1 in ctpm_xoa)
         {
             a.CTPMs.DeleteOnSubmit(tmp_pm1);
             a.SubmitChanges();
         }
         foreach (var tmp_pm1 in pt_xoa)
         {
             a.PHIEUTRAs.DeleteOnSubmit(tmp_pm1);
             a.SubmitChanges();
         }
         a.DOCGIAs.DeleteOnSubmit(b);
         a.SubmitChanges();
         ds.delete(ds.search_docgia(lvi.Text).Madocgia);
         load_list_docgia();
         cleardata();
         lvi = null;
     }
     else
     {
         MessageBox.Show("Chua chon doc gia");
     }
 }
Esempio n. 3
0
        private void btTim_doc_gia_Click(object sender, EventArgs e)
        {
            bool aa = false;
            var  b  = from c in a.DOCGIAs
                      select c;

            foreach (var i in b)
            {
                if (i.MADOCGIA == tbtim_Ma_doc_gia.Text)
                {
                    aa = true;
                }
            }

            if (aa == false)
            {
                MessageBox.Show("Ma doc gia khong ton tai");
            }
            else
            {
                aa = false;
                for (int i = 0; i < ds_PM.count(); i++)
                {
                    if (tbtim_Ma_doc_gia.Text == ds_PM[i].Ma_doc_gia)
                    {
                        aa = true;
                    }
                }
                if (aa == false)
                {
                    DOCGIA c = a.DOCGIAs.Where(x => x.MADOCGIA == tbtim_Ma_doc_gia.Text).Single();
                    tbMa_doc_gia.Text  = c.MADOCGIA;
                    tbTen_doc_gia.Text = c.HOTEN;
                }
                else
                {
                    MessageBox.Show("Doc gia dang muon sach");
                }
            }
        }
 partial void DeleteDOCGIA(DOCGIA instance);
 partial void UpdateDOCGIA(DOCGIA instance);
 partial void InsertDOCGIA(DOCGIA instance);