コード例 #1
0
 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);
 }
コード例 #2
0
 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();
 }
コード例 #3
0
        //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;
            }
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        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..");
            }
        }
コード例 #6
0
 public void InsertData(Product aProduct)
 {
     aProductGateway.InsertData(aProduct);
 }
コード例 #7
0
 public List<Product> GetAllProduct(Product aProduct)
 {
     return aProductGateway.GetAllProduct(aProduct);
 }