Ejemplo n.º 1
0
        private void Delete(int id)
        {
            try
            {
                using (KitDataContext db = new KitDataContext())
                {
                    var result =
                        from s in db.Groups
                        where s.Id == id
                        select s;

                    var deleteItems = result.ToList();

                    foreach (var deleteItem in deleteItems)
                    {
                        db.Groups.Remove(deleteItem);
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        private void Modify()
        {
            try
            {
                using (KitDataContext db = new KitDataContext())
                {
                    var result = db.Students.Find(_oldId);

                    if (!result.Id.Equals(textBoxID.Text))
                    {
                        Delete(result.Id);
                        AddData();
                    }

                    else
                    {
                        result.Name                = textBoxName.Text;
                        result.Class               = textBoxClass.Text;
                        result.DateOfBirth         = DateTime.Parse(dateTimePicker.Value.ToString());
                        result.Contact.PhoneNumber = textBoxPhoneNum.Text;
                        result.Contact.Email       = textBoxEmail.Text;
                        result.Gender              = SetGender();
                    }

                    db.SaveChanges();
                    //MessageBox.Show("Sửa thành viên thành công!", Program.applicationName);
                    dataGridView.Refresh();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Ejemplo n.º 3
0
        private void AddData()
        {
            try
            {
                if (textBoxGroupName.Text != String.Empty)
                {
                    using (KitDataContext db = new KitDataContext())
                    {
                        Group newGroup = new Group()
                        {
                            Name        = textBoxGroupName.Text,
                            Description = textBoxDescription.Text,
                            Students    = new List <Student>()
                        };

                        db.Groups.Add(newGroup);
                        db.SaveChanges();
                    }
                    LoadData(0, _take);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 4
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            try
            {
                using (KitDataContext db = new KitDataContext())
                {
                    var    salt          = BCrypt.Net.BCrypt.GenerateSalt();
                    var    pepper        = "CsUd9KpJVD";
                    string username      = textBoxUsername.Text;
                    string password      = textBoxPassword.Text;
                    var    resultStudent = db.Students.FirstOrDefault(s => s.Id.Equals(username));
                    var    resultUser    = db.Users.FirstOrDefault(s => s.Id.Equals(username));
                    if (resultUser == null)
                    {
                        if (resultStudent != null)
                        {
                            db.Users.Add(new User()
                            {
                                Id       = resultStudent.Id,
                                Password = BCrypt.Net.BCrypt.HashPassword(pepper + password, salt),
                                Priority = Priority.User,
                                Salt     = salt
                            });

                            db.SaveChanges();
                        }
                        else
                        {
                            this.labelWrongInfo.Visible = true;
                        }
                    }
                    else
                    {
                        var user = db.Users.FirstOrDefault(s => s.Id.Equals(username));
                        if (BCrypt.Net.BCrypt.Verify(pepper + password, user.Password) && user.Priority == Priority.Admin)
                        {
                            Thread thrd = new Thread(() =>
                            {
                                using (WelcomeForm welcomeForm = new WelcomeForm())
                                {
                                    Application.Run(welcomeForm);
                                }
                            });
                            thrd.Start();
                            this.Dispose();
                        }
                        else
                        {
                            this.labelWrongInfo.Visible = true;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Ejemplo n.º 5
0
        private void buttonRemove_Click(object sender, EventArgs e)
        {
            string id = dataGridViewStudentInGroup.Rows[_rowNo].Cells[0].Value.ToString();

            var student = StudentsList.FirstOrDefault(s => s.Id.Equals(id));

            using (KitDataContext db = new KitDataContext())
            {
                var result = db.Groups.Find(_groupId);
                var stu    = db.Students.FirstOrDefault(s => s.Id.Equals(student.Id));
                result.Students.Remove(stu);
                db.SaveChanges();
            }

            LoadData();
        }
        private void Delete(String id)
        {
            try
            {
                using (KitDataContext db = new KitDataContext())
                {
                    var result = db.Students.FirstOrDefault(s => s.Id.Equals(id));
                    var user   = db.Users.FirstOrDefault(s => s.Id.Equals(id));

                    db.Users.Remove(user);
                    db.Students.Remove(result);

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        private void AddData()
        {
            try
            {
                if (textBoxID.Text != String.Empty && textBoxName.Text != string.Empty)
                {
                    using (KitDataContext db = new KitDataContext())
                    {
                        var     pepper    = "CsUd9KpJVD";
                        var     salt      = BCrypt.Net.BCrypt.GenerateSalt();
                        Student newMember = new Student()
                        {
                            Id          = textBoxID.Text,
                            Name        = textBoxName.Text,
                            DateOfBirth = dateTimePicker.Value,
                            Class       = textBoxClass.Text,
                            Gender      = SetGender(),
                            Contact     = new Contact()
                            {
                                PhoneNumber = textBoxPhoneNum.Text,
                                Email       = textBoxEmail.Text
                            },
                            User = new User()
                            {
                                Password = BCrypt.Net.BCrypt.HashPassword(pepper + dateTimePicker.Value.Date, salt),
                                Salt     = salt,
                                Priority = Priority.User
                            }
                        };

                        db.Students.Add(newMember);
                        db.SaveChanges();
                    }
                    LoadData(0, _take);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 8
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string id = dataGridViewStudentOnDb.Rows[_rowNo].Cells[0].Value.ToString();

                using (KitDataContext db = new KitDataContext())
                {
                    var result = db.Groups.Find(_groupId);
                    var stu    = db.Students.FirstOrDefault(s => s.Id.Equals(id));
                    result.Students.Add(stu);
                    db.SaveChanges();
                }

                LoadData();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
Ejemplo n.º 9
0
        private void Modify()
        {
            try
            {
                using (KitDataContext db = new KitDataContext())
                {
                    var result = db.Groups.Find(textBoxID.Text);

                    if (!(result.Name.Equals(textBoxGroupName.Text) ||
                          result.Description.Equals(textBoxDescription.Text)))
                    {
                        result.Name        = textBoxGroupName.Text;
                        result.Description = textBoxDescription.Text;
                    }

                    db.SaveChanges();
                    dataGridViewGroup.Refresh();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }