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

Tuesday, 20 May 2014

C# code for how to assign the function or method returns value to the variable




Indroduction

Now I will explain how to assign the function return value to the variable.
Use the below code
Use the below method and return the value
public decimal totalinvbuylists(decimal val1, decimal val2)
        {

            decimal response = val1 * val2;
            return decimal.Round(response, 2, MidpointRounding.AwayFromZero); ;
        }



//Pass the parameter to the method and receve the function returned value assign to the decimal value

//calculation part for totalinvbuylist

decimal Noofunit = Convert.ToDecimal(PM_Noofunit.Text);
decimal Invbuylist = Convert.ToDecimal(PM_Invbuylist.Text);
decimal calctotalinvbuylist = totalinvbuylists(Noofunit, Invbuylist);



I hope this will helpful for you! Thanks.

C# code for binding the database table in grid view (OR) C# code for edit the table data value under dataset (OR) how to edit the loaded dataset value dynamically



Indroduction
Now I will explain binding the database table in grid view (AND)
How to edit the table data value under dataset (AND) how to edit the loaded dataset value dynamically


Use the below code   and stored procedure

Stored Procedure
create procedure [dbo].[sp_bindproduct]
as begin

select *
from dbo.Product_Master

end

c# code
     
public void showgrid()
        {
//make connection to DB
            using (SqlConnection CON1 = new SqlConnection(@"Data Source=PROV-SER-001\SQLEXPRESS;Initial Catalog=Jeds;Integrated Security=True"))
            {


//call the stored procedure
                SqlCommand cmd_bindproduct = new SqlCommand("sp_bindproduct", CON1);

//execute the stored procedure

                cmd_bindproduct.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter DA = new SqlDataAdapter(cmd_bindproduct);

//load the Db value into Dataset

                DataSet DS = new DataSet();
                DA.Fill(DS);
                //check the dataset if the value is 0 then become its N/A
//check dynamically              
 for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
                {
//load the coloumn value to string variable
                    string Svdiscountcost = DS.Tables[0].Rows[i]["PM_Svdiscountcost"].ToString();

                    if (Svdiscountcost == "0" || Svdiscountcost == null)
                    {
//Assign or edit the dataset value
                        DS.Tables[0].Rows[i]["PM_Svdiscountcost"] = "N/A";
                    }

                    string DiscountGM = DS.Tables[0].Rows[i]["PM_DiscountGM"].ToString();
                    if (DiscountGM == "0" || DiscountGM == null)
                    {
//Assign or edit the dataset value

                        DS.Tables[0].Rows[i]["PM_DiscountGM"] = "N/A";
                    }

                    string discountcostpallet = DS.Tables[0].Rows[i]["PM_Totaldiscountcost"].ToString();
                    if (discountcostpallet == "0" || discountcostpallet == null)
                    {
//Assign or edit the dataset value

                        DS.Tables[0].Rows[i]["PM_Totaldiscountcost"] = "N/A";
                    }


                }
//after edit the dataset Binding to the grid view
                GridView1.DataSource = DS;
                GridView1.DataBind();
            }
        }


I hope this will helpfull for you! Thanks

C# code for Reading the XML file content

C# code for Reading the XML file content


Indroduction
Now I will explain how to Read the XML file content in c#
.use the below code

 using System.Xml;

 XmlDocument doc = new XmlDocument();
 doc.Load("C:/Config/Connection.xml")
 XmlNodeList nodeList1 = doc.ChildNodes;
 string connection = nodeList1.Item(1).InnerText.ToString();

I hope this will helpful for you!Thanks.