public FrmAvalaibleCollateralProducts()
 {
     InitializeComponent();
     product = new CollateralProduct();
     InitializePackages();
     webBrowserPackage.ObjectForScripting = this;
 }
        /// <summary>
        /// Method to add a package into 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="colProduct">Package Object</param>
        /// <returns>The id of the package which has been added</returns>
        public int AddCollateralProduct(CollateralProduct colProduct)
        {
            string sqlText = @"INSERT INTO [CollateralProducts]
                                (
                                    [name]
                                    ,[desc]
                                    ,[deleted]
                                )
                                VALUES
                                (
                                    @name
                                    ,@desc
                                    ,@deleted
                                 )
                                 SELECT CONVERT(int, SCOPE_IDENTITY())";

            using (SqlConnection connection = GetConnection())
            using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, connection))
            {
                cmd.AddParam("@name", colProduct.Name);
                cmd.AddParam("@desc", colProduct.Description);
                cmd.AddParam("@deleted", colProduct.Delete);
                colProduct.Id = int.Parse(cmd.ExecuteScalar().ToString());
            }

            foreach (CollateralProperty collateralProperty in colProduct.Properties)
                AddCollateralProperty(colProduct.Id, collateralProperty);

            return colProduct.Id;
        }
 public FrmAvalaibleCollateralProducts()
 {
     InitializeComponent();
     product = new CollateralProduct();
     refreshListView();
     _package = new CollateralProduct();
     _selectedPackage = new CollateralProduct();
 }
        public void Package_Click(object sender, HtmlElementEventArgs e)
        {
            var tag = (HtmlElement)(sender);
            PackageFormId = Convert.ToInt32(tag.Id);
            product = ServicesProvider.GetInstance().GetCollateralProductServices().SelectCollateralProduct(PackageFormId);

            buttonDeletePackage.Enabled = true;
            buttonEditProduct.Enabled = true;
        }
        public FrmAddCollateralProduct()
        {
            InitializeComponent();

            propertyGrid.SelectedObject = myProperties;

            collateralProduct = new CollateralProduct();

            InitializeMenuPropertyTypes();
            SetAddNewProductMode(true);
        }
        public FrmAddCollateralProduct(CollateralProduct collateralProduct)
        {
            InitializeComponent();
            this.collateralProduct = collateralProduct;

            propertyGrid.SelectedObject = myProperties;

            InitializeMenuPropertyTypes();
            InitializeProductValues();
            SetAddNewProductMode(false);
        }
        public CollateralProduct SelectCollateralProductByPropertyId(int propertyId)
        {
            int productId;
            const string sqlProductIdText = @"SELECT product_id
                                             FROM [CollateralProperties]
                                             WHERE id = @id ";

               using (SqlConnection connection = GetConnection())
               using (OpenCbsCommand cmd = new OpenCbsCommand(sqlProductIdText, connection))
            {
                cmd.AddParam("@id", propertyId);
                using (OpenCbsReader reader = cmd.ExecuteReader())
                {
                    if (reader.Empty) return null; // nothing is coming... (c)
                    reader.Read();
                    productId = reader.GetInt("product_id");
                }
            }

            const string sqlText = @"SELECT
                                     [name]
                                    ,[desc]
                                    ,[deleted]
                                    FROM CollateralProducts
                                    WHERE id = @id";

            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand selectProduct = new OpenCbsCommand(sqlText, conn))
            {
                selectProduct.AddParam("@id", productId);
                using (OpenCbsReader reader = selectProduct.ExecuteReader())
                {
                    if (reader.Empty) return null;
                    reader.Read();

                    CollateralProduct colProduct = new CollateralProduct
                        {
                            Id = productId,
                            Name = reader.GetString("name"),
                            Description = reader.GetString("desc"),
                            Delete = reader.GetBool("deleted")
                        };

                    return colProduct;
                }
            }
        }
        /// <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;
        }
        /// <summary>
        /// Select all packages in database
        /// </summary>
        /// <param name="pShowAlsoDeleted"></param>
        /// <returns>a list contains all packages</returns>
        public List<CollateralProduct> SelectAllCollateralProducts(bool pShowAlsoDeleted)
        {
            List<CollateralProduct> packagesList = new List<CollateralProduct>();
            string sqlText = @"SELECT id
                               FROM CollateralProducts
                               WHERE 1 = 1";

            if (!pShowAlsoDeleted)
                sqlText += " AND deleted = 0";

            using (SqlConnection connection = GetConnection())
            using (OpenCbsCommand selectPackages = new OpenCbsCommand(sqlText, connection))
            {
                using (OpenCbsReader reader = selectPackages.ExecuteReader())
                {
                    if (reader.Empty) return new List<CollateralProduct>();
                    while (reader.Read())
                    {
                        CollateralProduct pack = new CollateralProduct { Id = reader.GetInt("id") };
                        packagesList.Add(pack);
                    }
                }
            }
            for (int i = 0; i < packagesList.Count; i++)
            {
                packagesList[i] = SelectCollateralProduct(packagesList[i].Id);
            }
            return packagesList;
        }
 private CollateralProduct retrieveSelectedPackage()
 {
     _package = (CollateralProduct)descriptionListView.SelectedItems[0].Tag;
     _selectedPackage = ServicesProvider.GetInstance().GetCollateralProductServices().SelectCollateralProduct(_package.Id);
     return _selectedPackage;
 }
        public ContractCollateralForm(CollateralProduct product, IExtensionActivator extensionActivator)
        {
            _extensionActivator = extensionActivator;
            this.product = product;
            contractCollateral = new ContractCollateral();
            myProperties = new CustomClass();
            collections = new CollectionList();

            InitializeComponent();
            FillCollateralProperties();
        }
 private void DeletePackage()
 {
     try
     {
         ServicesProvider.GetInstance().GetCollateralProductServices().DeleteCollateralProduct(retrieveSelectedPackage().Id);
         refreshListView();
         product = null;
         buttonDeletePackage.Enabled = false;
         buttonEditProduct.Enabled = false;
     }
     catch (Exception ex)
     {
         new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
     }
 }
        private static string _CreateHtmlForShowingPackage(CollateralProduct collateralProduct)
        {
            string img = "package.png";
            if (collateralProduct.Delete) img = "package_delete.png";

            string text = string.Format(@"
                            <form id='{1}' name='package{1}'>
                            <table id={1} cellpadding='0' cellspacing='0' border='0' class='list_content' onclick='click_book(this,{1});' onmouseenter='mouse_enter_book(this);' onmouseleave='mouse_leave_book(this);'>
                            <tr>
                                <td>
                                    <table class='book_list' cellpadding='0' cellspacing='0' border='0'>
                                    <tr>
                                        <td>
                                            <table cellpadding='0' cellspacing='0' border='0'>
                                                <tr>
                                                    <td><img id='{1}' src='{0}'/></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    </table>
                                </td>
                                <td style='width:100%'>
                                    <span >
                                        <span class='title_popup'>{2} ({3})</span>
                                    </span>
                                </td>
                            </tr>
                            </table></form>", Path.Combine(UserSettings.GetTemplatePath, img), collateralProduct.Id, collateralProduct.Name, collateralProduct.Description);

            return text;
        }
        public ContractCollateralForm(CollateralProduct product, ContractCollateral contractCollateral, bool isView)
        {
            this.product = product;
            this.contractCollateral = contractCollateral;
            myProperties = new CustomClass();
            collections = new CollectionList();

            InitializeComponent();
            FillCollateralPropertyValues(contractCollateral);

            if(isView)
            {
                propertyGrid.Enabled = false;
                groupBoxOwnerDetails.Enabled = false;
                buttonSave.Enabled = false;
            }
        }
        public ContractCollateralForm(CollateralProduct product)
        {
            this.product = product;
            contractCollateral = new ContractCollateral();
            myProperties = new CustomClass();
            collections = new CollectionList();

            InitializeComponent();
            FillCollateralProperties();
        }
 private void determineRowColor(CollateralProduct cP, ListViewItem lvi)
 {
     if (cP.Delete == true)
         lvi.BackColor = System.Drawing.Color.LightGray;
     else
         lvi.BackColor = System.Drawing.Color.White;
 }
 public void AddCollateralProduct(CollateralProduct collateralProduct)
 {
     var productName = collateralProduct.Name;
     CheckCollateralProductNameExistance(productName);
     collateralProductManager.AddCollateralProduct(collateralProduct);
 }