protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; Classes.Product objProduct = new Classes.Product(); SqlDataReader categoryData = objProduct.getParentCategoies(); if (categoryData == null) return; while (categoryData.Read()) { ListItem categoryItem = new ListItem(categoryData["name"].ToString(), categoryData["id"].ToString()); lstCategory.Items.Add(categoryItem); Classes.Product objProductB = new Classes.Product(); SqlDataReader childCategory = objProductB.getChildCategories(Convert.ToInt32(categoryData["id"])); if (childCategory != null) while (childCategory.Read()) { categoryItem = new ListItem("!_"+childCategory["name"].ToString(), childCategory["id"].ToString()); lstCategory.Items.Add(categoryItem); } objProductB.close(); } objProduct.close(); }
public static Classes.Product ConvertProdInProduct(int art) { Test dataBase = new Test(); Classes.Product product; MySqlCommand command = new MySqlCommand("SELECT * FROM `products` WHERE `Articule` = @aR", dataBase.getConnection()); command.Parameters.Add("@aR", MySqlDbType.Int32).Value = art; MySqlDataAdapter adapter = new MySqlDataAdapter(); DataTable table = new DataTable(); adapter.SelectCommand = command; adapter.Fill(table); List <string> str = new List <string>(); for (int i = 0; i < table.Rows.Count; i++) { for (int j = 0; j < table.Columns.Count; j++) { str.Add(table.Rows[i][j].ToString()); } product = new Classes.Product(str[0], Convert.ToInt32(str[1]), Convert.ToInt32(str[2])); return(product); } product = new Classes.Product("ERROR", -1, -1); return(product); }
private void AddProductToStack(Classes.Product product, int quantity) { var productGrid = new Grid { ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(5, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(22.5, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(22.5, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(22.5, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(22.5, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(5, GridUnitType.Star) }, }, }; productGrid.Children.Add(new Label { Text = product.Name, FontSize = 14, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Start, HorizontalTextAlignment = TextAlignment.Start }, 1, 3, 0, 1); productGrid.Children.Add(new Label { Text = quantity.ToString(), FontSize = 14, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, }, 3, 0); productGrid.Children.Add(new Label { Text = product.Price.ToString("N2"), FontSize = 14, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.End, }, 4, 0); productDetailsStack.Children.Add(productGrid); }
public double getProductPrice(int ID) { SqlCommand cmd = new SqlCommand("SELECT Price FROM Product WHERE productID = " + ID + "", con); SqlDataReader reader = cmd.ExecuteReader(); Classes.Product p = new Classes.Product(); while (reader.Read()) { p.price = Convert.ToDouble(reader["Price"]); List.Add(p); } reader.Close(); return(p.price); }
protected void btnAddProduct_Click(object sender, EventArgs e) { string name = txtName.Text.ToString(); string excerpt = txtExcerpt.Text.ToString(); string description = txtDescription.Text.ToString(); int cost = Convert.ToInt32(txtCost.Text); string inStock = radInStock.SelectedValue; string featured = radFeatured.SelectedValue; string status = radStatus.SelectedValue; string[] allowedExtensions = { ".JPG", ".PNG" }; string imageExtension = Path.GetExtension(fileImage.PostedFile.FileName).ToUpper(); bool error = false; if (!allowedExtensions.Contains(imageExtension)) { error = true; litError.Text = "Invalid Image Provided"; } if (error) return; string image = Guid.NewGuid().ToString() + imageExtension; string uploadDirectory = Path.Combine(Request.PhysicalApplicationPath, "uploads"); string uploadedFile = Path.Combine(uploadDirectory, image); fileImage.PostedFile.SaveAs(uploadedFile); Classes.Product objProduct = new Classes.Product(); if (objProduct.addProduct(name, excerpt, description, cost, inStock, featured, status, image)) { litError.Text = "Product Added Successfully"; int productId = objProduct.getProductIdByName(name); foreach (ListItem category in lstCategory.Items) { if (category.Selected) objProduct.mapProductToCategory(productId, Convert.ToInt32(category.Value)); } } }
public List <Classes.Product> getAllProductsDetails() { con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM Product", con); SqlDataReader reader = cmd.ExecuteReader(); //reads in the data and reutrns values to list while (reader.Read()) { Classes.Product p = new Classes.Product(); p.productID = (int)reader["ProductID"]; p.Name = (string)reader["Name"]; p.Brand = (string)reader["Brand"]; p.imagefile = (string)reader["ImageFile"]; p.price = Convert.ToDouble(reader["Price"]); p.longDescription = (string)reader["LongDescription"]; List.Add(p); } con.Close(); return(List); }
private void saveButton_Click(object sender, EventArgs e) { //if (HasSpecialChars(priceInput.Text) is true) //{ // buttonSave.Enabled = false; // priceInput.BackColor = Color.Coral; // MessageBox.Show("The price input field must be in USD Currency Format and cannot contain any alpha or special characters"); // return; //} if (inventoryInput.Text == "") { // If the value in the numeric updown is an empty string, replace with 0. inventoryInput.Text = "0"; } bool IV = InputValidation(); if (IV is false) { MessageBox.Show("Please check that all fields are completed correctly and try again."); return; } this.Hide(); // if its blank prompt user if (String.IsNullOrWhiteSpace(nameInput.Text) || String.IsNullOrWhiteSpace(Convert.ToString(inventoryInput.Value)) || String.IsNullOrWhiteSpace(priceInput.Text) || String.IsNullOrWhiteSpace(minInput.Text) || String.IsNullOrWhiteSpace(maxInput.Text) || String.IsNullOrEmpty(nameInput.Text) || String.IsNullOrEmpty(Convert.ToString(inventoryInput.Value)) || String.IsNullOrEmpty(priceInput.Text) || String.IsNullOrEmpty(minInput.Text) || String.IsNullOrEmpty(maxInput.Text)) { MessageBox.Show("Please fill out all fields. May not be empty."); InputValidation(); return; } if (Convert.ToInt32(maxInput.Text) < Convert.ToInt32(minInput.Text)) { MessageBox.Show("Max cannot be less than Min"); this.Show(); return; } else if (Enumerable.Range(Convert.ToInt32(minInput.Text), Convert.ToInt32(maxInput.Text)).Contains(Convert.ToInt32(inventoryInput.Text)) == false) { MessageBox.Show("Inventory must be between Min and Max values."); this.Show(); return; } if (associatedPartsDGV.RowCount == 0 && modifyOrNew == 0) // and product is new { MessageBox.Show("Product must contain atleast one associated part."); this.Show(); return; } else if (Convert.ToInt32(maxInput.Text) < Convert.ToInt32(minInput.Text)) { MessageBox.Show("Max cannot be less than Min"); this.Show(); return; } else { Product updatedProduct = new Product(Convert.ToInt32(IDinput.Text), nameInput.Text, Convert.ToDouble(priceInput.Text.Replace("$", "").Replace("$", "")), Convert.ToInt32(inventoryInput.Text), Convert.ToInt32(minInput.Text), Convert.ToInt32(maxInput.Text)); //foreach (Classes.Part part in DGVAssoParts) //{ // updatedProduct.AssociatedParts.Add(part); //} // Classes.Product productObject = Classes.Inventory.lookupProduct(Convert.ToInt32(IDinput.Text)); foreach (Classes.Part part in DGVAssoParts) { Debug.WriteLine(part.Name); updatedProduct.AddAssociatedPart(part); Debug.WriteLine("Product name" + updatedProduct.Name); foreach (Classes.Part x in updatedProduct.AssociatedParts) { Debug.WriteLine(x.Name); } // updatedProduct.AssociatedParts.Add(part); } Inventory.updateProduct(Convert.ToInt32(IDinput.Text), updatedProduct); if (Convert.ToInt32(maxInput.Text) < Convert.ToInt32(minInput.Text)) { MessageBox.Show("Your minimum exceeds your maximum."); } else if (modifyOrNew == 1) //modify { //lookup the newly made product make a product object Product thatNewProd = Inventory.lookupProduct(Convert.ToInt32(IDinput.Text)); //update that objects properties //{ // if (each.ProductID == Convert.ToInt32(IDinput.Text)) //was productID? // { thatNewProd.Name = nameInput.Text; thatNewProd.Price = Convert.ToDouble(priceInput.Text.Replace("$", "")); thatNewProd.InStock = Convert.ToInt32(inventoryInput.Text); thatNewProd.Min = Convert.ToInt32(minInput.Text); thatNewProd.Max = Convert.ToInt32(maxInput.Text); foreach (Classes.Part part in holdingAreaParts) { Classes.Product workingProduct = Inventory.lookupProduct(Convert.ToInt32(IDinput.Text)); workingProduct.AddAssociatedPart(part); } // } //} //this.Hide(); Main main = new Main(); main.ShowDialog(); return; } else { Inventory.addProduct(new Product( nameInput.Text, Convert.ToDouble(priceInput.Text.Replace("$", "")), Convert.ToInt32(inventoryInput.Text), Convert.ToInt32(minInput.Text), Convert.ToInt32(maxInput.Text))); //commit parts from holding area foreach (Classes.Part part in holdingAreaParts) { Classes.Product workingProduct = Inventory.lookupProduct(Convert.ToInt32(IDinput.Text)); workingProduct.AddAssociatedPart(part); } this.Close(); Main main = new Main(); main.Show(); } } }