Ejemplo n.º 1
0
        private void txtClass_TextChanged(object sender, EventArgs e)
        {
            QLHSDataContext context = new QLHSDataContext();

            ConditionToEnableBtn();
            if (txtStudent.Text != string.Empty)
            {
                var Student = context.HOCSINHs.Where(hs => hs.MaHocSinh.ToString() == txtStudent.Text);
                if (Student.Count() != 0)
                {
                    btnDeleteStudent.Enabled = true;
                    btnUpdateStudent.Enabled = true;
                    lbError.Hide();
                }
                else
                {
                    btnDeleteStudent.Enabled = false;
                    btnUpdateStudent.Enabled = false;
                    lbError.Show();
                }
            }
            else
            {
                lbError.Hide();
            }
            context.Dispose();
        }
        private void showListClass()
        {
            QLHSDataContext context = new QLHSDataContext();

            datagridviewClass.DataSource = (from Class in context.LOPHOCs
                                            select Class).ToList();
            context.Dispose();
        }
Ejemplo n.º 3
0
 public frmQuanLyHocSinh()
 {
     InitializeComponent();
     context = new QLHSDataContext();
     btnDeleteStudent.Enabled = false;
     btnUpdateStudent.Enabled = false;
     lbError.Hide();
 }
Ejemplo n.º 4
0
        private void showListStudent()
        {
            QLHSDataContext context     = new QLHSDataContext();
            var             listHocSinh = (from student in context.HOCSINHs
                                           select student).ToList();

            datagridviewStudent.DataSource = listHocSinh;
            context.Dispose();
        }
Ejemplo n.º 5
0
        private void showListStudent()
        {
            QLHSDataContext context     = new QLHSDataContext();
            var             listHocSinh = (from student in context.HOCSINHs
                                           where student.MaLop == Int32.Parse(txtIDClass.Text)
                                           select student).ToList();

            datagridviewListStudent.DataSource = listHocSinh;
            context.Dispose();
        }
Ejemplo n.º 6
0
        private void CheckConnectToServer()
        {
            QLHSDataContext context = new QLHSDataContext();

            if (!context.DatabaseExists())
            {
                DialogResult res = MessageBox.Show("Không thể kết nối đến Server! Vui lòng thử lại.", "ERROR");
                if (res == DialogResult.OK)
                {
                    this.Close();
                    context.Dispose();
                }
            }
        }
Ejemplo n.º 7
0
        private void frmSuaHocSinh_Load(object sender, EventArgs e)
        {
            QLHSDataContext context = new QLHSDataContext();
            var             Student = (from HocSinh in context.HOCSINHs
                                       where HocSinh.MaHocSinh.ToString() == txtIDStudent.Text
                                       select HocSinh).FirstOrDefault();

            if (Student != null)
            {
                txtFullName.Text     = Student.TenHocSinh;
                txtIDClass.Text      = Student.MaLop.ToString();
                txtSex.Text          = Student.GioiTinh;
                dateTimePicker1.Text = Student.NgaySinh.ToString();
            }
            context.Dispose();
        }
Ejemplo n.º 8
0
        private void frmSuaLopHoc_Load(object sender, EventArgs e)
        {
            QLHSDataContext context = new QLHSDataContext();
            var             Class   = (from LopHoc in context.LOPHOCs
                                       where LopHoc.MaLop.ToString() == txtIDClass.Text
                                       select LopHoc).FirstOrDefault();

            if (Class != null)
            {
                txtClassPresident.Text  = Class.LopTruong.ToString();
                txtIDTeacher.Text       = Class.GVQuanLy.ToString();
                txtNumberOfStudent.Text = Class.SiSo.ToString();
                dateTimePicker1.Text    = Class.NamBatDau.ToString();
                dateTimePicker2.Text    = Class.NamKetThuc.ToString();
            }
            context.Dispose();
        }
Ejemplo n.º 9
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            HOCSINH hocsinh = new HOCSINH
            {
                MaHocSinh  = Int32.Parse(txtIDStudent.Text),
                TenHocSinh = txtFullName.Text,
                NgaySinh   = Convert.ToDateTime(dtNgaySinh.Text),
                GioiTinh   = txtSex.Text,
                MaLop      = Int32.Parse(txtIDClass.Text)
            };
            QLHSDataContext context = new QLHSDataContext();

            context.HOCSINHs.InsertOnSubmit(hocsinh);
            context.SubmitChanges();
            context.Dispose();
            this.Close();
        }
Ejemplo n.º 10
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            QLHSDataContext context = new QLHSDataContext();
            var             student = (from HocSinh in context.HOCSINHs
                                       where HocSinh.MaHocSinh == Int32.Parse(txtIDStudent.Text)
                                       select HocSinh).FirstOrDefault();

            if (student != null)
            {
                student.MaLop      = Int32.Parse(txtIDClass.Text);
                student.NgaySinh   = Convert.ToDateTime(dateTimePicker1.Text);
                student.TenHocSinh = txtFullName.Text;
                student.GioiTinh   = txtSex.Text;
                context.SubmitChanges();
            }
            context.Dispose();
            this.Close();
        }
