private void AddDefaultSession(DayEntry activity) { // Clear the sessions from the previously selected row, and show a blank row Sessions.SetCurrentActivity(activity.Activity, 0); dev1_session session = new dev1_session(); session.Account = activity.Account; session.dev1_ActivityId = activity.Activity.Id.ToString(); session.dev1_ActivityTypeName = activity.Activity.LogicalName; session.dev1_ActivityId = activity.Activity.Id.ToString(); session.dev1_StartTime = Sessions.WeekStart; session.activitypointer_subject = activity.Activity.Name; session.activitypointer_regardingobjectid = activity.RegardingObjectId; Sessions.SelectedActivity = activity.Activity; session.dev1_Row = this.Sessions.GetCurrentWeek().Count; // Has the account been set - if not we need to look it up from the selected activity if (session.Account == null || session.activitypointer_regardingobjectid == null) { SetAccountAndRegardingFromActivity(session); } Sessions.AddItem(session); _selectedRows = new SelectedRange[1] { new SelectedRange() }; _selectedRows[0].FromRow = rows.Count + 1; _selectedRows[0].ToRow = rows.Count + 1; }
public override void AddItem(object item) { // TODO: Set current week from the datetime on the new session if (this.SelectedActivity != null) { List <dev1_session> sessions = GetCurrentWeek(); dev1_session itemAdding = (dev1_session)item; dev1_session newItem = new dev1_session(); newItem.dev1_Description = itemAdding.dev1_Description; newItem.dev1_StartTime = itemAdding.dev1_StartTime; newItem.dev1_Duration = itemAdding.dev1_Duration; newItem.Account = itemAdding.Account; newItem.activitypointer_regardingobjectid = itemAdding.activitypointer_regardingobjectid == null ? this.SelectedActivity : itemAdding.activitypointer_regardingobjectid; newItem.activitypointer_subject = itemAdding.activitypointer_regardingobjectid == null ? this.SelectedActivity.Name : itemAdding.activitypointer_subject; newItem.dev1_ActivityId = this.SelectedActivity.Id.ToString(); newItem.dev1_ActivityTypeName = this.SelectedActivity.LogicalName; // Set the activity reference switch (this.SelectedActivity.LogicalName) { case "phonecall": newItem.dev1_PhoneCallId = this.SelectedActivity; break; case "task": newItem.dev1_TaskId = this.SelectedActivity; break; case "letter": newItem.dev1_LetterId = this.SelectedActivity; break; case "email": newItem.dev1_EmailId = this.SelectedActivity; break; } newItem.EntityState = EntityStates.Created; // If no date set, set to the currently selected date if (newItem.dev1_StartTime == null) { newItem.dev1_StartTime = SelectedDay == null ? WeekStart : SelectedDay; } // Add to the sessions view cache AddSession(sessions, newItem); // Add to the data view as well data.Add(newItem); // refresh DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs(); args.From = data.Count - 1; args.To = data.Count - 1; this.OnDataLoaded.Notify(args, null, null); this.OnRowsChanged.Notify(null, null, null); } }
public Action SaveCommand() { if (_saveCommand == null) { _saveCommand = delegate() { bool confirmed = Script.Confirm(String.Format("Are you sure save these sessions?")); if (!confirmed) { return; } SessionVM stopSession = StopSession.GetValue(); dev1_session sessionToUpdate = stopSession.GetUpdatedModel(); try { OrganizationServiceProxy.Update(sessionToUpdate); // Save next session if (StartNewSession.GetValue()) { dev1_session nextSession = StartSession.GetValue().GetUpdatedModel(); OrganizationServiceProxy.Create(nextSession); } } catch (Exception ex) { Script.Alert("There was a problem saving your session. Please contact your system administrator.\n\n" + ex.Message); } }; } return(_saveCommand); }
public override void AddItem(object item) { // TODO: Set current week from the datetime on the new session if (this.SelectedActivity != null) { List<dev1_session> sessions = GetCurrentWeek(); dev1_session itemAdding = (dev1_session)item; dev1_session newItem = new dev1_session(); newItem.dev1_Description = itemAdding.dev1_Description; newItem.dev1_StartTime = itemAdding.dev1_StartTime; newItem.dev1_Duration = itemAdding.dev1_Duration; //newItem.activityName = itemAdding.activityName; newItem.dev1_ActivityId = this.SelectedActivity.Id.ToString(); newItem.dev1_ActivityTypeName = this.SelectedActivity.LogicalName; // Set the activity reference switch (this.SelectedActivity.LogicalName) { case "phonecall": newItem.dev1_PhoneCallId = this.SelectedActivity; break; case "task": newItem.dev1_TaskId = this.SelectedActivity; break; case "letter": newItem.dev1_LetterId = this.SelectedActivity; break; case "email": newItem.dev1_EmailId = this.SelectedActivity; break; } newItem.EntityState = EntityStates.Created; // If no date set, set to the currently selected date if (newItem.dev1_StartTime == null) { newItem.dev1_StartTime = SelectedDay == null ? WeekStart : SelectedDay; } // Add to the sessions view cache AddSession(sessions, newItem); // Add to the data view as well data.Add(newItem); // refresh DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs(); args.From = data.Count - 1; args.To = data.Count - 1; this.OnDataLoaded.Notify(args, null, null); this.OnRowsChanged.Notify(null, null, null); } }
private void SetAccountAndRegardingFromActivity(dev1_session session) { string fetchXml = @" <fetch> <entity name='activitypointer' > <attribute name='regardingobjectid' /> <filter type='and'> <condition attribute='activityid' operator='eq' value='{0}' /> </filter> <link-entity name='contract' from='contractid' to='regardingobjectid' visible='false' link-type='outer' alias='contract' > <attribute name='customerid' alias='contract_customerid'/> </link-entity> <link-entity name='opportunity' from='opportunityid' to='regardingobjectid' visible='false' link-type='outer' alias='opportunity' > <attribute name='customerid' alias='opportunity_customerid'/> </link-entity> <link-entity name='incident' from='incidentid' to='regardingobjectid' visible='false' link-type='outer' alias='incident' > <attribute name='customerid' alias='incident_customerid'/> </link-entity> </entity> </fetch>"; EntityCollection activities = OrganizationServiceProxy.RetrieveMultiple(String.Format(fetchXml, session.dev1_ActivityId)); if (activities.Entities.Count > 0) { EntityReference account = null; // Get the account either via the regarding object, or the related contract, opportunity, incident Entity activity = activities.Entities[0]; EntityReference incidentCustomerId = activity.GetAttributeValueEntityReference("incident_customerid"); EntityReference opportunityCustomerId = activity.GetAttributeValueEntityReference("opportunity_customerid"); EntityReference contractCustomerId = activity.GetAttributeValueEntityReference("contract_customerid"); EntityReference regarding = activity.GetAttributeValueEntityReference("regardingobjectid"); if (incidentCustomerId != null) { account = incidentCustomerId; } else if (opportunityCustomerId != null) { account = opportunityCustomerId; } else if (contractCustomerId != null) { account = contractCustomerId; } else if (regarding != null && regarding.LogicalName == "account") { account = regarding; } session.Account = account; session.activitypointer_regardingobjectid = activity.GetAttributeValueEntityReference("regardingobjectid"); } }
private static void OnStartEndDateChanged(object sender) { // Calculate the duration dev1_session session = (dev1_session)sender; // Ensure that the end date is the same as the start date if (session.dev1_StartTime != null && session.dev1_EndTime != null) { session.dev1_EndTime.SetDate(session.dev1_StartTime.GetUTCDate()); session.dev1_EndTime.SetMonth(session.dev1_StartTime.GetUTCMonth()); session.dev1_EndTime.SetFullYear(session.dev1_StartTime.GetUTCFullYear()); } session.dev1_Duration = SessionVM.CalculateDuration(session.dev1_StartTime, session.dev1_EndTime); }
private static void OnDurationChanged(object sender) { dev1_session session = (dev1_session)sender; DateTime startTime = session.dev1_StartTime; if (startTime != null) { int?duration = session.dev1_Duration; int?startTimeMilliSeconds = startTime.GetTime(); startTimeMilliSeconds = startTimeMilliSeconds + (duration * 1000 * 60); DateTime newEndDate = new DateTime((int)startTimeMilliSeconds); session.dev1_EndTime = newEndDate; } }
public SessionVM(StartStopSessionViewModel vm, dev1_session data) { if (data != null) { this.dev1_sessionid.SetValue(data.dev1_sessionId); this.dev1_description.SetValue(data.dev1_Description); this.dev1_duration.SetValue(data.dev1_Duration); this.dev1_endtime.SetValue(data.dev1_EndTime); this.dev1_starttime.SetValue(data.dev1_StartTime); // Calculate the time elements GetTime(dev1_starttime, StartTimeTime); GetTime(dev1_endtime, EndTimeTime); // Set activity if (data.dev1_LetterId != null) { this.Activity.SetValue(data.dev1_LetterId); } else if (data.dev1_TaskId != null) { this.Activity.SetValue(data.dev1_TaskId); } // TODO: Add more activity types } // Add events to calculate duration dev1_endtime.Subscribe(delegate(DateTime value) { OnStartEndDateChanged(); }); dev1_starttime.Subscribe(delegate(DateTime value) { OnStartEndDateChanged(); }); StartTimeTime.Subscribe(delegate(string value) { OnStartEndDateChanged(); }); EndTimeTime.Subscribe(delegate(string value) { OnStartEndDateChanged(); }); dev1_duration.Subscribe(delegate(int? value) { OnDurationChanged(); }); AddValidation(); }
public StartStopSessionViewModel(Guid activityToStartStop, Guid sessionToStartStop) { // Create start session dev1_session newSession = new dev1_session(); newSession.dev1_StartTime = DateTime.Now; StartSession = (Observable<SessionVM>)ValidatedObservableFactory.ValidatedObservable(new SessionVM(this, newSession)); // Load the Sessions dev1_session session = (dev1_session)OrganizationServiceProxy.Retrieve(dev1_session.EntityLogicalName, "{FD722AC2-B234-E211-A471-000C299FFE7D}", new string[] { "AllColumns" }); SessionVM sessionVM = new SessionVM(this, session); StopSession = (Observable<SessionVM>)ValidatedObservableFactory.ValidatedObservable(sessionVM); DependentObservableOptions<bool> isFormValidDependantProperty = new DependentObservableOptions<bool>(); isFormValidDependantProperty.Model = this; isFormValidDependantProperty.GetValueFunction = new Func<bool>(delegate { StartStopSessionViewModel vm = (StartStopSessionViewModel)isFormValidDependantProperty.Model; if (vm.StartNewSession.GetValue()) { return ValidationRules.AreValid( new object[] { ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StopSession, ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StartSession }); } else { return ValidationRules.AreValid( new object[] { ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StopSession }); } }); CanSave = Knockout.DependentObservable<bool>(isFormValidDependantProperty); }
private void AddSession(List <dev1_session> sessions, dev1_session session) { sessions.Add(session); // Set the account field derived from the regarding object (depending on type) if (session.opportunity_customerid != null) { session.Account = session.opportunity_customerid; } else if (session.contract_customerid != null) { session.Account = session.contract_customerid; } else if (session.incident_customerid != null) { session.Account = session.incident_customerid; } else if (session.activitypointer_regardingobjectid != null && session.activitypointer_regardingobjectid.LogicalName == "account") { session.Account = session.activitypointer_regardingobjectid; } // Calculate duration/end date if (session.dev1_EndTime == null && session.dev1_Duration != null) { OnDurationChanged(session); } else if (session.dev1_Duration == null) { OnStartEndDateChanged(session); } // Is the session read only? if (session.StatusCode != null && session.StatusCode.Value.Value != (int)dev1_session_StatusCode.Draft) { session.EntityState = EntityStates.ReadOnly; } // Subscribe to the Property Changed event so we can re-calculate the duration or end date session.PropertyChanged += new Xrm.ComponentModel.PropertyChangedEventHandler(OnSessionPropertyChanged); }
public override void AddItem(object item) { dev1_session session = new dev1_session(); DayEntry activity = (DayEntry)item; if ((activity.Activity != null) && (activity.Activity.Id != null)) { session.dev1_ActivityId = activity.Activity.Id.ToString(); session.dev1_ActivityTypeName = activity.Activity.LogicalName; //session.activityName = activity.Activity.Name; session.dev1_ActivityId = activity.Activity.Id.ToString(); session.dev1_StartTime = sessions.WeekStart; sessions.SelectedActivity = activity.Activity; sessions.AddItem(session); _selectedRows = new SelectedRange[1] { new SelectedRange() }; _selectedRows[0].FromRow = rows.Count + 1; _selectedRows[0].ToRow = rows.Count + 1; Refresh(); } }
public dev1_session GetUpdatedModel() { dev1_session session = new dev1_session(); SetTime(dev1_starttime, StartTimeTime); SetTime(dev1_endtime, EndTimeTime); KnockoutMappingSpecification mapping = new KnockoutMappingSpecification(); mapping.Ignore = new string[] { "dev1_letterid", "dev1_taskid", "dev1_emailid" }; if (this.dev1_sessionid.GetValue() != null) { session.dev1_sessionId = this.dev1_sessionid.GetValue(); } session.dev1_Description = this.dev1_description.GetValue(); session.dev1_StartTime = this.dev1_starttime.GetValue(); session.dev1_EndTime = this.dev1_endtime.GetValue(); session.dev1_Duration = this.dev1_duration.GetValue(); return(session); }
public SessionVM(StartStopSessionViewModel vm, dev1_session data) { if (data != null) { this.dev1_sessionid.SetValue(data.dev1_sessionId); this.dev1_description.SetValue(data.dev1_Description); this.dev1_duration.SetValue(data.dev1_Duration); this.dev1_endtime.SetValue(data.dev1_EndTime); this.dev1_starttime.SetValue(data.dev1_StartTime); // Calculate the time elements GetTime(dev1_starttime, StartTimeTime); GetTime(dev1_endtime, EndTimeTime); // Set activity if (data.dev1_LetterId != null) { this.Activity.SetValue(data.dev1_LetterId); } else if (data.dev1_TaskId != null) { this.Activity.SetValue(data.dev1_TaskId); } // TODO: Add more activity types } // Add events to calculate duration dev1_endtime.Subscribe(delegate(DateTime value) { OnStartEndDateChanged(); }); dev1_starttime.Subscribe(delegate(DateTime value) { OnStartEndDateChanged(); }); StartTimeTime.Subscribe(delegate(string value) { OnStartEndDateChanged(); }); EndTimeTime.Subscribe(delegate(string value) { OnStartEndDateChanged(); }); dev1_duration.Subscribe(delegate(int?value) { OnDurationChanged(); }); AddValidation(); }
public StartStopSessionViewModel(Guid activityToStartStop, Guid sessionToStartStop) { // Create start session dev1_session newSession = new dev1_session(); newSession.dev1_StartTime = DateTime.Now; StartSession = (Observable <SessionVM>)ValidatedObservableFactory.ValidatedObservable(new SessionVM(this, newSession)); // Load the Sessions dev1_session session = (dev1_session)OrganizationServiceProxy.Retrieve(dev1_session.EntityLogicalName, "{FD722AC2-B234-E211-A471-000C299FFE7D}", new string[] { "AllColumns" }); SessionVM sessionVM = new SessionVM(this, session); StopSession = (Observable <SessionVM>)ValidatedObservableFactory.ValidatedObservable(sessionVM); DependentObservableOptions <bool> isFormValidDependantProperty = new DependentObservableOptions <bool>(); isFormValidDependantProperty.Model = this; isFormValidDependantProperty.GetValueFunction = new Func <bool>(delegate { StartStopSessionViewModel vm = (StartStopSessionViewModel)isFormValidDependantProperty.Model; if (vm.StartNewSession.GetValue()) { return(ValidationRules.AreValid( new object[] { ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StopSession, ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StartSession })); } else { return(ValidationRules.AreValid( new object[] { ((StartStopSessionViewModel)isFormValidDependantProperty.Model).StopSession })); } }); CanSave = Knockout.DependentObservable <bool>(isFormValidDependantProperty); }
public Action SaveCommand() { if (_saveCommand == null) { _saveCommand = delegate() { bool confirmed = Script.Confirm(String.Format("Are you sure save these sessions?")); if (!confirmed) return; try { IsBusy.SetValue(true); IsBusyProgress.SetValue(0); IsBusyMessage.SetValue("Saving..."); // Create a an array of sessions to be saved List<dev1_session> editedSessions = SessionDataView.GetEditedSessions(); DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack) { dev1_session session = editedSessions[index]; // Create verson of session to save dev1_session sessionToSave = new dev1_session(); sessionToSave.dev1_sessionId = session.dev1_sessionId; sessionToSave.dev1_ActivityId = session.dev1_ActivityId; sessionToSave.dev1_ActivityTypeName = session.dev1_ActivityTypeName; sessionToSave.dev1_Description = session.dev1_Description; sessionToSave.dev1_Duration = session.dev1_Duration; sessionToSave.dev1_EmailId = session.dev1_EmailId; sessionToSave.dev1_EndTime = session.dev1_EndTime; sessionToSave.dev1_LetterId = session.dev1_LetterId; sessionToSave.dev1_PhoneCallId = session.dev1_PhoneCallId; sessionToSave.dev1_sessionId = session.dev1_sessionId; sessionToSave.dev1_StartTime = session.dev1_StartTime; sessionToSave.dev1_TaskId = session.dev1_TaskId; sessionToSave.dev1_Row = session.dev1_Row; IsBusyProgress.SetValue((index / editedSessions.Count) * 100); // Create/Update the session if (session.dev1_sessionId == null) { if (sessionToSave.dev1_Duration != null && sessionToSave.dev1_Duration > 0) { OrganizationServiceProxy.BeginCreate(sessionToSave, delegate(object result) { IsBusyProgress.SetValue((index / editedSessions.Count) * 100); try { session.dev1_sessionId = OrganizationServiceProxy.EndCreate(result); session.EntityState = EntityStates.Unchanged; session.RaisePropertyChanged("EntityState"); nextCallback(); } catch (Exception ex) { // TODO: Mark error row Script.Alert(ex.Message); nextCallback(); } }); } else nextCallback(); } else { OrganizationServiceProxy.BeginUpdate(sessionToSave, delegate(object result) { try { OrganizationServiceProxy.EndUpdate(result); session.EntityState = EntityStates.Unchanged; session.RaisePropertyChanged("EntityState"); nextCallback(); } catch (Exception ex) { // TODO: Mark error row Script.Alert(ex.Message); nextCallback(); } }); } }, editedSessions.Count, delegate() { // Completed IsBusyProgress.SetValue(100); IsBusy.SetValue(false); }, delegate(Exception ex) { // Error ReportError(ex); }); } catch (Exception ex) { ReportError(ex); } }; } return _saveCommand; }
public Action SaveCommand() { if (_saveCommand == null) { _saveCommand = delegate() { bool confirmed = Script.Confirm(String.Format("Are you sure save these sessions?")); if (!confirmed) { return; } try { IsBusy.SetValue(true); IsBusyProgress.SetValue(0); IsBusyMessage.SetValue("Saving..."); // Create a an array of sessions to be saved List <dev1_session> editedSessions = SessionDataView.GetEditedSessions(); DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack) { dev1_session session = editedSessions[index]; IsBusyProgress.SetValue((index / editedSessions.Count) * 100); // Create/Update the session if (session.dev1_sessionId == null) { OrganizationServiceProxy.BeginCreate(session, delegate(object result) { IsBusyProgress.SetValue((index / editedSessions.Count) * 100); try { session.dev1_sessionId = OrganizationServiceProxy.EndCreate(result); session.EntityState = EntityStates.Unchanged; session.RaisePropertyChanged("EntityState"); nextCallback(); } catch (Exception ex) { // TODO: Mark error row Script.Alert(ex.Message); nextCallback(); } }); } else { OrganizationServiceProxy.BeginUpdate(session, delegate(object result) { try { OrganizationServiceProxy.EndUpdate(result); session.EntityState = EntityStates.Unchanged; session.RaisePropertyChanged("EntityState"); nextCallback(); } catch (Exception ex) { // TODO: Mark error row Script.Alert(ex.Message); nextCallback(); } }); } }, editedSessions.Count, delegate() { // Completed IsBusyProgress.SetValue(100); IsBusy.SetValue(false); }, delegate(Exception ex) { // Error ReportError(ex); }); } catch (Exception ex) { ReportError(ex); } }; } return(_saveCommand); }
public Action DeleteCommand() { if (_deleteCommand == null) { _deleteCommand = delegate() { List <int> selectedRows = DataViewBase.RangesToRows(this.SessionDataView.GetSelectedRows()); if (selectedRows.Count == 0) { return; } bool confirmed = Script.Confirm(String.Format("Are you sure you want to delete the {0} selected sessions?", selectedRows.Count)); if (!confirmed) { return; } IsBusyMessage.SetValue("Deleting Sessions..."); IsBusyProgress.SetValue(0); IsBusy.SetValue(true); // Get each item to remove List <dev1_session> itemsToDelete = new List <dev1_session>(); for (int i = 0; i < selectedRows.Count; i++) { itemsToDelete.Add((dev1_session)this.SessionDataView.GetItem(i)); } DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack) { dev1_session session = itemsToDelete[index]; IsBusyProgress.SetValue((index / selectedRows.Count) * 100); OrganizationServiceProxy.BeginDelete(session.LogicalName, session.dev1_sessionId, delegate(object result) { try { OrganizationServiceProxy.EndDelete(result); this.SessionDataView.RemoveItem(session); this.SessionDataView.Refresh(); nextCallback(); } catch (Exception ex) { Script.Alert(ex.Message); nextCallback(); } }); }, selectedRows.Count, delegate() { // Complete IsBusyProgress.SetValue(100); IsBusy.SetValue(false); SessionDataView.Refresh(); Days.ReCalculate(); }, delegate(Exception ex) { ReportError(ex); } ); }; } return(_deleteCommand); }
private void SetAccountAndRegardingFromActivity(dev1_session session) { string fetchXml = @" <fetch> <entity name='activitypointer' > <attribute name='regardingobjectid' /> <filter type='and'> <condition attribute='activityid' operator='eq' value='{0}' /> </filter> <link-entity name='contract' from='contractid' to='regardingobjectid' visible='false' link-type='outer' alias='contract' > <attribute name='customerid' alias='contract_customerid'/> </link-entity> <link-entity name='opportunity' from='opportunityid' to='regardingobjectid' visible='false' link-type='outer' alias='opportunity' > <attribute name='customerid' alias='opportunity_customerid'/> </link-entity> <link-entity name='incident' from='incidentid' to='regardingobjectid' visible='false' link-type='outer' alias='incident' > <attribute name='customerid' alias='incident_customerid'/> </link-entity> </entity> </fetch>"; EntityCollection activities = OrganizationServiceProxy.RetrieveMultiple(String.Format(fetchXml, session.dev1_ActivityId)); if (activities.Entities.Count > 0) { EntityReference account = null; // Get the account either via the regarding object, or the related contract, opportunity, incident Entity activity = activities.Entities[0]; EntityReference incidentCustomerId = activity.GetAttributeValueEntityReference("incident_customerid"); EntityReference opportunityCustomerId = activity.GetAttributeValueEntityReference("opportunity_customerid"); EntityReference contractCustomerId = activity.GetAttributeValueEntityReference("contract_customerid"); EntityReference regarding = activity.GetAttributeValueEntityReference("regardingobjectid"); if (incidentCustomerId != null) account= incidentCustomerId; else if (opportunityCustomerId != null) account= opportunityCustomerId; else if (contractCustomerId != null) account= contractCustomerId; else if (regarding != null && regarding.LogicalName == "account") account= regarding; session.Account = account; session.activitypointer_regardingobjectid = activity.GetAttributeValueEntityReference("regardingobjectid"); } }
private void AddDefaultSession(DayEntry activity) { // Clear the sessions from the previously selected row, and show a blank row Sessions.SetCurrentActivity(activity.Activity, 0); dev1_session session = new dev1_session(); session.Account = activity.Account; session.dev1_ActivityId = activity.Activity.Id.ToString(); session.dev1_ActivityTypeName = activity.Activity.LogicalName; session.dev1_ActivityId = activity.Activity.Id.ToString(); session.dev1_StartTime = Sessions.WeekStart; session.activitypointer_subject = activity.Activity.Name; session.activitypointer_regardingobjectid = activity.RegardingObjectId; Sessions.SelectedActivity = activity.Activity; session.dev1_Row = this.Sessions.GetCurrentWeek().Count; // Has the account been set - if not we need to look it up from the selected activity if (session.Account == null || session.activitypointer_regardingobjectid == null) SetAccountAndRegardingFromActivity(session); Sessions.AddItem(session); _selectedRows = new SelectedRange[1] { new SelectedRange() }; _selectedRows[0].FromRow = rows.Count + 1; _selectedRows[0].ToRow = rows.Count + 1; }
private void AddSession(List<dev1_session> sessions, dev1_session session) { sessions.Add(session); // Subscribe to the Property Changed event so we can re-calculate the duration or end date session.PropertyChanged += new Xrm.ComponentModel.PropertyChangedEventHandler(OnSessionPropertyChanged); }
private void AddSession(List <dev1_session> sessions, dev1_session session) { sessions.Add(session); // Subscribe to the Property Changed event so we can re-calculate the duration or end date session.PropertyChanged += new Xrm.ComponentModel.PropertyChangedEventHandler(OnSessionPropertyChanged); }
private void AddSession(List<dev1_session> sessions, dev1_session session) { sessions.Add(session); // Set the account field derived from the regarding object (depending on type) if (session.opportunity_customerid != null) session.Account = session.opportunity_customerid; else if (session.contract_customerid != null) session.Account = session.contract_customerid; else if (session.incident_customerid != null) session.Account = session.incident_customerid; else if (session.activitypointer_regardingobjectid != null && session.activitypointer_regardingobjectid.LogicalName == "account") session.Account = session.activitypointer_regardingobjectid; // Calculate duration/end date if (session.dev1_EndTime == null && session.dev1_Duration!=null) OnDurationChanged(session); else if (session.dev1_Duration == null) OnStartEndDateChanged(session); // Is the session read only? if (session.StatusCode != null && session.StatusCode.Value.Value != (int)dev1_session_StatusCode.Draft) session.EntityState = EntityStates.ReadOnly; // Subscribe to the Property Changed event so we can re-calculate the duration or end date session.PropertyChanged += new Xrm.ComponentModel.PropertyChangedEventHandler(OnSessionPropertyChanged); }
public dev1_session GetUpdatedModel() { dev1_session session = new dev1_session(); SetTime(dev1_starttime, StartTimeTime); SetTime(dev1_endtime, EndTimeTime); KnockoutMappingSpecification mapping = new KnockoutMappingSpecification(); mapping.Ignore = new string[] { "dev1_letterid", "dev1_taskid", "dev1_emailid" }; if ( this.dev1_sessionid.GetValue()!=null) session.dev1_sessionId = this.dev1_sessionid.GetValue(); session.dev1_Description = this.dev1_description.GetValue(); session.dev1_StartTime = this.dev1_starttime.GetValue(); session.dev1_EndTime = this.dev1_endtime.GetValue(); session.dev1_Duration = this.dev1_duration.GetValue(); return session; }
public override void AddItem(object item) { dev1_session session = new dev1_session(); DayEntry activity = (DayEntry)item; if ((activity.Activity != null) && (activity.Activity.Id!=null)) { session.dev1_ActivityId = activity.Activity.Id.ToString(); session.dev1_ActivityTypeName = activity.Activity.LogicalName; //session.activityName = activity.Activity.Name; session.dev1_ActivityId = activity.Activity.Id.ToString(); session.dev1_StartTime = sessions.WeekStart; sessions.SelectedActivity = activity.Activity; sessions.AddItem(session); _selectedRows = new SelectedRange[1] { new SelectedRange() }; _selectedRows[0].FromRow = rows.Count + 1; _selectedRows[0].ToRow = rows.Count + 1; Refresh(); } }
public static void SetUpGrids(TimeSheetViewModel vm) { // Create Timesheet Grid DataViewBase daysDataView = vm.Days; List <Column> columns = new List <Column>(); GridDataViewBinder.BindRowIcon(GridDataViewBinder.AddColumn(columns, "", 50, "icon"), "activity"); XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Account", 300, "account"), vm.AccountSeachCommand, "accountid", "name", null); XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Regarding", 300, "regardingObjectId"), vm.RegardingObjectSearchCommand, "id", "displayName", null); XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Activity", 300, "activity"), vm.ActivitySearchCommand, "activityid", "subject", "activitytypecode"); string[] daysOfWeek = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; int firstDayOfWeek = OrganizationServiceProxy.OrganizationSettings.WeekStartDayCode.Value.Value; GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek], 50, "day0"); GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 1], 50, "day1"); GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 2], 50, "day2"); GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 3], 50, "day3"); GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 4], 50, "day4"); GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 5], 50, "day5"); GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 6], 50, "day6"); GridDataViewBinder daysDataBinder = new GridDataViewBinder(); daysDataBinder.SelectActiveRow = true; daysDataBinder.AddCheckBoxSelectColumn = false; daysGrid = daysDataBinder.DataBindXrmGrid(daysDataView, columns, "timesheetGridContainer", null, true, true); // Set the totals row meta data daysDataView.OnGetItemMetaData += delegate(object item) { ItemMetaData metaData = new ItemMetaData(); DayEntry day = (DayEntry)item; if (day != null && day.isTotalRow) { metaData.Editor = delegate(EditorArguments args) { return(null); }; metaData.Columns = new Dictionary <object, Column>(); metaData.Columns["Account"] = new Column("editor", null); metaData.Columns["Regarding"] = new Column("editor", null); metaData.Columns["Activity"] = new Column("editor", null); metaData.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext) { switch (columnDef.Field) { case "account": case "regardingObjectId": return(""); case "activity": return("Total"); default: return(XrmDurationEditor.Formatter(row, cell, value, columnDef, dataContext)); } }; metaData.CssClasses = "days_total_row"; } else { metaData.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext) { switch (columnDef.Field) { case "account": case "regardingObjectId": case "activity": return(XrmLookupEditor.Formatter(row, cell, value, columnDef, dataContext)); default: return(XrmDurationEditor.Formatter(row, cell, value, columnDef, dataContext)); } }; } return(metaData); }; daysDataBinder.DataBindSelectionModel(daysGrid, daysDataView); // --------------------------------------- // Sessions Grid // --------------------------------------- DataViewBase sessionsDataView = vm.SessionDataView; List <Column> sessionGridCols = new List <Column>(); GridDataViewBinder.AddEditIndicatorColumn(sessionGridCols); XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Activity", 300, "activitypointer_subject")).Editor = null; XrmDateEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Date", 100, "dev1_starttime"), true); XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Start", 100, "dev1_starttime")).Validator = delegate(object value, object item) { dev1_session session = (dev1_session)item; DateTime newStartTime = (DateTime)value; ValidationResult result = new ValidationResult(); if (session.dev1_EndTime != null) { result.Valid = true; string valueText = (string)value; // Check if the end time is before the start time bool isValid = DateTimeEx.GetTimeDuration(newStartTime) < DateTimeEx.GetTimeDuration(session.dev1_EndTime); result.Valid = isValid; result.Message = "The start time must be before the end time"; } else { result.Valid = true; } return(result); }; XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "End", 100, "dev1_endtime")).Validator = delegate(object value, object item) { dev1_session session = (dev1_session)item; DateTime newEndTime = (DateTime)value; ValidationResult result = new ValidationResult(); if (session.dev1_StartTime != null) { result.Valid = true; string valueText = (string)value; // Check if the end time is before the start time bool isValid = DateTimeEx.GetTimeDuration(session.dev1_StartTime) < DateTimeEx.GetTimeDuration(newEndTime); result.Valid = isValid; result.Message = "The end time must be after the start time"; } else { result.Valid = true; } return(result); }; XrmDurationEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Duration", 70, "dev1_duration")); XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Description", 300, "dev1_description")); GridDataViewBinder sessionsDataBinder = new GridDataViewBinder(); sessionsDataBinder.SelectActiveRow = false; sessionsDataBinder.AddCheckBoxSelectColumn = true; sessionsGrid = sessionsDataBinder.DataBindXrmGrid(sessionsDataView, sessionGridCols, "sessionsGridContainer", null, true, true); sessionsGrid.OnBeforeEditCell.Subscribe(delegate(EventData e, object args) { // Stop the row from being edited if locked Entity item = (Entity)((EditEventData)args).item; bool result = sessionsDataView.OnBeforeEdit(item); Script.Literal("return {0}", result); }); daysGrid.OnActiveCellChanged.Subscribe(delegate(EventData e, object args) { CellSelection activeCell = daysGrid.GetActiveCell(); if (activeCell != null) { if (activeCell.Cell < StartDaysColumnIndex) { // Whole activity is selected vm.Days.SelectedDay = null; } else { vm.Days.SelectedDay = activeCell.Cell - (StartDaysColumnIndex - 1); } } }); }
public static void SetUpGrids(TimeSheetViewModel vm) { GridOptions daysGridOpts = new GridOptions(); daysGridOpts.EnableCellNavigation = true; daysGridOpts.EnableColumnReorder = false; daysGridOpts.AutoEdit = false; daysGridOpts.Editable = true; daysGridOpts.RowHeight = 20; daysGridOpts.HeaderRowHeight = 25; daysGridOpts.ForceFitColumns = false; daysGridOpts.EnableAddRow = true; // Create Timesheet Grid DataViewBase daysDataView = vm.Days; List <Column> columns = new List <Column>(); GridDataViewBinder.BindRowIcon(GridDataViewBinder.AddColumn(columns, "", 50, "icon"), "activity"); XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Activity", 300, "activity"), vm.ActivitySearchCommand, "activityid", "subject", "activitytypecode"); GridDataViewBinder.AddColumn(columns, "Mon", 50, "day0"); GridDataViewBinder.AddColumn(columns, "Tue", 50, "day1"); GridDataViewBinder.AddColumn(columns, "Wed", 50, "day2"); GridDataViewBinder.AddColumn(columns, "Thu", 50, "day3"); GridDataViewBinder.AddColumn(columns, "Fri", 50, "day4"); GridDataViewBinder.AddColumn(columns, "Sat", 50, "day5"); GridDataViewBinder.AddColumn(columns, "Sun", 50, "day6"); daysGrid = new Grid("#timesheetGridContainer", daysDataView, columns, daysGridOpts); GridDataViewBinder daysDataBinder = new GridDataViewBinder(); daysDataBinder.DataBindEvents(daysGrid, daysDataView, "timesheetGridContainer"); // Set the totals row meta data daysDataView.OnGetItemMetaData += delegate(object item) { DayEntry day = (DayEntry)item; if (day != null && day.isTotalRow) { ItemMetaData metaData = new ItemMetaData(); metaData.Editor = null; metaData.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext) { if (columnDef.Field == "activity") { return("Total"); } else { return(Formatters.DefaultFormatter(row, cell, value, columnDef, dataContext)); } }; metaData.CssClasses = "days_total_row"; return(metaData); } else { return(null); } }; daysDataBinder.DataBindSelectionModel(daysGrid, daysDataView); // --------------------------------------- // Sessions Grid // --------------------------------------- DataViewBase sessionsDataView = vm.SessionDataView; List <Column> sessionGridCols = new List <Column>(); GridDataViewBinder.AddEditIndicatorColumn(sessionGridCols); XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Description", 200, "dev1_description")); XrmDateEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Date", 200, "dev1_starttime"), true); XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Start", 100, "dev1_starttime")).Validator = delegate(object value, object item) { dev1_session session = (dev1_session)item; DateTime newStartTime = (DateTime)value; ValidationResult result = new ValidationResult(); if (session.dev1_EndTime != null) { result.Valid = true; string valueText = (string)value; // Check if the end time is before the start time bool isValid = DateTimeEx.GetTimeDuration(newStartTime) < DateTimeEx.GetTimeDuration(session.dev1_EndTime); result.Valid = isValid; result.Message = "The start time must be before the end time"; } else { result.Valid = true; } return(result); }; XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "End", 100, "dev1_endtime")).Validator = delegate(object value, object item) { dev1_session session = (dev1_session)item; DateTime newEndTime = (DateTime)value; ValidationResult result = new ValidationResult(); if (session.dev1_StartTime != null) { result.Valid = true; string valueText = (string)value; // Check if the end time is before the start time bool isValid = DateTimeEx.GetTimeDuration(session.dev1_StartTime) < DateTimeEx.GetTimeDuration(newEndTime); result.Valid = isValid; result.Message = "The end time must be after the start time"; } else { result.Valid = true; } return(result); }; XrmDurationEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Duration", 200, "dev1_duration")); GridDataViewBinder sessionsDataBinder = new GridDataViewBinder(); sessionsGrid = sessionsDataBinder.DataBindXrmGrid(sessionsDataView, sessionGridCols, "sessionsGridContainer", null, true, true); sessionsDataBinder.DataBindSelectionModel(sessionsGrid, sessionsDataView); daysGrid.OnActiveCellChanged.Subscribe(delegate(EventData e, object args) { CellSelection activeCell = daysGrid.GetActiveCell(); if (activeCell != null) { if (activeCell.Cell < 2) { // Whole activity is selected vm.Days.SelectedDay = null; } else { vm.Days.SelectedDay = activeCell.Cell - 1; } } }); }