public void BindData() { objmyclass.con.Open(); String cartId = cart.GetShoppingCartId(); string str; str = "SELECT dbo.Product_Master.Product_name, dbo.Product_Master.Prod_image, dbo.OrderMaster.Product_ID, dbo.OrderMaster.OrderMasterID,dbo.OrderMaster.Qty, dbo.OrderMaster.CartID,dbo.OrderMaster.Grossamount, OrderMaster.OrderMasterID,cast(dbo.OrderMaster.Price as decimal(18,2)) as Price FROM dbo.OrderMaster INNER JOIN dbo.Product_Master ON dbo.OrderMaster.Product_ID = dbo.Product_Master.Product_ID where OrderMaster.CartID='" + cartId + "'"; SqlDataAdapter da = new SqlDataAdapter(str, objmyclass.con); DataSet ds = new DataSet(); da.Fill(ds, "OrderMaster"); if (ds.Tables[0].Rows.Count > 0) { GridView1.DataSource = ds; GridView1.DataBind(); for (int i = 0; i < GridView1.Rows.Count; i++) { int prodid; prodid = Convert.ToInt32(GridView1.DataKeys[0].Value); Image imgProd = (Image)GridView1.Rows[i].FindControl("Image2"); TextBox txtqty = (TextBox)GridView1.Rows[i].FindControl("txtQty"); Label lbltotal = (Label)GridView1.Rows[i].FindControl("lbltotal"); imgProd.ImageUrl = ds.Tables[0].Rows[i]["Prod_image"].ToString(); txtqty.Text = ds.Tables[0].Rows[i]["Qty"].ToString(); total = float.Parse(ds.Tables[0].Rows[i]["Price"].ToString()) * float.Parse(ds.Tables[0].Rows[i]["Qty"].ToString()); if (total.ToString().Contains(".")) { lbltotal.Text = total.ToString(); //+ ".00"; } else { lbltotal.Text = total.ToString() + ".00"; } gtotal = gtotal + total; } if (gtotal.ToString().Contains(".")) { lblTotalAmount.Text = gtotal.ToString(); //+".00";bj } else { lblTotalAmount.Text = gtotal.ToString() + ".00"; } UpdateGrossAmount(); } else { GridView1.DataSource = null; GridView1.DataBind(); } objmyclass.con.Close(); }
protected void Page_Load(object sender, EventArgs e) { //objmyclass.con.Open(); String cartId = cart.GetShoppingCartId(); string price = ""; string msg; if (!Page.IsPostBack) { objmyclass.con.Open(); string str; str = "SELECT CartID, Product_ID FROM OrderMaster where Product_ID=" + Convert.ToInt32(Request.QueryString["pid"].ToString()) + " and CartID='" + cartId + "'"; SqlDataAdapter da = new SqlDataAdapter(str, objmyclass.con); DataSet dss = new DataSet(); da.Fill(dss, "OrderMaster"); if (dss.Tables[0].Rows.Count > 0) { msg = "Product Already Exist..!"; Response.Redirect("ShoppingCart.aspx?msg=" + msg); } else { string str1; str1 = "SELECT *, '$ ' + Rate FROM Product_Master WHERE Product_ID=" + Int32.Parse(Request.QueryString["pid"]); SqlDataAdapter da1 = new SqlDataAdapter(str1, objmyclass.con); DataSet ds = new DataSet(); da1.Fill(ds, "Product_Master"); if (ds.Tables[0].Rows.Count > 0) { price = ds.Tables[0].Rows[0]["Rate"].ToString(); } try { string strinsert; strinsert = "INSERT INTO OrderMaster(ClientId,CartID, Product_ID, Qty,price) VALUES(" + Convert.ToInt32(Session["ClientId"].ToString()) + ",'" + cartId + "', " + Int32.Parse(Request.QueryString["pid"]) + ",1," + price + ") "; // strinsert = "INSERT INTO OrderMaster(CartID, Product_ID, Qty,price,Deleteflag) VALUES('" + cartId + "', " + Int32.Parse(Request.QueryString["pid"]) + ",1," + price + ",1) "; SqlCommand cmd = new SqlCommand(strinsert, objmyclass.con); cmd.ExecuteNonQuery(); string dstrinsert; dstrinsert = "INSERT INTO BackupOrderMaster(ClientId,CartID, Product_ID, Qty,price) VALUES(" + Convert.ToInt32(Session["ClientId"].ToString()) + ",'" + cartId + "', " + Int32.Parse(Request.QueryString["pid"]) + ",1," + price + ") "; // dstrinsert = "INSERT INTO BackupOrderMaster(CartID, Product_ID, Qty,price,Deleteflag) VALUES('" + cartId + "', " + Int32.Parse(Request.QueryString["pid"]) + ",1," + price + ",1) "; SqlCommand cmd1 = new SqlCommand(dstrinsert, objmyclass.con); cmd1.ExecuteNonQuery(); objmyclass.con.Close(); objmyclass.con.Close(); msg = "Product Add to Cart Successfully..!!"; Response.Redirect("~/ShoppingCart.aspx?msg=" + msg); } catch (Exception ex) { //tran.Rollback(); } finally { objmyclass.con.Close(); } } } }