public static void UpdateByAPIFieldName(LoginUser loginUser, CustomFields customFields, int refID, string apiFieldName, string value) { value = value ?? ""; CustomField field = customFields.FindByApiFieldName(apiFieldName); //if (field == null) throw new Exception("Unable to find field '" + apiFieldName + "'"); if (field != null) { UpdateValue(loginUser, field.CustomFieldID, refID, value); } }
public string GetCustomFieldsSelect(ReferenceType refType, int?auxID, string refIDFieldName) { CustomFields = new CustomFields(LoginUser); int orgID = LoginUser.OrganizationID; Organization organization = Organizations.GetOrganization(LoginUser, LoginUser.OrganizationID); if (organization != null && organization.ParentID != 1) { orgID = (int)organization.ParentID; } _customFields.LoadByReferenceType(orgID, refType, auxID); return(GetCustomFieldsSelect(CustomFields, refIDFieldName)); }
public static CustomValue GetValue(LoginUser loginUser, int refID, string apiFieldName) { CustomFields customFields = new CustomFields(loginUser); customFields.LoadByOrganization(loginUser.OrganizationID); CustomField field = customFields.FindByApiFieldName(apiFieldName); if (field == null) { return(null); } return(GetValue(loginUser, field.CustomFieldID, refID)); }
public void ValidatePositions(int organizationID, ReferenceType refType, int auxID) { CustomFields fields = new CustomFields(LoginUser); fields.LoadByReferenceType(organizationID, refType, auxID); int i = 0; foreach (CustomField field in fields) { field.Position = i; i++; } fields.Save(); }
public static CustomField GetCustomFieldByApi(LoginUser loginUser, int organizationID, string apiFieldName) { CustomFields customFields = new CustomFields(loginUser); customFields.LoadByApiName(organizationID, apiFieldName); if (customFields.IsEmpty) { return(null); } else { return(customFields[0]); } }
public static CustomField GetCustomField(LoginUser loginUser, int customFieldID) { CustomFields customFields = new CustomFields(loginUser); customFields.LoadByCustomFieldID(customFieldID); if (customFields.IsEmpty) { return(null); } else { return(customFields[0]); } }
partial void BeforeRowEdit(CustomValue newValue) { CustomValue oldValue = CustomValues.GetCustomValue(LoginUser, newValue.CustomValueID); newValue.OrganizationID = LoginUser.OrganizationID; if (oldValue.Value == newValue.Value) { return; } CustomField customField = CustomFields.GetCustomField(LoginUser, newValue.CustomFieldID); string format = "Changed {0} from '{1}' to '{2}'."; ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, customField.RefType, newValue.RefID, string.Format(format, customField.Name, oldValue.Value, newValue.Value)); }
public CustomPortalColumnProxy GetProxy() { CustomPortalColumnProxy result = new CustomPortalColumnProxy(); result.CustomFieldID = this.CustomFieldID; result.StockFieldID = this.StockFieldID; result.Position = this.Position; result.OrganizationID = this.OrganizationID; result.CustomColumnID = this.CustomColumnID; if (result.CustomFieldID != null) { CustomFields cf = new CustomFields(BaseCollection.LoginUser); cf.LoadByCustomFieldID((int)result.CustomFieldID); TicketTypes ticketTypes = new TicketTypes(BaseCollection.LoginUser); ticketTypes.LoadAllPositions(BaseCollection.LoginUser.OrganizationID); TicketType ticketType = ticketTypes.FindByTicketTypeID(cf[0].AuxID); if (ticketType == null) { result.FieldText = cf[0].Name; } else { result.FieldText = string.Format("{0} ({1})", cf[0].Name, ticketType.Name); } } else { ReportTableFields rt = new ReportTableFields(BaseCollection.LoginUser); rt.LoadByReportTableFieldID((int)result.StockFieldID); result.FieldText = rt[0].Alias; } return(result); }
public void MovePositionDown(int customFieldID) { CustomFields fields1 = new CustomFields(LoginUser); fields1.LoadByCustomFieldID(customFieldID); ValidatePositions(fields1[0].OrganizationID, fields1[0].RefType, fields1[0].AuxID); if (fields1.IsEmpty || fields1[0].Position >= GetMaxPosition(fields1[0].OrganizationID, fields1[0].RefType, fields1[0].AuxID)) { return; } CustomFields fields2 = new CustomFields(LoginUser); fields2.LoadByPosition(fields1[0].OrganizationID, fields1[0].RefType, fields1[0].AuxID, fields1[0].Position + 1); if (!fields2.IsEmpty) { fields2[0].Position = fields2[0].Position - 1; fields2.Save(); } fields1[0].Position = fields1[0].Position + 1; fields1.Save(); }
public string GetSQL() { StringBuilder builder = new StringBuilder(); ReportTables tables = new ReportTables(_loginUser); tables.LoadAll(); string con = _matchAll ? " AND " : " OR "; foreach (ReportCondition condition in _items) { string value = ""; if (condition.Value1 is string && condition.Value1.ToString().ToLower() == "self") { User user = Users.GetUser(_loginUser, _loginUser.UserID); condition.Value1 = user.FirstLastName; } if (condition.Value2 is string && condition.Value2.ToString().ToLower() == "self") { User user = Users.GetUser(_loginUser, _loginUser.UserID); condition.Value2 = user.FirstLastName; } if (!condition.IsCustomField) { ReportTableField field = (ReportTableField)ReportTableFields.GetReportTableField(_loginUser, condition.FieldID); if (condition.Value1.ToString().Trim() == "" && (condition.ConditionOperator == ConditionOperator.IsEqualTo || condition.ConditionOperator == ConditionOperator.IsNotEqualTo)) { //ticketsview.customers will not be null if (field.ReportTableFieldID == 251) { if (condition.ConditionOperator == ConditionOperator.IsEqualTo) { value = " = ''"; } else if (condition.ConditionOperator == ConditionOperator.IsNotEqualTo) { value = " <> ''"; } } else { if (condition.ConditionOperator == ConditionOperator.IsEqualTo) { value = " IS NULL"; } else if (condition.ConditionOperator == ConditionOperator.IsNotEqualTo) { value = " IS NOT NULL"; } } } else { switch (field.DataType) { case "bit": if (condition.ConditionOperator == ConditionOperator.IsEqualTo) { value = " = "; } else { value = " <> "; } if ((bool)condition.Value1) { value = value + "1"; } else { value = value + "0"; } break; case "datetime": if (condition.ConditionOperator == ConditionOperator.IsGreaterThan || condition.ConditionOperator == ConditionOperator.IsLessThan) { switch (condition.ConditionOperator) { case ConditionOperator.IsGreaterThan: value = " > "; break; case ConditionOperator.IsLessThan: value = " < "; break; default: break; } DateTime date = (DateTime)condition.Value1; value = value + "'" + DataUtils.DateToUtc(_loginUser, date).ToString("g", CultureInfo.GetCultureInfo("en-US")) + "'"; } else { DateTime date1 = (DateTime)condition.Value1; DateTime date2; if (condition.ConditionOperator == ConditionOperator.IsEqualTo || condition.ConditionOperator == ConditionOperator.IsNotEqualTo) { date2 = date1.AddDays(1); } else { date2 = (DateTime)condition.Value2; } value = " BETWEEN '" + DataUtils.DateToUtc(_loginUser, date1).ToString("g", CultureInfo.GetCultureInfo("en-US")) + "' AND '" + DataUtils.DateToUtc(_loginUser, date2).ToString("g", CultureInfo.GetCultureInfo("en-US")) + "'"; if (condition.ConditionOperator == ConditionOperator.IsNotInBetween || condition.ConditionOperator == ConditionOperator.IsNotEqualTo) { value = " NOT" + value; } } break; case "int": if (condition.ConditionOperator != ConditionOperator.IsInBetween && condition.ConditionOperator != ConditionOperator.IsNotInBetween) { switch (condition.ConditionOperator) { case ConditionOperator.IsEqualTo: value = " = "; break; case ConditionOperator.IsNotEqualTo: value = " <> "; break; case ConditionOperator.IsGreaterThan: value = " > "; break; case ConditionOperator.IsLessThan: value = " < "; break; default: break; } int i = (int)condition.Value1; value = value + i.ToString(); } else { int i1 = (int)condition.Value1; int i2 = (int)condition.Value2; value = " BETWEEN " + i1.ToString() + " AND " + i2.ToString(); if (condition.ConditionOperator == ConditionOperator.IsNotInBetween) { value = " NOT" + value; } } break; case "float": if (condition.ConditionOperator != ConditionOperator.IsInBetween && condition.ConditionOperator != ConditionOperator.IsNotInBetween) { switch (condition.ConditionOperator) { case ConditionOperator.IsEqualTo: value = " = "; break; case ConditionOperator.IsNotEqualTo: value = " <> "; break; case ConditionOperator.IsGreaterThan: value = " > "; break; case ConditionOperator.IsLessThan: value = " < "; break; default: break; } double d = (double)condition.Value1; value = value + d.ToString(); } else { int i1 = (int)condition.Value1; int i2 = (int)condition.Value2; value = " BETWEEN " + i1.ToString() + " AND " + i2.ToString(); if (condition.ConditionOperator == ConditionOperator.IsNotInBetween) { value = " NOT" + value; } } break; default: switch (condition.ConditionOperator) { case ConditionOperator.IsEqualTo: value = " = '" + condition.Value1.ToString() + "'"; break; case ConditionOperator.IsNotEqualTo: value = " <> '" + condition.Value1.ToString() + "'"; break; case ConditionOperator.StartsWith: value = " LIKE '" + condition.Value1.ToString() + "%'"; break; case ConditionOperator.EndsWith: value = " LIKE '%" + condition.Value1.ToString() + "'"; break; case ConditionOperator.Contains: value = " LIKE '%" + condition.Value1.ToString() + "%'"; break; default: break; } break; } } value = tables.FindByReportTableID(field.ReportTableID).TableName + ".[" + field.FieldName + "]" + value; } else { CustomField field = (CustomField)CustomFields.GetCustomField(_loginUser, condition.FieldID); if (condition.Value1.ToString().Trim() == "") { if (condition.ConditionOperator == ConditionOperator.IsEqualTo) { value = " IS NULL"; } else if (condition.ConditionOperator == ConditionOperator.IsNotEqualTo) { value = " IS NOT NULL"; } } else { switch (field.FieldType) { case CustomFieldType.Text: case CustomFieldType.PickList: switch (condition.ConditionOperator) { case ConditionOperator.IsEqualTo: value = " = '" + condition.Value1.ToString() + "'"; break; case ConditionOperator.IsNotEqualTo: value = " <> '" + condition.Value1.ToString() + "'"; break; case ConditionOperator.StartsWith: value = " LIKE '" + condition.Value1.ToString() + "%'"; break; case ConditionOperator.EndsWith: value = " LIKE '%" + condition.Value1.ToString() + "'"; break; case ConditionOperator.Contains: value = " LIKE '%" + condition.Value1.ToString() + "%'"; break; default: break; } break; case CustomFieldType.Date: case CustomFieldType.Time: case CustomFieldType.DateTime: if (condition.ConditionOperator != ConditionOperator.IsInBetween && condition.ConditionOperator != ConditionOperator.IsNotInBetween) { switch (condition.ConditionOperator) { case ConditionOperator.IsEqualTo: value = " = "; break; case ConditionOperator.IsNotEqualTo: value = " <> "; break; case ConditionOperator.IsGreaterThan: value = " > "; break; case ConditionOperator.IsLessThan: value = " < "; break; default: break; } DateTime date = (DateTime)condition.Value1; value = value + "'" + DataUtils.DateToUtc(_loginUser, date).ToString("g", _loginUser.CultureInfo) + "'"; } else { DateTime date1 = (DateTime)condition.Value1; DateTime date2 = (DateTime)condition.Value2; value = " BETWEEN '" + DataUtils.DateToUtc(_loginUser, date1).ToString("g", _loginUser.CultureInfo) + "' AND '" + DataUtils.DateToUtc(_loginUser, date2).ToString("g", _loginUser.CultureInfo) + "'"; if (condition.ConditionOperator == ConditionOperator.IsNotInBetween) { value = " NOT" + value; } } break; case CustomFieldType.Boolean: if (condition.ConditionOperator == ConditionOperator.IsEqualTo) { value = " = "; } else { value = " <> "; } if ((bool)condition.Value1) { value = value + "'True'"; } else { value = value + "'False'"; } break; case CustomFieldType.Number: if (condition.ConditionOperator != ConditionOperator.IsInBetween && condition.ConditionOperator != ConditionOperator.IsNotInBetween) { switch (condition.ConditionOperator) { case ConditionOperator.IsEqualTo: value = " = "; break; case ConditionOperator.IsNotEqualTo: value = " <> "; break; case ConditionOperator.IsGreaterThan: value = " > "; break; case ConditionOperator.IsLessThan: value = " < "; break; default: break; } int i = (int)condition.Value1; value = value + i.ToString(); } else { int i1 = (int)condition.Value1; int i2 = (int)condition.Value2; value = " BETWEEN " + i1.ToString() + " AND " + i2.ToString(); if (condition.ConditionOperator == ConditionOperator.IsNotInBetween) { value = " NOT" + value; } } break; default: break; } } value = DataUtils.GetCustomFieldColumn(_loginUser, field, DataUtils.GetReportPrimaryKeyFieldName(field.RefType), true, false) + value; } if (builder.Length < 1) { builder.Append("((" + value + ")"); } else { builder.Append(con + "(" + value + ")"); } } if (builder.Length > 0) { builder.Append(")"); } return(builder.ToString().Trim()); }
public static string GetTicketProperties(LoginUser loginUser, int ticketID) { TicketsViewItem ticket = TicketsView.GetTicketsViewItem(loginUser, ticketID); if (ticket == null) { return(""); } StringBuilder builder = new StringBuilder(); builder.Append(@"<div style=""background-color: #EDF0F5; color: #004394; margin-bottom:10px; padding-left:5px; border: solid 1px #9FB0CF; font-size: 18px; font-weight: bold;"" class=""ui-corner-all"">Ticket Properties</div>"); builder.Append(@"<table width=""100%"" cellpadding=""0"" cellspacing=""5"" border=""0"">"); builder.Append("<tr>"); builder.Append(GetColumn("Opened By", ticket.CreatorName)); builder.Append(GetColumn("Opened On", ticket.DateCreated.ToString("g", loginUser.CultureInfo))); builder.Append("</tr>"); builder.Append("<tr>"); builder.Append(GetColumn("Last Modified By", ticket.ModifierName)); builder.Append(GetColumn("Last Modified On", ticket.DateModified.ToString("g", loginUser.CultureInfo))); builder.Append("</tr>"); builder.Append("<tr>"); if (ticket.IsClosed) { builder.Append(GetColumn("Days Closed", ticket.DaysClosed.ToString())); } else { builder.Append(GetColumn("Days Opened", ticket.DaysOpened.ToString())); } builder.Append(GetColumn("Total Time Spent", DataUtils.MinutesToDisplayTime(Tickets.GetTicketActionTime(ticket.Collection.LoginUser, ticket.TicketID)))); builder.Append("</tr>"); if (ticket.IsClosed && ticket.DateClosed != null) { builder.Append("<tr>"); if (ticket.CloserID != null) { builder.Append(GetColumn("Closed By", ticket.CloserName)); } builder.Append(GetColumn("Closed On", ((DateTime)ticket.DateClosed).ToString("g", loginUser.CultureInfo))); builder.Append("</tr>"); } builder.Append("<tr>"); builder.Append(GetColumn("Ticket Type", ticket.TicketTypeName)); builder.Append(GetColumn("Assigned Group", ticket.GroupName)); builder.Append("</tr>"); builder.Append("<tr>"); builder.Append(GetColumn("Status", ticket.Status)); builder.Append(GetColumn("Product", ticket.ProductName)); builder.Append("</tr>"); builder.Append("<tr>"); builder.Append(GetColumn("Severity", ticket.Severity)); builder.Append(GetColumn("Reported Version", ticket.ReportedVersion)); builder.Append("</tr>"); builder.Append("<tr>"); builder.Append(GetColumn("Assigned To", ticket.UserName)); builder.Append(GetColumn("Resolved Version", ticket.SolvedVersion)); builder.Append("</tr>"); builder.Append("<tr>"); builder.Append(GetColumn("Visible On Portal", ticket.IsVisibleOnPortal.ToString())); builder.Append(GetColumn("Knowledge Base", ticket.IsKnowledgeBase.ToString())); builder.Append("</tr>"); CustomFields fields = new CustomFields(ticket.Collection.LoginUser); fields.LoadByTicketTypeID(ticket.OrganizationID, ticket.TicketTypeID); bool flag = false; foreach (CustomField field in fields) { flag = !flag; if (flag) { builder.Append("<tr>"); } CustomValue value; value = CustomValues.GetValue(ticket.Collection.LoginUser, field.CustomFieldID, ticket.TicketID); builder.Append(GetColumn(field.Name + "", value.Value)); if (!flag) { builder.Append("</tr>"); } } if (flag) { builder.Append("</tr>"); } builder.Append("</table>"); return(builder.ToString()); }
public CustomField(DataRow row, CustomFields customFields) : base(row, customFields) { _customFields = customFields; }