Exemplo n.º 1
0
        public bool updateRegisterSale(SaleProductModel sale)
        {
            string        query = "UPDATE saleProduct SET idProduct = @idProduct, idStore = @idStore, quantity = @quantity, total = @total WHERE id = @id";
            SqlConnection conn  = new SqlConnection(cadena);
            SqlCommand    cmd   = new SqlCommand(query, conn);

            try
            {
                conn.Open();
                cmd.Parameters.Add("@id", System.Data.SqlDbType.Int).Value         = sale.id;
                cmd.Parameters.Add("@idProduct", System.Data.SqlDbType.Int).Value  = sale.idProduct;
                cmd.Parameters.Add("@idStore", System.Data.SqlDbType.Money).Value  = sale.idStore;
                cmd.Parameters.Add("@quantity", System.Data.SqlDbType.Int).Value   = sale.quantity;
                cmd.Parameters.Add("@discount", System.Data.SqlDbType.Float).Value = sale.discount;
                cmd.Parameters.Add("@total", System.Data.SqlDbType.Money).Value    = sale.total;

                int register = cmd.ExecuteNonQuery();

                return(register == 1);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                conn.Close();
            }
        }
Exemplo n.º 2
0
        public SaleProductModel returnRegisterSale(int id)
        {
            string           query = "SELECT idProduct, idStore, quantity, discount, total FROM saleProduct WHERE id = @id";
            SqlConnection    conn  = new SqlConnection(cadena);
            SqlCommand       cmd   = new SqlCommand(query, conn);
            SaleProductModel sale  = new SaleProductModel();


            try
            {
                conn.Open();
                cmd.Parameters.Add("@id", System.Data.SqlDbType.Int).Value = id;
                SqlDataReader dr = cmd.ExecuteReader();


                if (dr.Read())
                {
                    sale.idProduct = dr.GetInt32(0);
                    sale.idStore   = dr.GetInt32(1);
                    sale.quantity  = dr.GetInt32(2);
                    sale.discount  = dr.GetDouble(3);
                    sale.total     = dr.GetDecimal(4);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                conn.Close();
            }
            return(sale);
        }
Exemplo n.º 3
0
        public bool createRegisterSale(SaleProductModel sale)
        {
            string        query = "INSERT INTO saleProduct VALUES(@idProduct, @idStore, @quantity, @discount, @total, GETDATE())";
            SqlConnection conn  = new SqlConnection(cadena);
            SqlCommand    cmd   = new SqlCommand(query, conn);

            try
            {
                conn.Open();
                cmd.Parameters.Add("@idProduct", System.Data.SqlDbType.Int).Value  = sale.idProduct;
                cmd.Parameters.Add("@idStore", System.Data.SqlDbType.Money).Value  = sale.idStore;
                cmd.Parameters.Add("@quantity", System.Data.SqlDbType.Int).Value   = sale.quantity;
                cmd.Parameters.Add("@discount", System.Data.SqlDbType.Float).Value = sale.discount;
                cmd.Parameters.Add("@total", System.Data.SqlDbType.Money).Value    = sale.total;

                int register = cmd.ExecuteNonQuery();
                return(register == 1);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                conn.Close();
            }
        }