Wednesday, 21 May 2014

C# code for how to maintain the product Price history from the site admin

Indroduction

Now I will explain how to maintain the product Price history from the site admin.Let me explain the scenario like
“We have a all the product with essential details in the website. But  today the product price is some amount like 10 k after two month the site admin want to increase or change  the product price and also the site admin  want to maintain a entire price update history in database  not only last price history..That situation will go for below code”
Use the below C# code and Stored Procedure

Stored Procedure

Create procedure [dbo].[sp_pricehistory]

@upc bigint,
@pricedate date,
@changedprice money

AS
BEGIN
--Price update history start
if exists (select PM_Invbuylist from  Product_Master where PM_Invbuylist=@changedprice and PM_UPC =@upc)
begin
print 'not insert'
return -1
end

else
begin
print 'insert'

DECLARE @oldpricey money

SELECT @oldpricey = (select PM_Invbuylist from dbo.Product_Master where PM_UPC=@upc)

print @oldpricey

 insert into Price_History
(
PM_UPC,
PM_Pricechangedate,
PM_Changedprice

)
values
(
@upc,
@pricedate,
@oldpricey
                   
)
end
                                         

END


C# code to execute the stored procedure and changed price will stored or maintain in the other table
        
/// <summary>
        /// price history maintenence
        /// </summary>
        /// <param name="upc"></param>
        /// <param name="date"></param>
        /// <param name="price"></param>

        public void price_history(long upc, string date, string price)
        {
            if (CONNECTION.State == ConnectionState.Closed)
            {
                CONNECTION.Open();
            }
            SqlCommand cmd = new SqlCommand("sp_pricehistory", CONNECTION);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@upc", upc);
            cmd.Parameters.AddWithValue("@pricedate", DateTime.Today.ToString());
            cmd.Parameters.AddWithValue("@changedprice", price);
            cmd.ExecuteNonQuery();
        }


 I hope this will helpful for you! thanks

No comments:

Post a Comment