Ejemplo n.º 1
0
        /**********************************************************************
        *  /**Description: Xoa sach khi click button xoa
        *  /**Params :
        *  /**Write by: Nguyen Nhat Linh
        *  /**Create date: 10/4/2018
        **********************************************************************/
        private void btXoa_Click(object sender, EventArgs e)
        {
            if (lvi != null)
            {
                lvi = lvDanh_sach_sach.SelectedItems[0];
                SACH a    = data.SACHes.Where(s => s.MASACH == lvi.Text).Single();
                var  ctpm = from pm in data.CTPMs

                            where pm.MASACH == lvi.Text
                            select pm;
                var pm_xoa = from bb in data.PHIEUMUONs
                             join pm in data.CTPMs on bb.MAPHIEUMUON equals pm.MAPHIEUMUON
                             where pm.MASACH == lvi.Text
                             select bb;
                var pt_xoa = from pt in data.PHIEUTRAs
                             join bb in data.PHIEUMUONs on pt.MAPHIEUMUON equals bb.MAPHIEUMUON
                             join pm in data.CTPMs on bb.MAPHIEUMUON equals pm.MAPHIEUMUON
                             where pm.MASACH == lvi.Text
                             select pt;
                foreach (var tmp_pm in ctpm)
                {
                    data.CTPMs.DeleteOnSubmit(tmp_pm);
                    data.SubmitChanges();
                }
                foreach (var tmp_pm1 in pm_xoa)
                {
                    data.PHIEUMUONs.DeleteOnSubmit(tmp_pm1);
                    data.SubmitChanges();
                }
                foreach (var tmp_pm1 in pt_xoa)
                {
                    data.PHIEUTRAs.DeleteOnSubmit(tmp_pm1);
                    data.SubmitChanges();
                }
                data.SACHes.DeleteOnSubmit(a);
                data.SubmitChanges();
                string tmp = lvi.Text;
                danh_sach_sach.delete(danh_sach_sach.search(tmp).Masach);
                load_list_danh_sach_sach();
                lvi = null;
                MessageBox.Show("Xoa thanh cong");
            }
            else
            {
                MessageBox.Show("Chua chon sach de xoa");
            }
        }
Ejemplo n.º 2
0
        private void lvDanhsach_sach_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvDanhsach_sach.SelectedItems.Count > 0)
            {
                if (lvDanhsach_sach.SelectedItems[0].SubItems[1].Text != "0")
                {
                    if (tbMa_sach_1.Text == "" || tbMa_sach_2.Text == "")
                    {
                        if (tbMa_sach_1.Text == "" || (tbMa_sach_1.Text == "" && tbMa_sach_2.Text == ""))
                        {
                            lvi = lvDanhsach_sach.SelectedItems[0];
                            tbTen_sach_1.Text = lvi.Text;
                            SACH tmp3 = a.SACHes.Where(s => s.TENSACH == lvi.Text).Single();
                            tbMa_sach_1.Text = tmp3.MASACH;
                        }
                        else if (tbMa_sach_2.Text == "")
                        {
                            lvi = lvDanhsach_sach.SelectedItems[0];
                            tbTen_sach_2.Text = lvi.Text;
                            SACH tmp = a.SACHes.Where(x => x.TENSACH == lvi.Text).Single();
                            tbMa_sach_2.Text = tmp.MASACH;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Chi duoc muon  toi da 2 quyen");
                    }
                }
                else
                {
                    MessageBox.Show("Da het sach nay");
                }
            }

            lvi = null;
        }
Ejemplo n.º 3
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;
            }
        }
 partial void DeleteSACH(SACH instance);
 partial void UpdateSACH(SACH instance);
 partial void InsertSACH(SACH instance);