Click here to Skip to main content
15,894,343 members

How to reset a variable in every week on monday?

SanSkun asked:

Open original thread
Hi Friends,
I have one requirement like to send 25 mail every week.So what i did,I took one count and made count++ on sending every mail.When it reached to 25 it displays alert already crossed limit for this week.But my problem is that how to reset that count on start of the week i.e on Monday.
Here some code that i have written.
C#
try
        {
            string body = "";
            string tbl_custInfo = "";
            int countno1=1;
            int countno=1;
            string xmlfile = Server.MapPath("App_code/count.xml").Trim().ToLower();
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(xmlfile);

            XmlNodeList CountNodeList = xmldoc.SelectNodes("//section");

            foreach (XmlNode CountNode in CountNodeList)
            {
                if (CountNode.HasChildNodes)
                {
                    countno =Convert.ToInt32(CountNode.ChildNodes[0].InnerText.Trim().ToLower());
             
             var testDay = DateTime.Now.DayOfWeek.ToString();
             //if (testDay == "Sunday")
             //if (testDay == "Monday" && countno != 1)
             //{

             //    CountNode.ChildNodes[0].InnerText = countno1.ToString();
              

             //}
            
             if ((testDay == "Monday" || testDay == "Tuesday" || testDay == "Wednesday" || testDay == "Thursday" || testDay == "Friday" || testDay == "Saturday" || testDay == "Sunday") && (countno <= 3))
            {
               
            
            tbl_custInfo = "<table style='border:solid 1px #eee;padding-removed30px;' align='center' width='100%'>";
            tbl_custInfo += "<tr><td colspan='2' style='border-removedsolid 1px #aec6d8;text-align:center;font-weight:bold;color:#8d8f8a;'>Customer Contact Details</td></tr>";
            tbl_custInfo += "<tr><td style='border-removedsolid 1px #eee;'>Name :</td><td style='border-removedsolid 1px #eee;'>" + txtName.Value.Trim() + "</td></tr>";
            tbl_custInfo += "<tr><td style='border-removedsolid 1px #eee;'>Phone :</td><td style='border-removedsolid 1px #eee;'>" + txtPhone.Value.Trim() + "</td></tr>";
           
            tbl_custInfo += "<tr><td style='border-removedsolid 1px #eee;'>Email :</td><td style='border-removedsolid 1px #eee;'>" + txtEmail.Value.Trim() + "</td></tr>";

            tbl_custInfo += "<tr><td style='border-removedsolid 1px #eee;'>Message :</td><td style='border-removedsolid 1px #eee;'>" + txtComment.Value.Trim() + "</td></tr>";
            tbl_custInfo += "</table><br/><br/>";

            body = "<br/>" + tbl_custInfo;
           
            SmtpClient sc = new SmtpClient();
            MailMessage mm = new MailMessage();

            if (ConfigurationManager.AppSettings["MailFrom"].ToString().Trim() != "")
            {
                mm.From = new MailAddress(ConfigurationManager.AppSettings["MailFrom"].ToString().Trim(), txtEmail.Value.ToString().Trim());
            }
            if (ConfigurationManager.AppSettings["MailTo"].ToString().Trim() != "")
            {
                mm.To.Add(ConfigurationManager.AppSettings["MailTo"].ToString().Trim());
            }
            if (ConfigurationManager.AppSettings["MailBCc"].ToString().Trim() != "")
            {
                mm.Bcc.Add(ConfigurationManager.AppSettings["MailBCc"].ToString().Trim());
            }
            mm.Subject = ConfigurationManager.AppSettings["Subject"].ToString().Trim();
            mm.ReplyTo = new MailAddress(txtEmail.Value);
            mm.Body = body;

            mm.IsBodyHtml = true;

            sc.Send(mm);
            
            
            countno1 = countno1 + 1;
            CountNode.ChildNodes[0].InnerText = countno1.ToString();
          
            xmldoc.Save(xmlfile);
            this.ClientScript.RegisterStartupScript(this.GetType(), "animo", "<script language=\"javaScript\">" + "alert('Thanks for Contacting Us.');" + "window.location.href='contact.aspx';" + "<" + "/script>");

     }
    else
    {
                this.ClientScript.RegisterStartupScript(this.GetType(), "animo", "<script language=\"javaScript\">" + "alert('no more available time slots and to try again in 14 (or 7) days.');" + "window.location.href='contact.aspx';" + "<" + "/script>");
            }
          
       }
          
                  }
        }
        catch { }

Please help me out.
Tags: C# 3.5, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900