I have some user areas that I will require a check to take place on, no matter which page the user logs into.
I have a login control on the master page of each protected area and I have a table that will contain a username and date.
the date should be entered when they register and a second date which is 12 months on from when they register.
What I need to do is this.
1, check one area and check - A, at 2 months before the subscription is due and display a friendly message, B at 1 month before the due date and do the same as a, then when the date runs out I want it to then automatically forward them to a payment page.
I have no idea how to write it or to implement it, can anyone help?
Thanks
Loading
David GreenPosted Feb 5, 2009, 3:20 PM
How Can I combine this to work with your code??
Also how can I get it so that on the final check ie date is today or past today, I want the page to direct them to a payment page.
protected void Page_Load(object sender, EventArgs e)
{
GetRenewal();
CompareDates();
}
protected void GetRenewal()
{
string UserName = Membership.GetUser().UserName;
// Declare Objects
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
// Read connection string
string connectionString = ConfigurationManager.ConnectionStrings["Team45"].ConnectionString;
// Initialize connection
conn = new SqlConnection(connectionString);
// Create the command
comm = new SqlCommand("SELECT RenewalDate FROM Memberships WHERE UserName = @UserName", conn);
// Add Command Parameters
comm.Parameters.AddWithValue("@UserName", Membership.GetUser().UserName);
// Enclose db code in try-catch-finally
try
{
conn.Open();
reader = comm.ExecuteReader();
// Display the data on the form
if (reader.Read())
{
RenewalLabel.Text = reader["RenewalDate"].ToString();
}
//Close the reader
reader.Close();
}
catch
{
//Display Error
//dbErrorLabel.Text = "Error finding clubid";
}
finally
{
// Close the connection
conn.Close();
}
}
protected void CompareDates()
{
DateTime dtNow = DateTime.Now.AddMonths(-11).AddDays(-5);
DateTime dtExpires = dtNow.AddMonths(12);
DateTime dtFirstWarn = dtNow.AddMonths(10);
DateTime dtSecondWarn = dtNow.AddMonths(11);
Response.Write("Signup Date: " +
dtNow.ToShortDateString() + "
");
Response.Write("Expire Date: " +
dtExpires.ToShortDateString() + "
");
Response.Write("1st Warn Date: " +
dtFirstWarn.ToShortDateString() + "
");
Response.Write("2nd Warn Date: " +
dtSecondWarn.ToShortDateString() + "
");
string message = string.Empty;
if (DateTime.Now < dtExpires)
message = "Not Expired Yet
";
if (DateTime.Now < dtExpires &&
DateTime.Now > dtFirstWarn &&
DateTime.Now < dtSecondWarn)
message = "Warning, you got two months to renew
";
if (DateTime.Now < dtExpires &&
DateTime.Now > dtFirstWarn &&
DateTime.Now > dtSecondWarn)
message = "Warning, you got one month to renew
";
if (DateTime.Now >= dtExpires)
message = "That's it, you are terminated
";
Response.Write(message);
}
}
Scott LyslePosted Jan 28, 2009, 1:22 AM
Something like this but assuming that you will write the values to the database and recover them to test for a warning message:
protected void Page_Load(object sender, EventArgs e)
{
DateTime dtNow = DateTime.Now.AddMonths(-11).AddDays(-5);
DateTime dtExpires = dtNow.AddMonths(12);
DateTime dtFirstWarn = dtNow.AddMonths(10);
DateTime dtSecondWarn = dtNow.AddMonths(11);
Response.Write("Signup Date: " +
dtNow.ToShortDateString() + "
");
Response.Write("Expire Date: " +
dtExpires.ToShortDateString() + "
");
Response.Write("1st Warn Date: " +
dtFirstWarn.ToShortDateString() + "
");
Response.Write("2nd Warn Date: " +
dtSecondWarn.ToShortDateString() + "
");
string message = string.Empty;
if (DateTime.Now < dtExpires)
message = "Not Expired Yet
";
if (DateTime.Now < dtExpires &&
DateTime.Now > dtFirstWarn &&
DateTime.Now < dtSecondWarn)
message = "Warning, you got two months to renew
";
if (DateTime.Now < dtExpires &&
DateTime.Now > dtFirstWarn &&
DateTime.Now > dtSecondWarn)
message = "Warning, you got one month to renew
";
if (DateTime.Now >= dtExpires)
message = "That's it, you are terminated
";
Response.Write(message);
}