Пример #1
0
        /**********************************************************************
        *  /**Description: Luu du lieu thay doi xuong database, cap nhat du lieu
        *  /**Params :
        *  /**Write by: Nguyen Nhat Linh
        *  /**Create date: 10/4/2018
        **********************************************************************/
        private void btLuu_Click(object sender, EventArgs e)
        {
            if (tbTac_gia.Text.Length == 0 ||
                Char.IsNumber(tbTac_gia.Text[tbTac_gia.Text.Length - 1]) ||
                !Char.IsNumber(tbSo_luong.Text[tbSo_luong.Text.Length - 1]) ||
                tb_Ten_sach.Text.Length == 0 || Convert.ToInt32(tbSo_luong.Text) < 0 ||
                tbSo_luong.Text == "" || cbLoai.Text == "")
            {
                if (tbTac_gia.Text.Length == 0 || Char.IsNumber(tbTac_gia.Text[tbTac_gia.Text.Length - 1]))
                {
                    errorProvider1.SetError(tbTac_gia, "Ten tac gia khong co so");
                }
                if (cbLoai.Text.Length == 0)
                {
                    errorProvider1.SetError(cbLoai, "Loai khong duoc de trong");
                }
                if (tbSo_luong.Text.Length == 0 || !Char.IsNumber(tbSo_luong.Text[tbSo_luong.Text.Length - 1]) || Convert.ToInt32(tbSo_luong.Text) <= 0)
                {
                    errorProvider1.SetError(tbSo_luong, "So luong la so nguyen duong");
                }
                if (tb_Ten_sach.Text.Length == 0)
                {
                    errorProvider1.SetError(tb_Ten_sach, "Ten sach khong duoc de trong");
                }
            }
            else
            {
                this.errorProvider1.Clear();
                Sach tmp  = new Sach(tbMa_sach.Text, tb_Ten_sach.Text, cbLoai.Text, tbTac_gia.Text, Convert.ToInt32(tbSo_luong.Text));
                SACH tmp1 = new SACH();

                tmp1.MASACH    = tbMa_sach.Text;
                tmp1.TENSACH   = tb_Ten_sach.Text;
                tmp1.LOAI      = cbLoai.Text;
                tmp1.TENTACGIA = tbTac_gia.Text;
                tmp1.SOLUONG   = Convert.ToInt32(tbSo_luong.Text);
                if (kiem_tra == 0)
                {
                    SACH tmp2 = data.SACHes.Where(s => s.MASACH == lvi.Text).Single();
                    lvi = lvDanh_sach_sach.SelectedItems[0];
                    danh_sach_sach.delete(danh_sach_sach.search(lvi.Text).Masach);
                    data.SACHes.DeleteOnSubmit(tmp2);
                    data.SACHes.InsertOnSubmit(tmp1);
                    data.SubmitChanges();
                    MessageBox.Show("Sua thanh cong");
                    enableControl(false);
                    //data.SACHes.InsertOnSubmit(tmp1);
                    danh_sach_sach.add(tmp);
                    load_list_danh_sach_sach();
                }

                if (kiem_tra == 1)
                {
                    MessageBox.Show("Them thanh cong");
                    data.SACHes.InsertOnSubmit(tmp1);
                    data.SubmitChanges();
                    enableControl(false);
                    danh_sach_sach.add(tmp);
                    load_list_danh_sach_sach();
                }
                lvi = null;
            }
        }
Пример #2
0
 public void add(Sach a)
 {
     ds.Add(a);
 }