private List<ContractCollateral> GetCollaterals(int pLoanId) { List<int> collateralIds = new List<int>(); const string q = @"SELECT [id] FROM [CollateralsLinkContracts] WHERE contract_id = @contract_id "; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { c.AddParam("@contract_id", pLoanId); using (OpenCbsReader r = c.ExecuteReader()) { if (r == null || r.Empty) return new List<ContractCollateral>(); while (r.Read()) collateralIds.Add(r.GetInt("id")); } } List<ContractCollateral> contractCollaterals = new List<ContractCollateral>(); foreach (int collateralId in collateralIds) { ContractCollateral contractCollateral = new ContractCollateral(); List<CollateralPropertyValue> propertyValues = new List<CollateralPropertyValue>(); string sqlPropertyText = @"SELECT [contract_collateral_id], [property_id], [value] FROM [CollateralPropertyValues] WHERE contract_collateral_id = @contract_collateral_id "; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(sqlPropertyText, conn)) { c.AddParam("@contract_collateral_id", collateralId); using (OpenCbsReader r = c.ExecuteReader()) { if (r == null || r.Empty) return new List<ContractCollateral>(); while (r.Read()) { CollateralPropertyValue propertyValue = new CollateralPropertyValue { Id = collateralId, Property = new CollateralProperty { Id = r.GetInt("property_id") }, //Property. = _collateralProductManager.SelectCollateralProperty(r.GetInt("property_id")), Value = r.GetString("value") }; propertyValues.Add(propertyValue); } } } foreach (CollateralPropertyValue propertyValue in propertyValues) { propertyValue.Property = _collateralProductManager.SelectCollateralProperty(propertyValue.Property.Id); } contractCollateral.PropertyValues = propertyValues; contractCollaterals.Add(contractCollateral); } return contractCollaterals; }
public void AddCollateralPropertyValue(ContractCollateral contractCollateral, CollateralPropertyValue propertyValue, SqlTransaction pSqlTransac) { string q = @"INSERT INTO [CollateralPropertyValues] ([contract_collateral_id], [property_id], [value]) VALUES (@contract_collateral_id, @property_id, @value)"; using (OpenCbsCommand c = new OpenCbsCommand(q, pSqlTransac.Connection, pSqlTransac)) { c.AddParam("@contract_collateral_id", contractCollateral.Id); c.AddParam("@property_id", propertyValue.Property.Id); c.AddParam("@value", propertyValue.Value); c.ExecuteNonQuery(); } }
private void buttonSave_Click(object sender, EventArgs e) { string amountProperty = string.Empty; if (myProperties.GetPropertyValueByName("Montant") != null) amountProperty = "Montant"; if (myProperties.GetPropertyValueByName("Сумма") != null) amountProperty = "Сумма"; if (myProperties.GetPropertyValueByName("Amount") != null) amountProperty = "Amount"; if (decimal.Parse(myProperties.GetPropertyValueByName(amountProperty).ToString()) <= 0) { MessageBox.Show("Please, enter collateral amount!"); return; } List<CollateralPropertyValue> propertyValues = new List<CollateralPropertyValue>(); foreach(CollateralProperty collateralProperty in product.Properties) { CollateralPropertyValue contractCollateralProperty = new CollateralPropertyValue(); contractCollateralProperty.Property = collateralProperty; if (collateralProperty.Type == OCollateralPropertyTypes.Number) { var decimalValue = (decimal) myProperties.GetPropertyValueByName(collateralProperty.Name); contractCollateralProperty.Value = Converter.CustomFieldDecimalToString(decimalValue); } else if (collateralProperty.Type == OCollateralPropertyTypes.String) { //if ((string)myProperties.GetPropertyValueByName(collateralProperty.Name) == string.Empty) MessageBox.Show("String is empty!"); contractCollateralProperty.Value = (string) myProperties.GetPropertyValueByName(collateralProperty.Name); } else if (collateralProperty.Type == OCollateralPropertyTypes.Date) { DateTime dateValue = (DateTime) myProperties.GetPropertyValueByName(collateralProperty.Name); contractCollateralProperty.Value = Converter.CustomFieldDateToString(dateValue); } else if (collateralProperty.Type == OCollateralPropertyTypes.Collection) { //if ((string)myProperties.GetPropertyValueByName(collateralProperty.Name) == null) MessageBox.Show("collection is null!"); //int index = Collection.GetItemIndexByName((string)myProperties.GetPropertyValueByName(collateralProperty.Name)); //if (index != -1) contractCollateralProperty.Value = index.ToString(); int index = collections.GetItemIndexByName(collateralProperty.Name, (string)myProperties.GetPropertyValueByName(collateralProperty.Name)); if (index != -1) contractCollateralProperty.Value = index.ToString(); } else if (collateralProperty.Type == OCollateralPropertyTypes.Owner) { //if (myProperties.GetPropertyValueByName(collateralProperty.Name) == null) MessageBox.Show("Person is null!"); //MessageBox.Show(myProperties.GetPropertyValueByName(collateralProperty.Name).GetType().ToString()); if (myProperties.GetPropertyValueByName(collateralProperty.Name).GetType() == typeof(Person)) contractCollateralProperty.Value = ((Person)myProperties.GetPropertyValueByName(collateralProperty.Name)).Id.ToString(); } propertyValues.Add(contractCollateralProperty); } contractCollateral.PropertyValues = propertyValues; Close(); }