示例#1
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            var row = GetCurrentRow();

            if (row == null)
            {
                DialogHelper.ShowMissingSelectedRow();
                return;
            }

            string maLop = row.Cells["MALOP"].Value.ToString();
            string maGV  = GetEqualName(row.Cells["MAGV"].Value.ToString(), dtGiangVien, 1, 0);

            LopHoc    lophoc  = new LopHoc();
            CT_LopHoc chitiet = new CT_LopHoc();

            chitiet.delete(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword(), maLop, maGV);
            lophoc.delete(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword(), maLop);

            ShowTable();
            this.Cursor = Cursors.Arrow;
        }
示例#2
0
        //void InitPhongHoc()
        //{
        //    PhongHoc ph = new PhongHoc();
        //    dtPhongHoc = ph.getAllId(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword());


        //    PopulatePhongHoc();
        //}
        //private int PopulatePhongHoc()
        //{
        //    UIHelper.PopulateComboBoxWithDataTable(dtPhongHoc, cbMaPhong);
        //    return 0;
        //}
        #region init ---------
        void InitChiTiet()
        {
            CT_LopHoc chitiet = new CT_LopHoc();

            dtChiTiet = chitiet.getAll(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword());
        }
示例#3
0
        private void InsertOrUpdateCurrentValueToDatabase(bool isUpdate = false)
        {
            string maLop = txtMaLopHoc.Text;
            string maKH  = cbMaKhoaHoc.Text;

            string maGV = GetEqualName(cbGiangVien.Text, dtGiangVien, 0, 1);

            DateTime ngayBD = dateNgayBatDau.Value;

            DateTime ngayKT = dateNgayKetThuc.Value;

            string maHP = GetEqualName(cbHocPhi.Text, dtHocPhi, 0, 1);

            int siSo;

            try
            {
                siSo = int.Parse(txtSiSo.Text);
            }
            catch (Exception e)
            {
                DialogHelper.ShowErrorDialog("Sĩ số nhập vào không hợp lệ!");
                return;
            }

            // điền thiếu thì báo lỗi
            if (maLop == "" ||
                maKH == "" ||
                maGV == "" ||
                maHP == "" ||
                siSo == 0)
            {
                DialogHelper.ShowMissingField();
                return;
            }


            if (isUpdate)
            {
                var row = GetCurrentRow();
                if (row == null)
                {
                    DialogHelper.ShowMissingSelectedRow();
                    return;
                }

                string _maLopRow = row.Cells["MALOP"].Value.ToString();

                if (maLop != _maLopRow)
                {
                    DialogHelper.ShowCannotModifiyPrimaryKey();
                    return;
                }
            }


            bool isSuccess = true;

            LopHoc    lophoc  = new LopHoc();
            CT_LopHoc chitiet = new CT_LopHoc();

            if (!isUpdate)
            {
                isSuccess = lophoc.insert(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword(), maLop, maKH, ngayBD.Date, ngayKT.Date, siSo, maHP) == 1;
                chitiet.insert(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword(), maLop, maGV);
            }
            else
            {
                isSuccess = lophoc.update(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword(), maLop, maKH, ngayBD.Date, ngayKT.Date, siSo, maHP) == 1;


                string oldGV = GetEqualName(maLop, dtChiTiet, 0, 1);
                // nếu có thay giảng viên
                if (!oldGV.Equals(maGV))
                {
                    isSuccess &= chitiet.delete(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword(), maLop, oldGV) == 1;
                    isSuccess &= chitiet.insert(AccountHelper.getAccountId(), AccountHelper.getAccoutPassword(), maLop, maGV) == 1;
                }
            }


            if (isSuccess)
            {
                InitChiTiet();
                ShowTable();
                ClearField();
                return;
            }
            else
            {
                DialogHelper.ShowErrorOnUpdate();
                return;
            }
        }