private void SaveButton_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=DESKTOP-P024OII\\TARIQULPC;Initial Catalog=Library_Management_System;Integrated Security=True"); try { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "insert into BooksInfo values('" + BookNameTextBox.Text + "', '" + AuthorNameTextBox.Text + "', '" + dateTimePicker1.Text + "', " + PriceTextBox.Text + ", " + QuantityTextBox.Text + ", " + QuantityTextBox.Text + ")"; cmd.ExecuteNonQuery(); MessageBox.Show("Book is successfully added"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } BookNameTextBox.Clear(); AuthorNameTextBox.Clear(); PriceTextBox.Clear(); QuantityTextBox.Clear(); }
//Event Handler for Add Button in Cart private void AddButton_Click(object sender, EventArgs e) { //Conveting CUrrent quantity to integer int.TryParse(QuantityTextBox.Text, out int CurrentValue); //Adding 1 to current quantity CurrentValue += 1; //Finding the product in List in conventional Way using sequencial search //We can use List Find methods as well in order to find and return us the direct item from list for (int i = 0; i < MainForm.ProductList.Count; i++) { //Matching product selected from list, if Found, Adding one product to the cart if (MainForm.ProductList[i].ProductCategory == this.ProdCat && MainForm.ProductList[i].ProductID == this.ProdID) { //Check if Stock is available if (CurrentValue <= MainForm.ProductList[i].ProductQuantity) { MainForm.TotalItems += 1; MainForm.GrandTotal += this._ProductPrice; MainForm frm = (MainForm)this.FindForm(); frm.TotalItemsLabel.Text = MainForm.TotalItems.ToString(); frm.GrandTotalLabel.Text = MainForm.GrandTotal.ToString(); QuantityTextBox.Text = CurrentValue.ToString(); ProductTotalPriceLabel.Text = (CurrentValue * this._ProductPrice).ToString(); break; } else { MessageBox.Show("Requested Quantities of " + this.ProdName + " are not available in inventory", "Not Enough Items Available", MessageBoxButtons.OK, MessageBoxIcon.Error); QuantityTextBox.Focus(); } } } }
private void clearButton_Click(object sender, EventArgs e) { MenuNameTextBox.Clear(); priceTextBox.Clear(); QuantityTextBox.Clear(); TypeComboBox.SelectedItem = null; }
private bool IsValidated() { if (QuantityTextBox.Text.Trim() == string.Empty) { MessageBox.Show("Please add new quantity.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); QuantityTextBox.Clear(); QuantityTextBox.Focus(); HasValidationFailed = true; return(false); } int result = 0; bool isNumeric = int.TryParse(QuantityTextBox.Text.Trim(), out result); if (!isNumeric) { MessageBox.Show("Quantity should be interger (1,2,3,...).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); QuantityTextBox.Clear(); QuantityTextBox.Focus(); HasValidationFailed = true; return(false); } return(true); }
private void addButton_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(MenuNameTextBox.Text)) { if (!string.IsNullOrEmpty(TypeComboBox.SelectedIndex.ToString())) { if (!string.IsNullOrEmpty(priceTextBox.Text)) { int result = ms.AddMenu(MenuNameTextBox.Text, Convert.ToInt32(priceTextBox.Text), Convert.ToInt32(QuantityTextBox.Text), TypeComboBox.SelectedItem.ToString()); if (result == 1) { MessageBox.Show("Item successfully added to menu!"); mda = new MenuDataAccess(); dataGridView1.DataSource = mda.GetMenuData(); MenuNameTextBox.Clear(); priceTextBox.Clear(); QuantityTextBox.Clear(); TypeComboBox.SelectedItem = null; } } else { MessageBox.Show("Please Enter a price!"); } } else { MessageBox.Show("Please Enter quantity!"); } } else { MessageBox.Show("Please Enter name!"); } }
// when user clicks 'add to cart' button private void button1_Click(object sender, EventArgs e) { // if user chooses '-- Select Book --' option if (comboBox1.SelectedIndex == 0 || AuthorTextBox.Text == "") { MessageBox.Show("Please, choose a book from the list.", "Missing order details", MessageBoxButtons.OK, MessageBoxIcon.Warning); comboBox1.Focus(); } // if quantity box value starts with 0 or is empty else if (QuantityTextBox.Text == "" || QuantityTextBox.Text.StartsWith("0")) { MessageBox.Show("Please, enter the valid number of books.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); QuantityTextBox.Focus(); } // if user chooses '-- Select Customer --" option else if (CustomerComboBox.SelectedIndex == 0) { MessageBox.Show("Please, choose the customer", "Missing Order Details", MessageBoxButtons.OK, MessageBoxIcon.Error); CustomerComboBox.Focus(); } else { string BookID = IsbnTextBox.Text.ToString(); var index = this.DataList.Rows.Add(); // add new row and get index of this row var lineTotal = decimal.Parse(PriceTextBox.Text.TrimStart('$')) * decimal.Parse(QuantityTextBox.Text); this.DataList.Rows[index].Cells[0].Value = comboBox1.SelectedValue.ToString(); this.DataList.Rows[index].Cells[1].Value = decimal.Parse(PriceTextBox.Text.TrimStart('$')).ToString("C2"); this.DataList.Rows[index].Cells[2].Value = QuantityTextBox.Text; this.DataList.Rows[index].Cells[3].Value = lineTotal.ToString("C2"); orderDetailsList.Add(new OrderDetails(BookID, int.Parse(QuantityTextBox.Text), lineTotal)); this.Lines.Add(lineTotal); // store Line Total values in the list when book is added to the DataGridView CalculateTotalAmount(); // calculate total amount for user to pay } }
private void AddDataItem_Click(object sender, RoutedEventArgs e) { ItemController CallItem = new ItemController(); //var combo = CategoryComboBox.SelectedValue.ToString(); //MessageBox.Show(CategoryComboBox.Text); if (ItemNameTextBox.Text.Length == 0 && QuantityTextBox.Text.Length == 0 && CategoryComboBox.Text == "") { ItemNameErrorMessage.Text = "Item Name Can't Be Empty!"; QuantityErrorMessage.Text = "Item Quantity Can't Be Empty!"; CategoryErrorMessage.Text = "You Must Choose Category Item!"; ItemNameTextBox.Focus(); QuantityTextBox.Focus(); CategoryComboBox.Focus(); } else if (ItemNameTextBox.Text.Length == 0 && QuantityTextBox.Text.Length == 0) { ItemNameErrorMessage.Text = "Item Name Can't Be Empty!"; QuantityErrorMessage.Text = "Item Quantity Can't Be Empty!"; ItemNameTextBox.Focus(); QuantityTextBox.Focus(); } else if (ItemNameTextBox.Text.Length == 0 && CategoryComboBox.Text == "") { ItemNameErrorMessage.Text = "Item Name Can't Be Empty!"; CategoryErrorMessage.Text = "You Must Choose Category Item!"; ItemNameTextBox.Focus(); CategoryComboBox.Focus(); } else if (QuantityTextBox.Text.Length == 0 && CategoryComboBox.Text == "") { CategoryErrorMessage.Text = "You Must Choose Category Item!"; QuantityErrorMessage.Text = "Item Quantity Can't Be Empty!"; QuantityTextBox.Focus(); CategoryComboBox.Focus(); } else if (ItemNameTextBox.Text.Length == 0) { ItemNameErrorMessage.Text = "Item Name Can't Be Empty!"; ItemNameTextBox.Focus(); } else if (QuantityTextBox.Text.Length == 0) { QuantityErrorMessage.Text = "Item Quantity Can't Be Empty!"; QuantityTextBox.Focus(); } else if (CategoryComboBox.Text == "") { CategoryErrorMessage.Text = "You Must Choose Category Item!"; CategoryComboBox.Focus(); } else { string Iname = ItemNameTextBox.Text; int Iqty = Convert.ToInt32(QuantityTextBox.Text); int Icat = Convert.ToInt32(CategoryComboBox.SelectedValue.ToString()); CallItem.AddItem(Iname, Iqty, Icat, email, name, roles); } }
public void Cleardata() { FilenameLabel.Text = "FileNotSelected"; PriceTextBox.Clear(); QuantityTextBox.Clear(); ProductCodeTextBox.Clear(); ProductNameTextBox.Clear(); }
private bool IsValidated() { if (ClientNameTextBox.Text.Trim() == string.Empty) { MessageBox.Show("Client Name is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ClientNameTextBox.Focus(); return(false); } if (ItemNameComboBox.SelectedIndex == -1) { MessageBox.Show("Item Name is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (QuantityTextBox.Text.Trim() == string.Empty) { MessageBox.Show("Quantity is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); QuantityTextBox.Focus(); return(false); } else { int tempQuantity; bool isNumeric = int.TryParse(QuantityTextBox.Text.Trim(), out tempQuantity); if (!isNumeric) { MessageBox.Show("Quantity should be integer value.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); QuantityTextBox.Clear(); QuantityTextBox.Focus(); return(false); } } if (UnitPriceTextBox.Text.Trim() == string.Empty) { MessageBox.Show("Unit Price is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); UnitPriceTextBox.Focus(); return(false); } else { decimal n; bool isDecimal = decimal.TryParse(UnitPriceTextBox.Text.Trim(), out n); if (!isDecimal) { MessageBox.Show("Unit Price should be decimal value.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); UnitPriceTextBox.Clear(); UnitPriceTextBox.Focus(); return(false); } } return(true); }
private void UpdateDataItem_Click(object sender, RoutedEventArgs e) { ItemController CallItem = new ItemController(); if (ItemNameTextBox.Text.Length == 0 && QuantityTextBox.Text.Length == 0 && CategoryComboBox.Text == "") { ItemNameErrorMessage.Text = "Item Name Can't Be Empty!"; QuantityErrorMessage.Text = "Item Quantity Can't Be Empty!"; CategoryErrorMessage.Text = "You Must Choose Category Item!"; ItemNameTextBox.Focus(); QuantityTextBox.Focus(); CategoryComboBox.Focus(); } else if (ItemNameTextBox.Text.Length == 0 && QuantityTextBox.Text.Length == 0) { ItemNameErrorMessage.Text = "Item Name Can't Be Empty!"; QuantityErrorMessage.Text = "Item Quantity Can't Be Empty!"; ItemNameTextBox.Focus(); QuantityTextBox.Focus(); } else if (ItemNameTextBox.Text.Length == 0 && CategoryComboBox.Text == "") { ItemNameErrorMessage.Text = "Item Name Can't Be Empty!"; CategoryErrorMessage.Text = "You Must Choose Category Item!"; ItemNameTextBox.Focus(); CategoryComboBox.Focus(); } else if (QuantityTextBox.Text.Length == 0 && CategoryComboBox.Text == "") { CategoryErrorMessage.Text = "You Must Choose Category Item!"; QuantityErrorMessage.Text = "Item Quantity Can't Be Empty!"; QuantityTextBox.Focus(); CategoryComboBox.Focus(); } else if (ItemNameTextBox.Text.Length == 0) { ItemNameErrorMessage.Text = "Item Name Can't Be Empty!"; ItemNameTextBox.Focus(); } else if (QuantityTextBox.Text.Length == 0) { QuantityErrorMessage.Text = "Item Quantity Can't Be Empty!"; QuantityTextBox.Focus(); } else if (CategoryComboBox.Text == "") { CategoryErrorMessage.Text = "You Must Choose Category Item!"; CategoryComboBox.Focus(); } else { string Iname = ItemNameTextBox.Text; int Iqty = Convert.ToInt32(QuantityTextBox.Text); int Icat = Convert.ToInt32(CategoryComboBox.SelectedValue.ToString()); CallItem.UpdateItem(Convert.ToInt16((dataGrid.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text), Iname, Iqty, Icat); } }
private void pictureBox3_Click(object sender, EventArgs e) { MedicineIdTextBox.Clear(); SellingPriceTextBox.Clear(); MedicineNameTextBox.Clear(); QuantityTextBox.Clear(); BuyingPriceTextBox.Clear(); ManufacturerTextBox.Clear(); }
private void saveButton_Click(object sender, EventArgs e) { int result = ms.EditMenu(id, MenuNameTextBox.Text, Convert.ToInt32(priceTextBox.Text), Convert.ToInt32(QuantityTextBox.Text), TypeComboBox.SelectedItem.ToString()); mda = new MenuDataAccess(); dataGridView1.DataSource = mda.GetMenuData(); MessageBox.Show("Item details successfully saved!"); MenuNameTextBox.Clear(); priceTextBox.Clear(); QuantityTextBox.Clear(); TypeComboBox.SelectedItem = null; }
/// <summary> /// Overi spravnost udaju mnozstvi pridavane polozky. /// Vstup musi byt ciselny, nesmi byt prazdny ani 0. /// </summary> /// <returns></returns> public bool VerifyQuantityInput() { string quantityString = QuantityTextBox.Text; if (!(int.TryParse(quantityString, out int quantity) && quantityString.Length > 0)) { QuantityTextBox.Clear(); QuantityFieldTLPanel.BackColor = Color.MistyRose; Message.QuantityFormatWarning(); return(false); }
private void ClearButton_Click(object sender, EventArgs e) { //Clear Textboxes TitleTextBox.Clear(); PriceTextBox.Clear(); ExtendedPriceTextBox.Clear(); DiscountedPriceTextBox.Clear(); DiscountTextBox.Clear(); QuantityTextBox.Clear(); //Set focus on Quantity QuantityTextBox.Focus(); }
private void GetSelectedItem() { Product = ProductsGrid.SelectedRows[0].DataBoundItem as Product; double temp; if (double.TryParse(QuantityTextBox.Text, out temp)) { Quantity = temp; } else { Quantity = 1; } QuantityTextBox.Focus(); }
private void AddOrderDetailsButton_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); //символен низ за връзка към базата данни – взема се от файл с име app.config con.ConnectionString = ConfigurationManager.ConnectionStrings["MassiveDynamic.Properties.Settings.MassiveDynamicConnectionString"].ConnectionString; //символен низ със заявката към базата данни string insertIntoOrderId = "'" + orderIDComboBox.Text + "'"; string insertIntoProductIDName = "'" + numberOfProductComboBox.Text + "'"; string insertIntounitPrice = "'" + UnitPriceTextBox.Text + "'"; string insertQuantity = "'" + QuantityTextBox.Text + "'"; //INSERT INTO table_name (column1,column2,column3,...) VALUES(value1, value2, value3,...); Insert into cheatSheet string insertCommand = string.Format("insert into OrderDetails (OrderID,ProductID,UnitPrice,Quantiy) values({0},{1},{2},{3});", insertIntoOrderId, insertIntoProductIDName, insertIntounitPrice, insertQuantity); SqlCommand com = new SqlCommand(insertCommand, con); //определяне на типа на командата - в конкретния случай е текст com.CommandType = CommandType.Text; try { //отваряме връзката към базата данни con.Open(); //изпълняваме командата / в този случай нямаме връщан резултат com.ExecuteNonQuery(); //извеждаме съобщение, че всичко е преминало успешно MessageBox.Show("Данните са добавени успешно!", "Message/Съобщение"); //изчистваме въведената стойност в текстовото поле UnitPriceTextBox.Clear(); QuantityTextBox.Clear(); } //ако не е преминало всичко успешно, това означава, че е възникнало изключение catch (Exception exe) { //извеждаме съобщение с възникналото изключение MessageBox.Show(exe.ToString(), "Message/Съобщение:"); } //затваря се връзката към базата данни con.Close(); //затваря се отворената форма this.Close(); }
private void CancelOrderButton_Click(object sender, EventArgs e) { NewOrderButton.Enabled = true; PrintOrderButton.Enabled = false; PrintPreviewButton.Enabled = false; CancelOrderButton.Enabled = false; ItemGroupBox.Enabled = false; ClientNameTextBox.Clear(); ItemNameComboBox.SelectedIndex = -1; QuantityTextBox.Clear(); UnitPriceTextBox.Clear(); CurrentStockTextBox.Clear(); TotalAmountTextBox.Text = "0"; SalesTaxTextBox.Text = "0"; TotalToPayTextBox.Text = "0"; CartDataGridView.DataSource = null; shoppingCart.Clear(); }
private void PriceTextBox_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Enter: { if (!decimal.TryParse(this.PriceTextBox.Text, out decimal price)) { this.PriceTextBox.Text = this.PriceTextBox.Text.Replace('.', ','); if (!decimal.TryParse(this.PriceTextBox.Text, out price)) { MessageBox.Show("Введите корректную цену!"); return; } //if } //if QuantityTextBox.Focus(); } break; default: break; }//switch }
private void AddToOrderButton_Click(object sender, RoutedEventArgs e) { if (IsAddOrderItemEligible()) { _selectedOrderEntry = new SupplyOrderEntry(_orderId, _selectedItem.Id, _selectedItem.Name, int.Parse(QuantityTextBox.Text), decimal.Parse(PriceTextBox.Text)); if (_newOrder.AddEntry(_selectedOrderEntry)) { RefreshSupplyDataGrid(); TotalAmountTextBox.Text = _newOrder.Total.ToString(); FinalInfoRefresh(); } else { MessageBox.Show("Item Is Already in the Order", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } QuantityTextBox.Focus(); }
protected void ProductCheckButton_Click(object sender, EventArgs e) { Valid = new Validation(); string GTIN = ProductTextBox.Text; string ProductID = Valid.GtinToPruductID(GTIN); string LocationID = LocationTextBox.Text; string shipmentID = Valid.GetShipmentID(BoxID); string OrderNumber = Valid.GetOrderNumber(BoxID); if (Valid.inNumeric(GTIN) == true) { ProductID = Valid.GtinToPruductID(GTIN); } else { ProductID = GTIN; } if (ProductID != "" && LocationID != "") { if (Valid.ProductIsInTHisOrder(Valid.GetShipmentID(BoxID), Valid.GetOrderNumber(BoxID), ProductID) == true || Valid.DescriptionInThisOrder(Valid.GetShipmentID(BoxID), Valid.GetOrderNumber(BoxID), ProductID, LocationID) == true) { if (Valid.ProductInEnteredLocation(Valid.GetShipmentID(BoxID), Valid.GetOrderNumber(BoxID), LocationID, ProductID) == true || Valid.DescriptionInEnteredLocation(LocationID, ProductID) == true) { if (Valid.IsThereAPriority1ReplenComingHere(LocationID) != true) { ProductTextBox.Text = ProductID.ToUpper(); LocationTextBox.Focus(); ProductInputGroup.Attributes["class"] = "form-group has-success"; QuantityTextBox.Focus(); } else { ProductTextBox.Text = ""; ProductTextBox.Attributes["placeholder"] = "Replen Can Not Pick"; ProductInputGroup.Attributes["class"] = "form-group has-error"; } } else { ProductTextBox.Text = ""; ProductTextBox.Attributes["placeholder"] = "Item not in This Location"; ProductInputGroup.Attributes["class"] = "form-group has-error"; } } else { ProductTextBox.Text = ""; ProductTextBox.Attributes["placeholder"] = "Item not in order"; ProductInputGroup.Attributes["class"] = "form-group has-error"; } } else { ProductTextBox.Text = ""; ProductTextBox.Attributes["placeholder"] = "Enter Product"; ProductInputGroup.Attributes["class"] = "form-group has-error"; } }
/// <summary> /// The currently selected book in the ComboBox will be added to the order summary grid. /// If the selection already exists in the table, the quantity is updated and the line total recalculates. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddTitleButton_Click(object sender, EventArgs e) { // Check if user has selected a book in the dropDown menu. If not, // show message and set focus to the dropDown. if (BookSelectionBox.SelectedIndex == -1) { BookSelectionBox.Focus(); MessageBox.Show("Select a Book from the DropDown Menu first.", "No Book Selected"); return; } // Following block checks if value passed in quantity box is valid. // If not, display message and set focus to quantity box. int parse; if (int.TryParse(QuantityTextBox.Text, out parse) == false || parse == 0) { MessageBox.Show("Enter a valid quantity.", "Invalid Quantity"); QuantityTextBox.Clear(); QuantityTextBox.Focus(); return; } string[] bookData = new string[4]; string connectionString = "server=localhost;user=root;database=book store;password="******"select title, author, isbn, price from books where title='{BookSelectionBox.Text}'", DBConnect); // Open Connection and retrieve data using mysql reader // SRC: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/retrieving-data-using-a-datareader DBConnect.Open(); // Read book data into bookData array. MySqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); bookData[0] = reader.GetString(0); bookData[1] = reader.GetString(1); bookData[2] = reader.GetString(2); bookData[3] = reader.GetString(3); } DBConnect.Close(); } Book tempBook = new Book(bookData[1], bookData[2], bookData[3], bookData[0]); // Create a tempBook to alias the currently selected item in the comboBox. int currentQty = 0; // Variable will track quantity of selected book already in the data grid. bool inTable = false; // Variable tracks whether the selected book is already in the grid. // Foreach loop checks if entry already exists. Also updates global qty. foreach (DataGridViewRow row in OrderSummaryData.Rows) { // If entry already exists, update currentQty. if (row.Cells[0].Value.ToString().Contains(tempBook.Title)) { currentQty += Convert.ToInt32(row.Cells[2].Value); currentRowIndex = row.Index; inTable = true; } } // If entry didn't exist in table, create a row and set row index to the new row. if (!inTable) { // If this is a subsequent addition. if (firstTitleAdded) { // Add a row and set to the new row's index - 1. I could not figure out why this was // necessary but it was the only way I could get the form to work. OrderSummaryData.Rows.Add(); currentRowIndex = OrderSummaryData.NewRowIndex - 1; } // If this is the first addition, set the bool and continue at first index. else { firstTitleAdded = true; } } // Set the cells of the added row to the book's attributes. OrderSummaryData.Rows[currentRowIndex].Cells[0].Value = tempBook.Title; OrderSummaryData.Rows[currentRowIndex].Cells[1].Value = tempBook.Price; // Update the quantity with the previous qty, if any, plus the new user-input qty. OrderSummaryData.Rows[currentRowIndex].Cells[2].Value = Convert.ToInt32(QuantityTextBox.Text) + currentQty; // Extract the price, without the dollar sign, and multiply it with the quantity. double num1 = Convert.ToDouble(OrderSummaryData.Rows[currentRowIndex].Cells[2].Value); double num2 = Convert.ToDouble(tempBook.Price.Substring(1)); double total = num1 * num2; OrderSummaryData.Rows[currentRowIndex].Cells[3].Value = total.ToString("C2"); // Add to 0.00 to keep 2 numbers after decimal point. // Calculate subtotal, tax, and total. Re-using num1 and num2 as subtotal and tax, respectively. num1 = 0; num2 = 0; total = 0; // Loop adds each line total and stores in num1 (subtotal). foreach (DataGridViewRow row in OrderSummaryData.Rows) { string temp = row.Cells[3].Value.ToString(); // First create a temp string with the line total string. num1 += Convert.ToDouble(temp.Substring(1)); // Extract the string without the '$' and store as subtotal. } num2 = 0.1 * num1; // Calculate tax (10% of subtotal). total = num1 + num2; // Total = tax + subtotal. // Set the textBoxes with subtotal, tax, total. SubtotalTextBox.Text = num1.ToString("C2"); TaxTextBox.Text = num2.ToString("C2"); TotalTextBox.Text = total.ToString("C2"); CancelOrderButton.Enabled = true; // Allow cancel order }
private void AddNewProduct_Click(object sender, EventArgs e) { if (IDTextBox.Text == "") { MessageBox.Show("ID can't be blank!!!", "Blank ID"); } else if (NameTextBox.Text == "") { MessageBox.Show("Name can't be blank!!!", "Blank Name"); } else if (UnitListComboBox.Text == "") { MessageBox.Show("Unit can't be blank!!!", "Blank Quantity"); } else if (QuantityTextBox.Text == "") { MessageBox.Show("Quantity can't be blank!!!", "Blank Quantity"); } else if (MoneyTextBox.Text == "") { MessageBox.Show("Money can't be blank!!!", "Blank Quantity"); } else if (MoneyUnitComboBox.Text == "") { MessageBox.Show("Money Unit can't be blank!!!", "Blank Quantity"); } else { int size = -1; int result = -1; try { DataTable dt = new DataTable(); dt.Columns.Add("id", typeof(int)); dt.Columns.Add("name", typeof(string)); dt.Columns.Add("unit", typeof(string)); dt.Columns.Add("quantity", typeof(int)); dt.Columns.Add("money", typeof(int)); dt.Columns.Add("moneyunit", typeof(string)); size = 0; DBUtils.OpenConnection(conn); string cmd = "Select * from StockManagementSystemDatabase.dbo.Product_Cards_Table where ProductID='" + IDTextBox.Text + "' or ProductName='" + NameTextBox.Text.ToUpper() + "';"; SqlCommand command = new SqlCommand(cmd, conn); SqlDataReader dataReader = command.ExecuteReader(); Product temp = new Product(); while (dataReader.Read()) { temp.setID((int)dataReader.GetValue(0)); temp.setName(dataReader.GetValue(1).ToString().ToUpper()); temp.setUnit(dataReader.GetValue(2).ToString()); temp.setQuantity((int)dataReader.GetValue(3)); temp.setMoney((int)dataReader.GetValue(4)); temp.setMoneyunit(dataReader.GetValue(5).ToString()); if (temp.getID() == Int32.Parse(IDTextBox.Text) | (temp.getName().ToUpper().CompareTo(NameTextBox.Text.ToUpper()) == 0)) { dt.Rows.Add(temp.getID(), temp.getName().ToUpper(), temp.getUnit(), temp.getQuantity(), temp.getMoney(), temp.getMoneyunit()); Console.WriteLine(dt.Rows[size].Field <int>(0) + "\t" + dt.Rows[size].Field <string>(1) + "\t" + dt.Rows[size].Field <string>(2) + "\t" + dt.Rows[size].Field <int>(3) + "\t" + dt.Rows[size].Field <int>(4) + "\t" + dt.Rows[size].Field <string>(5)); Console.WriteLine("BYID - > size:" + size); size++; } } dataReader.Close(); DBUtils.CloseConnection(conn); if (size == 0) { string Query = "insert into StockManagementSystemDatabase.dbo.Product_Cards_Table(ProductID,ProductName,ProductUnit,ProductQuantity, ProductMoney, ProductMoneyUnit) " + "values('" + this.IDTextBox.Text + "','" + this.NameTextBox.Text.ToUpper() + "','" + this.UnitListComboBox.Text + "','" + this.QuantityTextBox.Text + "','" + this.MoneyTextBox.Text + "','" + this.MoneyUnitComboBox.Text + "');"; SqlCommand MyCommand = new SqlCommand(Query, conn); DBUtils.OpenConnection(conn); MyCommand.ExecuteNonQuery(); MessageBox.Show("Save product", "SUCCESS INSERT"); //FillDataGridView(); cardTable.Rows.Add(this.IDTextBox.Text, this.NameTextBox.Text.ToUpper(), this.UnitListComboBox.Text, this.QuantityTextBox.Text, this.MoneyTextBox.Text, this.MoneyUnitComboBox.Text); DataGridView_Products.DataSource = cardTable; DataGridView_Products.Refresh(); string Query2 = "insert into StockManagementSystemDatabase.dbo.Move_Table(MoveProductID,MoveType,MoveDate,MoveQuantity,MoveQuantityUnit) " + "values('" + this.IDTextBox.Text + "','entry','" + DateTime.Today.ToString("yyyy-MM-dd") + "','" + this.QuantityTextBox.Text + "','" + this.UnitListComboBox.Text + "');"; SqlCommand MyCommand2 = new SqlCommand(Query2, conn); DBUtils.OpenConnection(conn); MyCommand2.ExecuteNonQuery(); DBUtils.CloseConnection(conn); result = 1; } else { result = 2; } } catch { if (result == 2) { MessageBox.Show("Same Product", "WARNING"); IDTextBox.Clear(); NameTextBox.Clear(); } else if (result == -1) { MessageBox.Show("NOLUYO!"); } } finally { DBUtils.CloseConnection(conn); DataGridView_Products.DataSource = cardTable; DataGridView_Products.Refresh(); FillDataGridView(); IDTextBox.Clear(); NameTextBox.Clear(); UnitListComboBox.Text = ""; QuantityTextBox.Clear(); MoneyTextBox.Clear(); MoneyUnitComboBox.Text = ""; } } }
private void UpdateThisButton_Click(object sender, EventArgs e) { try { DataTable dt = new DataTable(); dt.Columns.Add("id", typeof(int)); dt.Columns.Add("name", typeof(string)); dt.Columns.Add("unit", typeof(string)); dt.Columns.Add("quantity", typeof(int)); dt.Columns.Add("money", typeof(int)); dt.Columns.Add("moneyunit", typeof(string)); DBUtils.OpenConnection(conn); string cmd = "Select * from StockManagementSystemDatabase.dbo.Product_Cards_Table where ProductID=" + IDTextBox.Text + ";"; SqlCommand command = new SqlCommand(cmd, conn); SqlDataReader dataReader = command.ExecuteReader(); if (!dataReader.Read()) { MessageBox.Show("This product already exists.", "EXIST"); dataReader.Close(); DBUtils.CloseConnection(conn); } else { dataReader.Close(); DBUtils.CloseConnection(conn); string Query = "update StockManagementSystemDatabase.dbo.Product_Cards_Table set ProductID='" + IDTextBox.Text + "',ProductName='" + NameTextBox.Text + "',ProductUnit='" + UnitListComboBox.Text + "',ProductQuantity='" + QuantityTextBox.Text + "',ProductMoney='" + this.MoneyTextBox.Text + "',ProductMoneyUnit='" + this.MoneyUnitComboBox.Text + "' WHERE ProductID=@ProductID;"; SqlCommand MyCommand = new SqlCommand(Query, conn); MyCommand.Parameters.AddWithValue("@ProductID", IDTextBox.Text.ToString()); DBUtils.OpenConnection(conn); MyCommand.ExecuteNonQuery(); MessageBox.Show("Update product", "SUCCESS UPDATE"); } } catch (SqlException ex) { MessageBox.Show(ex.Message, "ERROR"); } finally { DBUtils.CloseConnection(conn); FillDataGridView(); InformationTextBox.Visible = false; AddNewProduct.Visible = true; IDTextBox.Enabled = true; NameTextBox.Enabled = true; IDTextBox.Clear(); NameTextBox.Clear(); UnitListComboBox.Text = ""; QuantityTextBox.Clear(); MoneyTextBox.Clear(); MoneyUnitComboBox.Text = ""; } }
private void addButton_Click(object sender, EventArgs e) { if ((int)companyNameComboBox.SelectedValue == -1) { MessageBox.Show("Please Select a Company"); return; } if ((int)itemNameComboBox.SelectedValue == -1) { MessageBox.Show("Please Select a Item"); return; } StockOut newStockOut = new StockOut(); newStockOut.CompanyId = (int)companyNameComboBox.SelectedValue; newStockOut.ItemId = (int)itemNameComboBox.SelectedValue; int Quantity; if (int.TryParse(QuantityTextBox.Text, out Quantity)) { if (Quantity > 0) { int availableQuantity = Convert.ToInt32(availableQuantityTextBox.Text); newStockOut.TakenQuantity = Quantity; } else { MessageBox.Show("Please Enter Amount for Stock"); return; } } else { MessageBox.Show("Invalid Value"); return; } newStockOut.InsertDate = DateTime.Now; //newStockOut.AvailableQuantity = Convert.ToInt32(availableQuantityTextBox.Text) - Convert.ToInt32(QuantityTextBox.Text); //newStockOut.ReorderLevel = Convert.ToInt32(reorderlevelTextBox.Text); //if (newStockOut.AvailableQuantity>newStockOut.TakenQuantity) //{ // int count = 0; // List<StockOut> stockOuts = new List<StockOut>(); // stockOuts.Add(newStockOut); // foreach (StockOut stockOut in stockOuts) // { // count++; // ListViewItem item=new ListViewItem(); // item.Text = count.ToString(); // if (!list) // { // } // } //} companyNameComboBox.SelectedValue = -1; itemNameComboBox.SelectedValue = -1; reorderlevelTextBox.Clear(); availableQuantityTextBox.Clear(); QuantityTextBox.Clear(); }
private void AddToCartButton_Click(object sender, EventArgs e) { if (IsValidated()) { if (Convert.ToInt16(QuantityTextBox.Text.Trim()) > Convert.ToInt16(CurrentStockTextBox.Text)) { MessageBox.Show("Quantity can't be greater than current stock!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool hasSameProductSelectedAgain = false; //If Product Is Reselected and Add it's value so update it's previous Value foreach (DataGridViewRow row in CartDataGridView.Rows) { if (Convert.ToInt16(row.Cells["ItemId"].Value) == Convert.ToInt16(ItemNameComboBox.SelectedValue)) { row.Cells["Quantity"].Value = Convert.ToInt16(row.Cells["Quantity"].Value) + Convert.ToInt16(QuantityTextBox.Text); row.Cells["TotalPrice"].Value = Convert.ToInt16(row.Cells["Quantity"].Value) * Convert.ToDecimal(row.Cells["UnitPrice"].Value); hasSameProductSelectedAgain = true; } } if (hasSameProductSelectedAgain == false) { CartItem item = new CartItem() { ItemId = Convert.ToInt16(ItemNameComboBox.SelectedValue), ItemName = ItemNameComboBox.Text, Quantity = Convert.ToInt16(QuantityTextBox.Text.Trim()), UnitPrice = Convert.ToDecimal(UnitPriceTextBox.Text.Trim()), TotalPrice = Convert.ToInt16(QuantityTextBox.Text.Trim()) * Convert.ToDecimal(UnitPriceTextBox.Text.Trim()) }; // Array, Collection, List, DataTable and DataSet shoppingCart.Add(item); CartDataGridView.DataSource = null; CartDataGridView.DataSource = shoppingCart; } decimal totalAmount = shoppingCart.Sum(x => x.TotalPrice); TotalAmountTextBox.Text = totalAmount.ToString(); decimal totalSalesTax = (16 * totalAmount) / 100; SalesTaxTextBox.Text = totalSalesTax.ToString(); decimal totalPay = totalAmount + totalSalesTax; TotalToPayTextBox.Text = totalPay.ToString(); //update stock in MySQL int productId = Convert.ToInt16(ItemNameComboBox.SelectedValue); int quantity = Convert.ToInt16(QuantityTextBox.Text); UpdateStockLevel(productId, quantity); ItemNameComboBox.SelectedIndex = -1; QuantityTextBox.Clear(); UnitPriceTextBox.Clear(); CurrentStockTextBox.Clear(); } }
private void BatchPrintButton_Click(object sender, RoutedEventArgs e) { if (PrintDatePicker.SelectedDate == null) { MessageBox.Show(" Please Select Date of BatchPrint", "Applicaiton Info", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (ModelSelectorComboBox.SelectedIndex == -1) { MessageBox.Show(" Please Select Model", "Applicaiton Info", MessageBoxButton.OK, MessageBoxImage.Information); return; } String model = Models[ModelSelectorComboBox.SelectedIndex].Name; String code = Models[ModelSelectorComboBox.SelectedIndex].Code; String date = PrintDatePicker.SelectedDate.Value.ToString("yyMMdd"); int serialNo; if (int.TryParse(InitialSerialNoTextBox.Text, out serialNo) == false) { MessageBox.Show(" Invalid Initial Serial No", "Applicaiton Info", MessageBoxButton.OK, MessageBoxImage.Information); return; } int quantity; if (int.TryParse(QuantityTextBox.Text, out quantity) == false) { MessageBox.Show(" Invalid Quantity of Reprints", "Applicaiton Info", MessageBoxButton.OK, MessageBoxImage.Information); return; } BatchPrintArgs bpa; if (F1RadioButton.IsChecked == true) { bpa = new BatchPrintArgs(model, code, date, serialNo, quantity, REPRINT_STAGE.F1); } else if (M1RadioButton.IsChecked == true) { bpa = new BatchPrintArgs(model, code, date, serialNo, quantity, REPRINT_STAGE.M1); } else if (IntegratedRadioButton.IsChecked == true) { bpa = new BatchPrintArgs(model, code, date, serialNo, quantity, REPRINT_STAGE.INTEGRATED); } else if (CombinationRadioButton.IsChecked == true) { bpa = new BatchPrintArgs(model, code, date, serialNo, quantity, REPRINT_STAGE.COMBINATION); } else { MessageBox.Show(" Please Select stage of Reprint", "Applicaiton Info", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (BatchPrint != null) { BatchPrint(this, bpa); } PrintDatePicker.SelectedDate = null; ModelSelectorComboBox.SelectedIndex = -1; InitialSerialNoTextBox.Clear(); QuantityTextBox.Clear(); F1RadioButton.IsChecked = M1RadioButton.IsChecked = IntegratedRadioButton.IsChecked = CombinationRadioButton.IsChecked = false; }
void Cleardata() { QuantityTextBox.Clear(); }
//Event Handler for QuantityTextBox change //If user directly enters value of quantity private void QuantityTextBox_Leave(object sender, EventArgs e) { int Value = 0; try { int CurrentValue = int.Parse(QuantityTextBox.Text); //checking if input is less than zero if (CurrentValue <= 0) { MessageBox.Show("Zero or Less quantity not Allowed. You can use delete button to remove the product from Cart"); QuantityTextBox.Undo(); QuantityTextBox.SelectAll(); QuantityTextBox.Focus(); } //if input is greater than 0 else { for (int i = 0; i < MainForm.ProductList.Count; i++) { //finding the product if (MainForm.ProductList[i].ProductCategory == this.ProdCat && MainForm.ProductList[i].ProductID == this.ProdID) { //checking the available stock quantity if (CurrentValue <= MainForm.ProductList[i].ProductQuantity) { //Rechecking the previous quantity QuantityTextBox.Undo(); if (QuantityTextBox.Text != CurrentValue.ToString()) { Value = CurrentValue; try { CurrentValue = CurrentValue - int.Parse(QuantityTextBox.Text); QuantityTextBox.Text = Value.ToString(); } catch { QuantityTextBox.Text = Value.ToString(); } } //Calculating Items and Totals using provided quantity MainForm.TotalItems += CurrentValue; MainForm.GrandTotal += (CurrentValue * this._ProductPrice); MainForm frm = (MainForm)this.FindForm(); frm.TotalItemsLabel.Text = MainForm.TotalItems.ToString(); frm.GrandTotalLabel.Text = MainForm.GrandTotal.ToString(); ProductTotalPriceLabel.Text = (Value * this._ProductPrice).ToString(); break; } else { MessageBox.Show("Requested Quantities of " + this.ProdName + " are not available in inventory", "Not Enough Items Available", MessageBoxButtons.OK, MessageBoxIcon.Error); QuantityTextBox.Undo(); QuantityTextBox.Focus(); } } } } } catch { MessageBox.Show("Only Numbers are allowed in quantity. Please enter valid quantity", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); QuantityTextBox.Focus(); QuantityTextBox.SelectAll(); QuantityTextBox.Undo(); } }
protected void QuantityButton_Click(object sender, EventArgs e) { Valid = new Validation(); string UserID = "Tturner"; Utility UT = new Utility(); string PickZone = CurrentZone; string ProductID = UT.GetProductID(ProductTextBox.Text); string LocationID = LocationTextBox.Text; string shipmentID = Valid.GetShipmentID(BoxID); string OrderNumber = Valid.GetOrderNumber(BoxID); string Quantity = QuantityTextBox.Text; int NumberOfMoveQueues = 0; int n; string orderLine; string InventoryRID; bool isNumeric = int.TryParse(Quantity, out n); if (isNumeric == true) { int EnteredQuantity = Convert.ToInt16(Quantity); if (Valid.IsValidQuantity(shipmentID, OrderNumber, ProductID, Quantity) == true) { QuantityTextBox.Text = ""; LocationTextBox.Text = ""; ProductTextBox.Text = ""; LocationTextBox.Focus(); QuantityInputGroup.Attributes["class"] = "form-group has-success"; orderLine = UT.GetOrderLine(shipmentID, OrderNumber, Quantity, ProductID); NumberOfMoveQueues = UT.GetNumberOfMoveQueues(shipmentID, OrderNumber, orderLine); int NQuantity = Convert.ToInt16(Quantity); for (int i = 0; i < NumberOfMoveQueues; i++) { string MoveQRID = UT.GetMoveQueueRID(shipmentID, OrderNumber, orderLine); int moveQQuantity = UT.GetMoveQueueQuantity(MoveQRID); InventoryRID = UT.GetInventoryRID(MoveQRID); UT.InsertPickIntoInventory(moveQQuantity.ToString(), shipmentID, OrderNumber, orderLine, UserID, InventoryRID); UT.deleteMoveQueue(MoveQRID); if (InventoryRID != "") { UT.UpdateInventory(UserID, moveQQuantity.ToString(), InventoryRID); UT.MoveToQCEmpty(InventoryRID, shipmentID, OrderNumber, orderLine); UT.InsertIntoAuditInventory(UserID, moveQQuantity.ToString(), shipmentID, OrderNumber, orderLine, ProductID, LocationID, InventoryRID); } else { //error message } } if (Valid.OrderDone(shipmentID, OrderNumber) == true) { UT.UpdateOoutboundShipments(shipmentID, OrderNumber); } if (Valid.IsQCRequired(UserID) == true) { UT.SetQCRequired(shipmentID, OrderNumber); } UT.DeleteInventoryAllocation(shipmentID, OrderNumber, orderLine); QuantityInputGroup.Attributes["class"] = "form-group"; LocationInputGroup.Attributes["class"] = "form-group"; ProductInputGroup.Attributes["class"] = "form-group"; //check to see if we need more inventory from another //updateLocationStatus } else { QuantityTextBox.Text = ""; QuantityTextBox.Attributes["placeholder"] = "Incorrect Quantity"; QuantityTextBox.Focus(); QuantityInputGroup.Attributes["class"] = "form-group has-error"; } } else { QuantityTextBox.Text = ""; BoxScannTextBox.Attributes["placeholder"] = "Please enter a number"; QuantityInputGroup.Attributes["class"] = "form-group has-error"; } }