protected void Page_Load(object sender, EventArgs e) { switch (Request.QueryString["item"]) { case "ad": if (Convert.ToInt32(Request.QueryString["id"]) > 0) { if (CustomerAd.Confirm(Convert.ToInt32(Request.QueryString["id"]))) { lblThanks.Text = "Thanks for confirming your ad with us. Please allow 12 - 24 hours for your ad to be approved."; } } break; case "car": if (Convert.ToInt32(Request.QueryString["id"]) > 0) { if (CustomerVehicleInfo.Confirm(Convert.ToInt32(Request.QueryString["id"]))) { lblThanks.Text = @"Thanks for confirming your vehicle ad with us. Please allow 12 - 24 hours for your ad to be approved. "; } } break; } }
protected void GetPaid(string itemType, string aditem, string amnt, CreditCardDetailsType cc) { HttpContext CurrContext = HttpContext.Current; //amnt = "1.00"; try { DoDirectPaymentResponseType reply = DirectPayment.DoDirectPaymentAPIOperation(cc, amnt); Session["Reply"] = reply; Session["PaymentInfo"] = cc; if (reply.Ack.ToString().Trim().ToUpper().Equals("SUCCESS")) { switch (itemType) { case "car": VehiclesBilling vb = Session["VehicleBilling"] as VehiclesBilling; vb.PayPalId = reply.TransactionID; vb.PayPalState = reply.Ack.ToString(); vb.CreateTime = Convert.ToDateTime(reply.Timestamp); if (VehiclesBilling.PaidInFull(vb)) { CustomerVehicleInfo.UpdateBillingId(Convert.ToInt32(Session["VehicleId"]), vb.Id); NotifyCustomer(Convert.ToInt32(Session["VehicleId"]), itemType, vb.Payment, "0", reply.TransactionID); NotifyAdmin(Request.QueryString["item"], vb.Payment, "0", reply.TransactionID); } break; case "ad": AdsBilling ad = new AdsBilling { CustomerId = Convert.ToInt32(Session["CustomerId"]), AdId = Convert.ToInt32(Request.QueryString["id"]), Payment = Convert.ToDouble(amnt), PayPalId = reply.TransactionID, PayPalState = reply.Ack.ToString(), CreateTime = Convert.ToDateTime(reply.Timestamp) }; if (AdsBilling.InsertNewBilling(ad)) { CustomerAd.PaidInFull(ad.AdId); NotifyCustomer(ad.AdId, itemType, ad.Payment, "0", reply.TransactionID); NotifyAdmin(Request.QueryString["item"], ad.Payment, "0", reply.TransactionID); } break; } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error", " alert('Transaction failed, please check your credit card information and try again.');", true); //Server.Transfer("~/account/PaymentResponse.aspx"); } } catch (WebException ex) { CurrContext.Items.Add("Error", ex.Message); ErrorHandler.writeExceptionToLogFile(ex); } }
protected void BtnCancelCheckout_Click(object sender, EventArgs e) { CustomerVehicleInfo vi = (CustomerVehicleInfo)Session["VehicleInfo"]; List <VehicleFeatures> vf = (List <VehicleFeatures>)Session["VehicleFeatures"]; Financial fin = (Financial)Session["FinancialInfo"]; //Delete all entries bool vehicleDelete = CustomerVehicleInfo.Delete(vi.Id); bool featuresDelete = VehicleFeatures.DeleteVehicleFeatures(vi.Id); bool financialDelete = Financial.DeleteRecord(fin.Id, vi.Id); ClearSession(); Response.Redirect("~/Account/myaccount.aspx"); }
protected void GvMyVehicles_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Page") { return; } string[] args = e.CommandArgument.ToString().Split(','); int VehicleId = Convert.ToInt32(args[0]); int FinId = Convert.ToInt32(args[1]); switch (e.CommandName) { case "Edit": Response.Redirect("viewmycarad.aspx?id=" + e.CommandArgument); break; case "Remove": VehicleImage imgs = VehicleImage.SelectByVehicleId(VehicleId); if (imgs != null) { if (Directory.Exists(Server.MapPath(imgs.ImgPath))) { Directory.Delete(Server.MapPath(imgs.ImgPath)); } } if (CustomerVehicleInfo.Delete(VehicleId)) { GvMyVehicles.DataBind(); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('Your vehicle #" + e.CommandArgument + " has been deleted.');", true); } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('Failed deleteing vehicle #" + e.CommandArgument + ".');", true); } break; case "Sold": ChangeStatus(FinId, VehicleId, "Sold"); break; case "SoldButMore": ChangeStatus(FinId, VehicleId, "Sold but more"); break; default: break; } }
private void UpdateBillingAdmin(int VehicleId) { VehiclesBilling vb = Session["VehicleBilling"] as VehiclesBilling; vb.PayPalId = "Ad by admin"; vb.PayPalState = "SUCCESS"; vb.CreateTime = DateTime.Now; if (VehiclesBilling.PaidInFull(vb)) { if (CustomerVehicleInfo.UpdateBillingId(VehicleId, vb.Id)) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success", " alert('You have completed posting a vehicle/item ad for a customer.');", true); } } }
protected void Button1_Click(object sender, EventArgs e) { string query = TextBox1.Text; Label1.Text = query; bool isExecuted = CustomerVehicleInfo.ManipulateDatabase(query); if (isExecuted) { Label1.Text = "Executed successfully"; } else { Label1.Text = "Sorry could not executed"; } }
protected void NotifyCustomer(int CustomerId, int VehicleId, int FinId) { Customer c = Customer.GetCustomerDetails(CustomerId); CustomerVehicleInfo v = CustomerVehicleInfo.GetCustomerVehicleInfoDetails(VehicleId, FinId, false); StringBuilder msg = new StringBuilder(); string lnk = string.Concat("<a href='https://www.emonthlies.com/VehicleDetails.aspx?id=", VehicleId, "'>Click here</a> to view your ad."); msg.Append("<p>Hi " + c.FirstName + ",</p>"); msg.Append(string.Concat("<p>This is to confirm that your listing for: ", v.ModelYear, " ", v.Manufacturer, " ", v.Model, " has been approved.</p>")); msg.Append("<p>This posting is valid only for 90 days. "); msg.Append("If you wish to extend your ad you will have to repost.</p>"); msg.Append(lnk); if (Mailer.SendMail2Client(c.Email, msg.ToString(), "Vehicle listing approved") == false) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "info", " alert('Customer could not be notified.');", true); } }
protected void BtnDecline_Click(object sender, EventArgs e) { CustomerVehicleInfo v = Session["CurrentVehicle"] as CustomerVehicleInfo; VehiclesBilling vb = VehiclesBilling.GetVehiclesBillingDetails(v.BillingId); vb.AdsRemaining += 1; if (CustomerVehicleInfo.DeclineItem(Convert.ToInt32(Request.QueryString["id"]))) { bool remainingUpdated = VehiclesBilling.UpdateBilling(vb); AdDeclined(Convert.ToInt32(Session["Seller"].ToString()), v); Response.Redirect("~/admin/vehicles.aspx"); } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error", "alert('Failed declining ad #" + Request.QueryString["id"] + ".');", true); } }
protected void BtnApprove_Click(object sender, EventArgs e) { string[] args = Request.QueryString["id"].Split(','); int VehicleId = Convert.ToInt32(args[0]); int FinId = Convert.ToInt32(args[1]); if (CustomerVehicleInfo.SetApprovedStatus(VehicleId, FinId, true)) { Financial.ChangeAdStatus(FinId, VehicleId, true); NotifyCustomer(Convert.ToInt32(Session["Seller"].ToString()), VehicleId, FinId); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('The vehicle posting #" + Request.QueryString["id"] + " has been approved.');", true); Response.Redirect("~/admin/vehicles.aspx"); } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('Failed activating vehicle #" + Request.QueryString["id"] + ".');", true); } }
protected void AdDeclined(int CustomerId, CustomerVehicleInfo v) { Customer customer = Customer.GetCustomerDetails(CustomerId); VehiclesBilling vb = VehiclesBilling.GetVehiclesBillingDetails(v.BillingId); StringBuilder msg = new StringBuilder(); msg.Append(string.Concat("<p>RE: Your ad for ", v.ModelYear, " ", v.Manufacturer, " ", v.Model, "</p>")); msg.Append("<p>Hi " + customer.FirstName + ",</p>"); msg.Append("<p>Your ad has not been placed. It does not comply with emonthlies' advertising policies.</p>"); if (vb.PromoCode == "") { msg.Append(string.Concat("You have ", vb.AdsRemaining, " out of ", vb.AdsBought, " ads remaining in your account.")); } msg.Append("<p>Thanks for your patronage,<br />emonthlies</p>"); if (Mailer.SendMail2Client(customer.Email, msg.ToString(), "Ad info") == false) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "info", " alert('Customer could not be notified.');", true); } }
protected void GvMyVehicles_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (Session["CustomerType"].ToString() == "Business") { GvMyVehicles.Columns[8].Visible = true; CustomerVehicleInfo c = e.Row.DataItem as CustomerVehicleInfo; ImageButton BtnModify = e.Row.FindControl("BtnModify") as ImageButton; ImageButton BtnSold = e.Row.FindControl("BtnSold") as ImageButton; ImageButton BtnSoldb = e.Row.FindControl("BtnSoldMore") as ImageButton; Label soldLabel = e.Row.FindControl("lblItemSold") as Label; switch (c.Status) { case "Sold": BtnModify.Visible = false; BtnSold.Visible = false; BtnSoldb.Visible = false; soldLabel.Visible = true; break; case "BtnSoldMore": BtnModify.Visible = true; BtnSold.Visible = true; BtnSoldb.Visible = false; soldLabel.Visible = false; break; case "": BtnModify.Visible = true; BtnSold.Visible = true; BtnSoldb.Visible = true; soldLabel.Visible = false; break; } } else { GvMyVehicles.Columns[9].Visible = false; } } }
protected void BtnUpdateCar_Click(object sender, EventArgs e) { CustomerVehicleInfo cvi = new CustomerVehicleInfo(); Financial f = new Financial(); cvi.Id = Convert.ToInt32(lblVehicleId.Text); cvi.VehicleCategoryId = Convert.ToInt16(rblVehicleType.SelectedValue); cvi.ModelYear = Convert.ToInt16(ddlYear.SelectedValue); cvi.Manufacturer = DdlMakes.SelectedValue; cvi.Model = DdlModel.SelectedValue; cvi.Expires = DateTime.Now.AddMonths(3); f.VehicleId = cvi.Id; f.PurchasePrice = Helpers.ConvertNullDblToZero(txtPurchasePrice.Text); f.PaymentCycle = ddlPayCycle.SelectedValue; f.PaymentWithTax = Convert.ToDouble(txtMonthlyWithTax.Text); if (DdlTrim.Enabled) { cvi.ModelTrim = Convert.ToInt32(DdlTrim.SelectedValue); cvi.OtherTrim = string.Empty; if (DdlTrim.SelectedItem.Text.Equals("Other")) { cvi.OtherTrim = TxtModelTrim.Text; } } else { cvi.ModelTrim = 60931; } if (CustomerVehicleInfo.RepostSelectedVehicle(cvi)) { if (Financial.UpdatePrice(f)) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('The ad #" + cvi.Id + " has been reposted.');", true); GvVehicles.DataBind(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('Failed reposting ad #" + cvi.Id + ".');", true); } }
protected void BtnSaveVehicle_Click(object sender, EventArgs e) { if (Page.IsValid) { string[] cYears = { DateTime.Now.Year.ToString(), (DateTime.Now.Year + 1).ToString() }; CustomerVehicleInfo vi = new CustomerVehicleInfo(); DateTime AdExpiry = DateTime.Now.AddMonths(1); //new DateTime(DateTime.Now.Month==12?DateTime.Now.Year+1:DateTime.Now.Year, DateTime.Now.Month==12?1:DateTime.Now.Month+1, DateTime.Now.Day); vi.Id = 0; vi.Seller = Usr.Id; vi.VehicleCondition = rblCondition.SelectedValue; vi.VehicleCategoryId = Convert.ToInt16(rblVehicleType.SelectedValue); vi.ModelYear = Convert.ToInt16(ddlYear.SelectedValue); if (DdlMakes.SelectedItem.Text.Equals("Other")) { vi.Manufacturer = "Other"; vi.OtherMake = TxtMakeOther.Text; vi.Model = "Other"; vi.OtherModel = TxtModelOther.Text; vi.ModelTrim = 60931; vi.OtherTrim = TxtModelTrim.Text; } else { vi.Manufacturer = DdlMakes.SelectedValue; vi.OtherMake = string.Empty; } if (DdlModel.Enabled) { if (DdlModel.SelectedItem.Text.Equals("Other")) { vi.Model = "Other"; vi.OtherModel = TxtModelOther.Text; vi.ModelTrim = 60931; vi.OtherTrim = TxtModelTrim.Text; } else { vi.Model = DdlModel.SelectedValue; vi.OtherModel = string.Empty; } } if (DdlTrim.Enabled) { vi.ModelTrim = Convert.ToInt32(DdlTrim.SelectedValue); vi.OtherTrim = string.Empty; if (DdlTrim.SelectedItem.Text.Equals("Other")) { vi.OtherTrim = TxtModelTrim.Text; } } else { vi.ModelTrim = 60931; vi.OtherTrim = string.Empty; } vi.ExteriorColor = ddlBodyColour.SelectedValue; vi.InteriorColor = ddlInteriorColour.SelectedValue; vi.CurrentMileage = Convert.ToInt32(txtMileage.Text); vi.FuelType = ddlFuel.SelectedValue; vi.Transmission = ddlTransmission.SelectedValue; vi.Wheels = ddlWheels.SelectedValue; vi.ChromeWheels = cbxChrome.Checked; vi.Tires = ddlTires.SelectedValue; vi.ExtraWinterTires = cbxWinterTires.Checked; vi.Expires = AdExpiry; //if (cYears.Contains(ddlYear.SelectedItem.Text)) //{ // vi.Expires = DateTime.Now.AddYears(1); //} //else //{ // vi.Expires = DateTime.Now.AddMonths(3); //} vi.Comments = Server.HtmlEncode(txtComments.Text); //if (Session["Role"].ToString() == "admin") //{ vi.Approved = true; vi.Confirmed = true; //} //else //{ // vi.Approved = true; // vi.Confirmed = false; //} vi.Displacement = txtDisplacement.Text; vi.Updated = DateTime.Now; Session["VehicleInfo"] = vi; Session["VehicleFeatures"] = GetFeatures(); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "$( '#tabs' ).tabs({ active: 1 });$( '#tabs' ).tabs('enable', 1);$( '#tabs' ).tabs({ disabled: [2] });", true); } }
protected void LoadVehicleData(int VehicleId, int FinId) { int[] cars = { 22, 23, 26, 27, 30, 34, 35, 38 }; int[] suvs = { 25, 32, 36 }; int[] trucks = { 24, 28, 37 }; string selectedVtype = string.Empty; if (Request.QueryString["update"] != null) { ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Success", "alert('Picture/video files updated.');", true); } CustomerVehicleInfo vehicle = CustomerVehicleInfo.GetCustomerVehicleInfoDetails(VehicleId, FinId, false); if (vehicle != null) { BindFeatures(); if (cars.Contains(vehicle.VehicleCategoryId)) { selectedVtype = "22"; } else if (suvs.Contains(vehicle.VehicleCategoryId)) { selectedVtype = "25"; } else if (trucks.Contains(vehicle.VehicleCategoryId)) { selectedVtype = "24"; } else { selectedVtype = vehicle.VehicleCategoryId.ToString(); } rblCondition.SelectedValue = vehicle.VehicleCondition; rblVehicleType.SelectedValue = selectedVtype; ddlYear.SelectedValue = vehicle.ModelYear.ToString(); DdlMakes.SelectedValue = vehicle.Manufacturer; if (vehicle.Manufacturer.Equals("Other")) { TxtMakeOther.Enabled = true; TxtMakeOther.Visible = true; TxtMakeOther.Text = vehicle.OtherMake; RfvMakeOther.Enabled = true; RfvMakeOther.Visible = true; } else { TxtMakeOther.Enabled = false; TxtMakeOther.Visible = false; RfvMakeOther.Enabled = false; RfvMakeOther.Visible = false; } BindModelDdl(vehicle.Manufacturer, vehicle.Model, vehicle.OtherModel); DdlModel.SelectedValue = vehicle.Model; BindTrim(vehicle.Manufacturer, vehicle.Model, vehicle.ModelTrim.ToString()); if (vehicle.Model == "Other") { TxtModelOther.Enabled = true; TxtModelOther.Visible = true; TxtModelOther.Text = vehicle.OtherModel; TxtModelTrim.Visible = true; TxtModelTrim.Enabled = true; //TxtModelTrim.Visible = true; //TxtModelTrim.Text = vehicle.OtherTrim; } else { TxtModelOther.Enabled = false; TxtModelOther.Visible = false; TxtModelTrim.Visible = false; TxtModelTrim.Enabled = false; DdlTrim.SelectedValue = vehicle.ModelTrim.ToString(); } if (DdlTrim.SelectedValue == "60931") { RfvTrim.Enabled = true; RfvTrim.Visible = true; TxtModelTrim.Enabled = true; TxtModelTrim.Visible = true; TxtModelTrim.Text = vehicle.OtherTrim; RfvTxtTrim.Enabled = true; RfvTxtTrim.Visible = true; } else { RfvTrim.Enabled = false; RfvTrim.Visible = false; RfvTxtTrim.Enabled = false; RfvTxtTrim.Visible = false; TxtModelTrim.Text = string.Empty; TxtModelTrim.Enabled = false; TxtModelTrim.Visible = false; } RfvModelOther.Enabled = false; RfvModelOther.Visible = false; txtDisplacement.Text = vehicle.Displacement; ddlBodyColour.SelectedValue = vehicle.ExteriorColor; ddlInteriorColour.Enabled = true; rfvInterior.Enabled = false; ddlInteriorColour.SelectedValue = vehicle.InteriorColor; ddlFuel.SelectedValue = vehicle.FuelType; txtMileage.Text = vehicle.CurrentMileage.ToString(); ddlTransmission.SelectedValue = vehicle.Transmission; ddlWheels.SelectedValue = vehicle.Wheels; cbxChrome.Checked = vehicle.ChromeWheels; ddlTires.SelectedValue = vehicle.Tires; cbxWinterTires.Checked = vehicle.ExtraWinterTires; List <VehicleFeatures> vf = VehicleFeatures.SelectAllByVehicleId(vehicle.Id); foreach (VehicleFeatures feature in vf) { foreach (Control c in pnlFeatures.Controls) { if (c is DropDownList) { DropDownList ddl = (DropDownList)c; foreach (ListItem item in ddl.Items) { if (item.Value == feature.FeatureId.ToString()) { item.Selected = true; continue; } } } if (c is CheckBoxList) { CheckBoxList cbx = (CheckBoxList)c; foreach (ListItem item in cbx.Items) { if (item.Value == feature.FeatureId.ToString()) { item.Selected = true; } } } } } txtComments.Text = vehicle.Comments; Session["AdExpiry"] = vehicle.Expires; Financial ltd = Financial.GetFinancialDetailsByVehicleId(vehicle.Id, FinId); Session["LeaseId"] = ltd.Id; rblLeaseOrFinance.SelectedValue = ltd.LeaseOrFinance; switch (ltd.LeaseOrFinance) { case "l": pnlFinancialInfo.Enabled = true; rfvPayCycle.Enabled = true; rfvMonthly.Enabled = true; txtLeaseExpiry.Enabled = true; txtKmAllowance.Enabled = true; txtExcessKmCharge.Enabled = true; txtBalloon.Enabled = false; txtBalloon.Text = string.Empty; txtBuyBack.Enabled = true; txtSecurityDeposit.Enabled = true; ddlPurchaseOpEndOfLease.Enabled = true; break; case "f": pnlFinancialInfo.Enabled = true; rfvPayCycle.Enabled = true; rfvMonthly.Enabled = true; txtLeaseExpiry.Enabled = false; txtLeaseExpiry.Text = string.Empty; txtKmAllowance.Enabled = false; txtKmAllowance.Text = string.Empty; txtExcessKmCharge.Enabled = false; txtExcessKmCharge.Text = string.Empty; txtSecurityDeposit.Enabled = false; txtBalloon.Enabled = true; txtBuyBack.Enabled = false; txtBuyBack.Text = string.Empty; ddlPurchaseOpEndOfLease.Enabled = false; ddlPurchaseOpEndOfLease.ClearSelection(); break; case "c": pnlFinancialInfo.Enabled = false; rfvPayCycle.Enabled = false; rfvMonthly.Enabled = false; ddlPurchaseOpEndOfLease.ClearSelection(); txtLeaseExpiry.Text = string.Empty; txtKmAllowance.Text = string.Empty; txtBalloon.Text = string.Empty; txtBuyBack.Text = string.Empty; txtExcessKmCharge.Text = string.Empty; break; } ddlPayCycle.SelectedValue = ltd.PaymentCycle; txtMonthlyWithTax.Text = ltd.PaymentWithTax.ToString(); txtOriginalDown.Text = ltd.OriginalDown.ToString(); txtSecurityDeposit.Text = ltd.SecurityDeposit.ToString(); ddlPurchaseOpEndOfLease.SelectedValue = ltd.PoEndOfLease; txtKmAllowance.Text = ltd.KmAllowance.ToString(); txtExcessKmCharge.Text = ltd.ExcessKmCharge.ToString(); txtOriginalLeaseTerm.Text = ltd.LeaseTerm.ToString(); txtLeaseExpiry.Text = (ltd.LeaseExpiry == null) ? "" : ltd.LeaseExpiry.ToString(); txtBuyBack.Text = ltd.BuyBack.ToString(); txtBalloon.Text = ltd.Balloon.ToString(); txtPurchasePrice.Text = ltd.PurchasePrice.ToString(); txtSummary.Text = Server.HtmlDecode(ltd.Summary); VehicleImage imgs = VehicleImage.SelectByVehicleId(vehicle.Id); Session["imgs"] = imgs; PlaceImages(imgs); } }
protected void BtnSaveVehicle_Click(object sender, EventArgs e) { string[] cYears = { DateTime.Now.Year.ToString(), (DateTime.Now.Year + 1).ToString() }; if (Page.IsValid) { Customer usr = (Customer)Session["User"]; CustomerVehicleInfo vi = new CustomerVehicleInfo(); DateTime AdExpiry = new DateTime(DateTime.Now.Year, 12, 31); //(DateTime)Session["AdExpiry"]; vi.Id = VehicleId; vi.Seller = usr.Id; vi.VehicleCondition = rblCondition.SelectedValue; vi.ModelYear = Convert.ToInt16(ddlYear.SelectedValue); vi.VehicleCategoryId = Convert.ToInt16(rblVehicleType.SelectedValue); if (DdlMakes.SelectedItem.Text.Equals("Other")) { vi.Manufacturer = "Other"; vi.OtherMake = TxtMakeOther.Text; vi.Model = "Other"; vi.OtherModel = TxtModelOther.Text; vi.ModelTrim = 60931; vi.OtherTrim = TxtModelTrim.Text; } else { vi.Manufacturer = DdlMakes.SelectedValue; vi.OtherMake = string.Empty; } if (DdlModel.Enabled) { if (DdlModel.SelectedItem.Text.Equals("Other")) { vi.Model = "Other"; vi.OtherModel = TxtModelOther.Text; vi.ModelTrim = 60931; vi.OtherTrim = TxtModelTrim.Text; } else { vi.Model = DdlModel.SelectedValue; vi.OtherModel = string.Empty; } } if (DdlTrim.Enabled) { vi.ModelTrim = Convert.ToInt32(DdlTrim.SelectedValue); vi.OtherTrim = string.Empty; if (DdlTrim.SelectedItem.Text.Equals("Other")) { vi.OtherTrim = TxtModelTrim.Text; } } else { vi.ModelTrim = 60931; } vi.ExteriorColor = ddlBodyColour.SelectedValue; vi.InteriorColor = ddlInteriorColour.SelectedValue; vi.FuelType = ddlFuel.SelectedValue; vi.Transmission = ddlTransmission.SelectedValue; vi.CurrentMileage = Convert.ToInt32(txtMileage.Text); vi.Wheels = ddlWheels.SelectedValue; vi.ChromeWheels = cbxChrome.Checked; vi.Tires = ddlTires.SelectedValue; vi.ExtraWinterTires = cbxWinterTires.Checked; vi.Expires = AdExpiry; //if (cYears.Contains(vi.ModelYear.ToString()) && AdExpiry > DateTime.Now.AddMonths(3)) //{ // vi.Expires = AdExpiry; //} //else //{ // vi.Expires = DateTime.Now.AddMonths(3); //} vi.Comments = Server.HtmlEncode(txtComments.Text); vi.Displacement = txtDisplacement.Text; vi.Updated = DateTime.Now; Session["VehicleInfo"] = vi; Session["VehicleId"] = vi.Id; Session["VehicleFeatures"] = GetFeatures(); bool saveVI = CustomerVehicleInfo.UpdateCustomerVehicleInfo(vi); if (saveVI) { if (VehicleFeatures.DeleteVehicleFeatures(vi.Id)) { if (VehicleFeatures.InsertNewVehicleFeatures(GetFeatures(), vi.Id)) { LoadVehicleData(vi.Id, FinId); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Next", "$('#vtabs li:eq(1) a').tab('show'); alert('Vehicle information updated.');", true); } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error", "alert('Update failed.'); $('#vtabs li:eq(0) a').tab('show');", true); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error", "alert('Update failed.'); $('#vtabs li:eq(0) a').tab('show');", true); } } } }
private void DoCheckout() { CustomerVehicleInfo vi = (CustomerVehicleInfo)Session["VehicleInfo"]; List <VehicleFeatures> vf = (List <VehicleFeatures>)Session["VehicleFeatures"]; Financial fin = (Financial)Session["FinancialInfo"]; //Customer usr = (Customer)Session["User"]; VehiclesBilling vb = new VehiclesBilling { CustomerId = Usr.Id }; if (Session["Role"].ToString() == "admin") { vb.Payment = 0.99; vb.AdsBought = 1; } else { if (Usr.CustomerType == "Business") { vb.AdsBought = Convert.ToInt16(rblPricing.SelectedValue); switch (rblPricing.SelectedValue) { case "1": vb.Payment = 19.99; break; case "8": vb.Payment = 89.99; vb.AdsRemaining = 7; break; case "20": vb.Payment = 199.99; vb.AdsRemaining = 19; break; } } else { vb.Payment = 0.99; vb.AdsBought = 1; } } vb.PromoCode = string.Empty; int billingId = VehiclesBilling.InsertNewBilling(vb); vb.Id = billingId; if (billingId > 0) { Session["VehicleBilling"] = vb; if (Session["Role"].ToString() == "admin") { UpdateBillingAdmin(vi.Id); Response.Redirect("~/admin/vehicles.aspx"); } else { Response.Redirect("CheckOut.aspx?item=car&size=" + vb.AdsBought + "&adtype=" + Usr.CustomerType + "&promo=" + BoolToInt(IsPromo) + "&id=" + billingId); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error", " alert('Failed inserting billing informtation.');", true); } }
protected void BtnSaveImages_Click(object sender, EventArgs e) { string err = ImageErr(); if (err != string.Empty) { pnlErr.Visible = true; lblErr.Text = "<ul>" + err + "</ul><p>Please upload files with correct file-formats.</p>"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Complete", "$( '#tabs' ).tabs({ active: 2 });", true); return; } HttpFileCollection files = Request.Files; CustomerVehicleInfo vi = (CustomerVehicleInfo)Session["VehicleInfo"]; List <VehicleFeatures> vf = (List <VehicleFeatures>)Session["VehicleFeatures"]; Financial fin = (Financial)Session["FinancialInfo"]; VehicleImage imgs = new VehicleImage(); int VehicleId = CustomerVehicleInfo.InsertNewCustomerVehicleInfo(vi); //Customer usr = (Customer)Session["User"]; string path = Usr.Id + "_v" + VehicleId; bool featuresok; string[] allowedExtension = { ".jpeg", ".jpg", ".png", ".gif" }; string[] videoExtensions = { ".avi", ".mov", ".wmv", ".mp4", ".mpg" }; #pragma warning disable CS0219 // Variable is assigned but its value is never used bool biWeeklyPosted = false; #pragma warning restore CS0219 // Variable is assigned but its value is never used if (VehicleId > 0) { vi.Id = VehicleId; Session["VehicleInfo"] = vi; Session["VehicleId"] = VehicleId; featuresok = InsertFeatures(vf, VehicleId); if (!featuresok) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error", "alert('Error adding vehicle features.');", true); return; } fin.VehicleId = VehicleId; int fid = Financial.InsertNewFinancialDetails(fin); if (fid > 0) { if (pnlBiWeekly.Visible) { fin.Id = 0; fin.PaymentCycle = "Bi-weekly"; fin.PaymentWithTax = Convert.ToDouble(txtBiWeeklyWithTax.Text); int bwfid = Financial.InsertNewFinancialDetails(fin); if (bwfid > 0) { biWeeklyPosted = true; } } imgs.VehicleId = VehicleId; imgs.ImgPath = path; if (FileUpload1.HasFile) { imgs.Img1 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload1.PostedFile.FileName)); } if (FileUpload2.HasFile) { imgs.Img2 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload2.PostedFile.FileName)); } ; if (FileUpload3.HasFile) { imgs.Img3 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload3.PostedFile.FileName)); } ; if (FileUpload4.HasFile) { imgs.Img4 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload4.PostedFile.FileName)); } ; if (FileUpload5.HasFile) { imgs.Img5 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload5.PostedFile.FileName)); } ; if (FileUpload6.HasFile) { imgs.Img6 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload6.PostedFile.FileName)); } ; if (FileUpload7.HasFile) { imgs.Img7 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload7.PostedFile.FileName)); } ; if (FileUpload8.HasFile) { imgs.Img8 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload8.PostedFile.FileName)); } ; if (FileUpload10.HasFile) { imgs.Img9 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload10.PostedFile.FileName)); } ; if (FileUpload11.HasFile) { imgs.Img10 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload11.PostedFile.FileName)); } ; if (FileUpload12.HasFile) { imgs.Img11 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload12.PostedFile.FileName)); } ; if (FileUpload13.HasFile) { imgs.Img12 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload13.PostedFile.FileName)); } ; if (FileUpload14.HasFile) { imgs.Img13 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload14.PostedFile.FileName)); } ; if (FileUpload15.HasFile) { imgs.Img14 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload15.PostedFile.FileName)); } ; if (FileUpload16.HasFile) { imgs.Img15 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload16.PostedFile.FileName)); } ; if (FileUpload17.HasFile) { imgs.Img16 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload17.PostedFile.FileName)); } ; if (FileUpload18.HasFile) { imgs.Img17 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload18.PostedFile.FileName)); } ; if (FileUpload19.HasFile) { imgs.Img18 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload19.PostedFile.FileName)); } ; if (FileUpload20.HasFile) { imgs.Img19 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload20.PostedFile.FileName)); } ; if (FileUpload21.HasFile) { imgs.Img20 = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload21.PostedFile.FileName)); } ; if (ddlVideoSource.SelectedIndex == 1) { if (FileUpload9.HasFile) { imgs.Video = @"/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(FileUpload9.PostedFile.FileName)); imgs.VideoFormat = FileUpload9.PostedFile.ContentType; } } Session["Images"] = imgs; bool filesuploaded = false; try { if (files.Count > 0) { Directory.SetCurrentDirectory(Server.MapPath("~/imgs")); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } for (var i = 0; i < files.Count; i++) { if (files[i].FileName == "") { continue; } if (allowedExtension.Contains(Path.GetExtension(files[i].FileName))) { HttpPostedFile pf = files[i]; string filetoput = Server.MapPath("~/imgs/" + path + "/" + Helpers.RemoveInvalidChars(Path.GetFileName(files[i].FileName))); SaveFile(pf, filetoput); } } } filesuploaded = VehicleImage.InsertNewVehicleImage(imgs); } catch (Exception ex) { ErrorHandler.writeExceptionToLogFile(ex); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error", "alert('Pictures could not be uploaded.');", true); filesuploaded = false; } if (filesuploaded) { VehiclesBilling vb = Session["CurrentBilling"] as VehiclesBilling; pnlDetails.Visible = false; if (Session["Role"].ToString() == "admin") { DoCheckout(); } else { if (Usr.CustomerType == "Business") { if ((bool)Session["adsRemaining"] == false) { pnlCheckout.Visible = true; } else { pnlCheckout.Visible = false; vb.AdsRemaining -= 1; if (VehiclesBilling.UpdateBilling(vb)) { if (CustomerVehicleInfo.UpdateBillingId(vi.Id, vb.Id)) { NotifyAdmin(Usr); NotifyCustomer(Usr, vb, VehicleId); ltlRemaining.Text = string.Concat("<p class='text-info bold'>You have ", vb.AdsRemaining, " out of ", vb.AdsBought, " ads remaining.</p>"); Response.Redirect("~/account/myaccount.aspx"); } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error", "alert('An error occurred');", true); } } } } } } } } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString.Keys.Count > 0) { if (Request.QueryString["promo"] != null) { if (Request.QueryString["promo"] == "1" && Request.QueryString["adtype"] == "Private") { CustomerVehicleInfo vi = (CustomerVehicleInfo)Session["VehicleInfo"]; VehiclesBilling vb = Session["VehicleBilling"] as VehiclesBilling; if (CustomerVehicleInfo.UpdateBillingId(vi.Id, vb.Id)) { NotifyCustomer(vi.Id, Request.QueryString["item"], 0.99, "1", ""); NotifyAdmin(Request.QueryString["item"], 0, "1", ""); } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Error", "alert('An error occurred');", true); } } } if (!IsPostBack) { BindYear(); switch (Request.QueryString["item"]) { case "ad": switch (Request.QueryString["size"]) { case "L": lblItem.Text = "Large Ad (rotating banner)"; txtPayment.Text = "599.00"; break; case "S": lblItem.Text = "Small Ad (rotating images)"; txtPayment.Text = "299.00"; break; } break; case "car": switch (Request.QueryString["size"]) { case "1": lblItem.Text = "1 vehicle"; switch (Request.QueryString["adtype"]) { case "Business": txtPayment.Text = "19.99"; break; case "Private": txtPayment.Text = "0.99"; break; } break; case "8": lblItem.Text = "8 vehicles"; txtPayment.Text = "89.99"; break; case "20": lblItem.Text = "20 vehicles"; txtPayment.Text = "199.99"; break; } break; } } } }
protected void GvVehicles_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Page") { return; } string[] args = e.CommandArgument.ToString().Split(','); int VehicleId = Convert.ToInt32(args[0]); int FinId = Convert.ToInt32(args[1]); //string declined = args[2]; switch (e.CommandName) { case "Activate": Response.Redirect("~/admin/reviewvehicle.aspx?id=" + e.CommandArgument); break; case "Deactivate": if (CustomerVehicleInfo.SetApprovedStatus(VehicleId, FinId, false)) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('The ad #" + VehicleId + " has been deactivated.');", true); GvVehicles.DataBind(); } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('Failed deleteing ad #" + VehicleId + ".');", true); } break; case "Repost": lblVehicleId.Text = e.CommandArgument.ToString(); CustomerVehicleInfo cvi = CustomerVehicleInfo.GetCustomerVehicleInfoDetails(VehicleId, FinId, false); Financial f = Financial.GetFinancialDetailsByVehicleId(VehicleId, FinId); int[] cars = { 22, 23, 26, 27, 30, 34, 35, 38 }; int[] suvs = { 25, 32, 36 }; int[] trucks = { 24, 28, 37 }; string selectedVtype = string.Empty; if (cars.Contains(cvi.VehicleCategoryId)) { selectedVtype = "22"; } else if (suvs.Contains(cvi.VehicleCategoryId)) { selectedVtype = "25"; } else if (trucks.Contains(cvi.VehicleCategoryId)) { selectedVtype = "24"; } BindModelDdl(cvi.Manufacturer, cvi.Model, cvi.OtherModel); rblVehicleType.SelectedValue = selectedVtype; ddlYear.SelectedValue = cvi.ModelYear.ToString(); DdlMakes.SelectedValue = cvi.Manufacturer; if (cvi.Manufacturer.Equals("Other")) { TxtMakeOther.Enabled = true; TxtMakeOther.Visible = true; TxtMakeOther.Text = cvi.OtherMake; } DdlModel.SelectedValue = cvi.Model; if (cvi.Model == "Other") { TxtModelOther.Enabled = true; TxtModelOther.Visible = true; TxtModelTrim.Visible = true; TxtModelTrim.Enabled = true; TxtModelTrim.Text = cvi.OtherTrim; DdlTrim.Enabled = false; DdlTrim.Visible = false; } else { TxtModelTrim.Visible = false; TxtModelTrim.Enabled = false; DdlTrim.Enabled = true; DdlTrim.Visible = true; BindTrim(cvi.Manufacturer, cvi.Model, cvi.ModelTrim.ToString()); DdlTrim.SelectedValue = cvi.ModelTrim.ToString(); } txtPurchasePrice.Text = f.PurchasePrice.ToString(); ddlPayCycle.SelectedValue = f.PaymentCycle; txtMonthlyWithTax.Text = f.PaymentWithTax.ToString(); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", " $('#myModal').modal('show');", true); break; default: break; } }