private void editProfile_Click(object sender, EventArgs e) { Global.ClearErrors(errorProvider1, textBoxs); var account = new Account() { Username = username.Text, Password = password.Text, Role = role.Text, FamilyName = familyName.Text, GivenName = givenName.Text, Gender = gender.Text, Contact = contact.Text, Email = email.Text, }; List <List <string> > err; if (Global.IsValid <Account>(account, out err)) { using (var db = new SunwayCafeContext()) { if (editProfile.Text == "Add Staff") { db.Accounts.Add(account); } else { var query = db.Accounts.Where(acc => acc.Id == Id).FirstOrDefault(); query.Username = account.Username; query.Password = account.Password; query.Role = account.Role; query.FamilyName = account.FamilyName; query.GivenName = account.GivenName; query.Gender = account.Gender; query.Contact = account.Contact; query.Email = account.Email; } db.SaveChanges(); if (accountPageRef == null) { var query = db.Accounts.Where(acc => acc.Id == Id).FirstOrDefault(); Global.user.Details = query; profilePageRef.RefreshPage(); } else { accountPageRef.RefreshListView(); } } this.Close(); } else { foreach (var er in err) { errorProvider1.SetError(textBoxs[er[0]], er[1]); textBoxs[er[0]].BorderColor = Color.Red; } } }
private void button1_Click(object sender, EventArgs e) { Global.ClearErrors(errorProvider1, textBoxs); string stockType = string.Empty; string stockUnit = string.Empty; //Type RadioBUtton if (ingredient.Checked == true) { stockType = ingredient.Text; } else if (spice.Checked == true) { stockType = spice.Text; } else if (others.Checked == true) { stockType = others.Text; } //Unit RadioButton if (gram.Checked == true) { stockUnit = gram.Text; } else if (miliLiter.Checked == true) { stockUnit = miliLiter.Text; } else if (piece.Checked == true) { stockUnit = piece.Text; } var stock = new Stock() { Name = name.Text, Type = stockType, Qty = quantity.Text, Unit = stockUnit, CriticalLevel = criticalLevel.Text, }; List <List <string> > err; if (Global.IsValid <Stock>(stock, out err)) { using (var db = new SunwayCafeContext()) { if (button1.Text == "Update") { var query = db.Stocks.Where(acc => acc.Id == Id).FirstOrDefault(); query.Name = stock.Name; query.Type = stock.Type; query.Qty = stock.Qty; query.Unit = stock.Unit; query.CriticalLevel = stock.CriticalLevel; } else { db.Stocks.Add(stock); } db.SaveChanges(); } stockPageRef.RefreshListView(); this.Close(); } else { foreach (var er in err) { errorProvider1.SetError(textBoxs[er[0]], er[1]); textBoxs[er[0]].BorderColor = Color.Red; } } }
private void button1_Click_1(object sender, EventArgs e) { Global.ClearErrors(errorProvider1, textBoxs); var success = true; if (!decimal.TryParse(priceBox.Text.Trim(), out decimal priceVal)) { errorProvider1.SetError(priceBox, "Numbers only."); priceBox.BorderColor = Color.Red; success = false; } if (!decimal.TryParse(costPriceBox.Text.Trim(), out decimal costVal)) { errorProvider1.SetError(costPriceBox, "Numbers only."); costPriceBox.BorderColor = Color.Red; success = false; } if (String.IsNullOrEmpty(textBox2.Text.Trim())) { errorProvider1.SetError(textBox2, "The Name field is required."); textBox2.BorderColor = Color.Red; success = false; } var msg = string.Empty; using (SunwayCafeContext db = new SunwayCafeContext()) { if (success) { if (button1.Text == "Create") { Item item = new Item() { Name = textBox2.Text.Trim(), ImageURL = Global.ConvertImageToBinary(pictureBox.Image), SellingPrice = priceVal, CostPrice = costVal, Type = Food.Checked ? Food.Text : Drinks.Text }; db.Items.Add(item); msg = "Item Created"; } else { if (OrderOptions.selectItemName != null) { var item = db.Items.Where(d => d.Name == OrderOptions.selectItemName).First(); item.Name = textBox2.Text.Trim(); if (pictureBox.Image != OrderOptions.selectedItemImage) { item.ImageURL = Global.ConvertImageToBinary(pictureBox.Image); } item.SellingPrice = priceVal; item.CostPrice = costVal; item.Type = Food.Checked ? Food.Text : Drinks.Text; msg = "Item Updated"; } } db.SaveChanges(); MessageBox.Show(msg); itemPageRef.loadData(); this.Close(); } } }