void LoadDeliveryType() { ChargeDetails cat = new ChargeDetails(); ddlDeliType.Items.Clear(); DataTable dt1 = cat.SelectChargeDetails(); ListItem listItem = new ListItem(); listItem.Text = "<Select Charge Type>"; listItem.Value = "0"; //listItem.Attributes.Add("style", "background-Black:white;color:White"); ddlDeliType.Items.Add(listItem); for (int i = 0; i < dt1.Rows.Count; i++) { listItem = new ListItem(); listItem.Text = dt1.Rows[i]["ChargeName"].ToString(); listItem.Value = dt1.Rows[i]["ChargeId"].ToString(); //listItem.Attributes.Add("style", "background-color:Black;color:white"); ddlDeliType.Items.Add(listItem); } }
protected void btnBuy_Click(object sender, EventArgs e) { if (Session["UserId"] == null) Response.Redirect("Login.aspx"); else { if (ddlDeliType.SelectedIndex != 0) { #region .. GET HISTORY ID .. int intHistoryId = 0; objCart = new CartDetails(); DataTable dtMax = objCart.SelectMaxID(); if (dtMax.Rows.Count > 0) { string st = dtMax.Rows[0]["HistroyId"].ToString(); if (dtMax.Rows[0]["HistroyId"].ToString() == "") intHistoryId = 0; else intHistoryId = Convert.ToInt32(dtMax.Rows[0]["HistroyId"].ToString()); } intHistoryId++; #endregion #region .. BUY DETAILS .. DataTable dtCart = objCart.SelectUserCartDetails(Convert.ToInt32(Session["UserId"].ToString())); double delPrice = 0; int intChargeId = int.Parse(ddlDeliType.SelectedItem.Value.ToString().Trim()); ChargeDetails chg = new ChargeDetails(); DataTable dt = chg.SelectChargeDetailsByID(intChargeId); string strType = ""; string strAmount = ""; if (dt.Rows.Count > 0) { strType = dt.Rows[0]["ChargeType"].ToString(); strAmount = dt.Rows[0]["AmountOrPercent"].ToString(); } double dblDeliAmount = Convert.ToDouble(strAmount); if (strType == "0") delPrice = Convert.ToDouble(decTotalPrice) + dblDeliAmount; else if (strType == "1") delPrice = Convert.ToDouble(decTotalPrice) + (Convert.ToDouble(decTotalPrice) * (dblDeliAmount / 100)); string strLocationId = ""; string strLocationName = ""; if (Session["Location"] != null) strLocationName = Session["Location"].ToString(); City objCity = new City(); DataTable dtCity = objCity.SelectCityByName(strLocationName); if (dtCity.Rows.Count > 0) strLocationId = dtCity.Rows[0]["CityId"].ToString(); else strLocationId = "0"; for (int i = 0; i < dtCart.Rows.Count; i++) { objCart.CreateBuyDetails( Convert.ToInt32(dtCart.Rows[i]["AdPostId"].ToString()), intHistoryId, Convert.ToInt32(Session["UserId"].ToString()), Convert.ToDecimal(delPrice), int.Parse(ddlDeliType.SelectedItem.Value.ToString().Trim()), Convert.ToInt32(strLocationId), "BOUGHT", 1, ddlDeliType.SelectedItem.Text.ToString().Trim(), Convert.ToInt32(strType), Convert.ToDouble(strAmount) ); objCart.UpdateCartStatus(Convert.ToInt32(dtCart.Rows[i]["AdPostId"].ToString()), Convert.ToInt32(Session["UserId"].ToString())); } decTotalPrice = 0; #endregion Response.Redirect("MyPurchases.aspx"); } else { lblError.Visible = true; lblError.Text = "Select Delivery charges"; } } }
protected void ddlDeliType_SelectedIndexChanged(object sender, EventArgs e) { if (ddlDeliType.SelectedIndex != 0) { objCart = new CartDetails(); DataTable dtCart = objCart.SelectUserCartDetails(Convert.ToInt32(Session["UserId"].ToString())); double delPrice = 0; int intChargeId = int.Parse(ddlDeliType.SelectedItem.Value.ToString().Trim()); ChargeDetails chg = new ChargeDetails(); DataTable dt = chg.SelectChargeDetailsByID(intChargeId); string strType = ""; string strAmount = ""; if (dt.Rows.Count > 0) { strType = dt.Rows[0]["ChargeType"].ToString(); strAmount = dt.Rows[0]["AmountOrPercent"].ToString(); } double dblDeliAmount = Convert.ToDouble(strAmount); if (strType == "0") delPrice = Convert.ToDouble(decTotalPrice) + dblDeliAmount; else if (strType == "1") { dblDeliAmount = (Convert.ToDouble(decTotalPrice) * (dblDeliAmount / 100)); delPrice = Convert.ToDouble(decTotalPrice) + dblDeliAmount; } //decTotalPrice = 0; trDeliAmt.Visible = true; trTotalAmt.Visible = true; lblError.Visible = false; lblDeliAmt.Text = "$ " +String.Format("{0:0.00}", dblDeliAmount); lblTotalAmt.Text = "$ " + String.Format("{0:0.00}", delPrice); } else { trDeliAmt.Visible = false; lblError.Visible = true; trTotalAmt.Visible = false; } }