Esempio n. 1
0
 private static ClientDataSet.EntityFieldsValuesDataTable GetEntityFieldValues(Guid organizationId, Guid entityFieldId, string localEntityId)
 {
     using (EntityFieldsValuesTableAdapter adapter = new EntityFieldsValuesTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
     {
         return(adapter.GetEntityFieldValues(entityFieldId, localEntityId));
     }
 }
Esempio n. 2
0
        internal static void SaveEntityCustomFields(Entity entity, Guid organizationId, string localEntityId)
        {
            if (localEntityId == null)
            {
                return;
            }

            ClientDataSet.EntityFieldsValuesDataTable table = GetEntityFieldsValues(organizationId, entity.Id, localEntityId);
            foreach (EntityField field in entity.CustomFields)
            {
                DataRow[] rows = table.Select(string.Format(CultureInfo.InvariantCulture, "{0} = '{1}' AND {2} = '{3}'"
                                                            , table.EntityFieldIdColumn.ColumnName, field.Id, table.LocalEntityIdColumn.ColumnName, Support.PreserveSingleQuote(localEntityId)));

                List <object> values = new List <object>(field.SelectedValues);
                if (field.AllowDBNull && (values.Count == 0))
                {
                    values.Add(null);
                }

                foreach (ClientDataSet.EntityFieldsValuesRow row in rows)
                {
                    object obj = null;
                    if (!row.IsValueNull())
                    {
                        obj = Support.ConvertStringToType(row.Value, field.DataType);
                    }
                    if (field.SelectedValues.Contains(obj))
                    {
                        values.Remove(obj);
                    }
                    else
                    {
                        row.Delete();
                    }
                }

                foreach (object obj in values)
                {
                    ClientDataSet.EntityFieldsValuesRow row = table.NewEntityFieldsValuesRow();
                    row.EntityFieldValueId = Guid.NewGuid();
                    row.EntityFieldId      = field.Id;
                    row.LocalEntityId      = localEntityId;
                    if (!Support.IsNullOrDBNull(obj))
                    {
                        row.Value = Convert.ToString(obj, CultureInfo.CurrentCulture);
                    }
                    table.AddEntityFieldsValuesRow(row);
                }
            }

            using (EntityFieldsValuesTableAdapter adapter = new EntityFieldsValuesTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
            {
                adapter.Update(table);
            }

            RemoveFromCache();
        }
Esempio n. 3
0
        internal static void SaveEntityCustomField(EntityField field, Guid organizationId, string localEntityId)
        {
            if (localEntityId == null)
            {
                return;
            }

            ClientDataSet.EntityFieldsValuesDataTable table = GetEntityFieldValues(organizationId, field.Id, localEntityId);

            List <object> values = new List <object>(field.SelectedValues);

            if (field.AllowDBNull && (values.Count == 0))
            {
                values.Add(null);
            }

            foreach (ClientDataSet.EntityFieldsValuesRow row in table)
            {
                object obj = null;
                if (!row.IsValueNull())
                {
                    obj = Support.ConvertStringToType(row.Value, field.DataType);
                }
                if (field.SelectedValues.Contains(obj))
                {
                    values.Remove(obj);
                }
                else
                {
                    row.Delete();
                }
            }

            foreach (object obj in values)
            {
                ClientDataSet.EntityFieldsValuesRow row = table.NewEntityFieldsValuesRow();
                row.EntityFieldValueId = Guid.NewGuid();
                row.EntityFieldId      = field.Id;
                row.LocalEntityId      = localEntityId;
                if (!Support.IsNullOrDBNull(obj))
                {
                    row.Value = Convert.ToString(obj, CultureInfo.CurrentCulture);
                }
                table.AddEntityFieldsValuesRow(row);
            }

            using (EntityFieldsValuesTableAdapter adapter = new EntityFieldsValuesTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
            {
                adapter.Update(table);
            }

            RemoveFromCache();
        }