Ejemplo n.º 11
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            LOPHOC lophoc = new LOPHOC
            {
                MaLop      = Int32.Parse(txtIDClass.Text),
                SiSo       = Int32.Parse(txtNumberOfStudent.Text),
                LopTruong  = Int32.Parse(txtClassPresident.Text),
                GVQuanLy   = Int32.Parse(txtIDTeacher.Text),
                NamBatDau  = Convert.ToDateTime(dateTimePicker1.Text),
                NamKetThuc = Convert.ToDateTime(dateTimePicker2.Text)
            };
            QLHSDataContext context = new QLHSDataContext();

            context.LOPHOCs.InsertOnSubmit(lophoc);
            context.SubmitChanges();
            context.Dispose();
            this.Close();
        }
Ejemplo n.º 12
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            QLHSDataContext context = new QLHSDataContext();
            var             Class   = (from LopHoc in context.LOPHOCs
                                       where LopHoc.MaLop.ToString() == txtIDClass.Text
                                       select LopHoc).FirstOrDefault();

            if (Class != null)
            {
                Class.SiSo       = Int32.Parse(txtNumberOfStudent.Text);
                Class.LopTruong  = Int32.Parse(txtClassPresident.Text);
                Class.GVQuanLy   = Int32.Parse(txtIDTeacher.Text);
                Class.NamBatDau  = Convert.ToDateTime(dateTimePicker1.Text);
                Class.NamKetThuc = Convert.ToDateTime(dateTimePicker2.Text);
                context.SubmitChanges();
            }
            context.Dispose();
            this.Close();
        }
        private void btnDeleteClass_Click(object sender, EventArgs e)
        {
            QLHSDataContext context = new QLHSDataContext();
            var             Class   = (from LopHoc in context.LOPHOCs
                                       where LopHoc.MaLop == Int32.Parse(txtClass.Text)
                                       select LopHoc).FirstOrDefault();
            var students = (from student in context.HOCSINHs
                            where student.MaLop == Int32.Parse(txtClass.Text)
                            select student).ToList();

            if (students.Count > 0)
            {
                context.HOCSINHs.DeleteAllOnSubmit(students);
                context.SubmitChanges();
            }
            if (Class != null)
            {
                context.LOPHOCs.DeleteOnSubmit(Class);
                context.SubmitChanges();
                clearListClass();
                showListClass();
                txtClass.Text = "";
                if (txtClass.Text != string.Empty)
                {
                    var Class1 = context.LOPHOCs.Where(lh => lh.MaLop == Int32.Parse(txtClass.Text)).ToList();
                    if (Class1.Count == 0)
                    {
                        lbError.Show();
                        btnDeleteClass.Enabled     = false;
                        btnUpdateClass.Enabled     = false;
                        btnShowListStudent.Enabled = false;
                    }
                }
                else
                {
                    lbError.Hide();
                }
            }
            context.Dispose();
        }
Ejemplo n.º 14
0
        private void txtIDClass_TextChanged(object sender, EventArgs e)
        {
            QLHSDataContext context = new QLHSDataContext();

            if (txtIDClass.Text != string.Empty)
            {
                var Class = context.LOPHOCs.Where(lh => lh.MaLop.ToString() == txtIDClass.Text);
                if (Class.Count() != 0)
                {
                    btnAdd.Enabled = true;
                    lbError.Hide();
                }
                else
                {
                    lbError.Show();
                }
            }
            else
            {
                lbError.Hide();
            }
        }
        private void txtStudent_TextChanged(object sender, EventArgs e)
        {
            QLHSDataContext context = new QLHSDataContext();

            ConditionToEnableBtn();
            if (txtClass.Text != string.Empty)
            {
                var Class = context.LOPHOCs.Where(lh => lh.MaLop == Int32.Parse(txtClass.Text)).ToList();
                if (Class.Count == 0)
                {
                    lbError.Show();
                    btnDeleteClass.Enabled     = false;
                    btnUpdateClass.Enabled     = false;
                    btnShowListStudent.Enabled = false;
                }
            }
            else
            {
                lbError.Hide();
            }
            context.Dispose();
        }
Ejemplo n.º 16
0
        private void btnDeleteStudent_Click(object sender, EventArgs e)
        {
            if (context == null)
            {
                context = new QLHSDataContext();
            }
            var Student = (from HocSinh in context.HOCSINHs
                           where HocSinh.MaHocSinh == Int32.Parse(txtStudent.Text)
                           select HocSinh).FirstOrDefault();

            if (Student != null)
            {
                context.HOCSINHs.DeleteOnSubmit(Student);
                context.SubmitChanges();
                clearListStudent();
                showListStudent();
                txtStudent.Text = "";
                if (txtStudent.Text != string.Empty)
                {
                    var Student1 = context.HOCSINHs.Where(hs => hs.MaHocSinh.ToString() == txtStudent.Text);
                    if (Student1.Count() == 0)
                    {
                        btnDeleteStudent.Enabled = false;
                        btnUpdateStudent.Enabled = false;
                        lbError.Hide();
                    }
                    else
                    {
                        lbError.Show();
                    }
                }
                else
                {
                    lbError.Hide();
                }
            }
            context.Dispose();
        }
Ejemplo n.º 17
0
 private void txtIDClass_TextChanged(object sender, EventArgs e)
 {
     if (txtIDClass.Text == string.Empty)
     {
         btnShow.Enabled = false;
         lbError.Hide();
     }
     else
     {
         QLHSDataContext context = new QLHSDataContext();
         var             Class   = context.LOPHOCs.Where(lh => lh.MaLop == Int32.Parse(txtIDClass.Text));
         if (Class.Count() > 0)
         {
             btnShow.Enabled = true;
             lbError.Hide();
         }
         else
         {
             btnShow.Enabled = false;
             lbError.Show();
         }
     }
 }