private void saveButton_Click(object sender, EventArgs e) { aProduct = new Product(); aProduct.Code = productCodeTextBox.Text; aProduct.Description = productDescriptionTextBox.Text; aProduct.Quantity = Convert.ToInt32(productQuantityTextBox.Text); aProductManager.InsertData(aProduct); }
private void showButton_Click(object sender, EventArgs e) { aProduct = new Product(); List<Product> products = aProductManager.GetAllProduct(aProduct); productListView.Items.Clear(); foreach (Product product in products) { ListViewItem lvi = new ListViewItem(product.Code); lvi.SubItems.Add(product.Description); lvi.SubItems.Add(product.Quantity.ToString()); productListView.Items.Add(lvi); } viewQuantityTextBox.Text = aProductManager.GetTotalQuantity().ToString(); }
//public bool HasThisProductNameStored(string name) //{ // aConnection.Open(); // string query = string.Format("SELECT description FROM tProduct WHERE description='{0}'", description); // SqlCommand command = new SqlCommand(query, aConnection); // SqlDataReader aReader = command.ExecuteReader(); // bool HasHow = aReader.HasRows; // aConnection.Close(); // return HasHow; //} public bool CheckAlreadyExist(Product aProduct) { aConnection.Open(); string query = string.Format("SELECT * FROM tProduct WHERE (code='{0}')", aProduct.Code); SqlCommand aCommand = new SqlCommand(query, aConnection); SqlDataReader aReader = aCommand.ExecuteReader(); if (aReader.HasRows) { aReader.Close(); aConnection.Close(); return true; } else { aReader.Close(); aConnection.Close(); return false; } }
public List<Product> GetAllProduct(Product aProduct) { aConnection.Open(); string query = string.Format("SELECT * FROM tProduct"); SqlCommand command = new SqlCommand(query, aConnection); List<Product> products = new List<Product>(); SqlDataReader aReader = command.ExecuteReader(); bool HasHow = aReader.HasRows; if (HasHow) { while (aReader.Read()) { Product product = new Product(); product.Id = (int)aReader[0]; product.Code = aReader[1].ToString(); product.Description = aReader[2].ToString(); product.Quantity = (int)aReader[3]; products.Add(product); } } aConnection.Close(); return products; }
public void InsertData(Product aProduct) { string insertCommandString = "INSERT INTO tProduct VALUES ('" + aProduct.Code + "','" + aProduct.Description + "','" + aProduct.Quantity + "')"; aConnection.Open(); aCommand = new SqlCommand(insertCommandString, aConnection); int dataSaveInDataBaseEfact = aCommand.ExecuteNonQuery(); aConnection.Close(); if (dataSaveInDataBaseEfact > 0) { MessageBox.Show("Product Saved.."); } else { MessageBox.Show("Product Save Failed.."); } }
public void InsertData(Product aProduct) { aProductGateway.InsertData(aProduct); }
public List<Product> GetAllProduct(Product aProduct) { return aProductGateway.GetAllProduct(aProduct); }