private void submitbtn_Click(object sender, EventArgs e) { loginverification login = new loginverification(); if (login.Verify(passwordtxt.Text, emailtxt.Text)) { if (login.CheckAdmin()) { Admin_Main_Menu menu = new Admin_Main_Menu(); this.Hide(); menu.ShowDialog(); this.Show(); } else { Customer_Main_Menu menu = new Customer_Main_Menu(DatabaseOperation.ReturnItem(emailtxt.Text)); this.Hide(); menu.ShowDialog(); this.Show(); } emailtxt.Text = ""; passwordtxt.Text = ""; } else { MessageBox.Show("Wrong email or password"); } }
public static Boolean UpdateProduct(int id, Product product) { if (DatabaseOperation.ReturnItem(product) == null) { return(false); } SqlConnection connection = RetaloDB.GetConnection(); string updateStatement = "UPDATE Products SET " + "Name = @Name" + "Description = @Description" + "Cost = @Cost" + "\"Product Type\" = @ProductType" + "WHERE PerID = @ID;"; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.Parameters.AddWithValue("@Name", product.Name); updateCommand.Parameters.AddWithValue("@Description", product.Description); updateCommand.Parameters.AddWithValue("@Cost", product.Cost); updateCommand.Parameters.AddWithValue("@ProductType", product.ProductType); updateCommand.Parameters.AddWithValue("@ID", product.ID); try{ connection.Open(); updateCommand.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally{ connection.Close(); } return(true); }
private void Getcustomerbtn_Click(object sender, EventArgs e) { int perid = 0; if (Int32.TryParse(IDtxt.Text, out perid)) { person = new Person(); person.ID = perid; person = DatabaseOperation.ReturnItem(person); if (person != null) { IDtxt.Text = person.ID.ToString(); FNametxt.Text = person.FName; LNametxt.Text = person.LName; Phonetxt.Text = person.Phone_Number; Emailtxt.Text = person.Email; Rewardptstxt.Text = person.Reward_Points.ToString(); Passwordtxt.Text = person.Password; Isteacherchkbx.Checked = person.IsTeacher; Isseniorchkbx.Checked = person.IsSenior; Isveteranchkbx.Checked = person.IsVeteran; Isadminchkbx.Checked = person.IsAdmin; } else { Reset_Text(); MessageBox.Show("You have selected a empty id, cannot edit or filled."); } } else { MessageBox.Show("Can't convert id box into a number, please put in a number into the id box."); } }
public static Boolean AddProduct(Product product) { if (DatabaseOperation.ReturnItem(product) != null) { return(false); } SqlConnection connection = RetaloDB.GetConnection(); string addStatement = "INSERT INTO Products (Name, Description, Cost, \"Product Type\") " + "Values(@Name, @Description, @Cost, @ProductType); "; SqlCommand addCommand = new SqlCommand(addStatement, connection); addCommand.Parameters.AddWithValue("@Name", product.Name); addCommand.Parameters.AddWithValue("@Description", product.Description); addCommand.Parameters.AddWithValue("@Cost", product.Cost); addCommand.Parameters.AddWithValue("@ProductType", product.ProductType); try{ connection.Open(); addCommand.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally{ connection.Close(); } return(true); }
public static Boolean UpdatePerson(int id, Person person) { if (DatabaseOperation.ReturnItem(person) == null) { return(false); } SqlConnection connection = RetaloDB.GetConnection(); string updateStatement = "UPDATE Person SET " + "FName = @FName, " + "LName = @LName, " + "\"Phone Number\" = @Phone_Number, " + "Email = @Email, " + "\"Reward Points\" = @Reward_Points, " + "password = @Password, " + "Is_Teacher = @IsTeacher, " + "Is_Admin = @IsAdmin, " + "Is_Senior = @IsSenior, " + "Is_Veteran = @IsVeteran " + "WHERE PerID = @ID;"; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.Parameters.AddWithValue("@FName", person.FName); updateCommand.Parameters.AddWithValue("@LName", person.LName); updateCommand.Parameters.AddWithValue("@Phone_Number", person.Phone_Number); updateCommand.Parameters.AddWithValue("@Email", person.Email); updateCommand.Parameters.AddWithValue("@Reward_Points", person.Reward_Points); updateCommand.Parameters.AddWithValue("@Password", person.Password); updateCommand.Parameters.AddWithValue("@IsTeacher", person.IsTeacher); updateCommand.Parameters.AddWithValue("@IsAdmin", person.IsAdmin); updateCommand.Parameters.AddWithValue("@IsSenior", person.IsSenior); updateCommand.Parameters.AddWithValue("@IsVeteran", person.IsVeteran); updateCommand.Parameters.AddWithValue("@ID", person.ID); try { connection.Open(); updateCommand.ExecuteNonQuery(); }catch (Exception ex) { throw ex; } finally { connection.Close(); } return(true); }
private void getproductbtn_Click(object sender, EventArgs e) { int id; if (Int32.TryParse(prodidtxt.Text, out id)) { product = new Product(); product.ID = id; product = DatabaseOperation.ReturnItem(product); if (product != null) { } } }
private void submitbtn_Click(object sender, EventArgs e) { if (ProductObjectFill()) { if (DatabaseOperation.AddorUpdateItem(product)) { MessageBox.Show("Addition or modification to the database is a success"); Update_Dataset(); } else { MessageBox.Show("Unable to add or modify the database, please try again later"); } } }
private void productaddbtn_Click(object sender, EventArgs e) { if (Int32.TryParse(prodidtxt.Text, out int id) && Int32.TryParse(productqtytxt.Text, out int productqty)) { Product product = new Product(); product.ID = id; product = DatabaseOperation.ReturnItem(product); product.ProductPurchasedQuantity = productqty; invoice.AddProduct(product); Update_Totals(); } else { MessageBox.Show("Please put in a numbe in the product id and amount of product."); } }
private void deletebtn_Click(object sender, EventArgs e) { int id = Int32.Parse(prodidtxt.Text); using (var form = new Confirmation()) { var result = form.ShowDialog(); if (result == DialogResult.OK) { if (DatabaseOperation.DeleteItem(id, "Product") == false) { MessageBox.Show("ID doesn't exist, can't delete."); } } } Update_Dataset(); }
private void Purchasebtn_Click(object sender, EventArgs e) { using (Confirmation form = new Confirmation("Are you sure you want to make this purchase?")) { var result = form.ShowDialog(); if (result == DialogResult.OK) { invoice = calculations.CalculateInvoice(customer, invoice, userewardschkbx.Checked); invoice.DateOfInvoice = DateTime.Now; if (DatabaseOperation.AddItem(invoice)) { MessageBox.Show("Successfully added the item into the database."); this.Close(); } else { MessageBox.Show("Something went wrong, please try again"); } } } }
private static Invoice PopulateProducts(Invoice invoice, SqlConnection connection) { string invoicedetailsselect = "Select *" + " From \"Invoice Detail\"" + " Where InvID = @id"; SqlCommand invoicedetailsselectcommand = new SqlCommand(invoicedetailsselect, connection); invoicedetailsselectcommand.Parameters.AddWithValue("@id", invoice.ID); try { connection.Open(); SqlDataReader productreader = invoicedetailsselectcommand.ExecuteReader(CommandBehavior.SingleRow); List <Product> products = new List <Product>(); while (productreader.Read()) { Product tempproduct = new Product(); tempproduct.ID = (int)productreader["ProdID"]; tempproduct = DatabaseOperation.ReturnItem(tempproduct); tempproduct.SetProductPurchasedQuantity((int)productreader["Quantity"]); products.Add(tempproduct); } invoice.ProductsInInvoice = products; } catch (Exception ex) { throw ex; } finally { connection.Close(); } return(invoice); }
public static Boolean AddInvoice(Invoice invoice) { if (DatabaseOperation.ReturnItem(invoice) != null) { return(false); } else { SqlConnection connect = RetaloDB.GetConnection(); string invoiceadd = "INSERT INTO Invoice (PerID, \"Date Of Invoice\", \"Amount Of Product\", \"Is Paid For\", \"Total Cost\") " + "Values(@PerID, @Date, @Amount, @Paid, @Cost);"; SqlCommand invoiceaddcommand = new SqlCommand(invoiceadd, connect); invoiceaddcommand.Parameters.AddWithValue("@PerID", invoice.PerID); invoiceaddcommand.Parameters.AddWithValue("@Date", invoice.DateOfInvoice); invoiceaddcommand.Parameters.AddWithValue("@Amount", invoice.TotalProductInInvoiceQuantity); invoiceaddcommand.Parameters.AddWithValue("@Paid", false); invoiceaddcommand.Parameters.AddWithValue("@Cost", invoice.TotalCost); try { connect.Open(); invoiceaddcommand.ExecuteNonQuery(); connect.Close(); AddInvoiceDetails(invoice, connect); } catch (Exception ex) { throw ex; } finally { connect.Close(); } return(true); } }
public Boolean Verify(String password, String email) { if (password == "" || email == "") { return(false); } person = DatabaseOperation.ReturnItem(email); if (person == null) { return(false); } else if (person.Password == password) { return(true); } else { return(false); } }
public static Boolean AddPerson(Person person) { if (DatabaseOperation.ReturnItem(person) != null) { return(false); } SqlConnection connection = RetaloDB.GetConnection(); string addStatement = "INSERT INTO Person (Fname, Lname, \"Phone Number\", Email, \"Reward Points\", password, Is_Teacher, Is_Admin, Is_Senior, Is_Veteran) " + "Values(@FName, @LName, @Phone_Number, @Email, " + "@Reward_Points, @Password, @IsTeacher, @IsAdmin, @IsSenior, @IsVeteran); "; SqlCommand addCommand = new SqlCommand(addStatement, connection); addCommand.Parameters.AddWithValue("@FName", person.FName); addCommand.Parameters.AddWithValue("@LName", person.LName); addCommand.Parameters.AddWithValue("@Phone_Number", person.Phone_Number); addCommand.Parameters.AddWithValue("@Email", person.Email); addCommand.Parameters.AddWithValue("@Reward_Points", person.Reward_Points); addCommand.Parameters.AddWithValue("@Password", person.Password); addCommand.Parameters.AddWithValue("@IsTeacher", person.IsTeacher); addCommand.Parameters.AddWithValue("@IsAdmin", person.IsAdmin); addCommand.Parameters.AddWithValue("@IsSenior", person.IsSenior); addCommand.Parameters.AddWithValue("@IsVeteran", person.IsVeteran); try{ connection.Open(); addCommand.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally{ connection.Close(); } return(true); }