Ejemplo n.º 1
0
 public static object GetValueFromCustomFieldTextOrDate(DataRow dataRow, CustomFieldType type, CustomFieldDataSet dataSet)
 {
     try
     {
         StringCollection value = new StringCollection();
         Guid mdPropID = Guid.Empty;
         if ((dataSet as CustomFieldDataSet).CustomFields.Any(t => t.MD_PROP_NAME == type.GetString()))
         {
             mdPropID = (dataSet as CustomFieldDataSet).CustomFields.First(t => t.MD_PROP_NAME == type.GetString()).MD_PROP_UID;
         }
         if (mdPropID == Guid.Empty)
         {
             return null;
         }
         if (type == CustomFieldType.EstStart || type == CustomFieldType.EstFinish)
         {
             if ((dataRow.Table.DataSet as ProjectDataSet).TaskCustomFields.Any(t => t.TASK_UID == (dataRow as ProjectDataSet.TaskRow).TASK_UID && t.MD_PROP_UID == mdPropID))
                 return (dataRow.Table.DataSet as ProjectDataSet).TaskCustomFields.First(t => t.TASK_UID == (dataRow as ProjectDataSet.TaskRow).TASK_UID && t.MD_PROP_UID == mdPropID && !t.IsDATE_VALUENull()).DATE_VALUE;
             else
                 return null;
         }
         else if (type == CustomFieldType.PMT || type == CustomFieldType.ReasonRecovery)
         {
             if ((dataRow.Table.DataSet as ProjectDataSet).TaskCustomFields.Any(t => t.TASK_UID == (dataRow as ProjectDataSet.TaskRow).TASK_UID && t.MD_PROP_UID == mdPropID && !t.IsTEXT_VALUENull()))
                 return (dataRow.Table.DataSet as ProjectDataSet).TaskCustomFields.First(t => t.TASK_UID == (dataRow as ProjectDataSet.TaskRow).TASK_UID && t.MD_PROP_UID == mdPropID && !t.IsTEXT_VALUENull()).TEXT_VALUE;
             else
                 return null;
         }
         return null;
     }
     catch
     {
         return null;
     }
 }
Ejemplo n.º 2
0
        private bool IsValid(object customFieldValue, CustomFieldType customFieldType, bool isRequired)
        {
            bool isValid = false;

            if (isRequired && string.IsNullOrEmpty(customFieldValue.ToString()))
            {
                isValid = false;
            }
            else
            {
                switch (customFieldType)
                {
                case CustomFieldType.Number:
                    int intValue = 0;
                    isValid = int.TryParse(customFieldValue.ToString(), out intValue);
                    break;

                default:
                    isValid = true;
                    break;
                }
            }

            return(isValid);
        }
