コード例 #1
0
        private void buttonAddProperty_Click(object sender, EventArgs e)
        {
            if (myProperties.Contains(textBoxPropertyName.Text))
            {
                MessageBox.Show("Property name must be unique!");
            }
            else
            {
                CustomProperty myProp = null;
                List<string> list = new List<string>();
                var type = (OCollateralPropertyTypes) Enum.Parse(typeof(OCollateralPropertyTypes), GetString(comboBoxPropertyTypes.Text), true);

                if (type == OCollateralPropertyTypes.Collection)
                {
                    if (listBox.Items.Count < 1)
                    {
                        MessageBox.Show("Please add at least one item to the collection!");
                        return;
                    }

                    foreach (string item in listBox.Items) list.Add(item);
                    myProp = new CustomProperty(textBoxPropertyName.Text, textBoxPropertyDesc.Text, list, typeof(List<string>), true, true);
                }
                else
                {
                    myProp = new CustomProperty(textBoxPropertyName.Text, textBoxPropertyDesc.Text, GetString("type"+type), typeof(string), true, true);
                }

                myProperties.Add(myProp);
                propertyGrid.Refresh();

                if (!isAddMode)
                {
                    CollateralProperty property = new CollateralProperty();
                    property.Name = textBoxPropertyName.Text;
                    property.Description = textBoxPropertyDesc.Text;

                    if (type == OCollateralPropertyTypes.Collection)
                    {
                        property.Type = OCollateralPropertyTypes.Collection;
                        property.Collection = list;
                    }
                    else
                    {
                        property.Type = (OCollateralPropertyTypes)Enum.Parse(typeof(OCollateralPropertyTypes), GetString(comboBoxPropertyTypes.Text), true);
                    }

                    editPropertyList.Add(property);
                }

                textBoxPropertyName.Text = string.Empty;
                textBoxPropertyDesc.Text = string.Empty;
                listBox.Items.Clear();
            }
        }
コード例 #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (textBoxProductName.Text.Length == 0)
            {
                MessageBox.Show("Please, enter collateral product name!");
                return;
            }
            if (textBoxProductDesc.Text.Length == 0)
            {
                MessageBox.Show("Please, enter collateral product description!");
                return;
            }
            if (myProperties.GetSize() == 0)
            {
                MessageBox.Show("Please, enter at least one property!");
                return;
            }
            try
            {
                if (isAddMode)
                {

                    collateralProduct.Name = textBoxProductName.Text;
                    collateralProduct.Description = textBoxProductDesc.Text;

                    List<CollateralProperty> propertiesList = new List<CollateralProperty>();

                    foreach (CustomProperty property in myProperties)
                    {
                        CollateralProperty collateralProperty = new CollateralProperty();
                        collateralProperty.Name = property.Name;
                        collateralProperty.Description = property.Description;

                        if (property.Value is List<string>)
                        {
                            collateralProperty.Type = OCollateralPropertyTypes.Collection;
                            collateralProperty.Collection = (List<string>)property.Value;
                        }
                        else
                        {
                            //collateralProperty.Type = (OCollateralPropertyTypes) Enum.Parse(typeof(OCollateralPropertyTypes), property.Value.ToString(), true);
                            collateralProperty.Type = (OCollateralPropertyTypes) Enum.Parse(typeof(OCollateralPropertyTypes),
                                GetString(property.Value.ToString()), true);
                        }

                        propertiesList.Add(collateralProperty);
                    }

                    collateralProduct.Properties = propertiesList;

                    ServicesProvider.GetInstance().GetCollateralProductServices().AddCollateralProduct(collateralProduct);
                }
                else
                {
                    ServicesProvider.GetInstance().GetCollateralProductServices().UpdateCollateralProduct(
                        collateralProduct.Id, collateralProduct.Name, textBoxProductName.Text, textBoxProductDesc.Text);

                    foreach (CollateralProperty property in editPropertyList)
                        ServicesProvider.GetInstance().GetCollateralProductServices().AddCollateralProperty(collateralProduct.Id, property);
                }

                Close();
            }
            catch (Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }
        }
コード例 #3
0
        public int AddCollateralProperty(int collateralProductId, CollateralProperty collateralProperty)
        {
            string sqlText = @"INSERT INTO [CollateralProperties]
                                        (
                                         [product_id]
                                        ,[type_id]
                                        ,[name]
                                        ,[desc]
                                        )

                               VALUES
                                        (
                                         @product_id
                                        ,@type_id
                                        ,@prop_name
                                        ,@prop_desc
                                        )
                             SELECT CONVERT(int, SCOPE_IDENTITY())";

            using (SqlConnection connection = GetConnection())
            using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, connection))
            {
                cmd.AddParam("@product_id", collateralProductId);
                cmd.AddParam("@prop_name", collateralProperty.Name);
                cmd.AddParam("@prop_desc", collateralProperty.Description);
                cmd.AddParam("@type_id", (int)Enum.Parse(typeof(OCollateralPropertyTypes), collateralProperty.Type.ToString()));
                collateralProperty.Id = int.Parse(cmd.ExecuteScalar().ToString());

                if (collateralProperty.Type == OCollateralPropertyTypes.Collection)
                    foreach (string colItem in collateralProperty.Collection)
                        AddCollateralPropertyCollectionItem(collateralProperty.Id, colItem);
            }

            return collateralProperty.Id;
        }
