shshva

shshva

  • NA
  • 37
  • 18.8k

Popup warning box alert or popup reminder

Jul 21 2011 3:51 AM
Hi All,

User requested to add popup warning alert or reminder for all except daily. Could anyone please help me to guide for the user request.. your help much appreacited. here is my coding for your reference. i've attached my folder for your reference.
Folder title.. CNS.
Login.asps.cs 
ME.aspx.cs
SPV.aspx.cs
Global.asax.cs





Global.asax.cs

using
System;using
System.Collections.Generic;using
System.Linq;using
System.Web;using
System.Web.Security;using
System.Web.SessionState;using
System.IO;using
System.ComponentModel;using
System.Web.Caching;namespace


sys {public class Global : System.Web.HttpApplication {#region


















logInfo.logout_time =
sdc.SubmitChanges();
}
Session.RemoveAll();
}


HttpAppprotected void Application_Start(object sender, EventArgs e) {}protected void Session_Start(object sender, EventArgs e) { }protected void Application_BeginRequest(object sender, EventArgs e) { }protected void Application_AuthenticateRequest(object sender, EventArgs e) { }protected void Application_Error(object sender, EventArgs e) { }protected void Session_End(object sender, EventArgs e) {sqlDataContext sdc = new sqlDataContext();if (Session["LoggedUser"] != null) {var logInfo = sdc.userLogs.FirstOrDefault(a => a.username == Session["loggedUser"].ToString() && a.logout_time == null);DateTime.Now;protected void Application_End(object sender, EventArgs e) { }#endregion






listPreventive= sdc.preventives.Where(a => a.Site ==emp.site).OrderBy(a => a.Category).ThenBy(a => a.Facility).ToList();


public List<PreventTable> OrigInitPreventTable(employee emp){sqlDataContext sdc = new sqlDataContext();List<preventive> listPreventive = new List<preventive>();//sort according to Due date, ie prioritized by urgency





pt.ID = p.ID;
pt.Category = p.Category;
pt.Facilities = p.Facility;
pt.Activity = p.Activity;
pt.Recurrence = p.Recurrence;




pr.ID =
p.preventiveRecords.Add(pr);


List<PreventTable> listPrevenTable = new List<PreventTable>();foreach (preventive p in listPreventive) {PreventTable pt = new PreventTable();if (p.preventiveRecords.Count == 0) {preventiveRecord pr = new preventiveRecord();Guid.NewGuid();//sdc.SubmitChanges();}


pr.ID =
p.preventiveRecords.Add(pr);
}










theDue =
}


theDue =
}


theDue = Due236monthly(p.DuePattern);
}












}
else if (p.preventiveRecords[p.preventiveRecords.Count - 1].Date_Done != null) {preventiveRecord pr = new preventiveRecord();Guid.NewGuid();if (!p.preventiveRecords[p.preventiveRecords.Count - 1].Date_Done.HasValue && !p.preventiveRecords[p.preventiveRecords.Count - 1].Date_Due.HasValue) {DateTime theDue = new DateTime();if (p.DuePattern != null) {if (p.Recurrence == "Yearly") {string[] s = p.DuePattern.Split('/');new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));if (p.Recurrence == "Monthly") {new DateTime(DateTime.Today.Year, DateTime.Today.Month, int.Parse(p.DuePattern));if (p.Recurrence == "2-Monthly" || p.Recurrence == "3-Monthly" || p.Recurrence == "6-Monthly") {if (p.Recurrence == "18-Monthly") {string[] s = p.DuePattern.Split('/');DateTime stated = new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));if (p.Start_Record == null) {if (DateTime.Today <= stated) theDue = stated;else theDue = stated.AddMonths(18);else theDue = p.Start_Record.Value.AddMonths(18);//this is only for first event}














}
if (p.Recurrence == "9-Monthly") {if (p.DuePattern.Split(',').Count() == 1) {string[] s = p.DuePattern.Split('/');DateTime stated = new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));if (p.Start_Record == null) {if (DateTime.Today <= stated) theDue = stated;else theDue = stated.AddMonths(9);else theDue = p.Start_Record.Value.AddMonths(18);//this is only for first event}
}












}
if (p.Recurrence == "2-Yearly") {string[] s = p.DuePattern.Split('/');DateTime stated = new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));if (p.Start_Record == null) {if (DateTime.Today < stated) theDue = stated;else theDue = stated.AddYears(1);else theDue = p.Start_Record.Value.AddYears(2);//next few record?}












}
if (p.Recurrence == "4-Yearly") {string[] s = p.DuePattern.Split('/');DateTime stated = new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));if (p.Start_Record == null) {if (DateTime.Today < stated) theDue = stated;else theDue = stated.AddYears(1);else theDue = p.Start_Record.Value.AddYears(4);//next few record?}
}












}
}
















}
}
}
















}
}
}


