private void updateBtn_Click(object sender, EventArgs e) { using (ProjectDatabaseEntities db = new ProjectDatabaseEntities()) { model = db.Customers.Where(x => x.customerName == newUSerId).FirstOrDefault(); model.customerName = nameShow.Text; model.phoneNumber = phnShow.Text; model.address = addShow.Text; db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); logn = db.Logins.Where(x => x.userId == newUSerId).FirstOrDefault(); logn.userId = nameShow.Text; db.Entry(logn).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Updated Successfully"); this.Visible = false; cstHome.Visible = true; } }
private void customerList_Load(object sender, EventArgs e) { ProjectDatabaseEntities cnn = new ProjectDatabaseEntities(); List <Customer> cst = cnn.Customers.ToList(); custGridView.DataSource = cst; }
private void buyItem_Load(object sender, EventArgs e) { ProjectDatabaseEntities cnn = new ProjectDatabaseEntities(); List <Product> pro = cnn.Products.ToList(); itemGridView.DataSource = pro; buy.Enabled = false; selectQuantityShow.Enabled = false; }
private void ItemList_Load(object sender, EventArgs e) { ProjectDatabaseEntities cnn = new ProjectDatabaseEntities(); List <Product> pro = cnn.Products.ToList(); itemGridView.DataSource = pro; updateBtn.Enabled = false; removeBtn.Enabled = false; }
private void EmpList_Load(object sender, EventArgs e) { ProjectDatabaseEntities cnn = new ProjectDatabaseEntities(); List <Employee> emp = cnn.Employees.ToList(); empListGrid.DataSource = emp; delEmpBtn.Enabled = false; updateInfo.Enabled = false; }
private void refreshBtn_Click(object sender, EventArgs e) { ProjectDatabaseEntities cnn = new ProjectDatabaseEntities(); List <Product> pro = cnn.Products.ToList(); itemGridView.DataSource = pro; updateBtn.Enabled = false; removeBtn.Enabled = false; productNameShow.Text = string.Empty; priceShow.Text = string.Empty; quantityShow.Text = string.Empty; }
private void refreshBtn_Click(object sender, EventArgs e) { name.Text = string.Empty; phnNumShow.Text = string.Empty; roleShow.Text = string.Empty; salaryShow.Text = string.Empty; ProjectDatabaseEntities cnn = new ProjectDatabaseEntities(); List <Employee> emp = cnn.Employees.ToList(); empListGrid.DataSource = emp; delEmpBtn.Enabled = false; updateInfo.Enabled = false; }
public updateInfo(cHome cstHome, string newUserId) { InitializeComponent(); this.cstHome = cstHome; this.newUSerId = newUserId; using (ProjectDatabaseEntities db = new ProjectDatabaseEntities()) { model = db.Customers.Where(x => x.customerName == newUSerId).FirstOrDefault(); nameShow.Text = model.customerName; phnShow.Text = model.phoneNumber; addShow.Text = model.address; } }
private void updateInfo_Click(object sender, EventArgs e) { model.userId = Convert.ToInt32(empListGrid.CurrentRow.Cells["userId"].Value); using (ProjectDatabaseEntities db = new ProjectDatabaseEntities()) { model = db.Employees.Where(x => x.userId == model.userId).FirstOrDefault(); model.employeeName = name.Text; model.phoneNumber = phnNumShow.Text; model.role = roleShow.Text; model.salary = Convert.ToInt32(salaryShow.Text); db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Updated successfully"); } }
private void updateBtn_Click(object sender, EventArgs e) { model.productId = Convert.ToInt32(itemGridView.CurrentRow.Cells["productId"].Value); using (ProjectDatabaseEntities db = new ProjectDatabaseEntities()) { model = db.Products.Where(x => x.productId == model.productId).FirstOrDefault(); model.productName = productNameShow.Text; model.price = Convert.ToInt32(priceShow.Text); model.availableQuantity = Convert.ToInt32(quantityShow.Text); db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Updated Successfully"); } }
private void itemClicked(object sender, EventArgs e) { if (itemGridView.CurrentRow.Index != -1) { model.productId = Convert.ToInt32(itemGridView.CurrentRow.Cells["productId"].Value); using (ProjectDatabaseEntities db = new ProjectDatabaseEntities()) { model = db.Products.Where(x => x.productId == model.productId).FirstOrDefault(); nameShow.Text = model.productName; priceShow.Text = Convert.ToString(model.price); quantityShow.Text = Convert.ToString(model.availableQuantity); } } buy.Enabled = true; selectQuantityShow.Enabled = true; }
private void delEmpBtn_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure?", "delete data", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (ProjectDatabaseEntities db = new ProjectDatabaseEntities()) { var entry = db.Entry(model); if (entry.State == System.Data.Entity.EntityState.Detached) { db.Employees.Attach(model); } db.Employees.Remove(model); db.SaveChanges(); MessageBox.Show("Removed"); } } }
private void empListGridDoubleClick(object sender, DataGridViewCellEventArgs e) { if (empListGrid.CurrentRow.Index != -1) { model.userId = Convert.ToInt32(empListGrid.CurrentRow.Cells["userId"].Value); using (ProjectDatabaseEntities db = new ProjectDatabaseEntities()) { model = db.Employees.Where(x => x.userId == model.userId).FirstOrDefault(); name.Text = model.employeeName; phnNumShow.Text = model.phoneNumber; roleShow.Text = model.role; salaryShow.Text = Convert.ToString(model.salary); } delEmpBtn.Enabled = true; updateInfo.Enabled = true; } }
private void buy_Click(object sender, EventArgs e) { if (Convert.ToInt32(selectQuantityShow.Text) < Convert.ToInt32(quantityShow.Text)) { model.productId = Convert.ToInt32(itemGridView.CurrentRow.Cells["productId"].Value); using (ProjectDatabaseEntities db = new ProjectDatabaseEntities()) { model = db.Products.Where(x => x.productId == model.productId).FirstOrDefault(); model.availableQuantity = Convert.ToInt32(Convert.ToInt32(quantityShow.Text) - Convert.ToInt32(selectQuantityShow.Text)); model.productName = nameShow.Text; model.price = Convert.ToInt32(priceShow.Text); db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Successfully Bought"); ProjectDatabaseEntities cnn = new ProjectDatabaseEntities(); List <Product> pro = cnn.Products.ToList(); itemGridView.DataSource = pro; buy.Enabled = false; selectQuantityShow.Enabled = false; selectQuantityShow.Text = "1"; nameShow.Text = string.Empty; priceShow.Text = string.Empty; quantityShow.Text = string.Empty; } } else { MessageBox.Show("Quantity is not available"); ProjectDatabaseEntities cnn = new ProjectDatabaseEntities(); List <Product> pro = cnn.Products.ToList(); itemGridView.DataSource = pro; buy.Enabled = false; selectQuantityShow.Enabled = false; selectQuantityShow.Text = "1"; nameShow.Text = string.Empty; priceShow.Text = string.Empty; quantityShow.Text = string.Empty; } }
private void LogInStaffBtn_Click(object sender, EventArgs e) { ProjectDatabaseEntities cnn = new ProjectDatabaseEntities(); List <Login> emp = cnn.Logins.ToList(); var data = (from a in emp where (a.userId.Equals(usernameTextbox.Text) && a.password.Equals(passwordTextbox.Text)) select a).FirstOrDefault(); if (data != null) { this.Visible = false; MessageBox.Show("Valid!"); if (data.status == 2) { newUSerId = usernameTextbox.Text; usernameTextbox.Text = string.Empty; passwordTextbox.Text = string.Empty; sHome home = new sHome(this, newUSerId); home.Visible = true; } else if (data.status == 1) { newUSerId = usernameTextbox.Text; usernameTextbox.Text = string.Empty; passwordTextbox.Text = string.Empty; eHome home = new eHome(this, newUSerId); home.Visible = true; } else if (data.status == 0) { newUSerId = usernameTextbox.Text; usernameTextbox.Text = string.Empty; passwordTextbox.Text = string.Empty; cHome home = new cHome(this, newUSerId); home.Visible = true; } } else { MessageBox.Show("invalid!"); } }
private void addBtn_Click(object sender, EventArgs e) { ProjectDatabaseEntities adp = new ProjectDatabaseEntities(); int maxId = adp.Products.Select(p => p.productId).DefaultIfEmpty(0).Max(); maxId++; prod.productName = nameShow.Text; prod.price = Convert.ToInt32(priceShow.Text); prod.availableQuantity = Convert.ToInt32(quantityShow.Text); prod.productId = maxId; adp.Products.Add(prod); adp.SaveChanges(); MessageBox.Show("Product Added"); nameShow.Text = string.Empty; priceShow.Text = string.Empty; quantityShow.Text = string.Empty; }
private void signUpBtn_Click(object sender, EventArgs e) { if (signUpPassTextbox.Text == signUpConfPassTextbox.Text) { ProjectDatabaseEntities addEmp = new ProjectDatabaseEntities(); int maxId = addEmp.Employees.Select(p => p.userId).DefaultIfEmpty(0).Max(); maxId++; emp.employeeName = signUpUsernameTextbox.Text; emp.phoneNumber = signUpContactTextbox.Text; emp.role = roleShow.Text; emp.salary = Convert.ToInt32(salaryShow.Text); emp.userId = maxId; addEmp.Employees.Add(emp); addEmp.SaveChanges(); int maxIdlog = addEmp.Logins.Select(p => p.id).DefaultIfEmpty(0).Max(); maxIdlog++; logn.userId = signUpUsernameTextbox.Text; logn.password = signUpPassTextbox.Text; logn.status = 1; logn.id = maxIdlog; addEmp.Logins.Add(logn); addEmp.SaveChanges(); MessageBox.Show("Account Created"); this.Visible = false; this.empList.Visible = true; } else { MessageBox.Show("Passwords do not match"); } }
private void signUpBtn_Click(object sender, EventArgs e) { if (signUpPassTextbox.Text == signUpConfPassTextbox.Text) { ProjectDatabaseEntities suo = new ProjectDatabaseEntities(); int maxId = suo.Customers.Select(p => p.userId).DefaultIfEmpty(0).Max(); maxId++; cust.customerName = signUpUsernameTextbox.Text; cust.phoneNumber = signUpContactTextbox.Text; cust.address = signUpAdd1.Text; cust.userId = maxId; suo.Customers.Add(cust); suo.SaveChanges(); int maxIdlog = suo.Logins.Select(p => p.id).DefaultIfEmpty(0).Max(); maxIdlog++; logn.userId = signUpUsernameTextbox.Text; logn.password = signUpPassTextbox.Text; logn.status = 0; logn.id = maxIdlog; suo.Logins.Add(logn); suo.SaveChanges(); MessageBox.Show("Account Created"); this.Visible = false; this.LoginPage.Visible = true; } else { MessageBox.Show("Password doesn't match"); } }