コード例 #4
0
        public CollateralProperty SelectCollateralProperty(int propertyId)
        {
            const string sqlPropertyText = @"SELECT
                                                  [type_id]
                                                , [name]
                                                , [desc]
                                             FROM CollateralProperties
                                             WHERE id = @id";

            CollateralProperty collateralProperty = new CollateralProperty();

            using (SqlConnection connection = GetConnection())
            using (OpenCbsCommand selectProperty = new OpenCbsCommand(sqlPropertyText, connection))
            {
                selectProperty.AddParam("@id", propertyId);
                using (OpenCbsReader propertyReader = selectProperty.ExecuteReader())
                {
                    if (propertyReader.Empty) return null; // nothing is coming! (c)
                    propertyReader.Read();

                    collateralProperty.Id = propertyId;
                    collateralProperty.Type = (OCollateralPropertyTypes)Enum.ToObject(typeof(OCollateralPropertyTypes),
                        propertyReader.GetInt("type_id"));
                    collateralProperty.Name = propertyReader.GetString("name");
                    collateralProperty.Description = propertyReader.GetString("desc");

                    if (collateralProperty.Type == OCollateralPropertyTypes.Collection)
                    {
                        List<string> propertyList = new List<string>();
                        const string sqlListText = @"SELECT [value]
                                                     FROM CollateralPropertyCollections
                                                     WHERE property_id = @property_id";

                        using (SqlConnection conn = GetConnection())
                        using (OpenCbsCommand selectList = new OpenCbsCommand(sqlListText, conn))
                        {
                            selectList.AddParam("@property_id", collateralProperty.Id);
                            using (OpenCbsReader listReader = selectList.ExecuteReader())
                            {
                                if (listReader.Empty) return null;

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

                                collateralProperty.Collection = propertyList;
                            }
                        }
                    }
                }
            }

            return collateralProperty;
        }
コード例 #5
0
        /// <summary>
        /// This method allows us to select a package from database.  We use the NullableTypes to make the correspondance between
        /// nullable int, decimal and double types in database and our own objects
        /// </summary>
        /// <param name="colProductId">id's of package searched</param>
        /// <returns>A package Object if id matches with datas in database, null if not</returns>
        public CollateralProduct SelectCollateralProduct(int colProductId)
        {
            const string sqlText = @"SELECT
                                             [name]
                                            ,[desc]
                                            ,[deleted]
                                    FROM CollateralProducts
                                    WHERE id = @id";

            CollateralProduct colProduct = new CollateralProduct();
            using (SqlConnection connection = GetConnection())
            using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, connection))
            {
                cmd.AddParam("@id", colProductId);
                using (OpenCbsReader reader = cmd.ExecuteReader())
                {
                    if (reader.Empty) return null;
                    reader.Read();
                    colProduct.Id = colProductId;
                    colProduct.Name = reader.GetString("name");
                    colProduct.Description = reader.GetString("desc");
                    colProduct.Delete = reader.GetBool("deleted");
                    reader.Dispose();
                }
            }

            List<CollateralProperty> properties = new List<CollateralProperty>();
                    const string sqlPropertyText = @"SELECT
                                                             id
                                                            ,type_id
                                                            ,[name]
                                                            ,[desc]
                                                     FROM CollateralProperties
                                                     WHERE product_id = @product_id";

            using (SqlConnection connection = GetConnection())
            using (OpenCbsCommand cmd = new OpenCbsCommand(sqlPropertyText, connection))
            {
                cmd.AddParam("@product_id", colProduct.Id);
                using (OpenCbsReader reader = cmd.ExecuteReader())
                {
                    if (reader.Empty) return null;

                    while (reader.Read())
                    {
                        CollateralProperty collateralProperty = new CollateralProperty();
                        collateralProperty.Id = reader.GetInt("id");
                        collateralProperty.Type = (OCollateralPropertyTypes)Enum.ToObject(typeof(OCollateralPropertyTypes),
                            reader.GetInt("type_id"));
                        collateralProperty.Name = reader.GetString("name");
                        collateralProperty.Description = reader.GetString("desc");

                        if (collateralProperty.Type == OCollateralPropertyTypes.Collection)
                        {
                            List<string> propertyList = new List<string>();
                            const string sqlListText = @"SELECT [value]
                                                         FROM CollateralPropertyCollections
                                                         WHERE property_id = @property_id";
                            using (SqlConnection conn = GetConnection())
                            using (OpenCbsCommand selectList = new OpenCbsCommand(sqlListText, conn))
                            {
                                selectList.AddParam("@property_id", collateralProperty.Id);
                                using (OpenCbsReader listReader = selectList.ExecuteReader())
                                {
                                    if (listReader.Empty) return null;

                                    while (listReader.Read())
                                    {
                                        propertyList.Add(listReader.GetString("value"));
                                    }
                                    collateralProperty.Collection = propertyList;
                                }
                            }
                        }
                        properties.Add(collateralProperty);
                    }
                    colProduct.Properties = properties;
                }
            }

            return colProduct;
        }
コード例 #6
0
 public void AddCollateralProperty(int collateralProductId, CollateralProperty collateralProperty)
 {
     collateralProductManager.AddCollateralProperty(collateralProductId, collateralProperty);
 }