void Application_Start(object sender, EventArgs e) { if (Convert.ToBoolean(Session["AppStartStatus"]) == true) { // Code that runs on application startup // Warranty Automation Application SqlConnection conGlobal = new SqlConnection (@"Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|\TRANE.mdf;Integrated Security=True;User Instance=True"); conGlobal.Open(); string selService; selService = "Select * From ServiceLink WHERE DatetimeSched='" + DateTime.Now.ToShortDateString() + "'"; SqlCommand globalCom = new SqlCommand(selService, conGlobal); SqlDataReader globalReader = globalCom.ExecuteReader(); if (globalReader.HasRows) { while (globalReader.Read()) { string affectedserials; affectedserials = globalReader["UnitSerial"].ToString(); //create the mail message MailMessage mail = new MailMessage(); //set the addresses mail.From = new MailAddress("[email protected]"); mail.To.Add("[email protected]"); // the password for both email addresses is "new12345@" //set the content mail.Subject = "Service Notification"; mail.Body = "A Product with Serial#: " + affectedserials.ToString() + " needs a service visit. Please check the Service Link records right away"; //send the message SmtpClient smtp = new SmtpClient(); smtp.EnableSsl = true; smtp.Send(mail); } globalReader.Close(); string updateDate; updateDate = "UPDATE ServiceLink SET DatetimeSched = '" + DateTime.Now.AddMonths(6).ToShortDateString() + "' WHERE DatetimeSched = '" + DateTime.Now.ToShortDateString() + "'"; SqlCommand comDateupdate = new SqlCommand(updateDate, conGlobal); comDateupdate.ExecuteNonQuery(); } } else if (Convert.ToBoolean(Session["AppStartStatus"]) == false) { //create the mail message MailMessage mail = new MailMessage(); //set the addresses mail.From = new MailAddress("[email protected]"); mail.To.Add("[email protected]"); // the password for both email addresses is "new12345@" //set the content mail.Subject = "Service Notification"; mail.Body = "Service Link is disabled."; //send the message SmtpClient smtp = new SmtpClient(); smtp.EnableSsl = true; smtp.Send(mail); } else if (Session["AppStartStatus"] == null) { //Make AppStart Status By default true Session["AppStartStatus"] = true; } }
Line 16: Line 17: Line 18: if (Convert.ToBoolean(Session["AppStartStatus"]) == true) Line 19: { Line 20: