private void Page_Load(object sender, System.EventArgs e) { DateTime dtCurrentDate; int l_iResult; try { OrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false); if (Request.QueryString["sid"] == null || Request.QueryString["equipid"] == null) { Session["lastpage"] = "wo_showEquipsForInspect.aspx"; Session["error"] = _functions.ErrorMessage(104); Response.Redirect("error.aspx", false); return; } try { EquipId = Convert.ToInt32(Request.QueryString["equipid"]); InspectSchedDetailId = Convert.ToInt32(Request.QueryString["sid"]); } catch (FormatException fex) { Session["lastpage"] = "wo_showEquipsForInspect.aspx"; Session["error"] = _functions.ErrorMessage(105); Response.Redirect("error.aspx", false); return; } NextBackControl.BackPage = "wo_showEquipsForInspect.aspx"; NextBackControl.NextText = " << Create >> "; if (!IsPostBack) { dtCurrentDate = DateTime.Now; // getting the main (fixed) data order = new clsWorkOrders(); order.iOrgId = OrgId; order.iEquipId = EquipId; order.iInspectSchedDetailId = InspectSchedDetailId; order.daCurrentDate = dtCurrentDate; l_iResult = order.GetInfoForCreateWOInspection(); if (l_iResult == -1) { Session["lastpage"] = "wo_showEquipsForInspect.aspx"; Session["error"] = _functions.ErrorMessage(147); Response.Redirect("error.aspx", false); return; } lblEquipId.Text = order.sEquipId.Value; lblWOType.Text = order.sType.Value; lblInspectSchedule.Text = order.sInspectSchedule.Value; lblInspectName.Text = order.sInspectionName.Value; lblStatus.Text = order.sStatusId.Value; lblLastInspectDate.Text = order.sLastInspection.Value; lblDateRange.Text = order.sDatesRange.Value; if (order.sStatusId.Value == "No Service History") { dtCurrentDate = dtCurrentDate.AddMinutes(60 - dtCurrentDate.Minute); //lblScheduledDate.Text = dtCurrentDate.ToLongDateString() + " " + dtCurrentDate.ToShortTimeString(); lblScheduledDate.Text = "System cannot calculate the optimal date for inspection without history. Please select the next scheduled date of inspection."; lblScheduledDate.Font.Italic = true; adtScheduled.Date = dtCurrentDate; // if exist a future work order then alert if (l_iResult == 1) { Header.ErrorMessage = "Warning: " + _functions.ErrorMessage(152); dtCurrentDate = dtCurrentDate.AddMinutes(60 - dtCurrentDate.Minute); //lblScheduledDate.Text = dtCurrentDate.ToLongDateString() + " " + dtCurrentDate.ToLongTimeString(); adtScheduled.Date = dtCurrentDate; } } else { l_iResult = order.GetDateTimeOfForecastInspection(); if (l_iResult == -1) { // error Header.ErrorMessage = _functions.ErrorMessage(order.iErrorCode.Value); NextBackControl.NextEnabled = false; adtScheduled.Date = dtCurrentDate.AddMinutes(60 - dtCurrentDate.Minute); return; } else { if (l_iResult == 1) { Header.ErrorMessage = "Warning: " + _functions.ErrorMessage(152); } // {dtCurrentDate = dtCurrentDate.AddMinutes(60-dtCurrentDate.Minute); // lblScheduledDate.Text = dtCurrentDate.ToLongDateString() + " " + dtCurrentDate.ToShortTimeString(); // adtScheduled.Date = dtCurrentDate; // return; } if (l_iResult == 2) { Header.ErrorMessage = "Warning: " + _functions.ErrorMessage(149); } if (dtCurrentDate < order.daScheduled.Value) { dtCurrentDate = order.daScheduled.Value; } else { dtCurrentDate = dtCurrentDate.AddMinutes(60 - dtCurrentDate.Minute); } lblScheduledDate.Text = dtCurrentDate.ToLongDateString() + " " + dtCurrentDate.ToShortTimeString(); adtScheduled.Date = dtCurrentDate; } } } } catch (Exception ex) { _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName); Session["lastpage"] = "wo_showEquipsForInspect.aspx"; Session["error"] = ex.Message; Session["error_report"] = ex.ToString(); Response.Redirect("error.aspx", false); } finally { if (order != null) { order.Dispose(); } } }