Files
ayanova7/source/MBI/schedule.aspx.cs
2018-06-29 19:47:36 +00:00

332 lines
13 KiB
C#

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
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 GZTW.AyaNova.BLL;
namespace AyaNovaMBI
{
public partial class schedule : System.Web.UI.Page
{
protected DateTime CurrentSchedDay
{
get
{
if (Session["SchedDate"] == null)
Session["SchedDate"] = DateTime.Today;
return (DateTime)Session["SchedDate"];
}
set
{
Session["SchedDate"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
this.Title = util.LocaleText("UI.Go.Schedule");
Session["ret"] = "schedule.aspx";
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
DisplayAppointments();
}
private void DisplayAppointments()
{
//Appointments come at us unordered in any way
//in the ayanova ui the schedule UI itself takes care of this
//so here since it's a simple list need to order it from a dataview
DataTable dt = new DataTable();
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("Display", typeof(string));
DataTable dtCurrent = new DataTable();
dtCurrent.Columns.Add("Date", typeof(DateTime));
dtCurrent.Columns.Add("Display", typeof(string));
DataRow dr = null;
lblActiveDay.Text = CurrentSchedDay.ToShortDateString();
if (CurrentSchedDay == DateTime.Today)
{
btnToday.Visible = false;
}
else
{
btnToday.Visible = true;
btnToday.Text = util.LocaleText("UI.Toolbar.Schedule.Today");
}
DateTime dtStop = CurrentSchedDay.AddHours(24);
AppointmentList apl = AppointmentList.GetList(CurrentSchedDay, dtStop, util.CurrentUserID);
User currentuser = util.CurrentUser;
//write out appointments
System.Text.StringBuilder s = new System.Text.StringBuilder();
//Fetch more detailed workorder info for each workorder in list
WorkorderServiceList wsl = null;
List<Guid> IDList = new List<Guid>();
foreach (AppointmentList.AppointmentListInfo i in apl)
{
if (i.SourceObjectType == RootObjectTypes.WorkorderItemScheduledUser)
{
IDList.Add(i.WorkorderID);
}
}
wsl = WorkorderServiceList.GetListFromIDList(IDList);
int nCurrent = 0;
foreach (AppointmentList.AppointmentListInfo i in apl)
{
switch (i.SourceObjectType)
{
#region workorders
case RootObjectTypes.WorkorderItemScheduledUser:
{
WorkorderServiceList.WorkorderServiceListInfo wsnfo = GetWSLInfo(i.WorkorderID, wsl);
if (//Currently happening or will start within the hour
(i.StartDateTime >= DateTime.Now && i.StartDateTime < DateTime.Now.AddHours(1)) ||
(i.StartDateTime <= DateTime.Now && i.EndDateTime > DateTime.Now)
)
{
//Within the hour
nCurrent++;
s.Length = 0;
s.Append("<span class=\"sectsubhead\">");
s.Append(i.StartDateTime.ToShortTimeString());
s.Append(" - ");
s.Append(i.EndDateTime.ToShortTimeString());
s.Append("</span>");
s.Append("<br/>");
s.Append(util.GetRoLink(nCurrent.ToString(), i.SourceObjectID, RootObjectTypes.WorkorderItemScheduledUser, i.ServiceNumber.ToString()));
s.Append(" ");
s.Append(util.GetRoLink("", wsnfo.LT_O_Client.Value, RootObjectTypes.Client, wsnfo.LT_O_Client.Display));
s.Append("<br/>");
s.Append(util.GetWOItemStatusLink(i.WorkorderItemID));
dr = dtCurrent.NewRow();
dr["Date"] = i.StartDateTime;
dr["Display"] = s.ToString();
dtCurrent.Rows.Add(dr);
}
else
{
//All DAY
s.Length = 0;
s.Append("<span class=\"sectsubhead\">");
s.Append(i.StartDateTime.ToShortTimeString());
s.Append(" - ");
s.Append(i.EndDateTime.ToShortTimeString());
s.Append("</span>");
s.Append("<br/>");
s.Append(util.GetRoLink("", i.SourceObjectID, RootObjectTypes.WorkorderItemScheduledUser, i.ServiceNumber.ToString()));
s.Append(" ");
s.Append(util.GetRoLink("", wsnfo.LT_O_Client.Value, RootObjectTypes.Client, wsnfo.LT_O_Client.Display));
s.Append("<br/>");
s.Append(util.GetWOItemStatusLink(i.WorkorderItemID));
dr = dt.NewRow();
dr["Date"] = i.StartDateTime;
dr["Display"] = s.ToString();
dt.Rows.Add(dr);
}
}
break;
#endregion
#region schedulemarkers
case RootObjectTypes.ScheduleMarker:
{
bool bApplies = false;
////Could be a bunch by region , global , dispatchzone, schedusergroup
////or could be a single by one user ID
switch (i.AppliesToObjectType)
{
case RootObjectTypes.User:
{//case 990
if (currentuser.ID == i.AppliesToObjectID)
bApplies = true;
}
break;
case RootObjectTypes.Region:
{
if (currentuser.RegionID == i.AppliesToObjectID)
bApplies = true;
}
break;
case RootObjectTypes.DispatchZone:
{
if (currentuser.DispatchZoneID == i.AppliesToObjectID)
bApplies = true;
}
break;
case RootObjectTypes.ScheduleableUserGroup:
{
ScheduleableUserGroupUsersList ScheduleMarkerGroup = ScheduleableUserGroupUsersList.GetList(i.AppliesToObjectID);
if (ScheduleMarkerGroup.Contains(currentuser.ID))
bApplies = true;
}
break;
case RootObjectTypes.Global:
{
bApplies = true;
}
break;
}
if (bApplies)
{
s.Length = 0;
s.Append("<span class=\"sectsubhead\">");
s.Append(i.StartDateTime.ToShortTimeString());
s.Append(" - ");
s.Append(i.EndDateTime.ToShortTimeString());
s.Append("</span>");
s.Append("<br/>");
s.Append(util.GetRoLink("", i.SourceObjectID, RootObjectTypes.ScheduleMarker, i.Subject));
s.Append("<br/>");
dr = dt.NewRow();
dr["Date"] = i.StartDateTime;
dr["Display"] = s.ToString();
dt.Rows.Add(dr);
}
}
break;
#endregion
}
}
//Got all our appointments in dt, now extract them in the correct order into stringbuilder
s.Length = 0;
//s.Append("<hr/>");
if (dtCurrent.Rows.Count > 0)
{
s.Append("<span class=\"secthead\">");
s.Append(util.LocaleText("UI.Label.TimeSpan.WithinTheHour"));
s.Append("</span>");
s.Append("<br/>");
DataView dv = dtCurrent.DefaultView;
dv.Sort = "Date";
foreach (DataRowView drv in dv)
{
s.Append(drv["Display"].ToString());
s.Append("<br/>");
}
s.Append("<hr/>");
}
if (dt.Rows.Count > 0)
{
s.Append("<span class=\"secthead\">");
s.Append(util.LocaleText("UI.Label.AllDay"));
s.Append("<br/>");
s.Append("</span>");
DataView dv = dt.DefaultView;
dv.Sort = "Date";
foreach (DataRowView drv in dv)
{
s.Append(drv["Display"].ToString());
s.Append("<br/>");
}
}
string smenu = util.PageMenu("schedule");
lithead.Text = smenu + "<hr/>";
litsched.Text = s.ToString();
litfoot.Text = "<hr/>" + smenu;
}
///// <summary>
///// Build a fragment of html for an appointment
///// </summary>
///// <param name="i"></param>
///// <returns></returns>
//private string BuildSM(AppointmentList.AppointmentListInfo i)
//{
// System.Text.StringBuilder s = new System.Text.StringBuilder();
// return s.ToString();
//}
/// <summary>
/// Workorderservicelist doesn't have a proper index retrieval
/// and don't want to touch it now so this will substitute
/// </summary>
/// <param name="WorkorderID"></param>
/// <returns></returns>
private WorkorderServiceList.WorkorderServiceListInfo GetWSLInfo(Guid WorkorderID, WorkorderServiceList wsl)
{
foreach (WorkorderServiceList.WorkorderServiceListInfo i in wsl)
{
if (i.LT_O_Workorder.Value == WorkorderID)
return i;
}
return new WorkorderServiceList.WorkorderServiceListInfo();
}
#region buttons
protected void btnNext_Click(object sender, EventArgs e)
{
CurrentSchedDay = CurrentSchedDay.AddDays(1);
}
protected void btnPrev_Click(object sender, EventArgs e)
{
CurrentSchedDay = CurrentSchedDay.AddDays(-1);
}
protected void btnToday_Click(object sender, EventArgs e)
{
CurrentSchedDay = DateTime.Today;
}
#endregion
//-------------------------------------------
}
}