pt.Due_Date = theDue;
p.preventiveRecords[p.preventiveRecords.Count - 1].Date_Due = theDue;
if (p.Recurrence == "Daily") {if (p.preventiveRecords[p.preventiveRecords.Count - 1].Date_Due == null)if (p.Start_Record == null) theDue = DateTime.Today.AddDays(1);else {if (p.preventiveRecords.Count < 2) theDue = p.Start_Record.Value.AddDays(1);else theDue = p.preventiveRecords[p.preventiveRecords.Count - 2].Date_Due.Value.AddDays(1);if (p.Recurrence == "Weekly") {if (p.preventiveRecords[p.preventiveRecords.Count - 1].Date_Due == null)if (p.Start_Record != null) theDue = p.Start_Record.Value.AddDays(7);else {if (p.preventiveRecords.Count < 2)for (int i = 0; i < 7; i++) {DateTime theDay = DateTime.Today.AddDays(i);if (theDay.DayOfWeek == DayOfWeek.Monday) theDue = theDay;else theDue = p.preventiveRecords[p.preventiveRecords.Count - 2].Date_Due.Value.AddDays(7);if (p.Recurrence == "2-Weekly") {if (p.preventiveRecords[p.preventiveRecords.Count - 1].Date_Due == null)if (p.Start_Record != null) theDue = p.Start_Record.Value.AddDays(14);else {if (p.preventiveRecords.Count < 2)for (int i = 7; i < 14; i++) {DateTime theDay = DateTime.Today.AddDays(i);if (theDay.DayOfWeek == DayOfWeek.Monday) theDue = theDay;else theDue = p.preventiveRecords[p.preventiveRecords.Count - 2].Date_Due.Value.AddDays(14);if (theDue != new DateTime()) {// not updated because not submitted yet. Should take from Count -2}
}


else pt.Due_Date = p.preventiveRecords[p.preventiveRecords.Count - 1].Date_Due.Value;//if(p.preventiveRecords[p.preventiveRecords.Count-1].Date_Done.HasValue)//test,listPrevenTable.Add(pt);
}
sdc.SubmitChanges();




return listPrevenTable;//Cache["prevenTable"] = listPrevenTable; //finally put DT into Cache[""] to send to SpvPrevent.aspx.cs

//var adt = (from a in sdc.preventives select new {Category= a.Category,Facilty=a.Facility,Activity=a.Activity,Recurrence=a.Recurrence });}






listPreventive= sdc.preventives.Where(a => a.Site == emp.site).OrderBy(a => a.Category).ThenBy(a => a.Facility).ToList();


public static List<PreventTable> InitPreventiveTable(employee emp) {List<preventive> listPreventive = new List<preventive>();sqlDataContext sdc = new sqlDataContext();//sort according to Due date, ie prioritized by urgency





List<PreventTable> listPrevenTable = new List<PreventTable>();foreach (preventive p in listPreventive) {//if (p.ID == 737) System.Diagnostics.Debugger.Break();

pt.ID = p.ID;
pt.Category = p.Category;
pt.Facilities = p.Facility;
pt.Activity = p.Activity;
pt.Recurrence = p.Recurrence;






lastPr.ID =
p.preventiveRecords.Add(lastPr);
lpr.Add(lastPr);
PreventTable pt = new PreventTable();List<preventiveRecord> lpr = new List<preventiveRecord>();preventiveRecord lastPr = new preventiveRecord();if (p.preventiveRecords.Count == 0) {Guid.NewGuid();//will this effect sdc.SubmitChange? This affect lastPr}
lpr = p.preventiveRecords.OrderBy(a => a.Date_Due).ToList();


lastPr = lpr.First(a => a.Date_Due == maxDue);


else {DateTime? maxDue = lpr.Max(a => a.Date_Due);if (DateTime.Now > lastPr.Date_Due) {//problem here: [preventiveRecord.Count-1].Date_Done.HasValue will never be found

pr.ID =
p.preventiveRecords.Add(pr);
lpr.Add(pr);
preventiveRecord pr = new preventiveRecord();Guid.NewGuid();//will this effect sdc.SubmitChange? This affect lastPrlastPr = pr;
}
//else lastPr = lpr.Single(a => a.Date_Due == lpr.Max(b => b.Date_Due));//not needed?}


if (!lastPr.Date_Done.HasValue && !lastPr.Date_Due.HasValue) {//for newly created

DateTime theDue = new DateTime();#region


if (p.DuePattern != null) {
if (p.Recurrence == "Yearly") {
string[] s = p.DuePattern.Split('/');
theDue = new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));
}
if (p.Recurrence == "Monthly") {
theDue = new DateTime(DateTime.Today.Year, DateTime.Today.Month, int.Parse(p.DuePattern));
}
if (p.Recurrence == "2-Monthly" || p.Recurrence == "3-Monthly" || p.Recurrence == "6-Monthly") {
theDue = Due236monthly(p.DuePattern);
}
if (p.Recurrence == "18-Monthly") {
string[] s = p.DuePattern.Split('/');
DateTime stated = new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));
if (p.Start_Record == null) {
if (DateTime.Today <= stated) theDue = stated;
else theDue = stated.AddMonths(18);
} else theDue = p.Start_Record.Value.AddMonths(18);//this is only for first event
}
if (p.Recurrence == "9-Monthly") {
if (p.DuePattern.Split(',').Count() == 1) {
string[] s = p.DuePattern.Split('/');
DateTime stated = new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));
if (p.Start_Record == null) {
if (DateTime.Today <= stated) theDue = stated;
else theDue = stated.AddMonths(9);
} else theDue = p.Start_Record.Value.AddMonths(18);//this is only for first event
}
}
if (p.Recurrence == "2-Yearly") {
string[] s = p.DuePattern.Split('/');
DateTime stated = new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));
if (p.Start_Record == null) {
if (DateTime.Today < stated) theDue = stated;
else theDue = stated.AddYears(1);
} else theDue = p.Start_Record.Value.AddYears(2);//next few record?
}
if (p.Recurrence == "4-Yearly") {
string[] s = p.DuePattern.Split('/');
DateTime stated = new DateTime(DateTime.Today.Year, int.Parse(s[1]), int.Parse(s[0]));
if (p.Start_Record == null) {
if (DateTime.Today < stated) theDue = stated;
else theDue = stated.AddYears(1);
} else theDue = p.Start_Record.Value.AddYears(4);//next few record?
}
}*/
duePattern/*#endregion












if (p.Recurrence == "Daily") {if (lastPr.Date_Due == null)if (p.Start_Record == null) theDue = DateTime.Today.AddDays(1);else {if (lpr.Count < 2) theDue = p.Start_Record.Value.AddDays(1);else //theDue = p.preventiveRecords[p.preventiveRecords.Count - 2].Date_Due.Value.AddDays(1);theDue =
}
}
DateTime.Today.AddDays(1);#region


















}


weeklyif (p.Recurrence == "Weekly") {if (lastPr.Date_Due == null)if (p.Start_Record != null) theDue = p.Start_Record.Value.AddDays(7);else {if (p.preventiveRecords.Count < 2)for (int i = 1; i < 8; i++) {DateTime theDay = DateTime.Today.AddDays(i);if (theDay.DayOfWeek == DayOfWeek.Monday) theDue = theDay;else theDue = lpr[lpr.Count - 2].Date_Due.Value.AddDays(7);//p.preventiveRecords[p.preventiveRecords.Count - 2].Date_Due.Value.AddDays(7);//how to get the second Max?}
}
#endregion
#region


if (lastPr.Date_Due == null)
if (p.Start_Record != null) {//should be 1 or 15
if(p.Start_Record.Value.Day<15) theDue = new DateTime(p.Start_Record.Value.Year, p.Start_Record.Value.Month, 15);
else {
DateTime m = p.Start_Record.Value.AddMonths(1);
theDue = new DateTime(m.Year, m.Month , 1);
}
} else { //if already started ie p.Start_Record.HasValue
if (p.preventiveRecords.Count < 2){
for (int i = 7; i < 14; i++) {
DateTime theDay = DateTime.Today.AddDays(i);
if (theDay.DayOfWeek == DayOfWeek.Monday) theDue = theDay;
}


}else theDue = p.preventiveRecords[p.preventiveRecords.Count - 2].Date_Due.Value.AddDays(14);
}
}*/
2-weekly/*if (p.Recurrence == "2-Weekly") {#endregion


pt.Due_Date = theDue;
p.preventiveRecords[p.preventiveRecords.IndexOf(lastPr)].Date_Due = theDue;
}
}
pt.last = lastPr;


if (theDue != new DateTime()) {else pt.Due_Date = lastPr.Date_Due.Value;//if (!lastPr.Date_Done.HasValue) listPrevenTable.Add(pt);
//only for this filesdc.SubmitChanges();
}




return listPrevenTable;//Cache["prevenTable"] = listPrevenTable; //finally put DT into Cache[""] to send to SpvPrevent.aspx.cs

//var adt = (from a in sdc.preventives select new {Category= a.Category,Facilty=a.Facility,Activity=a.Activity,Recurrence=a.Recurrence });}








m[0] = m[0].Split(






listDue.Add(dt);
}
due = listDue.Where(a =>


protected DateTime Due236monthly(string patten) {DateTime due = new DateTime();string[] m = patten.Split(',');string d = m[0].Split('/')[0];'/')[1];List<DateTime> listDue = new List<DateTime>();foreach (string s in m) {DateTime dt = new DateTime(DateTime.Today.Year, int.Parse(s), int.Parse(d));DateTime.Today <= a).Min();//if 10 Dec & today== 11 Dec?





listDue2.Add(
}
due = listDue2.Where(a =>
}


}
}










}
List<DateTime> listDue2 = new List<DateTime>();if (listDue.Max() < DateTime.Today) {foreach (DateTime dt in listDue) {new DateTime(dt.Year + 1, dt.Month, dt.Day));DateTime.Today <= a).Min();return due;public class PreventTable {public int ID;public string Category, Facilities, Activity, Recurrence;public DateTime Due_Date;public preventiveRecord last = new preventiveRecord();


ME.aspx.cs

using
System;using
System.Collections.Generic;using
System.Linq;using
System.Web;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.HtmlControls;namespace
















Page.Title = emp.role +


listPrevenTable =
LoadTable();
}


lb.Clear();






sys.CNS {public partial class ME1 : System.Web.UI.Page {List<PreventTable> listPrevenTable = new List<PreventTable>();static List<Button> lb = new List<Button>();List<DropDownList> listDdl = new List<DropDownList>();sqlDataContext sdc = new sqlDataContext();protected void Page_Load(object sender, EventArgs e) {employee emp=Cache["emp"] as employee;string sitename = emp.site;" site " + emp.site;if (!IsPostBack) { if (listPrevenTable.Count > 0) listPrevenTable.Clear(); }Global.InitPreventiveTable(emp);protected void LoadTable() {if (tbl.Rows.Count > 1) {int rowCount = tbl.Rows.Count - 1;for (int i = rowCount; i > 0; i--) tbl.Rows.RemoveAt(i);//}
listPrevenTable = listPrevenTable.OrderBy(a => a.Due_Date).ThenBy(a => a.Facilities).ThenBy(a => a.Recurrence).ToList();
//only upto next daylistPrevenTable = listPrevenTable.Where(a => a.Due_Date ==
listPrevenTable = listPrevenTable.Where(a => a.last.Date_Done ==




DateTime.Today.AddDays(1)).ToList();null).ToList();foreach (PreventTable pt in listPrevenTable) {//if (pt.ID == 736) System.Diagnostics.Debugger.Break();

tbl.Rows.Add(
tbl.Rows[tbl.Rows.Count - 1].Cells.Add(
tbl.Rows[tbl.Rows.Count - 1].Cells[0].InnerText = pt.Facilities;
tbl.Rows[tbl.Rows.Count - 1].Cells.Add(
tbl.Rows[tbl.Rows.Count - 1].Cells[1].InnerText = pt.Activity;
tbl.Rows[tbl.Rows.Count - 1].Cells.Add(
tbl.Rows[tbl.Rows.Count - 1].Cells[2].InnerText = pt.Recurrence;
tbl.Rows[tbl.Rows.Count - 1].Cells.Add(
tbl.Rows[tbl.Rows.Count - 1].Cells[3].Align =


tbl.Rows[tbl.Rows.Count - 1].Cells.Add(
listDdl.Add(
listDdl[listDdl.Count - 1].Items.Add(
listDdl[listDdl.Count - 1].Items.Add(
listDdl[listDdl.Count - 1].Items.Add(
listDdl[listDdl.Count - 1].Items.Add(




listDdl[listDdl.Count - 1].Enabled =
listDdl[listDdl.Count - 1].Text = pt.last.Status; }
tbl.Rows[tbl.Rows.Count - 1].Cells[4].Controls.Add(listDdl[listDdl.Count - 1]);
tbl.Rows[tbl.Rows.Count - 1].Cells.Add(
lb.Add(


lb[lb.Count - 1].Text =
}
lb[lb.Count - 1].CommandArgument = pt.ID.ToString();
lb[lb.Count - 1].CommandName = (lb.Count - 1).ToString();
lb[lb.Count - 1].Command +=
tbl.Rows[tbl.Rows.Count - 1].Cells[5].Controls.Add(lb[lb.Count - 1]);


preventive p = sdc.preventives.Single(a => a.ID == pt.ID);new HtmlTableRow());new HtmlTableCell());new HtmlTableCell());new HtmlTableCell());new HtmlTableCell());"Right";if (pt.Due_Date != new DateTime()) tbl.Rows[tbl.Rows.Count - 1].Cells[3].InnerText = pt.Due_Date.ToString("ddd d MMM yyyy");new HtmlTableCell());new DropDownList());"(Not done yet)");"Serviceable");"Degraded");"Unserviceable");if (pt.last.Date_Done==null) listDdl[listDdl.Count - 1].Enabled = true;else {false;new HtmlTableCell());new Button());if (pt.last.Date_Done == null) {"Do"; lb[lb.Count - 1].Enabled = true;else { lb[lb.Count - 1].Text = "Done"; lb[lb.Count - 1].Enabled = false; }new CommandEventHandler(MePrevent_Command);//tbl.Rows[tbl.Rows.Count - 1].Cells.Add(new HtmlTableCell()); tbl.Rows[tbl.Rows.Count - 1].Cells[7].InnerText = pt.ID.ToString();}


tbl.Visible =
lblAlert.Text =
}
}












lastPr = p.preventiveRecords.First(a => a.Date_Due == maxDue);






p.preventiveRecords[idxLast].Status = status;


p.preventiveRecords[idxLast].SME = Session[
p.preventiveRecords[idxLast].Date_Done =
sdc.SubmitChanges();


Session[
Server.Transfer(
}
}


listPrevenTable =
LoadTable();
}
}
}
if (tbl.Rows.Count == 1) {false;"All Done. No Alert";else lblAlert.Text = "Not yet done. Due date is tomorrow.";protected void MePrevent_Command(object sender, CommandEventArgs e) {int index = int.Parse(e.CommandName);string status = listDdl[index].Text; preventive p = sdc.preventives.Single(a => a.ID == int.Parse(e.CommandArgument.ToString()));preventiveRecord lastPr = new preventiveRecord();DateTime? maxDue=p.preventiveRecords.Max(b => b.Date_Due);int idxLast = p.preventiveRecords.IndexOf(lastPr);if (status != "(Not done yet)") {if (!p.Start_Record.HasValue) p.Start_Record = DateTime.Now;"loggedUser"].ToString();DateTime.Now;if (status == "Degraded" || status == "Unserviceable") {"Fault"] = p.preventiveRecords[idxLast];"MeCorrective.aspx");employee emp = Cache["emp"] as employee;Global.InitPreventiveTable(emp);



Attachment: sys.zip

Answers (2)