Ejemplo n.º 3
0
        public bool CustomFieldEditing_PreTransitionCRUD(string transition)
        {
            switch (transition.ToUpper())
            {
            case "SAVE":
                if (ASPxEdit.ValidateEditorsInContainer(formlayoutGeneralInfo))
                {
                    using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                    {
                        Guid selectedCustomFieldTypeId =
                            Guid.Parse(cbbCustomFieldType.SelectedItem.Value.ToString());
                        CustomFieldType customFieldType =
                            uow.GetObjectByKey <CustomFieldType>(selectedCustomFieldTypeId);
                        //Get eidting CustomField
                        NAS.DAL.CMS.ObjectDocument.CustomField customField =
                            uow.GetObjectByKey <NAS.DAL.CMS.ObjectDocument.CustomField>(CustomFieldId);
                        customField.Name = txtCustomFieldName.Text;
                        customField.CustomFieldTypeId = customFieldType;
                        //Set new Id to session variable
                        CustomFieldId = customField.CustomFieldId;
                        uow.CommitChanges();
                    }
                }
                else
                {
                    return(false);
                }
                break;

            default:
                break;
            }
            return(true);
        }
        public ActionResult EditCustomFieldType(CustomFieldType customFieldType)
        {
            var acResponse = new ActivityResponse();

            try
            {
                if (customFieldType.TableId < 1 || string.IsNullOrEmpty(customFieldType.FieldTypeId))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "An unknown error was encountered. Please try again.";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                if (string.IsNullOrEmpty(customFieldType.FieldTypeName))
                {
                    acResponse.Code    = -1;
                    acResponse.Message = "Please provide customFieldType Name";
                    return(Json(acResponse, JsonRequestBehavior.AllowGet));
                }

                _customFieldTypeService.Update(customFieldType);
                _unitOfWork.SaveChanges();

                acResponse.Code    = 5;
                acResponse.Message = "Custom Field Type was successfully updated";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                acResponse.Code    = -1;
                acResponse.Message = "An unknown error was encountered. Please try again.";
                return(Json(acResponse, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 5
0
        public int CreateField(EntityType entityType, String label, CustomFieldType customFieldType, String mask)
        {
            if (!_supportedEntityType.Contains(entityType) || String.IsNullOrEmpty(label))
            {
                throw new ArgumentException();
            }

            var resultMask = GetValidMask(customFieldType, mask);

            var sortOrder = Query(CrmDbContext.FieldDescription).Select(x => x.SortOrder).Max() + 1;

            var dbEntity = new DbFieldDescription
            {
                Label      = label,
                Type       = customFieldType,
                Mask       = resultMask,
                SortOrder  = sortOrder,
                EntityType = entityType,
                TenantId   = TenantID
            };

            CrmDbContext.FieldDescription.Add(dbEntity);

            CrmDbContext.SaveChanges();

            return(dbEntity.Id);
        }
Ejemplo n.º 6
0
 public void SetValue(CustomFieldType customFieldType, object value)
 {
     CustomFieldType = customFieldType;
     if (customFieldType == CustomFieldType.DateTime)
     {
         ValueDate   = DateTime.ParseExact(value.ToString(), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
         ValueDouble = null;
         ValueInt    = null;
         ValueString = null;
     }
     else if (customFieldType == CustomFieldType.Double)
     {
         ValueDouble = Convert.ToDouble(value);
         ValueDate   = null;
         ValueInt    = null;
         ValueString = null;
     }
     else if (customFieldType == CustomFieldType.Integer)
     {
         ValueInt    = Convert.ToInt32(value);
         ValueDate   = null;
         ValueDouble = null;
         ValueString = null;
     }
     else if (customFieldType == CustomFieldType.String)
     {
         ValueString = Convert.ToString(value);
         ValueDate   = null;
         ValueDouble = null;
         ValueInt    = null;
     }
     Value = Convert.ToString(value);
 }
Ejemplo n.º 7
0
        public void Test1([DataSources] string context)
        {
            Query.ClearCaches();

            var ms = new MappingSchema();

            ms.SetConvertExpression <string?, CustomFieldType?>(s => CustomFieldType.FromString(s));
            ms.SetConvertExpression <CustomFieldType, DataParameter>(_ => new DataParameter(null, _ != null ? _.ToString() : null), false);

            using (var db = GetDataContext(context, ms))
                using (var tbl = db.CreateLocalTable <Issue1363Record>())
                {
                    db.Insert(new Issue1363CustomRecord2()
                    {
                        Id = 1
                    });

                    db.Insert(new Issue1363CustomRecord2()
                    {
                        Id     = 2,
                        Field1 = new CustomFieldType()
                    });

                    db.Insert(new Issue1363CustomRecord2()
                    {
                        Id     = 3,
                        Field1 = new CustomFieldType()
                        {
                            Field1 = "test"
                        }
                    });

                    Assert(db);
                }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a custom field of the given type
        /// </summary>
        /// <param name="name">the name of the field</param>
        /// <param name="type">the type of the field</param>
        public void CreateCustomField(string name, CustomFieldType type)
        {
            QueryParameters parameters = new QueryParameters();

            parameters.Add("type", type);

            Post("contacts/fields/custom/" + HttpUtility.UrlEncode(name), parameters, null);
        }
Ejemplo n.º 9
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        if (Request["CustomFieldID"] != null)
        {
            _customFieldID = int.Parse(Request["CustomFieldID"]);
        }

        _refType = (ReferenceType)int.Parse(Request["RefType"]);
        if (Request["AuxID"] != null)
        {
            _auxID = int.Parse(Request["AuxID"]);
        }

        if (!IsPostBack)
        {
            LoadFieldTypes();
            if (_refType == ReferenceType.Tickets)
            {
                LoadParentFields();
                LoadParentProducts();
            }
            else
            {
                parentFields.Visible = false;
            }

            if (_customFieldID > -1)
            {
                LoadCustomField(_customFieldID);
            }
        }

        _manager.AjaxSettings.AddAjaxSetting(comboFieldType, divMain);
        _manager.AjaxSettings.AddAjaxSetting(comboParentField, comboParentValue);

        CustomFieldType selectedFieldType = GetSelectedFieldType();

        pnlPickList.Visible  = selectedFieldType == CustomFieldType.PickList;
        cbIsRequired.Visible = selectedFieldType != CustomFieldType.Boolean;
        if (_refType == ReferenceType.Tickets)
        {
            cbIsRequiredToClose.Visible = selectedFieldType != CustomFieldType.Boolean;
        }
        else
        {
            cbIsRequiredToClose.Visible = false;
        }

        if (_refType == ReferenceType.Assets)
        {
            cbIsVisibleOnPortal.Visible = false;
        }

        maskDiv.Visible = selectedFieldType == CustomFieldType.Text;
    }
Ejemplo n.º 10
0
        public bool CustomFieldCreatingHasNoInitData_PreTransitionCRUD(string transition)
        {
            switch (transition.ToUpper())
            {
            case "ACCEPT":
                if (ASPxEdit.ValidateEditorsInContainer(formlayoutGeneralInfo))
                {
                    using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                    {
                        Guid selectedCustomFieldTypeId =
                            Guid.Parse(cbbCustomFieldType.SelectedItem.Value.ToString());
                        CustomFieldType customFieldType =
                            uow.GetObjectByKey <CustomFieldType>(selectedCustomFieldTypeId);
                        //Create new CustomField
                        NAS.DAL.CMS.ObjectDocument.CustomField customField =
                            new NAS.DAL.CMS.ObjectDocument.CustomField(uow)
                        {
                            CustomFieldId     = Guid.NewGuid(),
                            Name              = txtCustomFieldName.Text,
                            CustomFieldTypeId = customFieldType
                        };
                        //Attach CustomField to ObjectTypeId
                        if (ObjectTypeId != null && !ObjectTypeId.Equals(Guid.Empty))
                        {
                            /*2013-12-12 Khoa.Truong DEL START
                             * Decoupling with the client using this form
                             * //Guid objectTypeId = ((ObjectTypeCustomFieldListing)Parent).ObjectTypeId;
                             * 2013-12-12 Khoa.Truong DEL END*/
                            ObjectType            objectType            = uow.GetObjectByKey <ObjectType>(ObjectTypeId);
                            ObjectTypeCustomField objectTypeCustomField = new ObjectTypeCustomField(uow)
                            {
                                ObjectTypeCustomFieldId = Guid.NewGuid(),
                                CustomFieldId           = customField,
                                ObjectTypeId            = objectType
                            };
                        }
                        //Attach new custom fields for all object of the object type

                        /*These code is replace with lazy updating for custom fields of each object
                         * //ObjectBO objectBO = new ObjectBO();
                         * //objectBO.UpdateCMSObjects(uow, objectTypeId);
                         */

                        uow.CommitChanges();
                    }
                }
                else
                {
                    return(false);
                }
                break;

            default:
                break;
            }
            return(true);
        }
Ejemplo n.º 11
0
 public Guid CreateCustomField(Guid mailingListID, String name, CustomFieldType type, Boolean isRequired, String context = null)
 {
     return _Manager.MakeRequest<Guid>(HttpMethod.POST, String.Format("/lists/{0}/customfields/create", mailingListID), new {
         Name = name,
         Type = type,
         IsRequired = isRequired,
         Context = context
     });
 }
Ejemplo n.º 12
0
        public static void DefineCustomFieldType(ICustomFieldRepository customFieldRepository, string name,
                                                 string dictionaryName, int min, int max, EntityTypeEnum entityType)
        {
            var customfieldType = new CustomFieldType(customFieldRepository.GetNextId(),
                                                      name, dictionaryName, min, max, entityType, "string");

            customFieldRepository.Add(customfieldType);
            DefinedCustomFields.Add(customfieldType);
        }
Ejemplo n.º 13
0
        public void GivenACustomFieldType_WhenAdd_ThenAddToContext()
        {
            var expected = new CustomFieldType {
                Id = 1
            };

            Target.Add(expected);

            MockDbSet.AssertWasCalled(m => m.Add(expected));
        }
Ejemplo n.º 14
0
        public void GivenACustomFieldType_WhenUpdate_ThenContextSetsModified()
        {
            var expected = new CustomFieldType {
                Id = 1
            };

            Target.Update(expected);

            MockContext.AssertWasCalled(m => m.SetModified(expected));
        }
Ejemplo n.º 15
0
        public void GivenACustomFieldType_WhenDelete_ThenRemoveFromContext()
        {
            var item = new CustomFieldType {
                Id = 1
            };

            Target.Remove(item);

            MockDbSet.AssertWasCalled(m => m.Remove(item));
        }
Ejemplo n.º 16
0
 public ColumnSpecBase(int number, string name, CustomFieldType dataType, string notes, bool required, string cultureCode, string example)
 {
     Number      = number;
     Name        = name;
     DataType    = dataType;
     Notes       = notes;
     Required    = required;
     CultureCode = cultureCode;
     Example     = example;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:CustomField"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="projectId">The project id.</param>
 /// <param name="name">The name.</param>
 /// <param name="dataType">Type of the data.</param>
 /// <param name="required">if set to <c>true</c> [required].</param>
 /// <param name="value">The value.</param>
 /// <param name="fieldType">Type of the field.</param>
 public CustomField(int id, int projectId, string name, ValidationDataType dataType, bool required, string value, CustomFieldType fieldType)
 {
     _Id = id;
         _ProjectId = projectId;
         _Name = name;
         _DataType = dataType;
         _Required = required;
         _Value = value;
         _FieldType = fieldType;
 }
        // GET: CustomFieldType/EditCustomFieldType/5
        public ActionResult GetCustomFieldType(int?id)
        {
            if (id == null)
            {
                return(Json(new CustomFieldType(), JsonRequestBehavior.AllowGet));
            }

            CustomFieldType customFieldType = _customFieldTypeService.Find(id);

            if (customFieldType == null)
            {
                return(Json(new CustomFieldType(), JsonRequestBehavior.AllowGet));
            }
            return(Json(customFieldType, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 19
0
        public int GetFieldId(EntityType entityType, String label, CustomFieldType customFieldType)
        {
            var result = Db.ExecuteList(GetFieldDescriptionSqlQuery(
                                            Exp.Eq("type", (int)customFieldType)
                                            & BuildEntityTypeConditions(entityType, "entity_type")
                                            & Exp.Eq("label", label))).ConvertAll(row => ToCustomField(row));

            if (result.Count == 0)
            {
                return(0);
            }
            else
            {
                return(result[0].ID);
            }
        }
Ejemplo n.º 20
0
        public async Task <bool> IsTagsAvailable(string externalToken, CustomFieldType fieldType,
                                                 CancellationToken token = default(CancellationToken))
        {
            var response = await GetTagsResponse(externalToken, token);

            if (response.StatusCode == HttpStatusCode.Forbidden)
            {
                return(false);
            }

            var tags = await HandleHttpResponseMessage <List <TagDetailsModel> >(response);

            var result = tags.Any(x => x.Type == fieldType);

            return(result);
        }
Ejemplo n.º 21
0
        protected void SetCustomFieldElement(IWebElement customFieldElement, CustomFieldType type, List <string> values)
        {
            switch (type)
            {
            case CustomFieldType.MultiSelect:
                customFieldElement = customFieldElement.FindElement(By.XPath("..//div[contains(@class,'select-component__control')]"));
                SelectMultipleValuesFromReactDropdownByText(customFieldElement, values);
                break;

            case CustomFieldType.Text:
                customFieldElement = customFieldElement.FindElement(By.XPath("..//input"));
                ClearInputAndTypeValue(customFieldElement, values[0]);
                break;

            case CustomFieldType.MultiLine:
                customFieldElement = customFieldElement.FindElement(By.XPath("..//textarea"));
                ClearInputAndTypeValue(customFieldElement, values[0]);
                break;

            case CustomFieldType.Image:
                var removeImageElementXPath = "//button[contains(@class, 'fileupload-component-btn-remove-file')]";
                if (IsElementPresent(By.XPath(removeImageElementXPath)))
                {
                    var removeImageElement = customFieldElement.FindElement(By.XPath($"..{removeImageElementXPath}"));
                    ClickElement(removeImageElement);
                }

                customFieldElement = customFieldElement.FindElement(By.XPath("..//input[@name='file']"));
                var filePath = FileHelper.GetImageFilePath(values[0]);
                customFieldElement.SendKeys(filePath);
                break;

            case CustomFieldType.DatePicker:
                customFieldElement = customFieldElement.FindElement(By.XPath("..//input"));
                if (!values.Any())
                {
                    values.Add(GetTodaysDate());
                }
                ClearInputAndTypeValue(customFieldElement, values[0]);
                break;

            default:
                throw new Exception($"The custom field type: '{type}' is currently not supported.");
            }
        }
Ejemplo n.º 22
0
        public virtual void AssignCustomField(CustomFieldType customFieldType)
        {
            if (customFieldTypeIdList == null)
            {
                customFieldTypeIdList = new List <CustomFieldTypeId>();
            }

            if (customFieldType == null)
            {
                throw new UnitArgumentException("Unit", "CustomFieldType");
            }
            if (customFieldType.EntityId != EntityTypeEnum.Unit)
            {
                throw new UnitArgumentException("Unit", "CustomFieldType");
            }

            customFieldTypeIdList.Add(customFieldType.Id);
        }
Ejemplo n.º 23
0
        public int CreateField(EntityType entityType, String label, CustomFieldType customFieldType, String mask)
        {
            if (!_supportedEntityType.Contains(entityType))
                throw new ArgumentException();


            var sortOrder = DbManager.ExecuteScalar<int>(Query("crm_field_description").SelectMax("sort_order")) + 1;

            return DbManager.ExecuteScalar<int>(
                                              Insert("crm_field_description")
                                              .InColumnValue("id", 0)
                                              .InColumnValue("label", label)
                                              .InColumnValue("type", (int)customFieldType)
                                              .InColumnValue("mask", mask)
                                              .InColumnValue("sort_order", sortOrder)
                                              .InColumnValue("entity_type", (int)entityType)
                                              .Identity(1, 0, true));
        }
        private void CreateCustomFields()
        {
            EntityType      entityType          = ProjContext.EntityTypes.ProjectEntity;
            CustomFieldType customFieldType     = CustomFieldType.TEXT;
            LookupTable     selectedLookupTable = null;
            bool            allowMultiSelect    = false;

            CB_EntityType.InvokeIfRequired(cb => entityType = cb.SelectedValue as EntityType);
            CB_Type.InvokeIfRequired(sb => customFieldType  = (CustomFieldType)CB_Type.SelectedValue);
            CB_LookupTable.InvokeIfRequired(cb =>
            {
                if (cb.SelectedIndex <= 0)
                {
                    return;
                }
                selectedLookupTable = cb.SelectedValue as LookupTable;
                if (CBX_AllowMultiSelect.Checked)
                {
                    allowMultiSelect = true;
                }
            });
            for (int customFieldCount = 1; customFieldCount <= Convert.ToInt32(NUD_CFNumber.Value); customFieldCount++)
            {
                CustomFieldCreationInformation cfCi = new CustomFieldCreationInformation
                {
                    Name       = TB_Name.Text + customFieldCount,
                    EntityType = entityType,
                    FieldType  = customFieldType
                };
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Creating custom field with name {0}", cfCi.Name);
                if (selectedLookupTable != null)
                {
                    cfCi.LookupTable = selectedLookupTable;
                    Log.WriteVerbose(new SourceInfo(), TB_Status, "Setting custom field to use lookup table {0}", selectedLookupTable.Name);
                }

                cfCi.LookupAllowMultiSelect = allowMultiSelect;
                ProjContext.CustomFields.Add(cfCi);
            }
            ProjContext.CustomFields.Update();
            ProjContext.ExecuteQuery();
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Adds a new custom field definition to a board.
        /// </summary>
        /// <param name="name">The field's name.</param>
        /// <param name="type">The field's data type.</param>
        /// <param name="ct">(Optional) A cancellation token for async processing.</param>
        /// <param name="options">(Optional) A collection of drop down options.</param>
        /// <returns>The <see cref="ICustomFieldDefinition"/> generated by Trello.</returns>
        public async Task <ICustomFieldDefinition> Add(string name, CustomFieldType type,
                                                       CancellationToken ct = default,
                                                       params IDropDownOption[] options)
        {
            var error = NotNullRule <string> .Instance.Validate(null, name);

            if (error != null)
            {
                throw new ValidationException <string>(name, new[] { error });
            }
            if (type == CustomFieldType.Unknown)
            {
                throw new ValidationException <CustomFieldType>(type, new string[] { });
            }

            var json = TrelloConfiguration.JsonFactory.Create <IJsonCustomFieldDefinition>();

            json.Name              = name;
            json.Board             = TrelloConfiguration.JsonFactory.Create <IJsonBoard>();
            json.Board.Id          = OwnerId;
            json.Type              = type;
            json.Display           = TrelloConfiguration.JsonFactory.Create <IJsonCustomFieldDisplayInfo>();
            json.Display.CardFront = true;
            if (type == CustomFieldType.DropDown)
            {
                json.Options = options.Select((o, i) =>
                {
                    var optionJson          = TrelloConfiguration.JsonFactory.Create <IJsonCustomDropDownOption>();
                    optionJson.Color        = o.Color;
                    optionJson.Pos          = TrelloConfiguration.JsonFactory.Create <IJsonPosition>();
                    optionJson.Pos.Explicit = i * 1024;
                    optionJson.Text         = o.Text;

                    return(optionJson);
                }).ToList();
            }

            var endpoint = EndpointFactory.Build(EntityRequestType.CustomFieldDefinition_Write_Create);
            var newData  = await JsonRepository.Execute(Auth, endpoint, json, ct);

            return(new CustomFieldDefinition(newData, Auth));
        }
Ejemplo n.º 26
0
        public int CreateField(EntityType entityType, String label, CustomFieldType customFieldType, String mask)
        {
            if (!_supportedEntityType.Contains(entityType) || String.IsNullOrEmpty(label))
            {
                throw new ArgumentException();
            }
            var resultMask = GetValidMask(customFieldType, mask);

            var sortOrder = Db.ExecuteScalar <int>(Query("crm_field_description").SelectMax("sort_order")) + 1;

            return(Db.ExecuteScalar <int>(
                       Insert("crm_field_description")
                       .InColumnValue("id", 0)
                       .InColumnValue("label", label)
                       .InColumnValue("type", (int)customFieldType)
                       .InColumnValue("mask", resultMask)
                       .InColumnValue("sort_order", sortOrder)
                       .InColumnValue("entity_type", (int)entityType)
                       .Identity(1, 0, true)));
        }
Ejemplo n.º 27
0
 public void DeleteCustomField(CustomFieldType customFieldType)
 {
     try
     {
         using (var scope = new TransactionScope())
         {
             customFieldRep.DeleteCustomField(customFieldType);
             scope.Complete();
         }
     }
     catch (Exception exp)
     {
         var res = customFieldRep.TryConvertException(exp);
         if (res == null)
         {
             throw;
         }
         throw res;
     }
 }
Ejemplo n.º 28
0
        public static CustomField Create(string name, CustomFieldType customFieldType, Guid assetId, string value, string valueString, DateTime?valueDate, int?valueInteger, double?valueDouble, Guid creatorid, DateTime createDateTime, string companyName)
        {
            var @entity = new CustomField
            {
                Id              = Guid.NewGuid(),
                Name            = name,
                CustomFieldType = customFieldType,
                AssetId         = assetId,
                Value           = value,
                ValueDate       = valueDate,
                ValueInt        = valueInteger,
                ValueDouble     = valueDouble,
                ValueString     = valueString,
                CreatorUserId   = creatorid,
                CreationTime    = createDateTime,
                CompanyName     = companyName,
                IsDeleted       = false
            };

            return(@entity);
        }
Ejemplo n.º 29
0
        public void LoadByOrganizationFieldTypeAndTicketType(int organizationID, CustomFieldType fieldType, int ticketTypeID, int selfID, int?customFieldCategoryID)
        {
            using (SqlCommand command = new SqlCommand())
            {
                string exceptSelfClause = string.Empty;
                if (selfID != -1)
                {
                    exceptSelfClause = " AND CustomFieldID <> @SelfID ";
                }

                string categoryClause = " AND CustomFieldCategoryID IS NULL ";
                if (customFieldCategoryID != null)
                {
                    categoryClause = " AND CustomFieldCategoryID = @CustomFieldCategoryID ";
                }

                command.CommandText = @"
        SELECT 
          *
        FROM
          CustomFields
        WHERE
          OrganizationID = @OrganizationID
          AND FieldType = @FieldType
          AND AuxID = @TicketType
          " + exceptSelfClause + @"
          " + categoryClause + @"
        ORDER BY
          Position";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@OrganizationID", organizationID);
                command.Parameters.AddWithValue("@FieldType", fieldType);
                command.Parameters.AddWithValue("@TicketType", ticketTypeID);
                command.Parameters.AddWithValue("@SelfID", selfID);
                command.Parameters.AddWithValue("@CustomFieldCategoryID", customFieldCategoryID ?? -1);
                Fill(command, "CustomFields");
            }
        }
Ejemplo n.º 30
0
        public int GetFieldId(EntityType entityType, String label, CustomFieldType customFieldType)
        {
            var sqlQuery = Query(CrmDbContext.FieldDescription).Where(x => x.Type == customFieldType && x.Label == label);

            if (entityType == EntityType.Company || entityType == EntityType.Person)
            {
                sqlQuery = sqlQuery.Where(x => x.EntityType == entityType || x.EntityType == EntityType.Contact);
            }
            else
            {
                sqlQuery = sqlQuery.Where(x => x.EntityType == entityType);
            }


            var result = sqlQuery.FirstOrDefault();

            if (result == null)
            {
                return(0);
            }

            return(result.Id);
        }
Ejemplo n.º 31
0
        private string GetCustomFieldTypeDisplayName(CustomFieldType customFieldType)
        {
            switch (customFieldType)
            {
            case CustomFieldType.MultiSelect:
                return("Multi Select");

            case CustomFieldType.Text:
                return("Text");

            case CustomFieldType.MultiLine:
                return("Multi Line");

            case CustomFieldType.Image:
                return("Image");

            case CustomFieldType.DatePicker:
                return("Date Picker");

            default:
                throw new ArgumentOutOfRangeException(nameof(customFieldType), customFieldType, null);
            }
        }
Ejemplo n.º 32
0
        public static string GetCustomFieldTypeName(CustomFieldType type)
        {
            string result;

            switch (type)
            {
            case CustomFieldType.Text: result = "Text"; break;

            case CustomFieldType.DateTime: result = "Date and Time"; break;

            case CustomFieldType.Boolean: result = "True or False"; break;

            case CustomFieldType.Number: result = "Number"; break;

            case CustomFieldType.PickList: result = "Pick List"; break;

            case CustomFieldType.Date: result = "Date"; break;

            case CustomFieldType.Time: result = "Time"; break;

            default: result = ""; break;
            }
            return(result);
        }
Ejemplo n.º 33
0
 public CustomFieldType AddCustomFieldType(string name, string dictionaryName,
                                           long minValue, long maxValue, int entityId, string typeId)
 {
     try
     {
         using (var scope = new TransactionScope())
         {
             var id = customFieldRep.GetNextId();
             var customFieldType = new CustomFieldType(id, name, dictionaryName, minValue, maxValue, Enumeration.FromValue <EntityTypeEnum>(entityId.ToString()), typeId);
             customFieldRep.Add(customFieldType);
             scope.Complete();
             return(customFieldType);
         }
     }
     catch (Exception exp)
     {
         var res = customFieldRep.TryConvertException(exp);
         if (res == null)
         {
             throw;
         }
         throw res;
     }
 }
        private string LocalizeFieldType(CustomFieldType fieldType)
        {
            switch (fieldType)
            {
            case CustomFieldType.Text:
                return(GetLocalResourceObject("TextType.Text").ToString());

            case CustomFieldType.DropDownList:
                return(GetLocalResourceObject("DropDownListType.Text").ToString());

            case CustomFieldType.Date:
                return(GetLocalResourceObject("DateType.Text").ToString());

            case CustomFieldType.RichText:
                return(GetLocalResourceObject("RichTextType.Text").ToString());

            case CustomFieldType.YesNo:
                return(GetLocalResourceObject("YesNoType.Text").ToString());

            case CustomFieldType.UserList:
                return(GetLocalResourceObject("UserListType.Text").ToString());
            }
            return("Unknown");
        }
        public void SetTypeWithDefaults(CustomFieldType type)
        {
            this.SetType(type);

            switch (type)
            {
                case CustomFieldType.RadioButton:
                    this.AddPredefinedMultiChoiceItem(CFPredefinedMultiChoiceItemManager.PredefinedItemType.YesOrNo);
                    break;

                case CustomFieldType.Dropdown:
                    this.AddPredefinedMultiChoiceItem(CFPredefinedMultiChoiceItemManager.PredefinedItemType.Agreement);
                    break;

                case CustomFieldType.Number:
                    this.SetOneLineLength(DefaultOneLineNumericLength);
                    break;

                case CustomFieldType.OneLineText:
                    this.SetOneLineLength(DefaultOneLineTextLength);
                    break;

                case CustomFieldType.Paragraph:
                    this.SetParagraphCharacterLimit(DefaultParagraphCharacterLimit);
                    break;

                default:
                    break;
            }
        }
 private string LocalizeFieldType(CustomFieldType fieldType)
 {
     switch (fieldType)
     {
         case CustomFieldType.Text:
             return GetLocalResourceObject("TextType.Text").ToString();
         case CustomFieldType.DropDownList:
             return GetLocalResourceObject("DropDownListType.Text").ToString();
         case CustomFieldType.Date:
             return GetLocalResourceObject("DateType.Text").ToString();
         case CustomFieldType.RichText:
             return GetLocalResourceObject("RichTextType.Text").ToString();
         case CustomFieldType.YesNo:
             return GetLocalResourceObject("YesNoType.Text").ToString();
         case CustomFieldType.UserList:
             return GetLocalResourceObject("UserListType.Text").ToString();
     }
     return "Unknown";
 }
Ejemplo n.º 37
0
        public int CreateField(EntityType entityType, String label, CustomFieldType customFieldType, String mask)
        {
            if (!_supportedEntityType.Contains(entityType) || String.IsNullOrEmpty(label))
                throw new ArgumentException();
            var resultMask = GetValidMask(customFieldType, mask);

            using (var db = GetDb())
            {
                var sortOrder = db.ExecuteScalar<int>(Query("crm_field_description").SelectMax("sort_order")) + 1;

                return db.ExecuteScalar<int>(
                                                  Insert("crm_field_description")
                                                  .InColumnValue("id", 0)
                                                  .InColumnValue("label", label)
                                                  .InColumnValue("type", (int)customFieldType)
                                                  .InColumnValue("mask", resultMask)
                                                  .InColumnValue("sort_order", sortOrder)
                                                  .InColumnValue("entity_type", (int)entityType)
                                                  .Identity(1, 0, true));
            }
        }
Ejemplo n.º 38
0
        private string GetValidMask(CustomFieldType customFieldType, String mask)
        {
            var resultMask = new Newtonsoft.Json.Linq.JObject();
            if (String.IsNullOrEmpty(mask) ||
                (customFieldType != CustomFieldType.TextField && customFieldType != CustomFieldType.TextArea && customFieldType != CustomFieldType.SelectBox))
            {
                return String.Empty;
            }

            try
            {
                var maskObj = Newtonsoft.Json.Linq.JToken.Parse(mask);
                if (customFieldType == CustomFieldType.TextField)
                {
                    var size = maskObj.Value<int>("size");
                    if (size == 0)
                    {
                        resultMask.Add("size", 1);
                    }
                    else if (size > Global.MaxCustomFieldSize)
                    {
                        resultMask.Add("size", Global.MaxCustomFieldSize);
                    }
                    else
                    {
                        resultMask.Add("size", size);
                    }
                }
                if (customFieldType == CustomFieldType.TextArea)
                {
                    var rows = maskObj.Value<int>("rows");
                    var cols = maskObj.Value<int>("cols");

                    if (rows == 0)
                    {
                        resultMask.Add("rows", 1);
                    }
                    else if (rows > Global.MaxCustomFieldRows)
                    {
                        resultMask.Add("rows", Global.MaxCustomFieldRows);
                    }
                    else
                    {
                        resultMask.Add("rows", rows);
                    }

                    if (cols == 0)
                    {
                        resultMask.Add("cols", 1);
                    }
                    else if (cols > Global.MaxCustomFieldCols)
                    {
                        resultMask.Add("cols", Global.MaxCustomFieldCols);
                    }
                    else
                    {
                        resultMask.Add("cols", cols);
                    }
                }
                if (customFieldType == CustomFieldType.SelectBox)
                {
                    if (maskObj is Newtonsoft.Json.Linq.JArray)
                    {
                        return mask;
                    }
                    else
                    {
                        throw new ArgumentException("Mask is not valid");
                    }
                }
            }
            catch (Exception ex)
            {
                if (customFieldType == CustomFieldType.TextField)
                {
                    resultMask.Add("size", Global.DefaultCustomFieldSize);
                }
                if (customFieldType == CustomFieldType.TextArea)
                {
                    resultMask.Add("rows", Global.DefaultCustomFieldRows);
                    resultMask.Add("cols", Global.DefaultCustomFieldCols);
                }
                if (customFieldType == CustomFieldType.SelectBox)
                {
                    throw ex;
                }
            }
            return JsonConvert.SerializeObject(resultMask);
        }
Ejemplo n.º 39
0
        public int GetFieldId(EntityType entityType, String label, CustomFieldType customFieldType)
        {
            using (var db = GetDb())
            {
                var result = db.ExecuteList(GetFieldDescriptionSqlQuery(
                    Exp.Eq("type", (int)customFieldType)
                    & BuildEntityTypeConditions(entityType, "entity_type")
                    & Exp.Eq("label", label))).ConvertAll(row => ToCustomField(row));

                if (result.Count == 0) return 0;
                else return result[0].ID;
            }
        }
Ejemplo n.º 40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:CustomField"/> class.
 /// </summary>
 /// <param name="projectId">The project id.</param>
 /// <param name="name">The name.</param>
 /// <param name="dataType">Type of the data.</param>
 /// <param name="required">if set to <c>true</c> [required].</param>
 /// <param name="fieldType">Type of the field.</param>
 public CustomField(int projectId, string name, ValidationDataType dataType, bool required,CustomFieldType fieldType)
     : this(Globals.NewId , projectId, name, dataType, required, String.Empty,fieldType)
 {
 }
Ejemplo n.º 41
0
        public static string[] GetValueFromMultiChoice(object oValue, CustomFieldType type)
        {
            Repository.Utility.WriteLog("GetValueFromMultiChoice started", System.Diagnostics.EventLogEntryType.Information);
            StringCollection value = new StringCollection();

            if (oValue != null)
            {
                string[] fieldValue = oValue.ToString().Split(",".ToCharArray());
                for (int i = 0; i < fieldValue.Length; i++)
                {
                    foreach (string fieldval in fieldValue[i].Split(",".ToCharArray()))
                    {
                        if (fieldval.StartsWith(type.GetString()))
                        {
                            if (!string.IsNullOrEmpty(fieldval))
                            {
                                value.Add(fieldval);
                            }
                        }
                    }
                }
            }

            if (value.Count == 0)
            {
                return new string[0];
            }
            string[] array = new string[value.Count];
            value.CopyTo(array, 0);
            Repository.Utility.WriteLog("GetValueFromMultiChoice completed successfully", System.Diagnostics.EventLogEntryType.Information);
            return array;
        }
 public void SetType(CustomFieldType type)
 {
     this.SelectType(StringEnum.GetStringValue(type));
 }