Пример #1
0
 public ItemModel(int itemID, ProductModel product, int quantity)
 {
     this.ItemID = itemID;
     this.Product = product;
     this.Quantity = quantity;
     Parcial = quantity * product.SalePrice;
 }
Пример #2
0
        private void button_cart_Click(object sender, EventArgs e)
        {
            if (numericUpDown_quantity.Value > 0 && listBox_products.Items.Count == 1)
            {
                ItemModel item = null;
                using (SqlConnection sqlConn =
                   new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MarotoDB.mdf;Integrated Security=True;"))
                {
                    using (SqlCommand sqlCommand = new SqlCommand())
                    {
                        sqlCommand.Parameters.AddWithValue("id", textBox_id.Text);
                        sqlCommand.CommandText = "SELECT * FROM PRODUCT WHERE ID = @id";
                        sqlCommand.Connection = sqlConn;
                        sqlConn.Open();
                        SqlDataReader dataReader;
                        dataReader = sqlCommand.ExecuteReader();

                        if (dataReader.Read())
                        {
                            ProductModel product = new ProductModel(Int32.Parse(dataReader["ID"].ToString()),
                                            dataReader["NAME"].ToString(),
                                            dataReader["PROVIDER"].ToString(),
                                            Convert.ToDateTime(dataReader["EXPIRATION_DATE"].ToString()),
                                            Int32.Parse(dataReader["QUANTITY"].ToString()),
                                            Decimal.Parse(dataReader["PURCHASE_PRICE"].ToString()),
                                            Decimal.Parse(dataReader["SALE_PRICE"].ToString()),
                                            dataReader["DESCRIPTION"].ToString());
                            item = new ItemModel(10, product, Int32.Parse(numericUpDown_quantity.Value.ToString()));
                        }
                        sqlConn.Close();
                    }
                }
                updateSale(item);
            }
        }
Пример #3
0
        private void button_search_Click(object sender, EventArgs e)
        {
            using (SqlConnection sqlConn =
                   new SqlConnection(connectionString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.CommandText = "SELECT * FROM PRODUCT WHERE ID = @id";

                    sqlCommand.Parameters.AddWithValue("id", textBox_id.Text);
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();
                    SqlDataReader dataReader;
                    dataReader = sqlCommand.ExecuteReader();

                    ProductModel product = null;
                    if (dataReader.Read())
                    {
                        product = new ProductModel(Int32.Parse(dataReader["ID"].ToString()),
                                            dataReader["NAME"].ToString(),
                                            dataReader["PROVIDER"].ToString(),
                                            Convert.ToDateTime(dataReader["EXPIRATION_DATE"].ToString()),
                                            Int32.Parse(dataReader["QUANTITY"].ToString()),
                                            Decimal.Parse(dataReader["PURCHASE_PRICE"].ToString()),
                                            Decimal.Parse(dataReader["SALE_PRICE"].ToString()),
                                            dataReader["DESCRIPTION"].ToString());
                    }
                    sqlConn.Close();

                    if (product != null)
                    {
                        textBox_id.Text = product.ProductID.ToString();
                        textBox_name.Text = product.ProductName.ToString();
                        textBox_fornecedor.Text = product.Provider.ToString();
                        dateTimePicker_data_validade.Text = product.ExpirationDate.ToString();
                        textBox_qtd_estoque.Text = product.Quantity.ToString();
                        textBox_preco_compra.Text = product.PurchasePrice.ToString();
                        textBox_preco_venda.Text = product.SalePrice.ToString();
                        textBox_descricao.Text = product.Description.ToString();
                    }
                    else
                    {
                        MessageBox.Show("Empty result");
                        clean_form();
                    }
                }
            }
        }