protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); this.SellingCompanyName.DataSource = Common.SellingCompany.FetchAll(); if (this.DataSource == null) { this.SellingCompanyName.FieldValue = CurrentSession.User.SellingCompanyId; } string pRefid = this.Request.QueryString["refid"]; string pRefmode = this.Request.QueryString["refmode"]; if (!string.IsNullOrEmpty(pRefmode)) { ActivityList.ActivityListMode eRefMode = (ActivityList.ActivityListMode)Enum.Parse(typeof(ActivityList.ActivityListMode), pRefmode); if ((int)eRefMode < 0) { Controls.PopupField pField = EndUser; string personFirstName = ""; string personSurname = ""; string orgName = ""; // If opening for Role, set EndUser or SalesPerson to that role on insert, depending on if this is our user if (eRefMode == ActivityList.ActivityListMode.PROLE_ID) { if (this.DataSource == null) { Role pRole = Role.FetchById(pRefid); if (this.DataSource != null && this.DataSource.EndUser.PersonRoleId != pRefid && this.DataSource.SalesPerson.PersonRoleId == pRefid) { pField = SalesPerson; } personFirstName = pRole.Person.FirstName; personSurname = pRole.Person.Surname; orgName = pRole.Organisation.Name; if (pRole.Person.OurPerson.HasValue && pRole.Person.OurPerson.Value == 1) { SalesPerson.FieldValue = pRefid; SalesPerson.FieldText = pRole.PersonName; } else { EndUser.FieldValue = pRefid; EndUser.FieldText = pRole.PersonName; } } } // Else if opening for Person, limit the picklist to Roles for that person only. // Limit the sales person picklist rather than the end user if they are the match to the passed person on update. else if (eRefMode == ActivityList.ActivityListMode.PN_ID) { Person pPerson = Person.FetchById(pRefid); if (this.DataSource != null && this.DataSource.EndUser.PersonId != pRefid && this.DataSource.SalesPerson.PersonId == pRefid) { pField = SalesPerson; } personFirstName = pPerson.FirstName; personSurname = pPerson.Surname; // .. and (if inserting) set the end user or sales person to the principal role for the person. if (this.DataSource == null) { if (pPerson.OurPerson.HasValue && pPerson.OurPerson.Value == 1) { SalesPerson.FieldValue = pPerson.PrincipalRole.Id; SalesPerson.FieldText = pPerson.PrincipalRole.PersonName; } else { EndUser.FieldValue = pPerson.PrincipalRole.Id; EndUser.FieldText = pPerson.PrincipalRole.PersonName; EndUser_PersonID.FieldValue = pPerson.Id; EndUser_PnName.FieldValue = pPerson.FullName; } } } // Else if opening for Organisation, show Roles for that organisaction only else if (eRefMode == ActivityList.ActivityListMode.ORG_ID) { Organisation pOrg = Organisation.FetchById(pRefid); if (this.DataSource != null && this.DataSource.EndUser.OrganisationId != pRefid && this.DataSource.SalesPerson.OrganisationId == pRefid) { pField = SalesPerson; } orgName = pOrg.Name; } // Else if opening for Opportunity, assume the end user has a role in the client organisation. else if (eRefMode == ActivityList.ActivityListMode.OPP_ID) { Opportunity pOpp = Opportunity.FetchById(pRefid); orgName = pOpp.ClientOppXref.Organisation.Name; //if(this.DataSource !=null && this.DataSource.EndUser) } if (!string.IsNullOrEmpty(personFirstName)) { pField.Filters.Add(new Web.Controls.PopupFieldFilter() { Type = Web.Controls.PopupFieldFilterTypes.Value, ParameterName = "personFirstName", Value = personFirstName }); } if (!string.IsNullOrEmpty(personSurname)) { pField.Filters.Add(new Web.Controls.PopupFieldFilter() { Type = Web.Controls.PopupFieldFilterTypes.Value, ParameterName = "personSurname", Value = personSurname }); } if (!string.IsNullOrEmpty(orgName)) { pField.Filters.Add(new Web.Controls.PopupFieldFilter() { Type = Web.Controls.PopupFieldFilterTypes.Value, ParameterName = "orgText", Value = orgName }); } } } string pType = this.Request.QueryString["reftype"]; if (pType == "Letter") { Type.DataSource = Code.FetchAllByType("ACT").Where(c => c.Value1 == "Letter" || c.Value1 == "Email" || c.Value1 == "Phone"); } else if (pType == "D-") { Type.DataSource = Code.FetchAllByType("ACT").Where(c => c.Value1.StartsWith("D-")); } if (this.SalesPerson.FieldValue.Length == 0) { this.SalesPerson.FieldValue = CurrentSession.User.Person.PrincipalRole.Id; this.SalesPerson.FieldText = CurrentSession.User.Person.PrincipalRole.PersonName; } if (this.StartDate.FieldValue.ToString() == "") { this.StartDate.FieldValue = DateTime.Now.Date; this.StartTime.FieldValue = DateTime.Now; } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); Controls.PopupField pField = Person; pField.Filters.Add(new Web.Controls.PopupFieldFilter() { Type = Web.Controls.PopupFieldFilterTypes.Value, ParameterName = "personType", Value = TimeLogFor == "Associate" ? "Associate" : "Volunteer" }); if (this.DataSource != null) { if (!string.IsNullOrEmpty(this.DataSource.ActId) && this.DataSource.Type == "Activity") { this.Activity.FieldValue = this.DataSource.ActId; Activities.Activity activity = Activities.Activity.FetchById(this.DataSource.ActId); if (activity != null) { this.Activity.FieldText = Activities.Activity.FetchById(this.DataSource.ActId).Name; } } else if (!string.IsNullOrEmpty(this.DataSource.ActId) && this.DataSource.Type == "Session") { var sessionObject = Learning.SessionXref.FetchAllBySessionId(this.DataSource.ActId); if (sessionObject.Any()) { var eventId = sessionObject.First().EventId; Learning.Event eventobj = Learning.Event.FetchById(eventId); if (eventobj != null) { this.Event.FieldText = eventobj.Product.Name; this.Event.FieldValue = eventId; this.EventId.FieldValue = this.DataSource.ActId; } } } } var sessionFields = new List <KeyValuePair <string, string> >(); //Query to get all the sessions in the DB var sessionsList = Query.Create() .Select("ACT_ID") .Select("ACT_SESSION_NAME") .Select("ACT_ACTION_DATE") .Select("ACT_START_TIME") .Select("SXREF_COURSE_ID") .From(QuerySources.Sessions); //Fetch all sessions var allSessionsFromView = sessionsList.Run(); foreach (var field in allSessionsFromView) { string startTime = string.IsNullOrEmpty(field.Values.ToList()[3].ToString()) ? "00:00" : field.Values.ToList()[3].ToString(); string courseId = string.IsNullOrEmpty(field.Values.ToList()[4].ToString()) ? "" : "=" + field.Values.ToList()[4].ToString(); string DisplayValue = string.Format(field.Values.ToList()[1] + " (" + field.Values.ToList()[2].ConvertTo <DateTime>().Date.ToString("dd/MMM/yyyy") + " - " + startTime + ")" + courseId); sessionFields.Add(new KeyValuePair <string, string>(field.Values.First().ToString(), DisplayValue)); } this.ServerSessionList.DataSource = sessionFields; }