private void RecoverTicketCustomValues(int orgID, int badTicketID, int goodTicketID) { CustomValues badCustomValues = new CustomValues(GetCorrupteLoginUser()); badCustomValues.LoadByReferenceTypeModifiedAfterRecovery(orgID, ReferenceType.Tickets, badTicketID); foreach (CustomValue badCustomValue in badCustomValues) { try { if (badCustomValue == null) { continue; } CustomValue goodCustomValue = CustomValues.GetValue(GetReviewLoginUser(), goodTicketID, badCustomValue.ApiFieldName); if (goodCustomValue != null) { goodCustomValue.Value = badCustomValue.Value; goodCustomValue.Collection.Save(); } } catch (Exception ex) { _exceptionOcurred = true; ExceptionLogs.LogException(GetCorrupteLoginUser(), ex, "recover"); } } }
public void SaveCustomFieldText(int refID, int fieldID, string value) { CustomValue customValue = CustomValues.GetValue(UserSession.LoginUser, fieldID, refID); customValue.Value = value; customValue.Collection.Save(); }
public void SaveCustomFieldBool(int refID, int fieldID, bool value) { CustomValue customValue = CustomValues.GetValue(UserSession.LoginUser, fieldID, refID); customValue.Value = value.ToString(); customValue.Collection.Save(); }
public string CreatePickListControl(CustomField field, bool isEditable = false, int organizationID = -1) { StringBuilder html = new StringBuilder(); string[] items = field.ListValues.Split('|'); if (isEditable) { CustomValue value = CustomValues.GetValue(TSAuthentication.GetLoginUser(), field.CustomFieldID, organizationID); html.AppendFormat(@"<div class='form-group'> <label for='{0}' class='col-xs-4 control-label'>{1}</label> <div class='col-xs-8'> <p class='form-control-static'><a class='editable' id='{0}' data-type='select'>{2}</a></p> </div> </div>", field.CustomFieldID, field.Name, value.Value); } else { html.AppendFormat("<div class='col-xs-8'><select class='form-control customField' id='{0}' name='{0}' type='picklist'>", field.CustomFieldID); foreach (string item in items) { html.AppendFormat("<option value='{0}'>{1}</option>", item, item); } html.Append("</select></div>"); } return(html.ToString()); }
public string CreateTextControl(CustomField field, bool isEditable = false, int organizationID = -1) { StringBuilder html = new StringBuilder(); if (isEditable) { CustomValue value = CustomValues.GetValue(TSAuthentication.GetLoginUser(), field.CustomFieldID, organizationID); html.AppendFormat(@"<div class='form-group'> <label for='{0}' class='col-xs-4 control-label'>{1}</label> <div class='col-xs-8'> <p class='form-control-static'><a class='editable' id='{0}' data-type='text'>{2}</a></p> </div> </div>", field.CustomFieldID, field.Name, value.Value); } else { StringBuilder mask = new StringBuilder(); if (!String.IsNullOrEmpty(field.Mask)) { mask.Append("placeholder='" + field.Mask + "'"); } html.AppendFormat("<div class='col-xs-8'><input class='form-control col-xs-10 customField {1}' id='{0}' name='{0}' {2}></div>", field.CustomFieldID, field.IsRequired ? "required" : "", mask.ToString()); } return(html.ToString()); }
public CustomValueProxy SaveCustomValue(int customFieldID, int refID, object value) { CustomValue customValue = CustomValues.GetValue(TSAuthentication.GetLoginUser(), customFieldID, refID); if (value == null) { customValue.Value = ""; customValue.Collection.Save(); return(null); } switch (customValue.FieldType) { case CustomFieldType.DateTime: customValue.Value = ((DateTime)value).ToString(); break; case CustomFieldType.Date: customValue.Value = ((DateTime)value).ToShortDateString(); break; default: customValue.Value = DataUtils.CleanValueScript(value.ToString()); break; } customValue.Collection.Save(); return(customValue.GetProxy()); }
public void SaveCustomFieldDate(int refID, int fieldID, DateTime?value) { DateTime?date; try { if (value == null) { date = null; } else { date = Convert.ToDateTime(value); } } catch (Exception) { date = null; } CustomValue customValue = CustomValues.GetValue(UserSession.LoginUser, fieldID, refID); if (date != null) { customValue.Value = DataUtils.DateToUtc(UserSession.LoginUser, date).ToString(); } else { customValue.Value = ""; } customValue.Collection.Save(); }
private string GetUserSlackID(int userID) { CustomValue customValue = CustomValues.GetValue(LoginUser, userID, "slackname"); if (customValue != null && !string.IsNullOrWhiteSpace(customValue.Value)) { return(customValue.Value); } return(null); }
public void SaveCustomFields() { CustomFields fields = new CustomFields(UserSession.LoginUser); fields.LoadByReferenceType(UserSession.LoginUser.OrganizationID, _refType, _auxID); foreach (CustomField field in fields) { Control control = GetCustomControl(_table, FieldIDToControlID(field.CustomFieldID)); if (control != null) { CustomValue value = CustomValues.GetValue(UserSession.LoginUser, field.CustomFieldID, _refID); if (control is RadInputControl) { value.Value = (control as RadInputControl).Text; } else if (control is CheckBox) { value.Value = (control as CheckBox).Checked.ToString(); } else if (control is RadComboBox) { value.Value = (control as RadComboBox).SelectedValue; } else if (control is RadDatePicker) { if (control is RadTimePicker) { DateTime?selectedNullableDateTime = (control as RadTimePicker).SelectedDate; if (selectedNullableDateTime != null) { DateTime selectedDateTime = (DateTime)selectedNullableDateTime; DateTime timeOnly = new DateTime(1970, 1, 1, selectedDateTime.Hour, selectedDateTime.Minute, 0, 0, UserSession.LoginUser.CultureInfo.Calendar); value.Value = DataUtils.DateToUtc(UserSession.LoginUser, timeOnly).ToString(); } } else { value.Value = DataUtils.DateToUtc(UserSession.LoginUser, (control as RadDatePicker).SelectedDate).ToString(); } } else if (control is RadDateTimePicker) { value.Value = DataUtils.DateToUtc(UserSession.LoginUser, (control as RadDateTimePicker).SelectedDate).ToString(); } value.Collection.Save(); } } }
public string CheckRequiredCustomFields() { CustomFields fields = new CustomFields(UserSession.LoginUser); fields.LoadByReferenceType(UserSession.LoginUser.OrganizationID, _refType, _auxID); foreach (CustomField field in fields) { Control control = GetCustomControl(_table, FieldIDToControlID(field.CustomFieldID)); if (control != null) { CustomValue value = CustomValues.GetValue(UserSession.LoginUser, field.CustomFieldID, _refID); if (value.IsRequired) { if (control is RadInputControl) { value.Value = (control as RadInputControl).Text; } else if (control is CheckBox) { value.Value = (control as CheckBox).Checked.ToString(); } else if (control is RadComboBox) { if (field.IsFirstIndexSelect && (control as RadComboBox).SelectedIndex == 0) { value.Value = ""; } else { value.Value = (control as RadComboBox).SelectedValue; } } else if (control is RadDateTimePicker) { value.Value = DataUtils.DateToUtc(UserSession.LoginUser, (control as RadDateTimePicker).SelectedDate).ToString(); } if (value.Value == "" || value.Value == null) { return(value.Name + " is a required value, please enter a value before saving"); } } } } return(""); }
public string CreateBooleanControl(CustomField field, bool isEditable = false, int organizationID = -1) { StringBuilder html = new StringBuilder(); if (isEditable) { CustomValue value = CustomValues.GetValue(TSAuthentication.GetLoginUser(), field.CustomFieldID, organizationID); html.AppendFormat(@"<div class='form-group'> <label for='{0}' class='col-xs-4 control-label'>{1}</label> <div class='col-xs-8'> <p class='form-control-static'><a class='editable' id='{0}' data-type='text'>{2}</a></p> </div> </div>", field.CustomFieldID, field.Name, value.Value); } else { html.AppendFormat("<div class='col-xs-1'><label><input class='customField' id='{0}' type='checkbox'></label></div>", field.CustomFieldID); } return(html.ToString()); }
public static void WriteTicketsViewItemXml(RestCommand command, XmlWriter writer, TicketsViewItem ticket, CustomFields customFields) { if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.BadRequest, "Invalid TicketID"); } writer.WriteElementString("TicketID", ticket.TicketID.ToString()); writer.WriteElementString("TicketNumber", ticket.TicketNumber.ToString()); writer.WriteElementString("TicketType", ticket.TicketTypeName.ToString()); writer.WriteElementString("Name", ticket.Name.ToString()); writer.WriteElementString("IsClosed", ticket.IsClosed.ToString()); if (customFields != null) { foreach (CustomField field in customFields) { CustomValue value = CustomValues.GetValue(command.LoginUser, field.CustomFieldID, ticket.TicketID); writer.WriteElementString(field.ApiFieldName, value.Value); } } }
private void WriteProperties(TicketGridViewItem ticket) { lblTitle.Text = "Ticket Number: " + ticket.TicketNumber.ToString(); lblDescription.Text = ticket.Name; StringBuilder builder = new StringBuilder(); builder.Append("<tr>"); builder.Append(GetColumn("Opened By", ticket.CreatorName)); builder.Append(GetColumn("Opened On", ticket.DateCreated.ToString("g", UserSession.LoginUser.CultureInfo))); builder.Append("</tr>"); builder.Append("<tr>"); builder.Append(GetColumn("Last Modified By", ticket.ModifierName)); // builder.Append("<td>Last Modified By:</td><td> <a href=\"../Default.aspx?UserID=" + ticket.ModifierID + "\" target=\"TSMain\">"); builder.Append(GetColumn("Last Modified On", ticket.DateModified.ToString("g", UserSession.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(UserSession.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", UserSession.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>"); builder.Append("<tr>"); builder.Append(GetColumn("Due Date", ticket.DueDate == null ? "" : ((DateTime)ticket.DueDate).ToString("g", UserSession.LoginUser.CultureInfo))); CustomFields fields = new CustomFields(UserSession.LoginUser); fields.LoadByTicketTypeID(UserSession.LoginUser.OrganizationID, ticket.TicketTypeID); bool flag = true; foreach (CustomField field in fields) { flag = !flag; if (flag) { builder.Append("<tr>"); } CustomValue value; value = CustomValues.GetValue(UserSession.LoginUser, field.CustomFieldID, ticket.TicketID, false); builder.Append(GetColumn(field.Name + "", value.Value)); if (!flag) { builder.Append("</tr>"); } } if (flag) { builder.Append("</tr>"); } litProperties.Text = builder.ToString(); }
private void LoadProperties(int organizationID) { lblProperties.Visible = true; Organizations organizations = new Organizations(UserSession.LoginUser); organizations.LoadByOrganizationID(organizationID); if (organizations.IsEmpty) { return; } Organization organization = organizations[0]; Users users = new Users(UserSession.LoginUser); string primaryUser = ""; if (organization.PrimaryUserID != null) { users.LoadByUserID((int)organization.PrimaryUserID); primaryUser = users.IsEmpty ? "" : users[0].LastName + ", " + users[0].FirstName; } lblProperties.Visible = organizations.IsEmpty; DataTable table = new DataTable(); table.Columns.Add("Name"); table.Columns.Add("Value"); string website = organization.Website; string link = ""; if (website != null) { if (website.IndexOf("http") < 0) { website = "http://" + website; } link = @"<a href=""" + website + @""" target=""OrganizationLink"">" + organization.Website + "</a>"; } table.Rows.Add(new string[] { "Name:", organization.Name }); table.Rows.Add(new string[] { "Website:", link }); table.Rows.Add(new string[] { "Description:", organization.Description }); table.Rows.Add(new string[] { "Service Agreement Expiration Date:", organization.SAExpirationDate == null ? "[None]" : ((DateTime)organization.SAExpirationDate).ToLongDateString() }); if (organization.SlaLevelID == null) { table.Rows.Add(new string[] { "Service Level Agreement:", "[None]" }); } else { SlaLevel level = SlaLevels.GetSlaLevel(UserSession.LoginUser, (int)organization.SlaLevelID); if (level != null) { table.Rows.Add(new string[] { "Service Level Agreement:", level.Name }); } } if (organizationID != UserSession.LoginUser.OrganizationID) { table.Rows.Add(new string[] { "Active:", organization.IsActive.ToString() }); if (UserSession.CurrentUser.IsSystemAdmin) { table.Rows.Add(new string[] { "API Enabled:", (organization.IsApiActive && organization.IsApiEnabled).ToString() }); table.Rows.Add(new string[] { "API Token:", organization.WebServiceID.ToString() }); table.Rows.Add(new string[] { "OrganizationID:", organization.OrganizationID.ToString() }); } } if (UserSession.CurrentUser.HasPortalRights) { table.Rows.Add(new string[] { "Portal Access:", organization.HasPortalAccess.ToString() }); } table.Rows.Add(new string[] { "Primary Contact:", primaryUser }); if (organization.DefaultSupportUserID != null) { User supportUser = Users.GetUser(UserSession.LoginUser, (int)organization.DefaultSupportUserID); table.Rows.Add(new string[] { "Default Support User:"******"Default Support User:"******"[None]" }); } if (organization.DefaultSupportGroupID != null) { Group supportGroup = (Group)Groups.GetGroup(UserSession.LoginUser, (int)organization.DefaultSupportGroupID); if (supportGroup != null) { table.Rows.Add(new string[] { "Default Support Group:", supportGroup.Name }); } else { table.Rows.Add(new string[] { "Default Support Group:", "[None]" }); } } else { table.Rows.Add(new string[] { "Default Support Group:", "[None]" }); } table.Rows.Add(new string[] { "Domains:", organization.CompanyDomains == null ? "[None Assigned]" : organization.CompanyDomains }); if (organization.SupportHoursMonth != 0) { table.Rows.Add(new string[] { "Support hours per month:", organization.SupportHoursMonth.ToString() }); } else { table.Rows.Add(new string[] { "Support hours per month:", "0" }); } CustomFields fields = new CustomFields(UserSession.LoginUser); fields.LoadByReferenceType(UserSession.LoginUser.OrganizationID, ReferenceType.Organizations); StringBuilder valueAsString = null; foreach (CustomField field in fields) { if (field.CustomFieldCategoryID != null) { continue; } CustomValue value = CustomValues.GetValue(UserSession.LoginUser, field.CustomFieldID, organizationID); switch (value.FieldType) { case CustomFieldType.Date: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("d", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } table.Rows.Add(new string[] { field.Name + ":", valueAsString.ToString() }); break; case CustomFieldType.Time: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("t", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } table.Rows.Add(new string[] { field.Name + ":", valueAsString.ToString() }); break; case CustomFieldType.DateTime: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("g", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } table.Rows.Add(new string[] { field.Name + ":", valueAsString.ToString() }); break; default: table.Rows.Add(new string[] { field.Name + ":", value.Value }); break; } } CustomFieldCategories cats = new CustomFieldCategories(UserSession.LoginUser); cats.LoadByRefType(ReferenceType.Organizations); StringBuilder builder = new StringBuilder(); string prop = "<div style=\"margin: 5px 5px 5px 15px; line-height: 20px;\"><span style=\"font-weight: bold;\">{0}: </span><span> {1}<br /></span></div>"; foreach (CustomFieldCategory cat in cats) { bool isExpanded = Settings.UserDB.ReadBool("Custom Cat Expanded (Customer) - " + cat.Category, false); string markerClass = isExpanded ? "ui-icon-triangle-1-s" : "ui-icon-triangle-1-e"; string displayClass = isExpanded ? "" : "ui-helper-hidden"; builder.Append("<div class=\"customfield-cat\"><span class=\"ui-icon " + markerClass + "\"></span><span class=\"caption\">" + cat.Category); builder.Append("</span></div><div class=\"ui-widget-content ts-separator " + displayClass + "\"></div>"); builder.Append("<div class=\"" + displayClass + "\">"); foreach (CustomField field in fields) { if (field.CustomFieldCategoryID != null && field.CustomFieldCategoryID == cat.CustomFieldCategoryID) { CustomValue value = CustomValues.GetValue(UserSession.LoginUser, field.CustomFieldID, organizationID); switch (value.FieldType) { case CustomFieldType.Date: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("d", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } builder.Append(string.Format(prop, field.Name, valueAsString.ToString())); break; case CustomFieldType.Time: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("t", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } builder.Append(string.Format(prop, field.Name, valueAsString.ToString())); break; case CustomFieldType.DateTime: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("g", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } builder.Append(string.Format(prop, field.Name, valueAsString.ToString())); break; default: builder.Append(string.Format(prop, field.Name, value.Value)); break; } } } builder.Append("</div>"); } litProperties.Text = builder.ToString(); rptProperties.DataSource = table; rptProperties.DataBind(); }
public void LoadValues() { CustomFields fields = new CustomFields(UserSession.LoginUser); fields.LoadByReferenceType(UserSession.LoginUser.OrganizationID, _refType, _auxID); foreach (CustomField field in fields) { Control control = GetCustomControl(_table, FieldIDToControlID(field.CustomFieldID)); CustomValue value = CustomValues.GetValue(UserSession.LoginUser, field.CustomFieldID, _refID); if (control != null && value != null) { try { if (control is RadInputControl) { (control as RadInputControl).Text = value.Value; } else if (control is CheckBox) { (control as CheckBox).Checked = bool.Parse(value.Value); } else if (control is RadComboBox) { (control as RadComboBox).SelectedValue = value.Value; } else if (control is RadDatePicker) { if (control is RadTimePicker) { if (value.Value == "") { (control as RadTimePicker).SelectedDate = null; } else { (control as RadTimePicker).SelectedDate = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); } } else { if (value.Value == "") { (control as RadDatePicker).SelectedDate = null; } else { (control as RadDatePicker).SelectedDate = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); } } } else if (control is RadDateTimePicker) { if (value.Value == "") { (control as RadDateTimePicker).SelectedDate = null; } else { (control as RadDateTimePicker).SelectedDate = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); } } } catch (Exception ex) { } } } }
private void LoadProperties(int userID) { Users users = new Users(UserSession.LoginUser); users.LoadByUserID(userID); lblProperties.Visible = users.IsEmpty; if (!users.IsEmpty) { User user = users[0]; DataTable table = new DataTable(); table.Columns.Add("Name"); table.Columns.Add("Value"); table.Rows.Add(new string[] { "Email:", "<a href=\"mailto:" + user.Email + "\">" + user.Email + "</a>" }); table.Rows.Add(new string[] { "Title:", user.Title }); table.Rows.Add(new string[] { "Active:", user.IsActive.ToString() }); table.Rows.Add(new string[] { "Prevent this email address from creating or updating tickets:", user.BlockInboundEmail.ToString() }); CustomFields fields = new CustomFields(UserSession.LoginUser); if (UserSession.CurrentUser.IsTSUser) { table.Rows.Add(new string[] { "System Administrator:", user.IsSystemAdmin.ToString() }); table.Rows.Add(new string[] { "Financial Administrator:", user.IsFinanceAdmin.ToString() }); table.Rows.Add(new string[] { "Portal User:"******"Last Logged In:", user.LastLogin.ToString("g", UserSession.LoginUser.CultureInfo) }); table.Rows.Add(new string[] { "In Office:", user.InOffice.ToString() }); table.Rows.Add(new string[] { "In Office Comment:", user.InOfficeComment }); if (user.IsActive) { table.Rows.Add(new string[] { "Activated On:", user.ActivatedOn.ToString("g", UserSession.LoginUser.CultureInfo) }); } else { if (user.DeactivatedOn != null) { DateTime dateTime = (DateTime)user.DeactivatedOn; table.Rows.Add(new string[] { "Deactivated On:", dateTime.ToString("g", UserSession.LoginUser.CultureInfo) }); } else { table.Rows.Add(new string[] { "Deactivated On:", "" }); } } } else { if (UserSession.CurrentUser.HasPortalRights) { table.Rows.Add(new string[] { "Portal User:"******"Last Logged In:", user.LastLogin.ToString("g", UserSession.LoginUser.CultureInfo) }); } } } fields.LoadByReferenceType(UserSession.LoginUser.OrganizationID, ReferenceType.Contacts); StringBuilder valueAsString = null; foreach (CustomField field in fields) { CustomValue value = CustomValues.GetValue(UserSession.LoginUser, field.CustomFieldID, userID); switch (value.FieldType) { case CustomFieldType.Date: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("d", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } table.Rows.Add(new string[] { field.Name + ":", valueAsString.ToString() }); break; case CustomFieldType.Time: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("t", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } table.Rows.Add(new string[] { field.Name + ":", valueAsString.ToString() }); break; case CustomFieldType.DateTime: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("g", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } table.Rows.Add(new string[] { field.Name + ":", valueAsString.ToString() }); break; default: table.Rows.Add(new string[] { field.Name + ":", value.Value }); break; } } rptProperties.DataSource = table; rptProperties.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { int productID; try { productID = int.Parse(Request["ProductID"]); } catch (Exception) { Response.Write(""); Response.End(); return; } lblProperties.Visible = true; Product product = (Product)Products.GetProduct(UserSession.LoginUser, productID); lblProperties.Visible = product == null; if (product == null) { return; } DataTable table = new DataTable(); table.Columns.Add("Name"); table.Columns.Add("Value"); table.Rows.Add(new string[] { "Name:", product.Name }); table.Rows.Add(new string[] { "Description:", product.Description }); table.Rows.Add(new string[] { "Product ID:", product.ProductID.ToString() }); CustomFields fields = new CustomFields(UserSession.LoginUser); fields.LoadByReferenceType(UserSession.LoginUser.OrganizationID, ReferenceType.Products); StringBuilder valueAsString = null; foreach (CustomField field in fields) { CustomValue value = CustomValues.GetValue(UserSession.LoginUser, field.CustomFieldID, productID); switch (value.FieldType) { case CustomFieldType.Date: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("d", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } table.Rows.Add(new string[] { field.Name + ":", valueAsString.ToString() }); break; case CustomFieldType.Time: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("t", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } table.Rows.Add(new string[] { field.Name + ":", valueAsString.ToString() }); break; case CustomFieldType.DateTime: valueAsString = new StringBuilder(); if (!string.IsNullOrEmpty(value.Value)) { try { DateTime valueAsDateTime = DataUtils.DateToLocal(UserSession.LoginUser, DateTime.Parse(value.Value)); valueAsString.Append(valueAsDateTime.ToString("g", UserSession.LoginUser.CultureInfo)); } catch { valueAsString.Append(value.Value); } } table.Rows.Add(new string[] { field.Name + ":", valueAsString.ToString() }); break; default: table.Rows.Add(new string[] { field.Name + ":", value.Value }); break; } } rptProperties.DataSource = table; rptProperties.DataBind(); }
public int SaveAsset(string data) { NewAssetSave info; try { info = Newtonsoft.Json.JsonConvert.DeserializeObject <NewAssetSave>(data); } catch (Exception e) { return(-1); } LoginUser loginUser = TSAuthentication.GetLoginUser(); Assets assets = new Assets(loginUser); Asset asset = assets.AddNewAsset(); asset.OrganizationID = TSAuthentication.OrganizationID; asset.Name = info.Name; asset.ProductID = info.ProductID; asset.ProductVersionID = info.ProductVersionID; asset.SerialNumber = info.SerialNumber; asset.WarrantyExpiration = DataUtils.DateToUtc(TSAuthentication.GetLoginUser(), info.WarrantyExpiration); asset.Notes = info.Notes; //Location 1=assigned (shipped), 2=warehouse, 3=junkyard asset.Location = "2"; asset.DateCreated = DateTime.UtcNow; asset.DateModified = DateTime.UtcNow; asset.CreatorID = loginUser.UserID; asset.ModifierID = loginUser.UserID; asset.Collection.Save(); string description = String.Format("Created asset {0} ", GetAssetReference(asset)); ActionLogs.AddActionLog(TSAuthentication.GetLoginUser(), ActionLogType.Insert, ReferenceType.Assets, asset.AssetID, description); foreach (CustomFieldSaveInfo field in info.Fields) { CustomValue customValue = CustomValues.GetValue(TSAuthentication.GetLoginUser(), field.CustomFieldID, asset.AssetID); if (field.Value == null) { customValue.Value = ""; } else { if (customValue.FieldType == CustomFieldType.DateTime) { customValue.Value = ((DateTime)field.Value).ToString(); //DateTime dt; //if (DateTime.TryParse(((string)field.Value), System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out dt)) //{ // customValue.Value = dt.ToUniversalTime().ToString(); //} } else { customValue.Value = field.Value.ToString(); } } customValue.Collection.Save(); } AssetHistory history = new AssetHistory(loginUser); AssetHistoryItem historyItem = history.AddNewAssetHistoryItem(); historyItem.OrganizationID = loginUser.OrganizationID; historyItem.Actor = loginUser.UserID; historyItem.AssetID = asset.AssetID; historyItem.ActionTime = DateTime.UtcNow; historyItem.ActionDescription = "Asset created."; historyItem.ShippedFrom = 0; historyItem.ShippedTo = 0; historyItem.TrackingNumber = string.Empty; historyItem.ShippingMethod = string.Empty; historyItem.ReferenceNum = string.Empty; historyItem.Comments = string.Empty; history.Save(); return(asset.AssetID); }