using System; using System.Data; using System.Configuration; using System.Collections; 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; using System.Text; using System.Web.Services; using System.Collections.Generic; using Telerik.Web.UI; public partial class WorkorderEdit : BaseEditPage { #region BizObject public Workorder mWorkorder; protected Workorder CurrentWorkorder { get { if (mWorkorder != null) return mWorkorder; string idstring = Request.QueryString["id"]; if (string.IsNullOrEmpty(idstring)) throw new ApplicationException("WorkorderEdit requires an existing workorder id to open"); //Workorders are cached by their ID number because the user may have more than one open at a time //and each can be in a changed state in cache but not saved yet due to the ability //to add new workorder items etc via ajax without having saved them yet. mWorkorder = (Workorder)Session["workorder"+idstring]; //Still not found? Might be in the cache if we came from the workorder new form... if (mWorkorder == null) { mWorkorder = (Workorder)Cache["workorder" + idstring]; if (mWorkorder != null) { //ok, found it in the Cache so xfer it to session //See the workordernew.aspx.cs form where this gets put in the Cache //for an explanation of why this is done this weird way Session["workorder" + idstring] = mWorkorder; Cache.Remove("workorder" + idstring); } } if (mWorkorder == null) { ClearSessionWoItem(); try { //case 207 //allow to open by specified relative rootobjecttype of workorder if (Request.QueryString["relative"] != null) { mWorkorder=Workorder.GetWorkorderByRelative((RootObjectTypes)int.Parse(Request.QueryString["relative"]),new Guid(idstring)); } else mWorkorder = Workorder.GetItem(new Guid(idstring)); Session["workorder" + idstring] = mWorkorder; } catch (System.Security.SecurityException) { CloseMe(); } } return mWorkorder; } } //Keep track of current workorder item between postbacks private WorkorderItem mCurrentWorkorderItem = null; protected WorkorderItem CurrentWorkorderItem { get { if (mCurrentWorkorderItem != null) return mCurrentWorkorderItem; else { //mCurrentWorkorderItem = (WorkorderItem)Session["workorderitem"]; //if (mCurrentWorkorderItem == null) //{ // //default to first workorder item in current workorder // //any further changes of workorder item active row will // //this will be updated by the xmlhttprequest handler for the workorder item // //grid // mCurrentWorkorderItem = CurrentWorkorder.WorkorderItems[0]; // System.Diagnostics.Debug.Assert(mCurrentWorkorderItem != null); // Session["workorderitem"] = mCurrentWorkorderItem; //} mCurrentWorkorderItem = CurrentWorkorder.WorkorderItems[CurrentWorkorderItemID]; return mCurrentWorkorderItem; } } //set //{ // mCurrentWorkorderItem = value; // Session["workorderitem"] = mCurrentWorkorderItem; //} } private Guid mCurrentWorkorderItemID = Guid.Empty; protected Guid CurrentWorkorderItemID { get { if (mCurrentWorkorderItemID != Guid.Empty) return mCurrentWorkorderItemID; else { object o=Session["currentwoitemidfor" + Request.QueryString["id"]]; if (o == null) { mCurrentWorkorderItemID = CurrentWorkorder.WorkorderItems[0].ID; Session["currentwoitemidfor" + Request.QueryString["id"]] = mCurrentWorkorderItemID; } else mCurrentWorkorderItemID = (Guid)o; return mCurrentWorkorderItemID; } } set { mCurrentWorkorderItemID = value; //A value of guid.empty means the workorder item represented by the current ID //has just been deleted so this forces a reset so that the currentworkorderitem //will automatically be picked up as the zeroth one in the workorder's workorderitems //list if (mCurrentWorkorderItemID == Guid.Empty) ClearSessionWoItem(); else Session["currentwoitemidfor" + Request.QueryString["id"]] = mCurrentWorkorderItemID; //force a reset on next access to currentworkorderitem mCurrentWorkorderItem = null; } } #endregion #region Page events private int rights = (int)SecurityLevelTypes.NoAccess; protected void Page_Init(object sender, EventArgs e) { if (!IsPostBack && !IsAjaxCallback) { //clear any remnants from prior session not removed //due to improper close Session.Remove("workorder" + Request.QueryString["id"]); ClearSessionWoItem(); } //Case 305 //Set up custom fields early so they can be retrieved from viewstate if (!IsCallback && IsPostBack) Util.ShowCustomFields("WorkorderItem", null, this.CustomFields, this.phCustom, false,this.rc1.ID,this.rt1.ID); //case 1387 rights = (int)CurrentWorkorder.Rights; if (Util.CurrentUser.IsClientOrHeadOfficeAccount || rights < (int)SecurityLevelTypes.ReadOnly)//Less than read only instead of NoAccess to catch records where it's zero instead of 1 { Util.Denied(Context); } if (CurrentWorkorder.IsServiceWorkorder) { //workorder items grid RadAjaxManager1.AjaxSettings[0].UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("gridLoan", "")); RadAjaxManager1.AjaxSettings[0].UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("gridExpense", "")); //Case 229 if (Util.GlobalSettings.UseInventory) RadAjaxManager1.AjaxSettings[0].UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("gridPartRequests", "")); //bug bug with new ajax manager you can't use a pageview as a control so must be wrapped in a real control like an asp.panel // RadAjaxManager1.AjaxSettings[0].UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("pv9", "")); RadAjaxManager1.AjaxSettings[0].UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("ospanel", "")); if (IsAjaxCallback) Util.Localize(pv9); //parts grid //Case 229 if (Util.GlobalSettings.UseInventory) RadAjaxManager1.AjaxSettings[4].UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("gridPartRequests", "")); } else { //Hide Expenses, loans, outside service tabs pv7.Visible = false; pv8.Visible = false; pv9.Visible = false; RadTabStrip1.Tabs[6].Visible = false; RadTabStrip1.Tabs[7].Visible = false; RadTabStrip1.Tabs[8].Visible = false; //hide label for grid part requests lblPartRequests.Visible = false; gridPartRequests.Visible = false; } //case 1317 if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemLabor) < (int)SecurityLevelTypes.ReadOnly) RadTabStrip1.Tabs[4].Visible=pv5.Visible = false; if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemUnit) < (int)SecurityLevelTypes.ReadOnly) RadTabStrip1.Tabs[0].Visible = pv1.Visible = false; if ((AyaBizUtils.Right(RootObjectTypes.WorkorderItemPart) < (int)SecurityLevelTypes.ReadOnly)) RadTabStrip1.Tabs[3].Visible = pv4.Visible = false; if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemTravel) < (int)SecurityLevelTypes.ReadOnly) RadTabStrip1.Tabs[5].Visible = pv6.Visible = false; if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemScheduledUser) < (int)SecurityLevelTypes.ReadOnly) RadTabStrip1.Tabs[1].Visible = pv2.Visible = false; if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemTask) < (int)SecurityLevelTypes.ReadOnly) RadTabStrip1.Tabs[2].Visible = pv3.Visible = false; if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemMiscExpense) < (int)SecurityLevelTypes.ReadOnly) RadTabStrip1.Tabs[6].Visible = pv7.Visible = false; if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemLoan) < (int)SecurityLevelTypes.ReadOnly) RadTabStrip1.Tabs[7].Visible = pv8.Visible = false; if (AyaBizUtils.Right(RootObjectTypes.WorkorderItemOutsideService) < (int)SecurityLevelTypes.ReadOnly) RadTabStrip1.Tabs[8].Visible = pv9.Visible = false; if (!Util.ShowCustomFields("WorkorderItem")) RadTabStrip1.Tabs[9].Visible = pv10.Visible = false; //case 1750 //Hidden controls need to be removed from ajax updated control or the whole thing breaks if (!pv2.Visible) RemoveAjaxUpdatedControl(0, "gridScheduledUsers"); if (!pv3.Visible) RemoveAjaxUpdatedControl(0, "gridTasks"); if (!pv4.Visible) { RemoveAjaxUpdatedControl(0, "gridParts"); RemoveAjaxUpdatedControl(0, "gridPartRequests"); } if (!pv5.Visible) RemoveAjaxUpdatedControl(0, "gridLabor"); if (!pv6.Visible) RemoveAjaxUpdatedControl(0, "gridTravel"); if (!pv8.Visible) RemoveAjaxUpdatedControl(0, "gridLoan"); if (!pv7.Visible) RemoveAjaxUpdatedControl(0, "gridExpense"); if (!pv9.Visible) RemoveAjaxUpdatedControl(0, "ospanel"); if (!pv1.Visible) { RemoveAjaxUpdatedControl(0, "cbWorkorderItemUnitServiceTypeID"); RemoveAjaxUpdatedControl(0, "cbWorkorderItemUnitID"); RemoveAjaxUpdatedControl(0, "edWarrantyInfo"); } // // // // // //gridLoan, gridExpense, gridPartRequests //Plus: // // } //case 1750 private void RemoveAjaxUpdatedControl(int ajaxSetting, string ControlID) { int nCount = RadAjaxManager1.AjaxSettings[ajaxSetting].UpdatedControls.Count; int MatchingItem = -1; for (int x = 0; x < nCount; x++) { if (RadAjaxManager1.AjaxSettings[ajaxSetting].UpdatedControls[x].ControlID == ControlID) { MatchingItem = x; break; } } if (MatchingItem != -1) { RadAjaxManager1.AjaxSettings[ajaxSetting].UpdatedControls.RemoveAt(MatchingItem); } } /// /// /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack && !IsAjaxCallback) { Util.GridInitEditable("WorkorderItems", gridWorkorderItems, "WorkorderItem"); Util.GridInitEditable("WorkorderItemScheduledUsers", gridScheduledUsers, "WorkorderItemScheduledUser"); Util.GridInitEditable("WorkorderItemTasks", gridTasks, "WorkorderItemTask"); Util.GridInitEditable("WorkorderItemParts", gridParts, "WorkorderItemPart"); Util.GridInitEditable("WorkorderItemPartRequests", gridPartRequests, "WorkorderItemPartRequest"); Util.GridInitEditable("WorkorderItemLabor", gridLabor, "WorkorderItemLabor"); gridLabor.MasterTableView.Columns.FindByUniqueName("BankColumn").Display = WorkorderBankableObject != null; Util.GridInitEditable("WorkorderItemTravel", gridTravel, "WorkorderItemTravel"); gridTravel.MasterTableView.Columns.FindByUniqueName("BankColumn").Display = WorkorderBankableObject != null; Util.GridInitEditable("WorkorderItemExpense", gridExpense, "WorkorderItemMiscExpense"); Util.GridInitEditable("WorkorderItemLoan", gridLoan, "WorkorderItemLoan"); InitPartsTab(); //Follow up menu item Telerik.Web.UI.RadMenuItem miFollow = new Telerik.Web.UI.RadMenuItem(); miFollow.ToolTip = Util.LocaleText("ScheduleMarker.Label.FollowUp"); miFollow.ImageUrl = "~/graphics/FollowUp24.png"; TypeAndID tid = CurrentWorkorder.FollowTypeAndID; miFollow.NavigateUrl = "FollowUpSelector.aspx?id=" + tid.ID.ToString() + "&type=" + ((int)tid.RootObjectType).ToString(); ; miFollow.Target = "_blank"; Master.Menu.Items.Add(miFollow); //create the client notes menu item { Telerik.Web.UI.RadMenuItem mi = new Telerik.Web.UI.RadMenuItem(); mi.ToolTip = Util.LocaleText("ClientNote.Label.List"); mi.ImageUrl = "~/graphics/ClientNotes24.png"; mi.NavigateUrl = "ClientNotesEdit.aspx?id=" + CurrentWorkorder.ClientID.ToString(); mi.Target = "_blank"; Master.Menu.Items.Add(mi); } //create the Set all parts used in service menu item if (CurrentWorkorder.IsServiceWorkorder && CurrentWorkorder.IsEditable) { Telerik.Web.UI.RadMenuItem mi = new Telerik.Web.UI.RadMenuItem(); mi.ToolTip = Util.LocaleText("UI.Toolbar.WorkorderForm.SetAllPartsUsedInService"); mi.ImageUrl = "~/graphics/PartToUsed24.png"; mi.Value = "SETALLPARTSUSED"; Master.Menu.Items.Add(mi); } //Case 728 if (CurrentWorkorder.ContractResolved() != null && !CurrentWorkorder.IsTemplate) { Telerik.Web.UI.RadMenuItem mi = new Telerik.Web.UI.RadMenuItem(); mi.ToolTip = Util.LocaleText("O.Contract"); mi.ImageUrl = "~/graphics/Contract24.png"; mi.NavigateUrl = "ContractEdit.aspx?id=" + CurrentWorkorder.ContractIDResolved().ToString(); mi.Target = "_blank"; Master.Menu.Items.Add(mi); } //case 73 //create the Wiki menu item if (CurrentWorkorder.CanWiki) Util.WikiPageInsertMenuItem(Master.Menu, CurrentWorkorder.RootObjectType, CurrentWorkorder.ID);//case 1584 was RootObjectTypes.Workorder //case 212 convert sched user to labor if (CurrentWorkorder.IsServiceWorkorder && CurrentWorkorder.IsEditable) { Telerik.Web.UI.RadMenuItem mi = new Telerik.Web.UI.RadMenuItem(); mi.ToolTip = Util.LocaleText("LT:Workorder.Label.Command.ConvertScheduledUserToLabor"); mi.ImageUrl = "~/graphics/ConvertScheduledUserToLabor24.png"; mi.Value = "CONVERTSCHEDUSERTOLABOR"; Master.Menu.Items.Add(mi); } } } protected void Page_LoadComplete(object sender, EventArgs e) { //Get data logic if (this.IsPostBack && !IsAjaxCallback)//Only on a postback and not a callback { GetData(); } #region Closed / Service completed status change handling //Handle change in closed or service completed status //Goes through each step, if any fail then processes and fills //page as normal and error is displayed //if all steps are ok, then saves and closes and exits //todo: need a javascript popup warning for setting close and service completed //at the client side like in winform ayanova //Check part requests outstanding if (mJustServiceCompleted || mJustClosed) { if (CurrentWorkorder.HasPartRequestsOnOrder) { if (mJustServiceCompleted) CurrentWorkorder.ServiceCompleted = false; mJustServiceCompleted = false; mJustClosed = false; Util.PopupAlert(this.Page, Util.LocaleText("Workorder.Label.Error.PartRequestsOnOrder"), "Closing / Service completed" ); } //Case 398 if (CurrentWorkorder.HasPartRequestsUnOrdered) { if (mJustServiceCompleted) CurrentWorkorder.ServiceCompleted = false; mJustServiceCompleted = false; mJustClosed = false; Util.PopupAlert(this.Page, Util.LocaleText("Workorder.Label.Error.PartRequestsUnOrdered"), "Closing / Service completed" ); } } //Check loan items if (mJustServiceCompleted || mJustClosed) { if (CurrentWorkorder.HasOutstandingLoanItems) { if(mJustServiceCompleted) CurrentWorkorder.ServiceCompleted = false; mJustServiceCompleted = false; mJustClosed = false; Util.PopupAlert(this.Page, Util.LocaleText("Workorder.Label.Error.LoanItemsNotReturned"), "Closing / Service completed" ); } } //Check workorder is valid and can be saved if (mJustServiceCompleted || mJustClosed) { if (!CurrentWorkorder.IsValid /*|| !CurrentWorkorder.IsSavable*/) //Case 348 { if (mJustServiceCompleted) CurrentWorkorder.ServiceCompleted = false; mJustServiceCompleted = false; mJustClosed = false; //Case 349 this.Master.SetErrors(Util.WorkorderBrokenRuleFinder(CurrentWorkorder)); } } //Save and close if service completed or close status has just changed if (mJustServiceCompleted || mJustClosed) { if (!CurrentWorkorder.AllPartsUsed) { CurrentWorkorder.SetAllPartsUsed(); } //this is the only place where service completed = true should be set //false can be set in get data if (mJustServiceCompleted) CurrentWorkorder.ServiceCompleted = true; //this is the only place where closed is set if (mJustClosed) CurrentWorkorder.Closed = true; //call save and exit if (SaveRecord()) { CloseForm(); return; } } #endregion //Load and set data in initial form load //and in all postbacks that are not a result of a rad //manager callback if (!IsAjaxCallback) { SetRights(); //Process toolbar clicks if they will affect the object //before updating the page display if (Master.AyMessage != null && Master.AyMessage.MessageType == AYMessageType.UpdateObject) HandleAyMessage(); SetData(); //Localize the page Util.Localize(this.Page); } //set page title, apparently an ajax callback causes title to reset so //need to call this each and every time SetTitle(); if (Master.AyMessage != null && Master.AyMessage.MessageType!=AYMessageType.UpdateObject) HandleAyMessage(); } #endregion #region Set access rights private void SetRights() { if (!CurrentWorkorder.IsEditable) { Util.SetReadOnly(this.Page); } //Check for special exception to enable service completed checkbox ckServiceCompleted.Enabled = CurrentWorkorder.IsServiceCompletedEditable; cbWorkorderStatusID.Enabled = ckServiceCompleted.Enabled; edInvoiceNumber.Enabled = CurrentWorkorder.IsInvoiceNumberEditable; Master.Menu.Items.FindItemByValue("LT:UI.Command.Save").Visible = CurrentWorkorder.IsSaveAllowed; Master.Menu.Items.FindItemByValue("LT:UI.Command.SaveClose").Visible = CurrentWorkorder.IsSaveAllowed; Master.Menu.Items.FindItemByValue("LT:UI.Command.Delete").Visible = CurrentWorkorder.IsDeleteable; Master.Menu.Items.FindItemByValue("LT:UI.Toolbar.Print").Visible = Report.UserCanViewReports; dtCloseByDate.Enabled = CurrentWorkorder.IsCloseByDateAllowed; //case 1902 bool itemEditable = CurrentWorkorder.IsWorkorderItemEditable; //set outside service rights if(!itemEditable || !CurrentWorkorder.IsOutsideServiceAllowed) Util.SetReadOnly(this.pv9); //Case 414 if (CurrentWorkorder.IsEditable) { //case 1902 - all items in the block below //case 1429 if (!itemEditable) Util.SetReadOnly(gridWorkorderItems); else if (!itemEditable || !(mWorkorder.IsDeleteable) || ((AyaBizUtils.Right("Object.WorkorderItem") < (int)SecurityLevelTypes.ReadWriteDelete))) Util.GridSetNoDelete(gridWorkorderItems); if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemTravel") < (int)SecurityLevelTypes.ReadWrite) Util.SetReadOnly(this.pv6); else if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemTravel") < (int)SecurityLevelTypes.ReadWriteDelete) Util.GridSetNoDelete(gridTravel); if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemTask") < (int)SecurityLevelTypes.ReadWrite) Util.SetReadOnly(this.pv3); else if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemTask") < (int)SecurityLevelTypes.ReadWriteDelete) Util.GridSetNoDelete(gridTasks); if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemScheduledUser") < (int)SecurityLevelTypes.ReadWrite) Util.SetReadOnly(this.pv2); else if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemScheduledUser") < (int)SecurityLevelTypes.ReadWriteDelete) Util.GridSetNoDelete(gridScheduledUsers); if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemPart") < (int)SecurityLevelTypes.ReadWrite) Util.SetReadOnly(this.pv4); else { if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemPart") < (int)SecurityLevelTypes.ReadWriteDelete) Util.GridSetNoDelete(gridParts); //changed in case 1483 if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemPart") < (int)SecurityLevelTypes.ReadWriteDelete) Util.GridSetNoDelete(gridPartRequests); } if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemMiscExpense") < (int)SecurityLevelTypes.ReadWrite) Util.SetReadOnly(this.pv7); else if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemMiscExpense") < (int)SecurityLevelTypes.ReadWriteDelete) Util.GridSetNoDelete(gridExpense); if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemLoan") < (int)SecurityLevelTypes.ReadWrite) Util.SetReadOnly(this.pv8); else if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemLoan") < (int)SecurityLevelTypes.ReadWriteDelete) Util.GridSetNoDelete(gridLoan); if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemLabor") < (int)SecurityLevelTypes.ReadWrite) Util.SetReadOnly(this.pv5); else if (!itemEditable || AyaBizUtils.Right("Object.WorkorderItemLabor") < (int)SecurityLevelTypes.ReadWriteDelete) Util.GridSetNoDelete(gridLabor); //case 1902 if (!itemEditable) Util.SetReadOnly(this.pv10); //also case 1902 and much of the above if(!itemEditable || AyaBizUtils.Right("Object.WorkorderItemUnit") < (int)SecurityLevelTypes.ReadWrite) Util.SetReadOnly(this.pv1); } ////This block is a workaround for pending case 350 in the biz object layer //bool bIsCloseAllowed = true; //if(AyaBizUtils.Right("Object.xWorkorder.Close") < (int)SecurityLevelTypes.ReadWrite) // bIsCloseAllowed=false; //if (AyaBizUtils.Right("Object.xWorkorder") < (int)SecurityLevelTypes.ReadWrite) // bIsCloseAllowed =false; //if (CurrentWorkorder.Closed) // bIsCloseAllowed = false; ////Case 346 and Case 347 //ckClosed.Enabled = bIsCloseAllowed && CurrentWorkorder.ServiceCompleted; //Case 405 ckClosed.Enabled = CurrentWorkorder.IsCloseAllowed; //case 1194 if (Util.GlobalSettings.HiddenControls.Count > 0) { #region hideable controls lsHideableControls = new List(); lsHideableControls.Add("edInternalReferenceNumber"); lsHideableControls.Add("lblInternalReferenceNumber"); lsHideableControls.Add("edCustomerReferenceNumber"); lsHideableControls.Add("edCustomerContactName"); lsHideableControls.Add("lblCustomerContactName"); lsHideableControls.Add("lblCustomerReferenceNumber"); lsHideableControls.Add("ckOnsite"); lsHideableControls.Add("cbProjectID"); lsHideableControls.Add("btnProjectID"); lsHideableControls.Add("cbWorkorderCategoryID"); lsHideableControls.Add("btnWorkorderCategoryID"); lsHideableControls.Add("ckServiceCompleted"); lsHideableControls.Add("edInvoiceNumber"); lsHideableControls.Add("lblInvoiceNumber"); lsHideableControls.Add("lblServiceDate"); lsHideableControls.Add("dtServiceDate"); lsHideableControls.Add("lblCloseByDate"); lsHideableControls.Add("dtCloseByDate"); lsHideableControls.Add("cbWorkorderStatusID"); lsHideableControls.Add("btnWorkorderStatusID"); lsHideableControls.Add("lblQuoteRequestDate"); lsHideableControls.Add("dtQuoteRequestDate"); lsHideableControls.Add("lblValidUntilDate"); lsHideableControls.Add("dtValidUntilDate"); lsHideableControls.Add("lblWorkorderQuoteStatusID"); lsHideableControls.Add("lblDateSubmitted"); lsHideableControls.Add("dtDateSubmitted"); lsHideableControls.Add("lblDateApproved"); lsHideableControls.Add("dtDateApproved"); lsHideableControls.Add("cbWorkorderQuoteStatusID"); lsHideableControls.Add("lblPreparedByID"); lsHideableControls.Add("cbPreparedByID"); lsHideableControls.Add("lblIntroduction"); lsHideableControls.Add("edIntroduction"); lsHideableControls.Add("cbPMWorkorderStatusID"); lsHideableControls.Add("btnPMWorkorderStatusID"); lsHideableControls.Add("lblPMStopGeneratingDate"); lsHideableControls.Add("dtPMStopGeneratingDate"); lsHideableControls.Add("lblPMNextServiceDate"); lsHideableControls.Add("dtPMNextServiceDate"); lsHideableControls.Add("lblPMDayOfTheWeek"); lsHideableControls.Add("cbPMDayOfTheWeek"); lsHideableControls.Add("ckPMActive"); lsHideableControls.Add("lblPMThresholdSpan"); lsHideableControls.Add("cbPMThresholdSpanUnit"); lsHideableControls.Add("edPMThresholdSpan"); lsHideableControls.Add("lblPMGenerateSpan"); lsHideableControls.Add("cbPMGenerateSpanUnit"); lsHideableControls.Add("edPMGenerateSpan"); #endregion mHideControlsFormName = "WorkorderForm[" + this.mWorkorder.WorkorderType.ToString() + "]"; HideSelectedControls(mHideControlsFormName, this); } } private string mHideControlsFormName = ""; private System.Collections.Generic.List lsHideableControls; //case 1194 /// /// Scan every control contained within passed in control (form) /// if on hiddencontrols list of global object then hide /// /// private void HideSelectedControls(string sFormName, System.Web.UI.Control c) { //deal with controls that are hideable only. // this is to stop people from using the api to hide controls that would normally // be unhideable due to necessity if (lsHideableControls.Contains(c.ID)) { string sHiddenTag = sFormName + ":" + c.ID; if (Util.GlobalSettings.HiddenControls.Contains(sHiddenTag)) c.Visible = false; } foreach (Control c2 in c.Controls) HideSelectedControls(sFormName, c2); } #endregion #region Set data private void SetTitle() { Workorder o = CurrentWorkorder; switch (o.WorkorderType) { case WorkorderTypes.Service: { if (o.WorkorderService.ServiceNumber != 0) this.Title = Util.LocaleText("O.WorkorderService") + " " + o.WorkorderService.ServiceNumber.ToString(); else this.Title = Util.LocaleText("O.WorkorderService"); } break; case WorkorderTypes.Quote: { if (o.WorkorderQuote.QuoteNumber != 0) this.Title = Util.LocaleText("O.WorkorderQuote") + " " + o.WorkorderQuote.QuoteNumber.ToString(); else this.Title = Util.LocaleText("O.WorkorderQuote"); } break; case WorkorderTypes.PreventiveMaintenance: { if (o.WorkorderPreventiveMaintenance.PreventiveMaintenanceNumber != 0) this.Title = Util.LocaleText("O.WorkorderPreventiveMaintenance") + " " + o.WorkorderPreventiveMaintenance.PreventiveMaintenanceNumber.ToString(); else this.Title = Util.LocaleText("O.WorkorderPreventiveMaintenance"); } break; } } private void SetData() { Workorder o = CurrentWorkorder; #region header Util.ComboInitialize(cbProjectID, "Project", o.ProjectID); Util.ComboInitialize(cbWorkorderCategoryID, "WorkorderCategory", o.WorkorderCategoryID); edClient.Text = DisplayFullerAddressForClientSelected(); edSummary.Text = o.Summary; edCustomerContactName.Text = o.CustomerContactName; edCustomerReferenceNumber.Text = o.CustomerReferenceNumber; edInternalReferenceNumber.Text = o.InternalReferenceNumber; ckOnsite.Checked = o.Onsite; pnlService.Visible = false; pnlQuote.Visible = false; pnlPM.Visible = false; ckClosed.Checked = o.Closed; switch (o.WorkorderType) { case WorkorderTypes.Service: { pnlService.Visible = true; if (AyaBizUtils.Right("Object.Report") < (int)SecurityLevelTypes.ReadOnly) Master.Menu.Items[0].Visible = false; else Util.ReportFillList(Master.Menu.Items[0], WorkorderServiceList.ReportKey, WorkorderServiceDetailedReportData.ReportKey); Util.ComboInitialize(cbWorkorderStatusID, "WorkorderStatus", o.WorkorderService.WorkorderStatusID); dtCloseByDate.DbSelectedDate = o.WorkorderService.CloseByDate; edInvoiceNumber.Text = o.WorkorderService.InvoiceNumber; dtServiceDate.DbSelectedDate = o.WorkorderService.ServiceDate; ckServiceCompleted.Checked = o.ServiceCompleted; } break; case WorkorderTypes.Quote: { pnlQuote.Visible = true; if (AyaBizUtils.Right("Object.Report") < (int)SecurityLevelTypes.ReadOnly) Master.Menu.Items[0].Visible = false; else Util.ReportFillList(Master.Menu.Items[0], WorkorderQuoteList.ReportKey, WorkorderQuoteDetailedReportData.ReportKey); Util.ComboInitialize(cbPreparedByID, "User", o.WorkorderQuote.PreparedByID); Util.ComboInitializeNonBiz(cbWorkorderQuoteStatusID, "QuoteStatus", (int)o.WorkorderQuote.QuoteStatus); edIntroduction.Text = o.WorkorderQuote.Introduction; dtDateApproved.DateInput.DbSelectedDate = o.WorkorderQuote.DateApproved; dtDateSubmitted.DateInput.DbSelectedDate = o.WorkorderQuote.DateSubmitted; dtQuoteRequestDate.DbSelectedDate = o.WorkorderQuote.QuoteRequestDate; dtValidUntilDate.DbSelectedDate = o.WorkorderQuote.ValidUntilDate; } break; case WorkorderTypes.PreventiveMaintenance: { pnlPM.Visible = true; if (AyaBizUtils.Right("Object.Report") < (int)SecurityLevelTypes.ReadOnly) Master.Menu.Items[0].Visible = false; else Util.ReportFillList(Master.Menu.Items[0], WorkorderPMList.ReportKey, WorkorderPMDetailedReportData.ReportKey); Util.ComboInitialize(cbPMWorkorderStatusID, "WorkorderStatus", o.WorkorderPreventiveMaintenance.WorkorderStatusID); Util.ComboInitializeNonBiz(cbPMGenerateSpanUnit, "UnitsOfTime", (int) o.WorkorderPreventiveMaintenance.GenerateSpanUnit); Util.ComboInitializeNonBiz(cbPMThresholdSpanUnit, "UnitsOfTime", (int) o.WorkorderPreventiveMaintenance.ThresholdSpanUnit); Util.ComboInitializeNonBiz(cbPMDayOfTheWeek, "DaysOfWeek", (int) o.WorkorderPreventiveMaintenance.DayOfTheWeek); ckPMActive.Checked = o.WorkorderPreventiveMaintenance.Active; edPMGenerateSpan.Text = o.WorkorderPreventiveMaintenance.GenerateSpan.ToString(); edPMThresholdSpan.Text = o.WorkorderPreventiveMaintenance.ThresholdSpan.ToString(); dtPMNextServiceDate.DbSelectedDate = o.WorkorderPreventiveMaintenance.NextServiceDate; dtPMStopGeneratingDate.DbSelectedDate = o.WorkorderPreventiveMaintenance.StopGeneratingDate; //Hide Expenses, loans, outside service tabs pv7.Visible = false; pv8.Visible = false; pv9.Visible = false; RadTabStrip1.Tabs[6].Visible = false; RadTabStrip1.Tabs[7].Visible = false; RadTabStrip1.Tabs[8].Visible = false; } break; } #endregion header IntializeUnitCombos(); IntializeTaskCombo(); if(CurrentWorkorder.IsServiceWorkorder) InitializeOutsideServiceTab(); ShowWarranty(); //case 1902 Util.ShowCustomFields("WorkorderItem", CurrentWorkorderItem, this.CustomFields, this.phCustom, !CurrentWorkorder.IsWorkorderItemEditable, this.rc1.ID, this.rt1.ID); ShowBank(); ShowMeterLink(); } #endregion set #region Get data private bool mJustClosed = false; private bool mJustServiceCompleted = false; private void GetData() { Workorder o = CurrentWorkorder; if (!o.IsEditable) { if (o.IsServiceCompletedEditable) { if (!o.ServiceCompleted && ckServiceCompleted.Checked) mJustServiceCompleted = true; //get's set later on in page load event //o.ServiceCompleted = ckServiceCompleted.Checked; o.WorkorderService.InvoiceNumber = edInvoiceNumber.Text; CurrentWorkorder.WorkorderService.WorkorderStatusID = Util.ComboValue(cbWorkorderStatusID); if (ckClosed.Checked && o.Closed == false) {//can't set it until we know it's going to be ok //otherwise could get an exception //so this is set in the page events at the end of load //based on the value of mJustClosed if settable // o.Closed = ckClosed.Checked; mJustClosed = true; } //This is the only other place service completed is //set aside from page load complete and there it's only //set if true, here it's only set if false if (ckServiceCompleted.Checked == false) o.ServiceCompleted = false; } return; } #region header o.ProjectID = Util.ComboValue(cbProjectID); o.WorkorderCategoryID=Util.ComboValue(cbWorkorderCategoryID); o.Summary = edSummary.Text; o.CustomerContactName = edCustomerContactName.Text; o.CustomerReferenceNumber = edCustomerReferenceNumber.Text; o.InternalReferenceNumber = edInternalReferenceNumber.Text; ckOnsite.Checked = o.Onsite; switch (o.WorkorderType) { case WorkorderTypes.Service: { CurrentWorkorder.WorkorderService.WorkorderStatusID=Util.ComboValue(cbWorkorderStatusID); OutsideServiceTabGetData(); //case 455 if(o.IsCloseByDateAllowed)//Case 517 o.WorkorderService.CloseByDate=dtCloseByDate.DbSelectedDate; //o.WorkorderService.ServiceDate = Util.GetDateIfChanged(o.WorkorderService.ServiceDate, dtServiceDate.DbSelectedDate); o.WorkorderService.ServiceDate = dtServiceDate.DbSelectedDate; //If going *to* service completed then can't set here, must be set //by page load code later on if (!o.ServiceCompleted && ckServiceCompleted.Checked) mJustServiceCompleted = true; else if (o.ServiceCompleted && !ckServiceCompleted.Checked) { //has gone from being service completed to not being service completed //so can set it here in the biz object: o.ServiceCompleted = ckServiceCompleted.Checked; } if (ckClosed.Checked && o.Closed == false) { //can't set it until we know it's going to be ok //otherwise could get an exception //so this is set in the page events at the end of load //based on the value of mJustClosed if settable //o.Closed = ckClosed.Checked; mJustClosed = true; } } break; case WorkorderTypes.Quote: { CurrentWorkorder.WorkorderQuote.PreparedByID = Util.ComboValue(cbPreparedByID); CurrentWorkorder.WorkorderQuote.QuoteStatus = cb2e.get(cbWorkorderQuoteStatusID); o.WorkorderQuote.Introduction = edIntroduction.Text; //Case 455 o.WorkorderQuote.DateApproved = dtDateApproved.DbSelectedDate; o.WorkorderQuote.DateSubmitted = dtDateSubmitted.DbSelectedDate; o.WorkorderQuote.QuoteRequestDate =dtQuoteRequestDate.DbSelectedDate; o.WorkorderQuote.ValidUntilDate = dtValidUntilDate.DbSelectedDate; } break; case WorkorderTypes.PreventiveMaintenance: { CurrentWorkorder.WorkorderPreventiveMaintenance.WorkorderStatusID = Util.ComboValue(cbPMWorkorderStatusID); CurrentWorkorder.WorkorderPreventiveMaintenance.GenerateSpanUnit = cb2e.get(cbPMGenerateSpanUnit); CurrentWorkorder.WorkorderPreventiveMaintenance.ThresholdSpanUnit = cb2e.get(cbPMThresholdSpanUnit); CurrentWorkorder.WorkorderPreventiveMaintenance.DayOfTheWeek = cb2e.get(cbPMDayOfTheWeek); o.WorkorderPreventiveMaintenance.Active = ckPMActive.Checked; o.WorkorderPreventiveMaintenance.GenerateSpan = int.Parse(edPMGenerateSpan.Text); o.WorkorderPreventiveMaintenance.ThresholdSpan = int.Parse(edPMThresholdSpan.Text); //Case 455 o.WorkorderPreventiveMaintenance.NextServiceDate = dtPMNextServiceDate.DbSelectedDate; o.WorkorderPreventiveMaintenance.StopGeneratingDate = dtPMStopGeneratingDate.DbSelectedDate; } break; } #endregion header if (o.IsWorkorderItemEditable)//case 1902 { UnitTabGetData(); Util.GetCustomFields("WorkorderItem", CurrentWorkorderItem, this.phCustom); UnitTabGetData(); } } #endregion #region get full client address /// /// retrieve address /// and contact info for selected Client /// private string DisplayFullerAddressForClientSelected() { //todo: scrap this if (mWorkorder.IsTemplate) return mWorkorder.NameAndAddress; else return mWorkorder.NameAndAddress; } #endregion #region Combo box events #region Header combos protected void cbProject_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { Util.ComboPopulateBizList("Project", cbProjectID, true, e,true); } protected void cbWorkorderCategory_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { Util.ComboPopulateBizList("WorkorderCategory", cbWorkorderCategoryID, true, e,false); } #endregion header combos #region workorder service combos protected void cbWorkorderStatus_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { Util.ComboPopulateBizList("WorkorderStatus", cbWorkorderStatusID, true, e,false); } #endregion #region Workorder quote combos protected void cbPreparedBy_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { Util.ComboPopulateBizList("UserPickList", cbPreparedByID, true, e, false);//case 58 not regional same as ayanova quote form } #endregion #region Workorder pm combos protected void cbPMWorkorderStatus_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { Util.ComboPopulateBizList("WorkorderStatus", cbPMWorkorderStatusID, true, e, false); } #endregion #endregion combo box events #region Workorder Items Grid Events #region Populate protected void gridWorkorderItems_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { gridWorkorderItems.DataSource = CurrentWorkorder.WorkorderItems; if (!this.IsPostBack) gridWorkorderItems.SelectedIndexes.Add(0); } protected void gridWorkorderItems_ItemDataBound(object sender, GridItemEventArgs e) { //Process fields in Data row... if (e.Item is GridEditFormItem && e.Item.DataItem is WorkorderItem)//case 1987 { string selectedStatusID = ((WorkorderItem)e.Item.DataItem).WorkorderStatusID.ToString(); string selectedTypeID = ((WorkorderItem)e.Item.DataItem).TypeID.ToString(); string selectedPriorityID = ((WorkorderItem)e.Item.DataItem).PriorityID.ToString(); if (e.Item.IsInEditMode) { Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbwostat") as Telerik.Web.UI.RadComboBox; bindgridcombo(WorkorderStatusList,cb, selectedStatusID); cb = e.Item.FindControl("cbwotype") as Telerik.Web.UI.RadComboBox; bindgridcombo(WorkorderTypeList, cb, selectedTypeID); cb = e.Item.FindControl("cbwopriority") as Telerik.Web.UI.RadComboBox; bindgridcombo(WorkorderPriorityList, cb, selectedPriorityID); Telerik.Web.UI.RadDateTimePicker rdp = e.Item.FindControl("dtRequest") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItem)e.Item.DataItem).RequestDate; rdp.SharedCalendar = rc1; rdp.SharedTimeView = rt1; //dpShared.Visible = true; TextBox tb = e.Item.FindControl("tbdetails") as TextBox; tb.Text = ((WorkorderItem)e.Item.DataItem).TechNotes; ((e.Item as GridEditableItem)["Summary"].Controls[0] as TextBox).MaxLength = 255; GridEditFormItem gefi = e.Item as GridEditFormItem; gefi["ID"].Style.Add("Display", "none"); } } else if (e.Item is GridDataItem && e.Item.DataItem is WorkorderItem) { string selectedStatusID = ((WorkorderItem)e.Item.DataItem).WorkorderStatusID.ToString(); string selectedTypeID = ((WorkorderItem)e.Item.DataItem).TypeID.ToString(); string selectedPriorityID = ((WorkorderItem)e.Item.DataItem).PriorityID.ToString(); Label l = e.Item.FindControl("lblwostat") as Label; l.Text = DisplayValueByID(WorkorderStatusList, selectedStatusID); l = e.Item.FindControl("lblwotype") as Label; l.Text = DisplayValueByID(WorkorderTypeList, selectedTypeID); l = e.Item.FindControl("lblwopriority") as Label; Image iflag = e.Item.FindControl("imgflag") as Image; if (selectedPriorityID == Guid.Empty.ToString()) { l.Visible = false; iflag.Visible = false; } else { l.Text = DisplayValueByID(WorkorderPriorityList, selectedPriorityID); iflag.ImageUrl = "dynimage.ashx?t=flag&argb=" + PriorityColor(selectedPriorityID); } l = e.Item.FindControl("lblrequest") as Label; l.Text = ((WorkorderItem)e.Item.DataItem).RequestDate.ToString(); l = e.Item.FindControl("lbldetails") as Label; l.Text = ((WorkorderItem)e.Item.DataItem).TechNotes; l.ToolTip = l.Text; } } private DataTable _wotype = null; private DataTable WorkorderTypeList { get { if (_wotype == null) {//case 1121 _wotype = Util.GetDataBiz("WorkorderItemTypeList", Guid.Empty, true, Guid.Empty, CurrentWorkorder.ListOfWorkorderItemTypesSelected(), false); } return _wotype; } } private DataTable _wopriority = null; private DataTable WorkorderPriorityList { get { if (_wopriority == null) {//case 1121 _wopriority = Util.GetDataBiz("WorkorderItemPriorityList", Guid.Empty, true, Guid.Empty, CurrentWorkorder.ListOfWorkorderItemPrioritiesSelected(), false); } return _wopriority; } } private DataTable _wostat=null; private DataTable WorkorderStatusList { get { if (_wostat == null) { //Case 11 changed from generic list to specific one that accounts for preselected items _wostat = Util.GetDataBiz("WorkorderStatusList", Guid.Empty, true, Guid.Empty, CurrentWorkorder.ListOfWorkorderItemStatusSelected(),false); } return _wostat; } } private string PriorityColor(string SelectedID) { if (string.IsNullOrEmpty(SelectedID)) return "0"; foreach (DataRow dr in WorkorderPriorityList.Rows) { if (dr["Value"].ToString() == SelectedID) return dr["Color"].ToString(); } return "0"; } private string DisplayValueByID(DataTable dt, string SelectedID) { if (string.IsNullOrEmpty(SelectedID)) return ""; foreach (DataRow dr in dt.Rows) { if (dr["Value"].ToString() == SelectedID) return dr["Display"].ToString(); } return ""; } private void bindgridcombo(DataTable dt, Telerik.Web.UI.RadComboBox cb, string selectedID) { cb.DataSource = dt; cb.DataValueField = "Value"; cb.DataTextField = "Display"; cb.DataBind(); if(!string.IsNullOrEmpty(selectedID)) cb.SelectedValue = selectedID; } #endregion populate #region Index changed protected void gridWorkorderItems_SelectedIndexChanged(object sender, EventArgs e) { //Get old values before change if (rights < (int)SecurityLevelTypes.ReadWrite || CurrentWorkorder.Closed || (CurrentWorkorder.WorkorderType == WorkorderTypes.Service && CurrentWorkorder.ServiceCompleted)) goto SKIPGET; OutsideServiceTabGetData(); SKIPGET: Util.GetCustomFields("WorkorderItem", CurrentWorkorderItem, this.phCustom); UnitTabGetData(); //Select new workorder item and fill tabs GridDataItem i = gridWorkorderItems.SelectedItems[0] as GridDataItem; CurrentWorkorderItemID = new Guid(i["ID"].Text); gridScheduledUsers.Rebind(); gridParts.Rebind(); gridPartRequests.Rebind(); gridTasks.Rebind(); gridLabor.Rebind(); gridTravel.Rebind(); if (CurrentWorkorder.IsServiceWorkorder) { gridExpense.Rebind(); gridLoan.Rebind(); } ShowWarranty(); IntializeUnitCombos(); InitializeOutsideServiceTab(); //case 1902 Util.ShowCustomFields("WorkorderItem", CurrentWorkorderItem, this.CustomFields, this.phCustom, !CurrentWorkorder.IsWorkorderItemEditable, this.rc1.ID, this.rt1.ID); ShowMeterLink(); } private void ShowWarranty() { edWarrantyInfo.Visible = true; edWarrantyInfo.Text = GetWarrantyInfo(CurrentWorkorderItem.UnitID.ToString()); } #endregion #region editing events /// ///takes the values in the current grid item and copies them /// to the corresponding workorder item /// /// private void UpdateWorkorderItemFromGrid(GridCommandEventArgs e) { Hashtable newValues = Util.GridExtractValues(e.Item); WorkorderItem wi = CurrentWorkorder.WorkorderItems[newValues["ID"].ToString()]; //WorkorderItem wi = CurrentWorkorderItem; Telerik.Web.UI.RadComboBox cbstat = ( Telerik.Web.UI.RadComboBox)e.Item.FindControl("cbwostat"); wi.WorkorderStatusID = new Guid(cbstat.SelectedValue); //Case 239 Telerik.Web.UI.RadComboBox cbtype = ( Telerik.Web.UI.RadComboBox)e.Item.FindControl("cbwotype"); wi.TypeID = new Guid(cbtype.SelectedValue); Telerik.Web.UI.RadComboBox cbpriority = ( Telerik.Web.UI.RadComboBox)e.Item.FindControl("cbwopriority"); wi.PriorityID = new Guid(cbpriority.SelectedValue); Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtRequest"); wi.RequestDate = picker.DbSelectedDate; //case 726 wi.WarrantyService = Util.ParseBool(newValues["WarrantyService"]); wi.Summary = Util.ObjectToString(newValues["Summary"]); // wi.TechNotes = Util.ObjectToString(newValues["TechNotes"]); TextBox tb = e.Item.FindControl("tbdetails") as TextBox; wi.TechNotes = Util.ParseMultiLineText(tb.Text);//case 1922 Util.GridCheckForBrokenRule(wi, e); ShowWarranty(); } protected void gridWorkorderItems_ItemCommand(object source, GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.EditCommandName: { ShowWarranty(); } break; case RadGrid.UpdateCommandName: { UpdateWorkorderItemFromGrid(e); } break; case RadGrid.InitInsertCommandName: { e.Canceled = true; CurrentWorkorderItemID = CurrentWorkorder.WorkorderItems.Add(CurrentWorkorder).ID; CurrentWorkorderItem.RequestDate = DBUtil.CurrentWorkingDateTime; e.Item.OwnerTableView.InsertItem(CurrentWorkorderItem); } break; case RadGrid.PerformInsertCommandName: { UpdateWorkorderItemFromGrid(e); } break; case RadGrid.DeleteCommandName: { //Can't delete if it's the only workorder item if (CurrentWorkorder.WorkorderItems.Count < 2) { e.Canceled = true; return; } Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); if (id == CurrentWorkorderItem.ID) { //this triggers a reset so that no current workorder item is currently //selected which in turn means the first one will be retrieved next time //there is a call to this CurrentWorkorderItemID = Guid.Empty; //todo: probably have to force a select here for the grid } CurrentWorkorder.WorkorderItems.Remove(newValues["ID"].ToString()); } } break; case RadGrid.CancelCommandName: { //If a user selects cancel and it's a new inserted item //then remove it if (e.Item is Telerik.Web.UI.GridDataInsertItem) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); if (id == CurrentWorkorderItem.ID) { //this triggers a reset so that no current workorder item is currently //selected which in turn means the first one will be retrieved next time //there is a call to this CurrentWorkorderItemID = Guid.Empty; //todo: probably have to force a select here for the grid } CurrentWorkorder.WorkorderItems.Remove(newValues["ID"].ToString()); } } } break; } } #endregion editing events #endregion #region Unit tab private void UnitTabGetData() { //case 1902 if (AyaBizUtils.Right("Object.WorkorderItemUnit") < (int)SecurityLevelTypes.ReadWrite) return; CurrentWorkorderItem.UnitID = Util.ComboValue(cbWorkorderItemUnitID); CurrentWorkorderItem.WorkorderItemUnitServiceTypeID = Util.ComboValue(cbWorkorderItemUnitServiceTypeID); } private void ShowMeterLink() { if (CurrentWorkorderItem.HasMeteredUnit) { hlMetered.Visible = true; hlMetered.Text = Util.LocaleText("Unit.Label.Metered"); hlMetered.NavigateUrl = "UnitMeterReadings.aspx?id=" + CurrentWorkorderItem.UnitID.ToString() + "&woitemid=" + CurrentWorkorderItem.ID.ToString(); hlMetered.Target = "_blank"; } else { hlMetered.Visible = false; } } // #region Unit combos private void IntializeUnitCombos() { Util.ComboInitialize(cbWorkorderItemUnitServiceTypeID, "UnitServiceType", CurrentWorkorderItem.WorkorderItemUnitServiceTypeID); Util.ComboPopulateBizList("ClientUnitList", cbWorkorderItemUnitID, false, CurrentWorkorder.ClientID, CurrentWorkorder.ListOfUnitsSelected(), null,false); cbWorkorderItemUnitID.SelectedValue = CurrentWorkorderItem.UnitID.ToString(); } /// /// More items selected, so populate list with all the client's units /// /// /// protected void cbWorkorderItemUnitID_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { Util.ComboPopulateBizList("ClientUnitList", cbWorkorderItemUnitID, false, CurrentWorkorder.ClientID, null, null,false); } /// /// /// /// /// protected void cbWorkorderItemUnitServiceTypeID_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { Util.ComboPopulateBizList("UnitServiceType", cbWorkorderItemUnitServiceTypeID, true,e,false); } //case 1617 protected void cbWorkorderItemUnitID_SelectedIndexChanged(object sender, EventArgs e) { } #endregion #endregion unit tab #region sched users Tab #region Populate protected void gridScheduledUsers_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { gridScheduledUsers.DataSource = CurrentWorkorderItem.ScheduledUsers; } protected void gridScheduledUsers_ItemDataBound(object sender, GridItemEventArgs e) { //Process fields in Data row... if (e.Item is GridDataItem && e.Item.DataItem is WorkorderItemScheduledUser) { string selectedUserID = ((WorkorderItemScheduledUser)e.Item.DataItem).UserID.ToString(); string selectedRateID = ((WorkorderItemScheduledUser)e.Item.DataItem).ServiceRateID.ToString(); if (e.Item.IsInEditMode) { Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbuser") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("UserPickListScheduleable", cb, true, Guid.Empty, CurrentWorkorder.ListOfScheduledUsersSelected(), null,true); cb.SelectedValue = selectedUserID; cb = e.Item.FindControl("cbrate") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("LaborRateList", cb, true,CurrentWorkorder.ContractIDResolved(), CurrentWorkorder.ListOfScheduledUsersLaborRatesSelected(), null,true); cb.SelectedValue = selectedRateID; Telerik.Web.UI.RadDateTimePicker rdp = e.Item.FindControl("dtstart") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItemScheduledUser)e.Item.DataItem).StartDate; rdp = e.Item.FindControl("dtstop") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItemScheduledUser)e.Item.DataItem).StopDate; } else { Label l = e.Item.FindControl("lbluser") as Label; l.Text = Util.GetBizObjectName("User", selectedUserID); l = e.Item.FindControl("lblrate") as Label; l.Text = Util.GetBizObjectName("Rate", selectedRateID); l = e.Item.FindControl("lblstart") as Label; l.Text = ((WorkorderItemScheduledUser)e.Item.DataItem).StartDate.ToString(); l = e.Item.FindControl("lblstop") as Label; l.Text = ((WorkorderItemScheduledUser)e.Item.DataItem).StopDate.ToString(); } Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstart"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstop"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } } } protected void gridScheduledUsers_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridDataInsertItem) { GridDataInsertItem item = e.Item as GridDataInsertItem; //RadDateTimePicker rdt = item.FindControl("dtstart") as RadDateTimePicker; //rdt.SharedTimeView = rt1; Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)item.FindControl("dtstart"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } picker = (Telerik.Web.UI.RadDateTimePicker)item.FindControl("dtstop"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } } } #endregion populate #region editing private void UpdateSchedUserFromGrid(GridCommandEventArgs e) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { WorkorderItemScheduledUser o = CurrentWorkorderItem.ScheduledUsers[newValues["ID"].ToString()]; Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbuser") as Telerik.Web.UI.RadComboBox; o.UserID = Util.ComboValue(cb); cb = e.Item.FindControl("cbrate") as Telerik.Web.UI.RadComboBox; o.ServiceRateID = Util.ComboValue(cb); //Since WorkorderItemscheduleduser automatically sets the other date //if only one is filled in we need to handle that here Telerik.Web.UI.RadDateTimePicker dtStart = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstart"); Telerik.Web.UI.RadDateTimePicker dtStop = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstop"); //Both dates filled in or not filled in? if ((dtStart.DbSelectedDate != null && dtStop.DbSelectedDate != null) || (dtStart.DbSelectedDate == null && dtStop.DbSelectedDate == null)) { o.StopDate = dtStop.DbSelectedDate; o.StartDate = dtStart.DbSelectedDate; } else { //Only one of the dates is filled in, so only set that one //Let the biz object autofill the other if (dtStart.DbSelectedDate != null) { o.StartDate = dtStart.DbSelectedDate; } else { o.StopDate = dtStop.DbSelectedDate; } } o.EstimatedQuantity = Util.ParseDecimal(newValues["EstimatedQuantity"]); Util.GridCheckForBrokenRule(o, e); } } protected void gridScheduledUsers_ItemCommand(object source, GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.UpdateCommandName: { UpdateSchedUserFromGrid(e); } break; case RadGrid.InitInsertCommandName: { e.Canceled = true; e.Item.OwnerTableView.InsertItem(CurrentWorkorderItem.ScheduledUsers.Add(CurrentWorkorderItem)); } break; case RadGrid.PerformInsertCommandName: { UpdateSchedUserFromGrid(e); } break; case RadGrid.DeleteCommandName: { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.ScheduledUsers.Remove(id); } } break; case RadGrid.CancelCommandName: { if (e.Item is Telerik.Web.UI.GridDataInsertItem) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.ScheduledUsers.Remove(id); } } } break; } } #endregion editing #endregion #region Tasks tab #region Tasks grid #region Populate protected void gridTasks_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { gridTasks.DataSource = CurrentWorkorderItem.Tasks; } protected void gridTasks_ItemDataBound(object sender, GridItemEventArgs e) { //Process fields in Data row... if (e.Item is GridDataItem && e.Item.DataItem is WorkorderItemTask)//case 1987 { WorkorderItemTaskCompletionTypes ct = ((WorkorderItemTask)e.Item.DataItem).WorkorderItemTaskCompletionType; string selectedTaskID = ((WorkorderItemTask)e.Item.DataItem).TaskID.ToString(); if (e.Item.IsInEditMode) { Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbcmp") as Telerik.Web.UI.RadComboBox; Util.ComboInitializeNonBiz(cb, "WorkorderItemTaskCompletionType", (int)ct); Label l = e.Item.FindControl("lbltask") as Label; l.Text = Util.GetBizObjectName("Task", selectedTaskID); } else { Label l = e.Item.FindControl("lbltask") as Label; l.Text = Util.GetBizObjectName("Task", selectedTaskID); FontInfo fon = l.Font; System.Drawing.Color col = l.ForeColor; switch (ct) { case WorkorderItemTaskCompletionTypes.Complete: fon.Bold = false; col = System.Drawing.Color.Gray; break; case WorkorderItemTaskCompletionTypes.NotApplicable: fon.Bold = false; fon.Italic = true; col = System.Drawing.Color.Gray; break; case WorkorderItemTaskCompletionTypes.Incomplete: fon.Bold = true; col = System.Drawing.Color.Black; break; } l.Font.CopyFrom(fon); l.ForeColor = col; l = e.Item.FindControl("lblcmp") as Label; l.Text = Util.GetNonBizName("WorkorderItemTaskCompletionType", (int)ct); l.Font.CopyFrom(fon); l.ForeColor = col; } } } #endregion populate #region Editing private void UpdateTaskFromGrid(GridCommandEventArgs e) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { WorkorderItemTask o = CurrentWorkorderItem.Tasks[newValues["ID"].ToString()]; Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbcmp") as Telerik.Web.UI.RadComboBox; o.WorkorderItemTaskCompletionType = cb2e.get(cb); Util.GridCheckForBrokenRule(o, e); } } protected void gridTasks_ItemCommand(object source, GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.UpdateCommandName: { UpdateTaskFromGrid(e); } break; case RadGrid.InitInsertCommandName: { e.Canceled = true; e.Item.OwnerTableView.InsertItem(CurrentWorkorderItem.Tasks.Add(CurrentWorkorderItem)); } break; case RadGrid.PerformInsertCommandName: { UpdateTaskFromGrid(e); } break; case RadGrid.DeleteCommandName: { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Tasks.Remove(id); } } break; case RadGrid.CancelCommandName: { //do nothing, no insert in this grid } break; } } #endregion edit #endregion tasks grid #region combo and button private void IntializeTaskCombo() { //fill combo with all tasks Util.ComboPopulateBizList("TaskGroup", cbWorkorderItemTasks, true, null,false); } protected void btnAddTask_Click(object sender, ImageClickEventArgs e) { ////copy tasks selected to workorder item Guid Selected = Util.ComboValue(cbWorkorderItemTasks); if (Selected == Guid.Empty) return; TaskGroup tg = TaskGroup.GetItem(Selected); foreach (TaskGroupTask t in tg.Tasks) { WorkorderItemTask wit = CurrentWorkorderItem.Tasks.Add(CurrentWorkorderItem); wit.TaskID = t.TaskID; wit.TaskGroupID = tg.ID; wit.WorkorderItemTaskCompletionType = WorkorderItemTaskCompletionTypes.Incomplete; } gridTasks.Rebind(); } #endregion combo and button #endregion tasks #region Parts Tab #region Populate /// /// Show or hide inventory related columns and items if applicable /// private void InitPartsTab() { bool show = CurrentWorkorder.UseInventory && CurrentWorkorder.WorkorderType==WorkorderTypes.Service; gridParts.Columns.FindByUniqueName("PartWarehouseID").Visible = show; gridParts.Columns.FindByUniqueName("PartSerialID").Visible = show; gridParts.Columns.FindByUniqueName("Used").Visible = show; gridPartRequests.Visible = show; show=CurrentWorkorder.HasReservedParts; GridColumn g=gridParts.Columns.FindByUniqueName("QuantityReserved"); g.Visible = show; if (show) { if (CurrentWorkorder.FromQuoteID != Guid.Empty) g.HeaderText = Util.LocaleText("WorkorderItemPart.Label.UI.QuantityReservedQuote"); else g.HeaderText = Util.LocaleText("WorkorderItemPart.Label.UI.QuantityReservedPM"); } } protected void gridParts_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { gridParts.DataSource = CurrentWorkorderItem.Parts; } protected void gridParts_ItemDataBound(object sender, GridItemEventArgs e) { //Process fields in Data row... if (e.Item is GridDataItem && e.Item.DataItem is WorkorderItemPart) { Guid warehouse = ((WorkorderItemPart)e.Item.DataItem).PartWarehouseID; Guid part = ((WorkorderItemPart)e.Item.DataItem).PartID; string tax = ((WorkorderItemPart)e.Item.DataItem).TaxPartSaleID.ToString(); string sn = ((WorkorderItemPart)e.Item.DataItem).PartSerialID.ToString(); decimal qty = ((WorkorderItemPart)e.Item.DataItem).Quantity; if (e.Item.IsInEditMode) { Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbwhs") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("PartWarehousePickList", cb, true,Guid.Empty,CurrentWorkorder.ListOfPartWarehousesSelected(), null,true); cb.SelectedValue = warehouse.ToString(); cb = e.Item.FindControl("cbpart") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("PartPickList", cb, true, Guid.Empty, CurrentWorkorder.ListOfPartsSelected(), null,false); cb.SelectedValue = part.ToString(); cb.DropDownWidth = System.Web.UI.WebControls.Unit.Pixel(400); cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("TaxCode", cb, true, null,false); cb.SelectedValue = tax; //can we fill the sn list? if (warehouse != Guid.Empty && part != Guid.Empty) { cb = e.Item.FindControl("cbsn") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("PartSerialPickList", cb, true, part, warehouse, null, null,false); cb.SelectedValue = sn; } TextBox tb = e.Item.FindControl("tbqty") as TextBox; tb.Text = qty.ToString("g29"); } else { Label l = e.Item.FindControl("lblwhs") as Label; l.Text = Util.GetBizObjectName("PartWarehouse", warehouse); l = e.Item.FindControl("lblpart") as Label; l.Text = Util.GetBizObjectName("Part", part); l = e.Item.FindControl("lbltax") as Label; l.Text = Util.GetBizObjectName("TaxCode", tax); l = e.Item.FindControl("lblsn") as Label; l.Text = Util.GetBizObjectName("PartSerial", sn); l = e.Item.FindControl("lblqty") as Label; l.Text = qty.ToString("g29"); Hashtable newValues = Util.GridExtractValues(e.Item); if (Util.ParseBool(newValues["Used"])) { GridDataItem di = (GridDataItem)e.Item; di["EditColumn"].Controls.Clear(); } } } } #endregion populate #region Edit private void UpdatePartFromGrid(GridCommandEventArgs e) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { WorkorderItemPart o = CurrentWorkorderItem.Parts[newValues["ID"].ToString()]; Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbwhs") as Telerik.Web.UI.RadComboBox; o.PartWarehouseID = Util.ComboValue(cb); cb = e.Item.FindControl("cbpart") as Telerik.Web.UI.RadComboBox; o.PartID = Util.ComboValue(cb); cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; o.TaxPartSaleID = Util.ComboValue(cb); cb = e.Item.FindControl("cbsn") as Telerik.Web.UI.RadComboBox; o.PartSerialID = Util.ComboValue(cb); TextBox qty = e.Item.FindControl("tbqty") as TextBox; o.Quantity = Util.ParseDecimal(qty.Text); if (CurrentWorkorder.IsServiceWorkorder && Util.GlobalSettings.UseInventory && o.PartID != Guid.Empty) { //if q > 1 check if serialized and if so set back to 1 if (o.Quantity > 1) { PartPickList pp = PartPickList.GetOnePart(o.PartID); if (pp.Count > 0) { if (pp[0].TrackSerialNumber) o.Quantity = 1; } } //Now check to see if there are enough in stock... decimal dOnHand = PartByWarehouseInventoryValuesFetcher.GetItem(o.PartID, o.PartWarehouseID).QuantityOnHand; if (dOnHand < o.Quantity && (o.PartID!=Guid.Empty && o.PartWarehouseID!=Guid.Empty))//case 2082 { //Nope, so make requests mCurrentWorkorderItem.MovePartToRequest(o.ID, o.Quantity - dOnHand); } } //used o.Used = Util.ParseBool(newValues["Used"]); //price o.Price = Util.ParseDecimal(newValues["Price"]); //discount o.Discount = Util.ParseDecimal(newValues["Discount"]); //description //CASE 229 o.Description = Util.ObjectToString(newValues["Description"]); Util.GridCheckForBrokenRule(o, e); //trigger an update to part requests gridPartRequests.Rebind(); } } protected void gridParts_ItemCommand(object source, GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.UpdateCommandName: { UpdatePartFromGrid(e); } break; case RadGrid.InitInsertCommandName: { e.Canceled = true; //case 1693 WorkorderItemPart wip = CurrentWorkorderItem.Parts.Add(CurrentWorkorderItem); Guid DefaultWarehouse = Util.CurrentUser.DefaultWarehouseID; if (DefaultWarehouse != Guid.Empty) wip.PartWarehouseID = DefaultWarehouse; //case 2082 System.Collections.Generic.List validWarehouseIdList = PartWarehouse.UserValidWarehouseIdList(Util.CurrentUserID, Guid.Empty); if (!validWarehouseIdList.Contains(wip.PartWarehouseID)) { wip.PartWarehouseID = Guid.Empty; } e.Item.OwnerTableView.InsertItem(wip); } break; case RadGrid.PerformInsertCommandName: { UpdatePartFromGrid(e); } break; case RadGrid.DeleteCommandName: { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Parts.Remove(id); } } break; case RadGrid.CancelCommandName: { if (e.Item is Telerik.Web.UI.GridDataInsertItem) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Parts.Remove(id); } } } break; } } #endregion edit #region dynamic updates private GridEditableItem partItem = null; protected void gridParts_InsertCommand(object source, GridCommandEventArgs e) { partItem = e.Item as GridEditableItem; } protected void cbpart_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) { HandleEditChange("part"); } protected void cbwhs_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) { HandleEditChange("whs"); } protected void cbsn_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) { HandleEditChange("sn"); } protected void tbqty_TextChanged(object sender, EventArgs e) { HandleEditChange("qty"); } /// /// refresh sn list, handle inventory etc /// private void HandleEditChange(string field) { GridEditableItem i; if (gridParts.EditItems.Count > 0) i = gridParts.EditItems[0] as GridEditableItem; else i = gridParts.MasterTableView.GetInsertItem(); Telerik.Web.UI.RadComboBox cbsn = i.FindControl("cbsn") as Telerik.Web.UI.RadComboBox; Telerik.Web.UI.RadComboBox cbpart = i.FindControl("cbpart") as Telerik.Web.UI.RadComboBox; Telerik.Web.UI.RadComboBox cbwhs = i.FindControl("cbwhs") as Telerik.Web.UI.RadComboBox; TextBox qty = i.FindControl("tbqty") as TextBox; Label stock = i.FindControl("lblstock") as Label; stock.Visible = false; Guid warehouse = Util.ComboValue(cbwhs); Guid part = Util.ComboValue(cbpart); //case 2082 if (part == Guid.Empty || warehouse == Guid.Empty) { //clear shit out and return qty.Text = "0"; return; } switch (field) { case "part": { #region part changed //set initial quantity if not previously set if (Util.ParseDecimal(qty.Text) == 0) qty.Text = "1"; //insert the contract discount if it applies Contract c = CurrentWorkorder.ContractResolved(); if (c != null) { //((WorkorderItemPart)i.DataItem).Discount = c.DiscountParts; GridTextBoxColumnEditor editor = i.EditManager.GetColumnEditor("Discount") as GridTextBoxColumnEditor; editor.Text = c.DiscountParts.ToString("g29"); } PopulateSNList(part,warehouse,cbsn); //set price automatically PartPickList pp = PartPickList.GetOnePart(part); if (pp.Count > 0) { GridTextBoxColumnEditor editor = i.EditManager.GetColumnEditor("Price") as GridTextBoxColumnEditor; editor.Text = pp[0].Retail.ToString("g29"); } #endregion } break; //case "whs": // { // } //break; case "sn": { #region new sn selected //change in serial number? if (Util.GlobalSettings.UseInventory) { //copy serial number to text serial number field GridTextBoxColumnEditor editor = i.EditManager.GetColumnEditor("Description") as GridTextBoxColumnEditor; editor.Text = cbsn.Text; } #endregion } break; //case "qty": // { // } // break; } #region check quantity and stock level if (CurrentWorkorder.IsServiceWorkorder && Util.GlobalSettings.UseInventory && part != Guid.Empty) { //get the user's selected amount decimal dCurrentQuantity = Util.ParseDecimal(qty.Text); if (dCurrentQuantity != 0) { //If it's serialized make sure it's only set to 1 PartPickList pp = PartPickList.GetOnePart(part); if (dCurrentQuantity != 1 && pp.Count > 0) { if (pp[0].TrackSerialNumber) { dCurrentQuantity = 1; qty.Text = "1"; } } //Now set inventory warning if insufficient stock... //TODO: find out why this code copied from winform AyaNova //is in a try catch block, it seems to be a hack for something //that should be cleaned up. try { //Now check to see if there are enough in stock... decimal dOnHand = PartByWarehouseInventoryValuesFetcher.GetItem(part, warehouse).QuantityOnHand; if (dOnHand < dCurrentQuantity) { //Out of stock set warning label SetStockWarningLabel(dOnHand, dCurrentQuantity, stock); } } catch { //probably failed due to none in stock at all //Need to order more //Out of stock, prompt if they want to put on request list SetStockWarningLabel(0, dCurrentQuantity, stock); } } } #endregion } /// /// set warning about stock level /// /// /// private void SetStockWarningLabel(decimal StockAmount, decimal TotalAmount, Label l) { l.Visible = true; decimal RequestAmount = TotalAmount - StockAmount; l.Text = "(!)"; l.ForeColor = System.Drawing.Color.Red; l.ToolTip=string.Format(Util.LocaleText("WorkorderItemPart.Label.Warning.InsufficientStock"),StockAmount,RequestAmount); } private void PopulateSNList(Guid part, Guid warehouse, Telerik.Web.UI.RadComboBox cbsn) { Guid sn = Util.ComboValue(cbsn); //clear the sn list: cbsn.Items.Clear(); //Refill it if there is enough info to do so if (warehouse != Guid.Empty && part != Guid.Empty) { Util.ComboPopulateBizList("PartSerialPickListForWorkorder", cbsn, true, part, warehouse, CurrentWorkorder.ListOfSerialNumbersSelected(sn), null,false); } } #endregion #region Part requests grid #region Populate protected void gridPartRequests_ItemDataBound(object sender, GridItemEventArgs e) { //Process fields in Data row... if (e.Item is GridDataItem && e.Item.DataItem is WorkorderItemPartRequest) { Guid warehouse = ((WorkorderItemPartRequest)e.Item.DataItem).PartWarehouseID; Guid part = ((WorkorderItemPartRequest)e.Item.DataItem).PartID; if (!e.Item.IsInEditMode) { Label l = e.Item.FindControl("lblwhs") as Label; l.Text = Util.GetBizObjectName("PartWarehouse", warehouse); l = e.Item.FindControl("lblpart") as Label; l.Text = Util.GetBizObjectName("Part", part); } } } protected void gridPartRequests_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { if (CurrentWorkorder.IsServiceWorkorder) gridPartRequests.DataSource = CurrentWorkorderItem.PartRequests; else { lblPartRequests.Visible = false; gridPartRequests.Visible = false; } //bool bshowgrid = (CurrentWorkorderItem.PartRequests.Count != 0); //if (!bshowgrid) //{ // //lblPartRequests.Style.Add("display", "none"); // gridPartRequests.Style.Add("display", "none"); // lblPartRequests.Text = "NO REQUESTS"; //} //else //{ // //lblPartRequests.Style.Remove("display"); // lblPartRequests.Text = "REQUESTS"; // gridPartRequests.Style.Remove("display"); //} } #endregion populate #region Edit protected void gridPartRequests_ItemCommand(object source, GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.DeleteCommandName: { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); bool bOnOrder = Util.ParseBool(newValues["OnOrder"]); if (bOnOrder) Util.PopupAlert(this.Page,Util.LocaleText("WorkorderItemPartRequest.Error.NotDeleteableOnOrder"), " "); else CurrentWorkorderItem.PartRequests.Remove(id); } } break; } } #endregion edit #endregion part requests grid #endregion parts tab #region Labor tab #region Populate protected void gridLabor_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { gridLabor.DataSource = CurrentWorkorderItem.Labors; ShowBank(); } //case 1617 private void ShowBank() { //case 1617, same as ayanova workorder form the following two blocks were transposed because unit bank trumps labor bank //Case 635 lblServiceBankBalance.Text = ""; Guid unitID = mCurrentWorkorderItem.UnitID; //Util.ComboValue(cbWorkorderItemUnitID); if (unitID != Guid.Empty) { if (GZTW.AyaNova.BLL.Unit.GetItem(unitID).UsesBanking) { lblTravelServiceBankBalance.Text=lblServiceBankBalance.Text = Util.StringWebify(ServiceBankCurrentBalanceFetcher.GetItem(unitID, RootObjectTypes.Unit).DisplayBalances); return; } } if (WorkorderBankableObject != null) { lblTravelServiceBankBalance.Text=lblServiceBankBalance.Text = Util.StringWebify(ServiceBankCurrentBalanceFetcher.GetItem(mWorkorderBankableObject.ID, mWorkorderBankableObject.RootObjectType).DisplayBalances); } } #region Bankable request cache private TypeAndID mWorkorderBankableObject = new TypeAndID(RootObjectTypes.Nothing,Guid.Empty); private TypeAndID WorkorderBankableObject { get { if (mWorkorderBankableObject!=null && mWorkorderBankableObject.RootObjectType == RootObjectTypes.Nothing) { mWorkorderBankableObject = CurrentWorkorder.BankableResolved(); } return mWorkorderBankableObject; } } private bool? mCurrentUnitIsBankable = null; private bool CurrentUnitIsBankable { get { if (mCurrentUnitIsBankable==null) { mCurrentUnitIsBankable=false; if(CurrentWorkorderItem.UnitID!=Guid.Empty) { //is this Unit bankable? UnitPickList up=UnitPickList.GetListOfOneSpecificUnit(CurrentWorkorderItem.UnitID); if(up.Count>0) { //If unit is bankable and client of workorder is owner of unit currently //then it's bankable to this client if(up[0].UsesBanking && up[0].ClientID==CurrentWorkorder.ClientID) { mCurrentUnitIsBankable=true; } } } } return (bool)mCurrentUnitIsBankable; } } #endregion protected void gridLabor_ItemDataBound(object sender, GridItemEventArgs e) { //Process fields in Data row... if (e.Item is GridEditFormItem && e.Item.DataItem is WorkorderItemLabor)//case 1987 { string selectedUserID = ((WorkorderItemLabor)e.Item.DataItem).UserID.ToString(); string selectedRateID = ((WorkorderItemLabor)e.Item.DataItem).ServiceRateID.ToString(); string tax = ((WorkorderItemLabor)e.Item.DataItem).TaxRateSaleID.ToString(); if (e.Item.IsInEditMode) { Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbuser") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("UserPickListScheduleable", cb, true, Guid.Empty, CurrentWorkorder.ListOfLaborUsersSelected(), null,true); cb.SelectedValue = selectedUserID; cb = e.Item.FindControl("cbrate") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("LaborRateList", cb, true, CurrentWorkorder.ContractIDResolved(), CurrentWorkorder.ListOfLaborRatesSelected(), null,true); cb.SelectedValue = selectedRateID; cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("TaxCode", cb, true, null,false); cb.SelectedValue = tax; Telerik.Web.UI.RadDateTimePicker rdp = e.Item.FindControl("dtstart") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItemLabor)e.Item.DataItem).ServiceStartDate; rdp = e.Item.FindControl("dtstop") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItemLabor)e.Item.DataItem).ServiceStopDate; TextBox tb = e.Item.FindControl("tbdetails") as TextBox; tb.Text = ((WorkorderItemLabor)e.Item.DataItem).ServiceDetails; //TODO: HIDE THE ID FIELD IN THE EDIT FORM AWAITING FORUM POST ANSWER GridEditFormItem gefi = e.Item as GridEditFormItem; gefi["ID"].Style.Add("Display", "none"); } } else if (e.Item is GridDataItem && e.Item.DataItem is WorkorderItemLabor)//case 1987 { string selectedUserID = ((WorkorderItemLabor)e.Item.DataItem).UserID.ToString(); string selectedRateID = ((WorkorderItemLabor)e.Item.DataItem).ServiceRateID.ToString(); string tax = ((WorkorderItemLabor)e.Item.DataItem).TaxRateSaleID.ToString(); Label l = e.Item.FindControl("lbluser") as Label; l.Text = Util.GetBizObjectName("User", selectedUserID); l = e.Item.FindControl("lblrate") as Label; l.Text = Util.GetBizObjectName("Rate", selectedRateID); l = e.Item.FindControl("lbltax") as Label; l.Text = Util.GetBizObjectName("TaxCode", tax); l = e.Item.FindControl("lblstart") as Label; l.Text = ((WorkorderItemLabor)e.Item.DataItem).ServiceStartDate.ToString(); l = e.Item.FindControl("lblstop") as Label; l.Text = ((WorkorderItemLabor)e.Item.DataItem).ServiceStopDate.ToString(); l = e.Item.FindControl("lbldetails") as Label; l.Text = ((WorkorderItemLabor)e.Item.DataItem).ServiceDetails; //Show bankable button if this row can be banked //and is not already banked bool isBanked=((WorkorderItemLabor)e.Item.DataItem).ServiceBankID != Guid.Empty; bool canBank = (WorkorderBankableObject != null && !isBanked); GridDataItem gdi = e.Item as GridDataItem; if (isBanked) { //disable editing and hide bank button gdi["EditColumn"].Controls.Clear(); gdi["BankColumn"].Controls.Clear(); gdi["DeleteColumn"].Controls.Clear(); } else { if (!canBank) gdi["BankColumn"].Controls.Clear(); } } Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstart"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstop"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } } protected void gridLabor_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormItem) { GridEditFormItem item = e.Item as GridEditFormItem; Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)item.FindControl("dtstart"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; } picker = (Telerik.Web.UI.RadDateTimePicker)item.FindControl("dtstop"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; } } } #endregion populate #region Edit private void UpdateLaborFromGrid(GridCommandEventArgs e) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { WorkorderItemLabor o = CurrentWorkorderItem.Labors[newValues["ID"].ToString()]; Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbuser") as Telerik.Web.UI.RadComboBox; o.UserID = Util.ComboValue(cb); cb = e.Item.FindControl("cbrate") as Telerik.Web.UI.RadComboBox; o.ServiceRateID = Util.ComboValue(cb); cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; o.TaxRateSaleID = Util.ComboValue(cb); //Since WorkorderItemLabor automatically sets the other date //if only one is filled in we need to handle that here Telerik.Web.UI.RadDateTimePicker dtStart = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstart"); Telerik.Web.UI.RadDateTimePicker dtStop = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstop"); //Both dates filled in or not filled in? if ((dtStart.DbSelectedDate != null && dtStop.DbSelectedDate != null) || (dtStart.DbSelectedDate == null && dtStop.DbSelectedDate == null)) { o.ServiceStopDate = dtStop.DbSelectedDate; o.ServiceStartDate = dtStart.DbSelectedDate; } else { //Only one of the dates is filled in, so only set that one //Let the biz object autofill the other if (dtStart.DbSelectedDate != null) { o.ServiceStartDate = dtStart.DbSelectedDate; } else { o.ServiceStopDate = dtStop.DbSelectedDate; } } o.ServiceRateQuantity = Util.ParseDecimal(newValues["ServiceRateQuantity"]); o.NoChargeQuantity = Util.ParseDecimal(newValues["NoChargeQuantity"]); TextBox tb = e.Item.FindControl("tbdetails") as TextBox; o.ServiceDetails = Util.ParseMultiLineText(tb.Text);//case 1922 Util.GridCheckForBrokenRule(o, e); } } protected void gridLabor_ItemCommand(object source, GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.UpdateCommandName: { UpdateLaborFromGrid(e); } break; case RadGrid.InitInsertCommandName: { e.Canceled = true; e.Item.OwnerTableView.InsertItem(CurrentWorkorderItem.Labors.Add(CurrentWorkorderItem)); } break; case RadGrid.PerformInsertCommandName: { UpdateLaborFromGrid(e); } break; case RadGrid.DeleteCommandName: { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Labors.Remove(id); } } break; case RadGrid.CancelCommandName: //case "Edit"://test case 1987 { if (e.Item is Telerik.Web.UI.GridDataInsertItem) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Labors.Remove(id); } } } break; case "BANK": { Hashtable newValues = Util.GridExtractValues(e.Item); WorkorderItemLabor o = CurrentWorkorderItem.Labors[newValues["ID"].ToString()]; if (o.ServiceRateID==Guid.Empty) return; if (o.ServiceRateQuantity == 0) return; if(o.ServiceBankID!=Guid.Empty) return; //Figure out what to apply this to... TypeAndID tid = null; if (CurrentUnitIsBankable) { tid = new TypeAndID(RootObjectTypes.Unit, CurrentWorkorderItem.UnitID); } if (tid == null) { if (WorkorderBankableObject == null) return; else tid = WorkorderBankableObject; } RatePickList mRateList; if (CurrentWorkorder.ContractResolved() == null) mRateList = RatePickList.GetList(true); else mRateList = RatePickList.GetListWithContract(CurrentWorkorder.ContractResolved().ID); decimal dCharge = mRateList[o.ServiceRateID].Charge; //case 1190 //Check if already banked Guid gPriorBank = ServiceBankCheckAlreadyBanked.GetBankID(o.ID, RootObjectTypes.WorkorderItemLabor); if (gPriorBank != Guid.Empty) { //case 1189 flag the labor record o.ApplyServiceBankID(gPriorBank); } else o.ApplyToServiceBank(tid, dCharge, Util.LocaleText("O.Workorder") + " " + CurrentWorkorder.WorkorderService.ServiceNumber.ToString()); gridLabor.Rebind(); } break; } } #endregion edit #endregion labor tab #region Travel tab #region Populate protected void gridTravel_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { gridTravel.DataSource = CurrentWorkorderItem.Travels; //case 1617 ShowBank(); } protected void gridTravel_ItemDataBound(object sender, GridItemEventArgs e) { //Process fields in Data row... if (e.Item is GridEditFormItem) { string selectedUserID = ((WorkorderItemTravel)e.Item.DataItem).UserID.ToString(); string selectedRateID = ((WorkorderItemTravel)e.Item.DataItem).TravelRateID.ToString(); string tax = ((WorkorderItemTravel)e.Item.DataItem).TaxRateSaleID.ToString(); if (e.Item.IsInEditMode) { Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbuser") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("UserPickListScheduleable", cb, true, Guid.Empty, CurrentWorkorder.ListOfTravelUsersSelected(), null,true); cb.SelectedValue = selectedUserID; cb = e.Item.FindControl("cbrate") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("TravelRateList", cb, true, CurrentWorkorder.ContractIDResolved(), CurrentWorkorder.ListOfTravelRatesSelected(), null,true); cb.SelectedValue = selectedRateID; cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("TaxCode", cb, true, null,false); cb.SelectedValue = tax; Telerik.Web.UI.RadDateTimePicker rdp = e.Item.FindControl("dtstart") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItemTravel)e.Item.DataItem).TravelStartDate; rdp = e.Item.FindControl("dtstop") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItemTravel)e.Item.DataItem).TravelStopDate; TextBox tb = e.Item.FindControl("tbdetails") as TextBox; tb.Text = ((WorkorderItemTravel)e.Item.DataItem).TravelDetails; GridEditFormItem gefi = e.Item as GridEditFormItem; gefi["ID"].Style.Add("Display", "none"); } } else if (e.Item is GridDataItem) { string selectedUserID = ((WorkorderItemTravel)e.Item.DataItem).UserID.ToString(); string selectedRateID = ((WorkorderItemTravel)e.Item.DataItem).TravelRateID.ToString(); string tax = ((WorkorderItemTravel)e.Item.DataItem).TaxRateSaleID.ToString(); Label l = e.Item.FindControl("lbluser") as Label; l.Text = Util.GetBizObjectName("User", selectedUserID); l = e.Item.FindControl("lblrate") as Label; l.Text = Util.GetBizObjectName("Rate", selectedRateID); l = e.Item.FindControl("lbltax") as Label; l.Text = Util.GetBizObjectName("TaxCode", tax); l = e.Item.FindControl("lblstart") as Label; l.Text = ((WorkorderItemTravel)e.Item.DataItem).TravelStartDate.ToString(); l = e.Item.FindControl("lblstop") as Label; l.Text = ((WorkorderItemTravel)e.Item.DataItem).TravelStopDate.ToString(); l = e.Item.FindControl("lbldetails") as Label; l.Text = ((WorkorderItemTravel)e.Item.DataItem).TravelDetails; //Show bankable button if this row can be banked //and is not already banked bool isBanked = ((WorkorderItemTravel)e.Item.DataItem).ServiceBankID != Guid.Empty; bool canBank = (WorkorderBankableObject != null && !isBanked); GridDataItem gdi = e.Item as GridDataItem; if (isBanked) { //disable editing and hide bank button gdi["EditColumn"].Controls.Clear(); gdi["BankColumn"].Controls.Clear(); gdi["DeleteColumn"].Controls.Clear(); } else { if (!canBank) gdi["BankColumn"].Controls.Clear(); } } Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstart"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstop"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } } protected void gridTravel_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormItem) { GridEditFormItem item = e.Item as GridEditFormItem; Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)item.FindControl("dtstart"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; } picker = (Telerik.Web.UI.RadDateTimePicker)item.FindControl("dtstop"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; } } } #endregion populate #region Edit private void UpdateTravelFromGrid(GridCommandEventArgs e) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { WorkorderItemTravel o = CurrentWorkorderItem.Travels[newValues["ID"].ToString()]; Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbuser") as Telerik.Web.UI.RadComboBox; o.UserID = Util.ComboValue(cb); cb = e.Item.FindControl("cbrate") as Telerik.Web.UI.RadComboBox; o.TravelRateID = Util.ComboValue(cb); cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; o.TaxRateSaleID = Util.ComboValue(cb); //Since WorkorderItemLabor automatically sets the other date //if only one is filled in we need to handle that here Telerik.Web.UI.RadDateTimePicker dtStart = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstart"); Telerik.Web.UI.RadDateTimePicker dtStop = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtstop"); //Both dates filled in or not filled in? if ((dtStart.DbSelectedDate != null && dtStop.DbSelectedDate != null) || (dtStart.DbSelectedDate == null && dtStop.DbSelectedDate == null)) { o.TravelStopDate = dtStop.DbSelectedDate; o.TravelStartDate = dtStart.DbSelectedDate; } else { //Only one of the dates is filled in, so only set that one //Let the biz object autofill the other if (dtStart.DbSelectedDate != null) { o.TravelStartDate = dtStart.DbSelectedDate; } else { o.TravelStopDate = dtStop.DbSelectedDate; } } o.TravelRateQuantity = Util.ParseDecimal(newValues["TravelRateQuantity"]); o.NoChargeQuantity = Util.ParseDecimal(newValues["NoChargeQuantity"]); o.Distance = Util.ParseDecimal(newValues["Distance"]); TextBox tb = e.Item.FindControl("tbdetails") as TextBox; o.TravelDetails = tb.Text; Util.GridCheckForBrokenRule(o, e); } } protected void gridTravel_ItemCommand(object source, GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.UpdateCommandName: { UpdateTravelFromGrid(e); } break; case RadGrid.InitInsertCommandName: { e.Canceled = true; e.Item.OwnerTableView.InsertItem(CurrentWorkorderItem.Travels.Add(CurrentWorkorderItem)); } break; case RadGrid.PerformInsertCommandName: { UpdateTravelFromGrid(e); } break; case RadGrid.DeleteCommandName: { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Travels.Remove(id); } } break; case RadGrid.CancelCommandName: { if (e.Item is Telerik.Web.UI.GridDataInsertItem) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Travels.Remove(id); } } } break; case "BANK": { Hashtable newValues = Util.GridExtractValues(e.Item); WorkorderItemTravel o = CurrentWorkorderItem.Travels[newValues["ID"].ToString()]; if (o.TravelRateID == Guid.Empty) return; if (o.TravelRateQuantity == 0) return; if (o.ServiceBankID != Guid.Empty) return; //Figure out what to apply this to... TypeAndID tid = null; if (CurrentUnitIsBankable) { tid = new TypeAndID(RootObjectTypes.Unit, CurrentWorkorderItem.UnitID); } if (tid == null) { if (WorkorderBankableObject == null) return; else tid = WorkorderBankableObject; } RatePickList mRateList; if (CurrentWorkorder.ContractResolved() == null) mRateList = RatePickList.GetList(true); else mRateList = RatePickList.GetListWithContract(CurrentWorkorder.ContractResolved().ID); decimal dCharge = mRateList[o.TravelRateID].Charge; //case 1190 //Check if already banked Guid gPriorBank = ServiceBankCheckAlreadyBanked.GetBankID(o.ID, RootObjectTypes.WorkorderItemTravel); if (gPriorBank != Guid.Empty) { //case 1189 flag the travel record o.ApplyServiceBankID(gPriorBank); } else o.ApplyToServiceBank(tid, dCharge, Util.LocaleText("O.Workorder") + " " + CurrentWorkorder.WorkorderService.ServiceNumber.ToString()); gridTravel.Rebind(); } break; } } #endregion edit #endregion travel tab #region Expense tab #region Populate protected void gridExpense_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { gridExpense.DataSource = CurrentWorkorderItem.Expenses; } protected void gridExpense_ItemDataBound(object sender, GridItemEventArgs e) { //Process fields in Data row... if (e.Item is GridEditFormItem) { string selectedUserID = ((WorkorderItemMiscExpense)e.Item.DataItem).UserID.ToString(); string tax = ((WorkorderItemMiscExpense)e.Item.DataItem).ChargeTaxCodeID.ToString(); if (e.Item.IsInEditMode) { Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbuser") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("UserPickListScheduleable", cb, true, Guid.Empty, CurrentWorkorder.ListOfMiscExpenseUsersSelected(), null,true); cb.SelectedValue = selectedUserID; cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("TaxCode", cb, true, null,false); cb.SelectedValue = tax; TextBox tb = e.Item.FindControl("tbdetails") as TextBox; tb.Text = ((WorkorderItemMiscExpense)e.Item.DataItem).Description; GridEditFormItem gefi = e.Item as GridEditFormItem; gefi["ID"].Style.Add("Display", "none"); } } else if (e.Item is GridDataItem) { string selectedUserID = ((WorkorderItemMiscExpense)e.Item.DataItem).UserID.ToString(); string tax = ((WorkorderItemMiscExpense)e.Item.DataItem).ChargeTaxCodeID.ToString(); Label l = e.Item.FindControl("lbluser") as Label; l.Text = Util.GetBizObjectName("User", selectedUserID); l = e.Item.FindControl("lbltax") as Label; l.Text = Util.GetBizObjectName("TaxCode", tax); l = e.Item.FindControl("lbldetails") as Label; l.Text = ((WorkorderItemMiscExpense)e.Item.DataItem).Description; } } #endregion populate #region Edit private void UpdateExpenseFromGrid(GridCommandEventArgs e) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { WorkorderItemMiscExpense o = CurrentWorkorderItem.Expenses[newValues["ID"].ToString()]; Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbuser") as Telerik.Web.UI.RadComboBox; o.UserID = Util.ComboValue(cb); cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; o.ChargeTaxCodeID = Util.ComboValue(cb); TextBox tb = e.Item.FindControl("tbdetails") as TextBox; o.Description = tb.Text; o.TotalCost = Util.ParseDecimal(newValues["TotalCost"]); o.TaxPaid = Util.ParseDecimal(newValues["TaxPaid"]); o.ChargeAmount = Util.ParseDecimal(newValues["ChargeAmount"]); o.Name = Util.ObjectToString(newValues["Name"]); o.ReimburseUser = Util.ParseBool(newValues["ReimburseUser"]); o.ChargeToClient = Util.ParseBool(newValues["ChargeToClient"]); Util.GridCheckForBrokenRule(o, e); } } protected void gridExpense_ItemCommand(object source, GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.UpdateCommandName: { UpdateExpenseFromGrid(e); } break; case RadGrid.InitInsertCommandName: { e.Canceled = true; e.Item.OwnerTableView.InsertItem(CurrentWorkorderItem.Expenses.Add(CurrentWorkorderItem)); } break; case RadGrid.PerformInsertCommandName: { UpdateExpenseFromGrid(e); } break; case RadGrid.DeleteCommandName: { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Expenses.Remove(id); } } break; case RadGrid.CancelCommandName: { if (e.Item is Telerik.Web.UI.GridDataInsertItem) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Expenses.Remove(id); } } } break; } } #endregion edit #endregion expense tab #region Loanitems tab #region Populate protected void gridLoan_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { gridLoan.DataSource = CurrentWorkorderItem.Loans; } protected void gridLoan_ItemDataBound(object sender, GridItemEventArgs e) { //Process fields in Data row... if (e.Item is GridEditFormItem) { string selectedLoanID = ((WorkorderItemLoan)e.Item.DataItem).LoanItemID.ToString(); string tax = ((WorkorderItemLoan)e.Item.DataItem).TaxCodeID.ToString(); //case 513 int nSelectedRate = (int)((WorkorderItemLoan)e.Item.DataItem).Rate; if (e.Item.IsInEditMode) { Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbloan") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("LoanItemPickList", cb, true, Guid.Empty, CurrentWorkorder.ListOfLoanItemsSelected(), null,true); cb.SelectedValue = selectedLoanID; cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; Util.ComboPopulateBizList("TaxCode", cb, true, null,false); cb.SelectedValue = tax; Telerik.Web.UI.RadDateTimePicker rdp = e.Item.FindControl("dtout") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItemLoan)e.Item.DataItem).OutDate; rdp = e.Item.FindControl("dtdue") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItemLoan)e.Item.DataItem).DueDate; rdp = e.Item.FindControl("dtreturn") as Telerik.Web.UI.RadDateTimePicker; rdp.DbSelectedDate = ((WorkorderItemLoan)e.Item.DataItem).ReturnDate; TextBox tb = e.Item.FindControl("tbnotes") as TextBox; tb.Text = ((WorkorderItemLoan)e.Item.DataItem).Notes; //Case 513 tb = e.Item.FindControl("tbloanerqty") as TextBox; tb.Text = ((WorkorderItemLoan)e.Item.DataItem).Quantity.ToString("g29"); cb = e.Item.FindControl("cbRate") as Telerik.Web.UI.RadComboBox; Util.ComboInitializeNonBiz(cb, "LoanItemRates", nSelectedRate); GridEditFormItem gefi = e.Item as GridEditFormItem; gefi["ID"].Style.Add("Display", "none"); } } else if (e.Item is GridDataItem) { string selectedLoanID = ((WorkorderItemLoan)e.Item.DataItem).LoanItemID.ToString(); string tax = ((WorkorderItemLoan)e.Item.DataItem).TaxCodeID.ToString(); //case 513 int nSelectedRate = (int)((WorkorderItemLoan)e.Item.DataItem).Rate; Label l = e.Item.FindControl("lblloan") as Label; l.Text = Util.GetBizObjectName("LoanItem", selectedLoanID); l = e.Item.FindControl("lbltax") as Label; l.Text = Util.GetBizObjectName("TaxCode", tax); l = e.Item.FindControl("lblout") as Label; l.Text = ((WorkorderItemLoan)e.Item.DataItem).OutDate.ToString(); l = e.Item.FindControl("lbldue") as Label; l.Text = ((WorkorderItemLoan)e.Item.DataItem).DueDate.ToString(); l = e.Item.FindControl("lblreturn") as Label; l.Text = ((WorkorderItemLoan)e.Item.DataItem).ReturnDate.ToString(); l = e.Item.FindControl("lblnotes") as Label; l.Text = ((WorkorderItemLoan)e.Item.DataItem).Notes; //Case 513 l = e.Item.FindControl("lblRate") as Label; l.Text = Util.GetNonBizName("LoanItemRates", nSelectedRate); l = e.Item.FindControl("lblloanerqty") as Label; l.Text = ((WorkorderItemLoan)e.Item.DataItem).Quantity.ToString("g29"); } Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtout"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtdue"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtreturn"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; //dpShared.Visible = true; } } protected void gridLoan_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditFormItem) { GridEditFormItem item = e.Item as GridEditFormItem; Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)item.FindControl("dtout"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; } picker = (Telerik.Web.UI.RadDateTimePicker)item.FindControl("dtdue"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; } picker = (Telerik.Web.UI.RadDateTimePicker)item.FindControl("dtreturn"); if (picker != null) { picker.SharedCalendar = rc1; picker.SharedTimeView = rt1; } } } #endregion populate #region Edit private void UpdateLoanFromGrid(GridCommandEventArgs e) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { WorkorderItemLoan o = CurrentWorkorderItem.Loans[newValues["ID"].ToString()]; Telerik.Web.UI.RadComboBox cb = e.Item.FindControl("cbloan") as Telerik.Web.UI.RadComboBox; o.LoanItemID = Util.ComboValue(cb); cb = e.Item.FindControl("cbtax") as Telerik.Web.UI.RadComboBox; o.TaxCodeID = Util.ComboValue(cb); //Case 513 cb = e.Item.FindControl("cbRate") as Telerik.Web.UI.RadComboBox; o.Rate = cb2e.get(cb); TextBox qty = e.Item.FindControl("tbloanerqty") as TextBox; o.Quantity = Util.ParseDecimal(qty.Text); Telerik.Web.UI.RadDateTimePicker picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtout"); o.OutDate = picker.DbSelectedDate; picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtdue"); o.DueDate = picker.DbSelectedDate; picker = (Telerik.Web.UI.RadDateTimePicker)e.Item.FindControl("dtreturn"); o.ReturnDate = picker.DbSelectedDate; TextBox tb = e.Item.FindControl("tbnotes") as TextBox; o.Notes = tb.Text; o.Charges = Util.ParseDecimal(newValues["Charges"]); Util.GridCheckForBrokenRule(o, e); } } protected void gridLoan_ItemCommand(object source, GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.UpdateCommandName: { UpdateLoanFromGrid(e); } break; case RadGrid.InitInsertCommandName: { e.Canceled = true; e.Item.OwnerTableView.InsertItem(CurrentWorkorderItem.Loans.Add(CurrentWorkorderItem)); } break; case RadGrid.PerformInsertCommandName: { UpdateLoanFromGrid(e); } break; case RadGrid.DeleteCommandName: { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Loans.Remove(id); } } break; case RadGrid.CancelCommandName: { if (e.Item is Telerik.Web.UI.GridDataInsertItem) { Hashtable newValues = Util.GridExtractValues(e.Item); if (newValues["ID"] != null) { Guid id = new Guid(newValues["ID"].ToString()); CurrentWorkorderItem.Loans.Remove(id); } } } break; } } #endregion edit #region dynamic updates Case 513 //NOTE: this code mimics the ayanova workorder form in that if a rate or qty changes //then charges are set, but if the loan item changes there is no change to the charges field //seems slightly wrong but consistency is king. //What it should probably do in both cases is if the loaner item changes then //it should check if there is a rate selected and if there is and only then, it should //recalc the charges based on the new item. private GridEditableItem loanItem = null; protected void gridLoan_InsertCommand(object source, GridCommandEventArgs e) { loanItem = e.Item as GridEditableItem; } protected void cbRate_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) { HandleLoanerEditChange(); } protected void tbloanerqty_TextChanged(object sender, EventArgs e) { HandleLoanerEditChange(); } /// /// update charges field dynamically /// private void HandleLoanerEditChange() { GridEditFormItem gefi; if (this.gridLoan.EditItems.Count > 0) gefi=((GridDataItem)gridLoan.EditItems[0]).EditFormItem; else gefi = gridLoan.MasterTableView.GetInsertItem() as GridEditFormItem; Telerik.Web.UI.RadComboBox cbloan = gefi.FindControl("cbloan") as Telerik.Web.UI.RadComboBox; Telerik.Web.UI.RadComboBox cbRate = gefi.FindControl("cbRate") as Telerik.Web.UI.RadComboBox; TextBox qty = gefi.FindControl("tbloanerqty") as TextBox; Guid loaneritem = Util.ComboValue(cbloan); LoanItemRates rateSelected = cb2e.get(cbRate); decimal quantitySelected = Util.ParseDecimal(qty.Text); //do nothing if None rate selected if (rateSelected == LoanItemRates.None) return; LoanItemPickList lipl=LoanItemPickList.GetOneLoanItem(loaneritem); decimal charges = quantitySelected * lipl.RateValue(loaneritem, rateSelected); GridTextBoxColumnEditor editor = gefi.EditManager.GetColumnEditor("Charges") as GridTextBoxColumnEditor; editor.Text = charges.ToString("g29"); // loanerrate = cbRate.SelectedValue; //switch (field) //{ // case "part": // { // #region part changed // //set initial quantity if not previously set // if (Util.ParseDecimal(qty.Text) == 0) // qty.Text = "1"; // //insert the contract discount if it applies // Contract c = CurrentWorkorder.ContractResolved(); // if (c != null) // { // //((WorkorderItemPart)i.DataItem).Discount = c.DiscountParts; // GridTextBoxColumnEditor editor = i.EditManager.GetColumnEditor("Discount") as GridTextBoxColumnEditor; // editor.Text = c.DiscountParts.ToString("g29"); // } // PopulateSNList(part, warehouse, cbsn); // //set price automatically // PartPickList pp = PartPickList.GetOnePart(part); // if (pp.Count > 0) // { // GridTextBoxColumnEditor editor = i.EditManager.GetColumnEditor("Price") as GridTextBoxColumnEditor; // editor.Text = pp[0].Retail.ToString("g29"); // } // #endregion // } // break; // //case "whs": // // { // // } // //break; // case "sn": // { // #region new sn selected // //change in serial number? // if (Util.GlobalSettings.UseInventory) // { // //copy serial number to text serial number field // GridTextBoxColumnEditor editor = i.EditManager.GetColumnEditor("Description") as GridTextBoxColumnEditor; // editor.Text = cbsn.Text; // } // #endregion // } // break; // //case "qty": // // { // // } // // break; //} } //private void PopulateSNList(Guid part, Guid warehouse, RadComboBox cbsn) //{ // Guid sn = Util.ComboValue(cbsn); // //clear the sn list: // cbsn.Items.Clear(); // //Refill it if there is enough info to do so // if (warehouse != Guid.Empty && part != Guid.Empty) // { // Util.ComboPopulateBizList("PartSerialPickListForWorkorder", cbsn, true, part, warehouse, CurrentWorkorder.ListOfSerialNumbersSelected(sn), null); // } //} #endregion #endregion loan items tab #region Outside service tab /// /// Set data equivalent for this tab only /// Set all values from biz object /// private void InitializeOutsideServiceTab() { if (!CurrentWorkorder.IsServiceWorkorder) return; WorkorderItemOutsideService o=CurrentWorkorderItem.OutsideService; Util.ComboInitialize(cbSentTo, "Vendor", o.VendorSentToID); Util.ComboInitialize(cbSentVia, "Vendor", o.VendorSentViaID); edRMA.Text = o.RMANumber; edRepairCost.Text = o.RepairCost.ToString("c"); edRepairPrice.Text = o.RepairPrice.ToString("c"); edTrackingNumber.Text = o.TrackingNumber; edShippingCost.Text = o.ShippingCost.ToString("c"); edShippingPrice.Text = o.ShippingPrice.ToString("c"); dtSent.DbSelectedDate = o.DateSent; dtETA.DbSelectedDate = o.DateETA; dtReturned.DbSelectedDate = o.DateReturned; edOutsideServiceNotes.Text = o.Notes; } private void OutsideServiceTabGetData() { if (!CurrentWorkorder.IsServiceWorkorder) return; //Case 409 if (AyaBizUtils.Right("Object.WorkorderItemOutsideService") < (int)SecurityLevelTypes.ReadWrite) return; WorkorderItemOutsideService o = CurrentWorkorderItem.OutsideService; o.VendorSentToID=Util.ComboValue(cbSentTo); o.VendorSentViaID = Util.ComboValue(cbSentVia); o.RMANumber = edRMA.Text; o.RepairCost = Util.ParseDecimal(edRepairCost.Text); o.RepairPrice = Util.ParseDecimal(edRepairPrice.Text); o.TrackingNumber = edTrackingNumber.Text; o.ShippingCost = Util.ParseDecimal(edShippingCost.Text); o.ShippingPrice = Util.ParseDecimal(edShippingPrice.Text); o.DateSent = dtSent.DbSelectedDate; o.DateETA = dtETA.DbSelectedDate; o.DateReturned = dtReturned.DbSelectedDate; o.Notes = edOutsideServiceNotes.Text; } protected void cbSentTo_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { Util.ComboPopulateBizList("Vendors:NonShipper", cbSentTo, false, CurrentWorkorderItem.OutsideService.VendorSentToID, null, null,false); } protected void cbSentVia_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) { Util.ComboPopulateBizList("Vendors:Shipper", cbSentVia, false, CurrentWorkorderItem.OutsideService.VendorSentViaID, null, null,false); } #endregion #region warrantyinfo // [WebMethod] public string GetWarrantyInfo(string sUnitID) { Guid unitid = new Guid(sUnitID); if (unitid == Guid.Empty) return ""; string returnvalue = ""; GZTW.AyaNova.BLL.Unit u = GZTW.AyaNova.BLL.Unit.GetItem(unitid); //Don't calc warranty for closed or s.c. workorders or ones without a unit if (!CurrentWorkorder.Closed && !CurrentWorkorder.ServiceCompleted) { string sDate = ""; if (u.WarrantyExpiryDateResolved != null) sDate = ((DateTime)u.WarrantyExpiryDateResolved).ToLongDateString(); switch (u.WarrantyStatusResolved) { case WarrantyStatus.None: returnvalue = Util.LocaleText("Unit.Label.UI.NotWarrantiedDisplay"); break; case WarrantyStatus.Expired: returnvalue = string.Format ( Util.LocaleText("Unit.Label.UI.WarrantyExpiredDisplay"), sDate ); break; case WarrantyStatus.Active: returnvalue = string.Format ( Util.LocaleText("Unit.Label.UI.WarrantiedDisplay"), sDate, u.WarrantyTermsResolved ); break; } } returnvalue = returnvalue + "\r\n=-=-=-=-=-=--=\r\n" + u.History; return returnvalue; } #endregion #region Toolbar and other master page messages /// /// Messages from master page /// void HandleAyMessage() { switch (Master.AyMessage.MessageType) { case AYMessageType.UpdateObject: { switch (Master.AyMessage.Message) { case "SETALLPARTSUSED": CurrentWorkorder.SetAllPartsUsed(); gridParts.Rebind(); break; case "CONVERTSCHEDUSERTOLABOR"://case 212 if (gridScheduledUsers.SelectedItems.Count > 0) { //convert foreach (GridDataItem item in gridScheduledUsers.SelectedItems) { Guid gSchedUserID = new Guid(item["ID"].Text); CurrentWorkorder.CreateLaborFromScheduledUser(CurrentWorkorderItemID,gSchedUserID); } gridLabor.Rebind(); } break; } } break; case AYMessageType.ToolBarClick: { #region tbclicks switch (Master.AyMessage.Message)// { case "LT:UI.Command.Close": CloseForm(); break; case "LT:UI.Command.Save": SaveRecord(); break; case "LT:UI.Command.SaveClose": if (SaveRecord()) CloseForm(); break; case "LT:UI.Command.Delete": //Case 875 if (CurrentWorkorder.IsDeleteable) { CurrentWorkorder.ApplyEdit(); CurrentWorkorder.Delete(); CurrentWorkorder.Save(); CloseForm(); } break; case "LT:UI.Command.RecordHistory": Util.PopupAlert(this.Page, Util.RecordHistoryText( CurrentWorkorder.Creator, CurrentWorkorder.Modifier, CurrentWorkorder.Created, CurrentWorkorder.Modified )," " ); //Util.PopupAlert(this.Page,Util.RecordHistoryText( // CurrentWorkorder.Creator, // CurrentWorkorder.Modifier, // CurrentWorkorder.Created, // CurrentWorkorder.Modified // ))); break; //case "LT:AssignedDoc.Label.List": // Response.Redirect("stub.aspx"); // break; } #endregion tbclicks } break; case AYMessageType.Print: { //Is the workorder clean (all changes saved)? //(this is necessary because reporting is done from the stored record, not the one in memory here) if (CurrentWorkorder.IsDirty) { Util.PopupAlert(this.Page, Util.LocaleText("Workorder.Label.Error.DirtyOrBrokenRules"), "" ); return; } string[] s = Master.AyMessage.Message.Split(','); bool summary = (s[0] != "PRINTDETAILED"); switch (CurrentWorkorder.WorkorderType) { case WorkorderTypes.Service: //case 1346 string sSig = ""; if (CurrentWorkorder.IsSignable) sSig = CurrentWorkorder.ID.ToString(); if (summary) Util.Report(Page,s[1], WorkorderServiceList.ReportKey, WorkorderServiceList.GetListForSingleItem(CurrentWorkorder.ID),sSig); else Util.Report(Page, s[1], WorkorderServiceDetailedReportData.ReportKey, WorkorderServiceDetailedReportData.GetItem(CurrentWorkorder.ID), sSig); break; case WorkorderTypes.PreventiveMaintenance: if (summary) Util.Report(Page, s[1], WorkorderPMList.ReportKey, WorkorderPMList.GetListForSingleItem(CurrentWorkorder.ID)); else Util.Report(Page, s[1], WorkorderPMDetailedReportData.ReportKey, WorkorderPMDetailedReportData.GetItem(CurrentWorkorder.ID)); break; case WorkorderTypes.Quote: if (summary) Util.Report(Page, s[1], WorkorderQuoteList.ReportKey, WorkorderQuoteList.GetListForSingleItem(CurrentWorkorder.ID)); else Util.Report(Page, s[1], WorkorderQuoteDetailedReportData.ReportKey, WorkorderQuoteDetailedReportData.GetItem(CurrentWorkorder.ID)); break; } } break; } } private bool SaveRecord() { if (!CurrentWorkorder.IsDirty) return true; if (CurrentWorkorder.IsSavable) { mWorkorder.Save(); Session.Remove("workorder" + Request.QueryString["id"]); ClearSessionWoItem(); mWorkorder = null; mCurrentWorkorderItem = null; this.Master.SetErrors(""); //show wo number in title SetTitle(); return true; } else { //Case 349 this.Master.SetErrors(Util.WorkorderBrokenRuleFinder(mWorkorder)); //this.Master.SetErrors(mWorkorder.BrokenRulesText); return false; } } private void CloseForm() { Session.Remove("workorder" + Request.QueryString["id"]); ClearSessionWoItem(); CloseMe(); } #endregion #region Session cleanup private void ClearSessionWoItem() { if (string.IsNullOrEmpty(Request.QueryString["id"])) throw new System.ApplicationException("WorkorderEdit->ClearSessionWoItem - ID value is empty"); Session.Remove("currentwoitemidfor" + Request.QueryString["id"]); } #endregion #region hyperlink buttons protected void btnProject_Click(object sender, EventArgs e) { Util.OpenEditWindow(this.Page, RootObjectTypes.Project, CurrentWorkorder.ProjectID); } #endregion }