private void addbutton_Click(object sender, EventArgs e) { try { Book model = new Book { Category = booksubjectTb.Text, Title = booktitleTb.Text, Author = authorTb.Text, Publisher = publisherTb.Text, Year_Released = yearTb.Text, Pages = pagesTb.Text, Shelf_Number = shelfnumberTb.Text, Num_of_Copies = numcopiesTb.Text, ISBN = isbnTb.Text, }; ctx.Books.Add(model); ctx.SaveChanges(); PopulateDataGridView(); clear(); MessageBox.Show("New Book was successfully added to database"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error cancel", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Addbutton_Click(object sender, EventArgs e) { try { Student model1 = new Student { StudentID = studentTb.Text.Trim(), L_Name = lnameTb.Text.Trim(), F_Name = fnameTb.Text.Trim(), Class = classTb.Text.Trim(), }; ctx.Students.Add(model1); ctx.SaveChanges(); clear(); PopulateDataGridView(); MessageBox.Show("New Student successfully added"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error cancel", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void userdeletebtn_Click(object sender, EventArgs e) { User model3 = new User(); if (UserDataGridView.CurrentRow.Index != -1) { model3.Id = Convert.ToInt32(UserDataGridView.CurrentRow.Cells["userid"].Value); model3.User_Name = Convert.ToString(UserDataGridView.CurrentRow.Cells["username"].Value); model3 = ctx.Users.Where(q => q.Id == model3.Id).FirstOrDefault(); try { MessageBox.Show("Do you really want to delete this record?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); ctx.Entry(model3).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); UpdateDataViewGrid(); MessageBox.Show("Record was deleted successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error cancel", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void createAccbutton_Click(object sender, EventArgs e) { var username_box = UserBox.Text; var password_box = PasswordtextBox.Text; var type = typetb.Text; var datecreated = DateTime.Now; var createdby = ((Administrator)MdiParent).accountName; var confirmpass = confirmpasstextBox.Text; if (String.IsNullOrEmpty(username_box) || String.IsNullOrEmpty(password_box)) { MessageBox.Show("Please Enter Valid Information"); } else { try { var user = new User { Type = type, User_Name = username_box, Password = EasyEncryption.SHA.ComputeSHA256Hash(password_box), Date_Created = datecreated, Created_by = createdby, }; ctx.Users.Add(user); ctx.SaveChanges(); if (password_box == confirmpass) { MessageBox.Show("Passwords Matched"); } else { MessageBox.Show("Password Error"); } MessageBox.Show("New user account was created"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.InnerException.ToString()); throw; } } }
private void addperiodbutton_Click(object sender, EventArgs e) { Period pd = new Period(); if (PeriodicalDataGridView.CurrentRow.Index != -1) { pd.Id = Convert.ToInt32(PeriodicalDataGridView.CurrentRow.Cells["Id"].Value); pd = ctx.Periods.Where(q => q.Id == pd.Id).FirstOrDefault(); pd.P_Category = categoryTb.Text; pd.Name = periodicalnameTb.Text; pd.ISBN = isbnTb.Text; pd.Volume_Number = volumenumberTb.Text; pd.Year = yearTb.Text; pd.Page_Number = pagenumberTb.Text; pd.Shelf_Num = shelfnumberTb.Text; try { ctx.Entry(pd).State = System.Data.Entity.EntityState.Added; ctx.SaveChanges(); clear(); UpdateDataViewGrid(); MessageBox.Show("Periodical added successfully"); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error Please cancel "); } } }
private void resetButtonresetButton_Click(object sender, EventArgs e) { var username_value = pusernameTb1.Text; var oldpass_value = oldpasstb.Text; var newpassword_value = newpasswordTb.Text; var confirmpass_value = confirmPasswordTb.Text; oldpass_value = EasyEncryption.SHA.ComputeSHA256Hash(oldpass_value); newpassword_value = EasyEncryption.SHA.ComputeSHA256Hash(newpassword_value); confirmpass_value = EasyEncryption.SHA.ComputeSHA256Hash(confirmpass_value); //u = ctx.Users.FirstOrDefault(q => q.Password == oldpass_value && q.User_Name == username_value); //User u = new User(); if (username_value == null) { MessageBox.Show("username field empty"); } else { var u = ctx.Users.FirstOrDefault(q => q.Password == oldpass_value && q.User_Name == username_value); if (u != null) { try { u.Password = newpassword_value; ctx.SaveChanges(); MessageBox.Show("Password Change Confirmed!"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("username not found!"); } } }