Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Update Student
            if (btnNewStudent.Enabled)
            {
                //TAIKHOAN _iUser = frmLogin._database.TAIKHOANs.Single(p => p.username == txtUser.Text);
                HOCSINH _iStudent = frmLogin._database.HOCSINHs.Single(p => p.mahs == txtIDStudent.Text);
                _iStudent.tenhs    = txtFullName.Text;
                _iStudent.ngaysinh = dtpDOB.Value;
                _iStudent.tencha   = txtFatherName.Text;
                _iStudent.tenme    = txtMotherName.Text;
                _iStudent.sdt      = txtPhoneNumber.Text;
                _iStudent.diachi   = txtAddress.Text;

                if (txtSex.SelectedItem.ToString() == "Male")
                {
                    _iStudent.gt = true;
                }
                else
                {
                    _iStudent.gt = false;
                }
                frmLogin._database.SubmitChanges();
            }
            else //Add New Student
            {
                HOCSINH _iStudent = new HOCSINH();
                _iStudent.mahs     = txtIDStudent.Text;
                _iStudent.tenhs    = txtFullName.Text;
                _iStudent.ngaysinh = dtpDOB.Value;
                _iStudent.tencha   = txtFatherName.Text;
                _iStudent.tenme    = txtMotherName.Text;
                _iStudent.sdt      = txtPhoneNumber.Text;
                _iStudent.diachi   = txtAddress.Text;
                frmLogin._database.HOCSINHs.InsertOnSubmit(_iStudent);
                TAIKHOAN _iUser = new TAIKHOAN();
                _iUser.username = txtIDStudent.Text;
                _iUser.maloai   = "HS";
                frmLogin._database.TAIKHOANs.InsertOnSubmit(_iUser);
                frmLogin._database.SubmitChanges();
                btnNewStudent.Enabled = true;
                btnCancel.Enabled     = false;
                frmAdmin._userManagementControl.LoadUserData();
            }
            LoadDGVStudent();
        }
Пример #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var _iDiem = from _diemData in frmLogin._database.DIEMs
                         where _diemData.mahs == txtIDStudent.Text
                         select _diemData;
            var _iPhanLop = from _phanlopData in frmLogin._database.PHANLOPs
                            where _phanlopData.mahs == txtIDStudent.Text
                            select _phanlopData;

            var _iKQHKMonHoc = from _kqhkMonHoc in frmLogin._database.KQHKMONHOCs
                               where _kqhkMonHoc.mahs == txtIDStudent.Text
                               select _kqhkMonHoc;
            var _iKQHKTongHop = from _kqhkTongHop in frmLogin._database.KQHKTONGHOPs
                                where _kqhkTongHop.mahs == txtIDStudent.Text
                                select _kqhkTongHop;

            var _iKQNHTongHop = from _kqnhTongHop in frmLogin._database.KQNHTONGHOPs
                                where _kqnhTongHop.mahs == txtIDStudent.Text
                                select _kqnhTongHop;
            var _iKQNHMonHoc = from _kqnhMonHoc in frmLogin._database.KQNHMONHOCs
                               where _kqnhMonHoc.mahs == txtIDStudent.Text
                               select _kqnhMonHoc;

            TAIKHOAN _iUser = frmLogin._database.TAIKHOANs.Single(p => p.username == txtIDStudent.Text);

            DialogResult _dialogResult = MessageBox.Show("Do you want to delete student ?", "Confirm", MessageBoxButtons.YesNo);

            if (_dialogResult == DialogResult.Yes)
            {
                try
                {
                    foreach (var _diemItem in _iDiem.ToList())
                    {
                        frmLogin._database.DIEMs.DeleteOnSubmit(_diemItem);
                    }
                    foreach (var _phanLopItem in _iPhanLop.ToList())
                    {
                        frmLogin._database.PHANLOPs.DeleteOnSubmit(_phanLopItem);
                    }
                    foreach (var _kqhkMonHoc in _iKQHKMonHoc.ToList())
                    {
                        frmLogin._database.KQHKMONHOCs.DeleteOnSubmit(_kqhkMonHoc);
                    }
                    foreach (var _kqhkTongHop in _iKQHKTongHop.ToList())
                    {
                        frmLogin._database.KQHKTONGHOPs.DeleteOnSubmit(_kqhkTongHop);
                    }
                    foreach (var _kqnhMonHoc in _iKQNHMonHoc.ToList())
                    {
                        frmLogin._database.KQNHMONHOCs.DeleteOnSubmit(_kqnhMonHoc);
                    }
                    foreach (var _kqnhTongHop in _iKQNHTongHop)
                    {
                        frmLogin._database.KQNHTONGHOPs.DeleteOnSubmit(_kqnhTongHop);
                    }
                    frmLogin._database.TAIKHOANs.DeleteOnSubmit(_iUser);
                    HOCSINH _iStudent = frmLogin._database.HOCSINHs.Single(p => p.mahs == txtIDStudent.Text);
                    frmLogin._database.HOCSINHs.DeleteOnSubmit(_iStudent);
                    frmLogin._database.SubmitChanges();
                    LoadDGVStudent();
                }
                catch (Exception Ex)
                {
                    MessageBox.Show(Ex.Message);
                }
                frmAdmin._userManagementControl.LoadUserData();
            }
        }
 partial void UpdateHOCSINH(HOCSINH instance);
 partial void DeleteHOCSINH(HOCSINH instance);
 partial void InsertHOCSINH(HOCSINH instance);