예제 #1
0
 public void UpdateCollectionField(CustomizableField field)
 {
     _customizableFieldsManager.DeleteCollection(field.Id);
     foreach (string value in field.Collection)
     {
         if (value.Trim().Length > 0)
         {
             _customizableFieldsManager.AddCollectionItem(field.Id, value);
         }
     }
 }
예제 #2
0
 public void DeleteField(CustomizableField field)
 {
     _customizableFieldsManager.DeleteField(field);
 }
예제 #3
0
        private void buttonAddProperty_Click(object sender, EventArgs e)
        {
            try
            {
                if (_myFields.Contains(textBoxFieldName.Text) || _myFields.Contains(textBoxFieldName.Text + "*"))
                {
                    MessageBox.Show(GetString("textUniqueField"));

                }

                string fieldName = textBoxFieldName.Text;
                if (checkBoxNewMandatory.Checked) fieldName += "*";

                CustomProperty myField;
                List<string> list = new List<string>();
                var type = (OCustomizableFieldTypes)Enum.Parse(typeof(OCustomizableFieldTypes), GetString(comboBoxFieldTypes.Text), true);

                if (type == OCustomizableFieldTypes.Collection)
                {
                    if (listBox.Items.Count < 1)
                    {
                        MessageBox.Show(GetString("textAddOneItem"));
                        return;
                    }

                    foreach (string item in listBox.Items) list.Add(item);
                    {
                        myField = new CustomProperty(fieldName, textBoxFieldDesc.Text, list, typeof(CustomCollection), true,
                                                     true);
                    }
                }
                else
                {
                    myField = new CustomProperty(fieldName, textBoxFieldDesc.Text, GetString("type" + type),
                                                 typeof(string), true, true);
                }

                _myFields.Add(myField);
                fieldGrid.Refresh();

                CustomizableField field = new CustomizableField
                {
                    Name = fieldName,
                    Description = textBoxFieldDesc.Text,
                    Entity =
                        (OCustomizableFieldEntities)
                        Enum.Parse(typeof(OCustomizableFieldEntities),
                                   GetString(comboBoxEntities.Text), true),
                    IsMandatory = checkBoxNewMandatory.Checked,
                    IsUnique = checkBoxNewUnique.Checked
                };

                if (type == OCustomizableFieldTypes.Collection)
                {
                    field.Type = OCustomizableFieldTypes.Collection;
                    field.Collection = list;
                }
                else
                {
                    field.Type = (OCustomizableFieldTypes)Enum.Parse(typeof(OCustomizableFieldTypes), GetString(comboBoxFieldTypes.Text), true);
                }

                if (_isAddMode)
                    _fieldList.Add(field);
                else
                    _editFieldList.Add(field);

                textBoxFieldName.Text = string.Empty;
                textBoxFieldDesc.Text = string.Empty;
                listBox.Items.Clear();
            }
            catch (Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }
        }
예제 #4
0
        private CustomizableField SelectCustomizableFieldById(int fieldId)
        {
            string sqlPropertyText = @"SELECT
                                        [id]
                                        ,[entity_id]
                                        ,[type_id]
                                        ,[name]
                                        ,[desc]
                                        ,[is_mandatory]
                                        ,[is_unique]
                                      FROM [AdvancedFields]
                                      WHERE id = @id";

            CustomizableField field;
            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand selectCmd = new OpenCbsCommand(sqlPropertyText, conn))
            {
                selectCmd.AddParam("@id", fieldId);

                using (OpenCbsReader reader = selectCmd.ExecuteReader())
                {
                    if (reader == null || reader.Empty) return null;
                    reader.Read();

                    field = new CustomizableField
                                {
                                    Id = reader.GetInt("id"),
                                    Entity =
                                        (OCustomizableFieldEntities)
                                        Enum.ToObject(typeof (OCustomizableFieldEntities),
                                                      reader.GetInt("entity_id")),
                                    Type =
                                        (OCustomizableFieldTypes)
                                        Enum.ToObject(typeof (OCustomizableFieldTypes),
                                                      reader.GetInt("type_id")),
                                    Name = reader.GetString("name"),
                                    Description = reader.GetString("desc"),
                                    IsMandatory = reader.GetBool("is_mandatory"),
                                    IsUnique = reader.GetBool("is_unique")
                                };
                }
            }

            if (field.Type == OCustomizableFieldTypes.Collection)
                {
                    List<string> fieldList = new List<string>();
                    const string sqlListText = @"SELECT [value]
                                                 FROM AdvancedFieldsCollections
                                                 WHERE field_id = @field_id";
                    using (SqlConnection conn2 = GetConnection())
                    using (OpenCbsCommand selectList = new OpenCbsCommand(sqlListText, conn2))
                    {
                        selectList.AddParam("@field_id", field.Id);
                        using (OpenCbsReader listReader = selectList.ExecuteReader())
                        {
                            if (listReader == null || listReader.Empty) return null;

                            while (listReader.Read())
                            {
                                fieldList.Add(listReader.GetString("value"));
                            }

                            field.Collection = fieldList;
                        }
                    }
                }

            return field;
        }
예제 #5
0
        private void AddCustomizableField(CustomizableField field)
        {
            string sqlText = @"INSERT INTO [AdvancedFields]
                                ([entity_id]
                                , [type_id]
                                , [name]
                                , [desc]
                                , [is_mandatory]
                                , [is_unique])
                               VALUES
                                (@entity_id
                                , @type_id
                                , @f_name
                                , @f_desc
                                , @is_mandatory
                                , @is_unique)
                               SELECT CONVERT(int, SCOPE_IDENTITY())";
            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand insertCmd = new OpenCbsCommand(sqlText, conn))
            {
                insertCmd.AddParam("@entity_id", (int)field.Entity);
                insertCmd.AddParam("@type_id", (int)field.Type);
                insertCmd.AddParam("@f_name", field.Name);
                insertCmd.AddParam("@f_desc", field.Description);
                insertCmd.AddParam("@is_mandatory", field.IsMandatory);
                insertCmd.AddParam("@is_unique", field.IsUnique);

                field.Id = int.Parse(insertCmd.ExecuteScalar().ToString());

                if (field.Type == OCustomizableFieldTypes.Collection)
                {
                    foreach (string colItem in field.Collection)
                    {
                        if (colItem.Trim().Length > 0)
                        {
                            AddCollectionItem(field.Id, colItem);
                        }
                    }
                }
            }
        }
예제 #6
0
        public void DeleteField(CustomizableField field)
        {
            if (field.Type == OCustomizableFieldTypes.Collection)
            {
                string sqlColText = @"DELETE FROM dbo.AdvancedFieldsCollections
                                      WHERE field_id = @field_id";
                using (SqlConnection conn = GetConnection())
                using (OpenCbsCommand deleteCmd = new OpenCbsCommand(sqlColText, conn))
                {
                    deleteCmd.AddParam("@field_id", field.Id);
                    deleteCmd.ExecuteNonQuery();
                }
            }

            string sqlText = @"DELETE FROM dbo.AdvancedFields
                               WHERE id = @field_id";
            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand deleteCmd = new OpenCbsCommand(sqlText, conn))
            {
                deleteCmd.AddParam("@field_id", field.Id);
                deleteCmd.ExecuteNonQuery();
            }
        }