예제 #1
0
        public void LoadForSoldWindow()
        {
            try
            {
                cmd = new SqlCommand();
                con.Open();
                cmd.Connection = con;

                //location table
                cmd.CommandText = "SELECT * FROM Inventory.Product WHERE productId = @Id";
                cmd.Parameters.AddWithValue("@Id", UpdateProdId);
                _reader = cmd.ExecuteReader();

                if (_reader.Read())
                {
                    //add image to the last node
                    LtProducts.AddLast(new Product(Base64ToImage(_reader["prodImage"].ToString()),
                                                   _reader["prodName"].ToString(), Convert.ToDouble(_reader["prodPrice"].ToString()),
                                                   Convert.ToInt32(_reader["prodQty"].ToString())));
                }

                _reader.Close();
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }

            finally
            {
                con.Close();
            }
        }
예제 #2
0
        public int PrepareProductToUpdate()
        {
            try
            {
                cmd = new SqlCommand();
                con.Open();
                cmd.Connection  = con;
                cmd.CommandText = "SELECT [product].prodImage ,[product].prodName ,[product].prodPrice, [product].prodShelfLife,[location].name,[supplier].suppName, [supplier].contactNumber FROM Inventory.Product AS product INNER JOIN Inventory.Supplier AS supplier ON [product].Supplier = [supplier].suppId INNER JOIN Inventory.Location AS location  ON [location].locaId = [product].Location WHERE [product].productId = @PRODUCT_ID";

                cmd.Parameters.AddWithValue("@PRODUCT_ID", UpdateProdId);
                _reader = cmd.ExecuteReader();

                if (_reader.Read())
                {
                    LtProducts.AddLast(new Product(Base64ToImage(_reader["prodImage"].ToString()),
                                                   _reader["prodName"].ToString(),
                                                   double.Parse(_reader["prodPrice"].ToString()),
                                                   _reader["name"].ToString(), _reader["prodShelfLife"].ToString(),
                                                   _reader["suppName"].ToString(), _reader["contactNumber"].ToString()));
                }

                return(0);
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.ToString());
                return(1);
            }

            finally
            {
                con.Close();
            }
        }