private void GetAllRecord(string search) { this.dataFoodStock.Rows.Clear(); foreach (FoodStock food in FoodStock.GetFoodStocks()) { if (food.Name.ToLower().Contains(search.ToLower())) { if (food.Quantity < 15 && food.AllowSendEmail == true) { Account myAcc = Account.GetSupplierAcc(); //create email form to supplier EmailSupplierForm emailSupplier = new EmailSupplierForm(myAcc.Email, food.Id, food.Name); emailSupplier.Show(); this.dataFoodStock.Rows.Add(food.Id, food.CategoryId, food.Name, food.Quantity, food.Price); } else if (food.Quantity > 0) { dataFoodStock.ClearSelection(); this.dataFoodStock.Rows.Add(food.Id, food.CategoryId, food.Name, food.Quantity, food.Price); } else { this.dataFoodStock.Rows.Add(food.Id, food.CategoryId, food.Name, food.Quantity, food.Price); } } } }
public ActionResult ManagePortion([Bind(Include = "FoodStockId, InventoryTransactionId,TDate, ItemId, Qty, Size,UnitId, LocationId")] FoodStock fs, ItemTypesEnum ItemTypeId, int lid) { using (var transaction = db.GetTransaction()) { try { //fetch the conversion var Existstk = db.SingleOrDefault <FoodStock>("select * from FoodStock where ItemId = " + fs.ItemId + " and locationId=" + lid + " and InventoryTransactionId=" + fs.InventoryTransactionId + " and TDate='" + String.Format("{0:yyyy-MM-dd}", fs.TDate) + "' "); var conv = db.FirstOrDefault <UnitConversion>("Select * from UnitConversion Where AUnitOfId = @0 and OfUnitId=@1 union select 10000,1,1,1", fs.UnitId, Existstk.UnitId); //default to 1 //if in edit mode add the old record qty back if (fs.FoodStockId > 0) { var OldVal = db.ExecuteScalar <decimal>("select Qty*Size as val from FoodStock where FoodStockId=@0", fs.FoodStockId); Existstk.Qty += (OldVal * conv.IsJust); } Existstk.Qty = Existstk.Qty - ((fs.Qty * fs.Size) * conv.IsJust); db.Update(Existstk); BaseSave <FoodStock>(fs, fs.FoodStockId > 0); transaction.Complete(); return(RedirectToAction("Portion", new { id = fs.InventoryTransactionId, LocationId = lid, Ite = ItemTypeId })); } catch (Exception ex) { db.AbortTransaction(); throw ex; } } }
private void CreditCardPay_Click(object sender, EventArgs e) { if (this.ItemListInCart.Rows.Count > 0) { //add all food object List <Receipt_Food> foodlist = new List <Receipt_Food>(); foreach (DataGridViewRow row in this.ItemListInCart.Rows) { int foodid = (int)row.Cells[1].Value; int quantity = (int)row.Cells[3].Value; FoodStock foodObj = FoodStock.FindById(foodid); foodlist.Add(new Receipt_Food(foodid, foodObj.Name, foodObj.Price, quantity)); } //make the receipt decimal totalPrice = 0; foreach (DataGridViewRow row in this.ItemListInCart.Rows) { totalPrice += (decimal)row.Cells[5].Value; } decimal tax = (totalPrice * 6 / 100); decimal servTax = this.orderType == "Dine-In" ? totalPrice * 10 / 100 : 0; decimal finaltotal = totalPrice + tax + servTax; Receipt newReceipt = new Receipt(tax, servTax, finaltotal, foodlist); newReceipt.Save(); /*Minus the stock from database*/ foreach (Receipt_Food currFood in newReceipt.FoodOrdered) { //food stock quantity minus ordered quantity FoodStock foodObj = FoodStock.FindById(currFood.FoodId); foodObj.Quantity -= currFood.QuantityOrdered; foodObj.Save(); if (foodObj.Quantity <= 0) { Account myAcc = Model.Account.GetSupplierAcc(); EmailSupplierForm emailSupplier = new EmailSupplierForm(myAcc.Email, foodObj.Id, foodObj.Name); emailSupplier.Show(); } } this.Hide(); ReceiptPage showReceipt = new ReceiptPage(newReceipt, finaltotal); showReceipt.Show(); this.Close(); } else { MessageBox.Show("You must have at least one item to checkout!"); } }
private void DeleteItem_Click(object sender, EventArgs e) { if (this.dataFoodStock.SelectedRows.Count > 0) { // have row selected int itemId = (int)dataFoodStock.SelectedRows[0].Cells[0].Value; FoodStock foodId = FoodStock.FindById(itemId); foodId.Delete(); GetAllRecord(""); } else { // no row is selected MessageBox.Show("Please select item to delete."); } }
public ActionResult MovEat(int lid, int FoodStockId, decimal Qty, int?LocationId, int ItemId, string submit) { using (var transaction = db.GetTransaction()) { try { var CurrUsr = User.Identity.GetUserId(); if (submit == "Move") { //Fetch the FoodStock record //var fs = db.FirstOrDefault<FoodStock>("select * from FoodStock where FoodStockId=@0", FoodStockId); var fs = db.SingleOrDefault <FoodStock>(FoodStockId); if (fs.Qty >= Qty) { var it = new InventoryTransaction { FoodStockId = FoodStockId, ItemId = ItemId, FromLocationId = lid, QtyRemoved = Qty, RecvdByUserId = CurrUsr, TDate = DateTime.Today, ToLocationId = LocationId, UnitId = fs.UnitId }; db.Insert(it); //record this move in Inventory Transaction table var tfs = new FoodStock { InventoryTransactionId = it.InventoryTransactionId, ItemId = ItemId, LocationId = LocationId.Value, Qty = Qty, Size = fs.Size, TDate = DateTime.Today, UnitId = fs.UnitId }; db.Insert(tfs); //Make the new entry in the benifiting location fs.Qty -= Qty; db.Update(fs); //update the loosing location's stock } else { throw new HttpRequestValidationException("Error: Insufficient Quantity in Stock!"); } } if (submit == "Use") { //Fetch the FoodStock record var fs = db.FirstOrDefault <FoodStock>("select * from FoodStock where FoodStockId=@0", FoodStockId); if (fs.Qty >= Qty) { var it = new InventoryTransaction { FoodStockId = FoodStockId, ItemId = ItemId, FromLocationId = lid, QtyRemoved = Qty, RecvdByUserId = CurrUsr, TDate = DateTime.Today, UnitId = fs.UnitId }; db.Insert(it); fs.Qty -= Qty; db.Update(fs); } else { throw new HttpRequestValidationException("Error: Insufficient Quantity in Stock!"); } } transaction.Complete(); return(RedirectToAction("MovEat", new { LocationId = lid })); } catch (Exception ex) { db.AbortTransaction(); throw ex; } } }
private void CashPayButton_Click(object sender, EventArgs e) { try { decimal cashPayed = Convert.ToDecimal(this.cashAmount.Text); if (this.ItemListInCart.Rows.Count > 0) { //add all food object List <Receipt_Food> foodlist = new List <Receipt_Food>(); foreach (DataGridViewRow row in this.ItemListInCart.Rows) { int foodid = (int)row.Cells[1].Value; int quantity = (int)row.Cells[3].Value; FoodStock foodObj = FoodStock.FindById(foodid); foodlist.Add(new Receipt_Food(foodid, foodObj.Name, foodObj.Price, quantity)); } //make the receipt decimal totalPrice = 0; foreach (DataGridViewRow row in this.ItemListInCart.Rows) { totalPrice += (decimal)row.Cells[5].Value; } decimal tax = (totalPrice * 6 / 100); decimal servTax = this.orderType == "Dine-In" ? totalPrice * 10 / 100 : 0; decimal finaltotal = totalPrice + tax + servTax; if (cashPayed >= finaltotal) { Receipt newReceipt = new Receipt(tax, servTax, finaltotal, foodlist); newReceipt.Save(); /*Minus the stock from database*/ foreach (Receipt_Food currFood in newReceipt.FoodOrdered) { Account myAcc = Model.Account.GetSupplierAcc(); //food stock quantity minus ordered quantity FoodStock foodObj = FoodStock.FindById(currFood.FoodId); foodObj.Quantity -= currFood.QuantityOrdered; foodObj.Save(); if (foodObj.Quantity <= 0) { EmailSupplierForm emailSupplier = new EmailSupplierForm(myAcc.Email, foodObj.Id, foodObj.Name); emailSupplier.Show(); } } this.Hide(); ReceiptPage showReceipt = new ReceiptPage(newReceipt, cashPayed); showReceipt.Show(); this.Close(); } else { MessageBox.Show("The cash amount cannot be lower than Total Price!"); } } else { MessageBox.Show("You must have at least one item to checkout!"); } } catch (Exception ex) { if (ex is FormatException) { MessageBox.Show("Cash Amount must be decimal number!"); } else { MessageBox.Show("Error saving receipt!"); } } }
public void ShowInputDialog(string itemname, string quantity, string price, string category, string caption, int getId) { Form prompt = new Form() { Width = 400, Height = 650, FormBorderStyle = FormBorderStyle.FixedDialog, Text = caption, StartPosition = FormStartPosition.CenterScreen }; Label itemNameLabel = new Label() { Left = 20, Top = 10, Text = itemname, Width = 300 }; TextBox itemNameTextBox = new TextBox() { Left = 20, Top = 30, Width = 200 }; Label quantityLabel = new Label() { Left = 20, Top = 80, Text = quantity, Width = 300 }; TextBox quantityTextBox = new TextBox() { Left = 20, Top = 100, Width = 200 }; Label priceLabel = new Label() { Left = 20, Top = 150, Text = price }; TextBox priceTextBox = new TextBox() { Left = 20, Top = 170, Width = 200 }; Label categoryLabel = new Label() { Left = 20, Top = 220, Text = category, Width = 300 }; ListBox categoryListBox = new ListBox() { Left = 20, Top = 245, Width = 200 }; PictureBox imagePictureBox = new PictureBox() { Left = 20, Top = 420, Width = 150, Height = 100 }; Label imageLabel = new Label() { Left = 20, Top = 360, Width = 400, Text = "No file is selected" }; Button imageButton = new Button() { Text = "Browse image", Left = 20, Width = 70, Top = 390 }; Button confirmation = new Button() { Text = "Ok", Left = 20, Width = 70, Top = 550 }; Button cancel = new Button() { Text = "Cancel", Left = 120, Width = 70, Top = 550 }; imageButton.Click += (sender, e) => { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "JPG Files(*.jpg)|*.jpg|PNG Files(*.png)|*.png|All Files(*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { imageLabel.Text = dlg.FileName.ToString(); imagePictureBox.ImageLocation = imageLabel.Text; imagePictureBox.SizeMode = PictureBoxSizeMode.StretchImage; } }; foreach (FoodCategory food in FoodCategory.GetFoodCategory()) { categoryListBox.Sorted = true; categoryListBox.Items.Add(food.Category); } //if getId is not equal negative 1 that means its a existing object if (getId != -1) { FoodStock foodId = FoodStock.FindById(getId); FoodCategory categoryId = FoodCategory.FindById(foodId.CategoryId); categoryListBox.SelectedItem = categoryId.Category; itemNameTextBox.Text = foodId.Name; quantityTextBox.Text = foodId.Quantity.ToString(); priceTextBox.Text = foodId.Price.ToString(); imagePictureBox.Image = ConvertBinaryToImage(foodId.Image); imagePictureBox.SizeMode = PictureBoxSizeMode.StretchImage; } //button click event handler confirmation.Click += (sender, e) => { try { string inputItemName = itemNameTextBox.Text; int inputQuantity = Convert.ToInt32(quantityTextBox.Text); decimal inputPrice = Convert.ToDecimal(priceTextBox.Text); int selectedItem = 0; string errorMessages = ""; bool validSendEmail = false; foreach (FoodStock food in FoodStock.GetFoodStocks()) { if (itemNameTextBox.Text.ToLower() == food.Name.ToLower() && getId != food.Id) { errorMessages += "Food name already exist please enter another food name\n"; } } if (categoryListBox.SelectedItem != null) { string selectedItemName = categoryListBox.Items[categoryListBox.SelectedIndex].ToString(); FoodCategory categoryId = FoodCategory.FindByCategory(selectedItemName); selectedItem = categoryId.Id; } else { errorMessages += "Please select one food category\n"; } if (inputQuantity < 0) { errorMessages += "Please enter positive integer for Quantity\n"; } if (inputPrice < 0) { errorMessages += "Please enter positive integer for Price\n"; } if (errorMessages != "") { MessageBox.Show(errorMessages); } else { prompt.DialogResult = DialogResult.OK; if (getId == -1) { byte[] imageByte = null; if (imageLabel.Text == "No file is selected") { Image noImage = Properties.Resources.noimage; using (var ms = new MemoryStream()) { noImage.Save(ms, noImage.RawFormat); imageByte = ms.ToArray(); } } else { FileStream fstream = new FileStream(imageLabel.Text, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fstream); imageByte = br.ReadBytes((int)fstream.Length); } validSendEmail = true; FoodStock newItem = new FoodStock(selectedItem, inputItemName, inputQuantity, inputPrice, validSendEmail, imageByte); newItem.Save(); GetAllRecord(""); } else { FoodStock foodId = FoodStock.FindById(getId); foodId.CategoryId = selectedItem; foodId.Name = inputItemName; if (inputQuantity > foodId.Quantity) { validSendEmail = true; } foodId.Quantity = inputQuantity; foodId.Price = inputPrice; foodId.AllowSendEmail = validSendEmail; byte[] imageByte = null; if (imageLabel.Text != "No file is selected") { FileStream fstream = new FileStream(imageLabel.Text, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fstream); imageByte = br.ReadBytes((int)fstream.Length); foodId.Image = imageByte; } foodId.Save(); GetAllRecord(""); } } } catch { MessageBox.Show("Please fill in all fields with appropriate values and select at least one food category."); } }; cancel.Click += (sender, e) => { prompt.Close(); }; prompt.Controls.Add(itemNameTextBox); prompt.Controls.Add(quantityTextBox); prompt.Controls.Add(priceTextBox); prompt.Controls.Add(itemNameLabel); prompt.Controls.Add(quantityLabel); prompt.Controls.Add(priceLabel); prompt.Controls.Add(categoryLabel); prompt.Controls.Add(categoryListBox); prompt.Controls.Add(imagePictureBox); prompt.Controls.Add(imageLabel); prompt.Controls.Add(imageButton); prompt.Controls.Add(confirmation); prompt.Controls.Add(cancel); prompt.AcceptButton = confirmation; prompt.ShowDialog(); }
public string ShowInputQuantityDialog(string quantity, string caption, int getId) { Form prompt = new Form() { Width = 300, Height = 180, FormBorderStyle = FormBorderStyle.FixedDialog, Text = caption, StartPosition = FormStartPosition.CenterScreen }; Label foodNameLabel = new Label() { Left = 20, Top = 10, Width = 300 }; foodNameLabel.Font = new Font(foodNameLabel.Font, FontStyle.Bold); Label originalQuantityLabel = new Label() { Left = 20, Top = 30, Width = 150 }; originalQuantityLabel.Font = new Font(originalQuantityLabel.Font, FontStyle.Bold); Label quantityLabel = new Label() { Left = 20, Top = 50, Text = quantity, Width = 300 }; TextBox quantityTextBox = new TextBox() { Left = 20, Top = 70, Width = 200 }; Button confirmation = new Button() { Text = "Ok", Left = 20, Width = 70, Top = 100 }; Button cancel = new Button() { Text = "Cancel", Left = 120, Width = 70, Top = 100 }; if (getId != -1) { FoodStock foodId = FoodStock.FindById(getId); foodNameLabel.Text = string.Format("Food name: {0}", foodId.Name); originalQuantityLabel.Text = string.Format("Original quantity: {0}", foodId.Quantity.ToString()); } //button click event handler confirmation.Click += (sender, e) => { try { FoodStock foodId = FoodStock.FindById(getId); int total = foodId.Quantity; int inputQuantity = Convert.ToInt32(quantityTextBox.Text); bool validSendEmail = true; string errorMessages = ""; if (inputQuantity < 0) { errorMessages += "Please enter positive integer for Quantity\n"; } else { total += inputQuantity; } if (errorMessages != "") { MessageBox.Show(errorMessages); } else { prompt.DialogResult = DialogResult.OK; FoodStock foodAdd = FoodStock.FindById(getId); foodAdd.Quantity = total; if (total >= 1) { validSendEmail = true; } else { validSendEmail = false; } foodAdd.AllowSendEmail = validSendEmail; foodAdd.AddStock(); GetAllRecord(""); } } catch { MessageBox.Show("Please Enter only Integer!\n"); } }; cancel.Click += (sender, e) => { prompt.Close(); }; prompt.Controls.Add(quantityTextBox); prompt.Controls.Add(quantityLabel); prompt.Controls.Add(originalQuantityLabel); prompt.Controls.Add(foodNameLabel); prompt.Controls.Add(confirmation); prompt.Controls.Add(cancel); prompt.AcceptButton = confirmation; return(prompt.ShowDialog() == DialogResult.OK ? quantityTextBox.Text : ""); }