using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; using vsilibrary.sql; using vsilibrary.functions; public partial class Member_Renew : System.Web.UI.Page { public DataTable dtUser; public int iMembershipUsers = 1; public float fMembershipAmount = 40.0f; public float fTotalAmount = 0f; public int iMonths; public float fPerMemberAmount = 40.0f; public string sSponsorshipLevel = "individual-1yr"; public bool IsSponsor = false; protected void Page_Load(object sender, EventArgs e) { this.dtUser = SqlHelper.SqlExecuteSql("SELECT * FROM People p LEFT JOIN Companies c ON p.CompanyID = c.CompanyID WHERE p.PersonID = {0}", convert.ToInt(Session["UserID"])); if (this.dtUser.Rows.Count > 0) { Functions.DistributeValues(Page, this.dtUser.Rows[0], "rs1"); this.IsSponsor = convert.ToBool(this.dtUser.Rows[0]["IsSponsor"]); } else { this.dtUser.Rows.Add(this.dtUser.NewRow()); } if (!Page.IsPostBack) { //Load Additional User List for (int i = 0; i <= 10; i++) cboAdditionalUsers.Items.Add(new ListItem(i.ToString())); if (this.IsSponsor) { //Bind Grid DataTable dtPeople = SqlHelper.SqlExecuteSql("SELECT * FROM People WHERE CompanyID={0} {1} ORDER BY IsSponsor DESC", convert.ToInt(Session["CompanyID"]), !this.IsSponsor ? String.Format(" AND PersonID={0}", this.dtUser.Rows[0]["PersonID"]) : ""); if (convert.ToString(this.dtUser.Rows[0]["SponsorshipLevel"]).IndexOf("platinum") >= 0 || convert.ToString(this.dtUser.Rows[0]["SponsorshipLevel"]).IndexOf("gold") >= 0 || convert.ToString(this.dtUser.Rows[0]["SponsorshipLevel"]).IndexOf("silver") >= 0) { this.iMembershipUsers = 4; } else { this.iMembershipUsers = 1; } cboAdditionalUsers.SelectedValue = convert.ToString(dtPeople.Rows.Count - this.iMembershipUsers); //Populate User Accounts int iPeople = 0; foreach (DataRow drPeople in dtPeople.Rows) { iPeople++; Functions.DistributeValues(Page, drPeople, String.Format("rs{0}", iPeople)); } } //Display User Fields displayUsers(iMembershipUsers + convert.ToInt(cboAdditionalUsers.SelectedValue)); //Update Prices UpdatePrice(); } else { if (rdo1.Checked) iMembershipUsers = 1; if (rdo2.Checked) iMembershipUsers = 1; if (rdo3.Checked) iMembershipUsers = 4; if (rdo4.Checked) iMembershipUsers = 4; if (rdo5.Checked) iMembershipUsers = 4; if (rdo6.Checked) iMembershipUsers = 4; if (rdo7.Checked) iMembershipUsers = 4; if (rdo8.Checked) iMembershipUsers = 4; } //Sponsorship Options plhSponsorshipOptions.Visible = plhUserAccounts.Visible = convert.ToBool(this.dtUser.Rows[0]["IsSponsor"]); //Events cmdSubmit.Click += new EventHandler(cmdSubmit_Click); cboPaymentMethod.SelectedIndexChanged += new EventHandler(cboPaymentMethod_SelectedIndexChanged); cboAdditionalUsers.SelectedIndexChanged += new EventHandler(cboAdditionalUsers_SelectedIndexChanged); } void cboAdditionalUsers_SelectedIndexChanged(object sender, EventArgs e) { //Display User Fields displayUsers(iMembershipUsers + convert.ToInt(cboAdditionalUsers.SelectedValue)); //Update Prices UpdatePrice(); } public void displayUsers(int iUsers) { trUser2.Visible = (iUsers >= 2); trUser3.Visible = (iUsers >= 3); trUser4.Visible = (iUsers >= 4); trUser5.Visible = (iUsers >= 5); trUser6.Visible = (iUsers >= 6); trUser7.Visible = (iUsers >= 7); trUser8.Visible = (iUsers >= 8); trUser9.Visible = (iUsers >= 9); trUser10.Visible = (iUsers >= 10); } public void rdo_CheckedChanged(object sender, EventArgs e) { updateSponsorship(); } public void updateSponsorship() { //switch (((RadioButton)sender).ID.ToLower()) { if (rdo1.Checked) { iMembershipUsers = 1; fMembershipAmount = 40.0f; iMonths = 12; fPerMemberAmount = 40.0f; sSponsorshipLevel = "individual-1yr"; } if (rdo2.Checked) { iMembershipUsers = 1; fMembershipAmount = 80.0f; iMonths = 24; fPerMemberAmount = 80.0f; sSponsorshipLevel = "individual-2yr"; } if (rdo3.Checked) { iMembershipUsers = 4; fMembershipAmount = 3000.0f; iMonths = 12; fPerMemberAmount = 40.0f; sSponsorshipLevel = "platinum-1yr"; } if (rdo4.Checked) { iMembershipUsers = 4; fMembershipAmount = 5500.0f; iMonths = 24; fPerMemberAmount = 80.0f; sSponsorshipLevel = "platinum-2yr"; } if (rdo5.Checked) { iMembershipUsers = 4; fMembershipAmount = 2000.0f; iMonths = 12; fPerMemberAmount = 40.0f; sSponsorshipLevel = "gold-1yr"; } if (rdo6.Checked) { iMembershipUsers = 4; fMembershipAmount = 3750.0f; iMonths = 24; fPerMemberAmount = 80.0f; sSponsorshipLevel = "gold-2yr"; } if (rdo7.Checked) { iMembershipUsers = 4; fMembershipAmount = 1750.0f; iMonths = 12; fPerMemberAmount = 40.0f; sSponsorshipLevel = "silver-1yr"; } if (rdo8.Checked) { iMembershipUsers = 4; fMembershipAmount = 3250.0f; iMonths = 24; fPerMemberAmount = 80.0f; sSponsorshipLevel = "silver-2yr"; } } //Display User Fields displayUsers(iMembershipUsers + convert.ToInt(cboAdditionalUsers.SelectedValue)); //Update Prices UpdatePrice(); } public void UpdatePrice() { this.fTotalAmount = fMembershipAmount + convert.ToInt(cboAdditionalUsers.SelectedValue) * fPerMemberAmount; lblTotalPrice.Text = this.fTotalAmount.ToString("C"); } void cboPaymentMethod_SelectedIndexChanged(object sender, EventArgs e) { switch (cboPaymentMethod.SelectedValue.ToLower()) { case "check": pnlCheckPayment.Visible = true; pnlCreditCardPayment.Visible = false; break; default: pnlCheckPayment.Visible = false; pnlCreditCardPayment.Visible = true; break; } } void cmdSubmit_Click(object sender, EventArgs e) { //Make sure page is valid if (!Page.IsValid) return; //Update Values this.updateSponsorship(); this.UpdatePrice(); //Variables int iCompanyID = convert.ToInt(Session["CompanyID"]); int iUsers = iMembershipUsers + convert.ToInt(cboAdditionalUsers.SelectedValue); DateTime oExpirationDate = DateTime.Now.AddMonths(iMonths); if (cboPaymentMethod.SelectedValue.ToLower() == "check") { oExpirationDate = DateTime.Now.AddDays(15); iMonths = 1; } int iTransactionID = Functions.ProcessTransaction(iCompanyID, sSponsorshipLevel, cboPaymentMethod.SelectedValue, this.fTotalAmount, CCNumber.Text, CCDisplayName.Text, CCExpDate.Text); if (iTransactionID == 0) { for (int i = 1; i <= iUsers; i++) UpdatePersonExpirationDate(String.Format("rs{0}", i), iMonths); /* if (sSponsorshipLevel.ToLower().IndexOf("individual") >= 0) { SqlHelper.SqlExecuteSql("UPDATE People SET ExpirationDate=CASE WHEN ExpirationDate < GETDATE() THEN '{0}' ELSE DATEADD(month,{1},ExpirationDate) END WHERE PersonID IN (SELECT TOP 1 PersonID FROM People WHERE CompanyID={2} ORDER BY PersonID ASC)", oExpirationDate, iMonths, iCompanyID); } else { SqlHelper.SqlExecuteSql("UPDATE People SET ExpirationDate=CASE WHEN ExpirationDate < GETDATE() THEN '{0}' ELSE DATEADD(month,{1},ExpirationDate) END WHERE PersonID IN (SELECT TOP 4 PersonID FROM People WHERE CompanyID={2} ORDER BY PersonID ASC)", oExpirationDate, iMonths, iCompanyID); } */ SqlHelper.SqlExecuteSql("UPDATE Companies SET ExpirationDate=CASE WHEN ExpirationDate < GETDATE() THEN '{0}' ELSE DATEADD(month,{1},ExpirationDate) END WHERE CompanyID={2}", oExpirationDate, iMonths, iCompanyID); Response.Redirect(String.Format("Renew_Confirmation.aspx?TransactionID={0}", iTransactionID)); } } public void UpdatePersonExpirationDate(string sRowPrefix, int iMonths) { string sEmail = ""; sEmail = ((TextBox)vsilibrary.functions.Reflection.FindControl(Page, String.Format("{0}_EmailPrimary", sRowPrefix))).Text; SqlHelper sqlHelper = new SqlHelper(); sqlHelper.PrimaryKey = "PersonID"; DataTable dtPeople = sqlHelper.ExecuteSql("SELECT * FROM People WHERE IsActive=1 AND EmailPrimary='{0}'", sEmail); if (dtPeople.Rows.Count == 0) sqlHelper.addRow(dtPeople); DataRow drPeople = dtPeople.Rows[0]; Functions.CollectValues(Page, drPeople, sRowPrefix); drPeople["CompanyID"] = convert.ToInt(Session["CompanyID"]); drPeople["IsActive"] = true; drPeople["Username"] = drPeople["EmailPrimary"]; if (convert.ToDate(drPeople["ExpirationDate"]) > DateTime.Now) drPeople["ExpirationDate"] = convert.ToDate(drPeople["ExpirationDate"]).AddMonths(iMonths); else drPeople["ExpirationDate"] = DateTime.Now.AddMonths(iMonths); if (convert.ToString(drPeople["ActivationDate"]) == "") drPeople["ActivationDate"] = DateTime.Now; if (convert.ToString(drPeople["UserPass"]) == "") drPeople["UserPass"] = Functions.RandomPassword(); drPeople["IsSponsor"] = (sRowPrefix.ToLower() == "rs1"); if (convert.ToString(drPeople["EmailPrimary"]) != "") { sqlHelper.Update(dtPeople); } } }