private void ButtonSend_Click(object sender, EventArgs e) { try { SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.Timeout = 10000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential("*****@*****.**", "Asd@1234"); MailMessage msg = new MailMessage(); msg.To.Add(textBoxTo.Text); msg.From = new MailAddress("*****@*****.**"); msg.Subject = textBoxSubject.Text; msg.Body = textBoxContent.Text; client.Send(msg); MessageBox.Show(string.Format("Successful send to {0}", textBoxTo.Text)); Model.FoodStock foodId = new Model.FoodStock(id, false); foodId.ValidToSendEmail(); this.Close(); } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private void ItemListInCart_CellEditEnding(object sender, DataGridViewCellEventArgs e) { int QuantityEntered = 0; try { String newValue = null; if (ItemListInCart[e.ColumnIndex, e.RowIndex].Value is System.Int32) { QuantityEntered = (System.Int32)ItemListInCart[e.ColumnIndex, e.RowIndex].Value; } else { newValue = (String)ItemListInCart[e.ColumnIndex, e.RowIndex].Value; QuantityEntered = Convert.ToInt32(newValue); } if (QuantityEntered > 0) { //check whether got enough stock foreach (DataGridViewRow row in this.ItemListInCart.SelectedRows) { int itemId = (int)row.Cells[1].Value; Model.FoodStock itemObject = Model.FoodStock.FindById(itemId); if (itemObject.Quantity >= QuantityEntered) { //modify quantity row.Cells[3].Value = QuantityEntered; row.Cells[4].Value = itemObject.Price; row.Cells[5].Value = QuantityEntered * itemObject.Price; } else { MessageBox.Show(String.Format("Cannot modify item {0} because you have only {1} stock", itemObject.Name, itemObject.Quantity)); //setback to only value ItemListInCart[e.ColumnIndex, e.RowIndex].Value = oldValueOfItemListInCart_CellEditing; } } UpdateTotalCalculation(); } else { MessageBox.Show("Please Enter Integer more than 0!"); //setback to only value ItemListInCart[e.ColumnIndex, e.RowIndex].Value = oldValueOfItemListInCart_CellEditing; } } catch (Exception ex) { MessageBox.Show("Please Enter only Integer!" + ex.Message); Console.WriteLine(ex.ToString()); //setback to only value ItemListInCart[e.ColumnIndex, e.RowIndex].Value = oldValueOfItemListInCart_CellEditing; } }
private void XQtyButton_Click(object sender, EventArgs e) { if (this.ItemListInCart.SelectedRows.Count > 0) { // have row selected string userinput = ShowQuantityInputDialog("Enter Quantity:", "Quantity Input Box"); if (userinput != "") { //if input returned not empty because if user cancel the return will be empty int newQuantity = Convert.ToInt32(userinput); foreach (DataGridViewRow row in this.ItemListInCart.SelectedRows) { int itemId = (int)row.Cells[1].Value; int currentNumberOfItem = (int)row.Cells[3].Value; Model.FoodStock itemObject = Model.FoodStock.FindById(itemId); if (itemObject.Quantity >= newQuantity) { //modify quantity row.Cells[3].Value = newQuantity; row.Cells[4].Value = itemObject.Price; row.Cells[5].Value = newQuantity * itemObject.Price; } else { MessageBox.Show(String.Format("{0} only have {1} stocks available.", itemObject.Name, itemObject.Quantity)); } } UpdateTotalCalculation(); } } else { // no row is selected MessageBox.Show("Please select an item to edit."); } }
private void AddQuantityToRow(DataGridViewRow row) { int itemId = (int)row.Cells[1].Value; int currentNumberOfItem = (int)row.Cells[3].Value; Model.FoodStock itemObject = Model.FoodStock.FindById(itemId); int newQuantity = currentNumberOfItem + 1; if (itemObject.Quantity >= newQuantity) { //add quantity, update price, update total price row.Cells[3].Value = newQuantity; row.Cells[4].Value = itemObject.Price; row.Cells[5].Value = newQuantity * itemObject.Price; UpdateTotalCalculation(); } else { MessageBox.Show(String.Format("You have only {0} stock for {1}!", itemObject.Quantity, itemObject.Name)); } }
private void MinusQuantityToRow(DataGridViewRow row) { int itemId = (int)row.Cells[1].Value; int currentNumberOfItem = (int)row.Cells[3].Value; Model.FoodStock itemObject = Model.FoodStock.FindById(itemId); int newQuantity = currentNumberOfItem - 1; if (newQuantity == 0) { //if queantity already zero remove from cart this.ItemListInCart.Rows.Remove(row); } else { //minus quantity row.Cells[3].Value = newQuantity; row.Cells[4].Value = itemObject.Price; row.Cells[5].Value = newQuantity * itemObject.Price; } UpdateTotalCalculation(); }
//function to add the item to the cart private void AddItem(object sender, EventArgs e) { System.Windows.Forms.Control layoutPanelObject = (System.Windows.Forms.Control)sender; Model.FoodStock chosenFood = (Model.FoodStock)layoutPanelObject.Tag; DataGridViewRow foundItemInCart = null; foreach (DataGridViewRow row in this.ItemListInCart.Rows) { int currentRowID = (int)row.Cells[1].Value; if (currentRowID == chosenFood.Id) { foundItemInCart = row; } } if (foundItemInCart == null) { int newNo = this.ItemListInCart.Rows.Count + 1; if (chosenFood.Quantity > 0) { this.ItemListInCart.Rows.Add(newNo, chosenFood.Id, chosenFood.Name, 1, chosenFood.Price, chosenFood.Price * 1); } else { MessageBox.Show("Item out of stock!"); } } else { //if enough quantity then show sucessfully added int currentNumberOfItem = (int)foundItemInCart.Cells[3].Value; AddQuantityToRow(foundItemInCart); } UpdateTotalCalculation(); }