private void dtGridCurrentStatusGoals_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (e.ColumnIndex == 3) { double excessFund = 0; if (e.RowIndex > 0 && double.Parse(dtGridCurrentStatusGoals.Rows[e.RowIndex - 1].Cells[4].Value.ToString()) > 0) { excessFund = double.Parse(dtGridCurrentStatusGoals.Rows[e.RowIndex - 1].Cells[4].Value.ToString()) - (double.Parse(dtGridCurrentStatusGoals.Rows[e.RowIndex].Cells[2].Value.ToString()) + double.Parse(dtGridCurrentStatusGoals.Rows[e.RowIndex].Cells[3].Value.ToString())); if (excessFund > 0) { if (dtGridCurrentStatusGoals.Rows[e.RowIndex].Cells[0].Value.ToString() != "0") { Goals goal = _goals.First(i => i.Id == int.Parse(dtGridCurrentStatusGoals.Rows[e.RowIndex].Cells[0].Value.ToString())); var drs = _dtPlan.Select("ID = " + _planeId); Planner planner = convertToPlanner(drs[0]); RiskProfileInfo _riskProfileInfo = new RiskProfileInfo(); dtGridCurrentStatusGoals.Rows[e.RowIndex].Cells[4].Value = excessFund; if (_goalCalculationInfo == null) { _goalCalculationInfo = new GoalsCalculationInfo(goal, planner, _riskProfileInfo, _riskProfileId, int.Parse(cmbPlanOption.Tag.ToString())); _goalCalculationInfo.GoalCalManager = cashFlowService.GoalCalculationMgr; } _goalCalculationInfo.SetGoalProfilevalue(double.Parse(dtGridCurrentStatusGoals.Rows[e.RowIndex].Cells[3].Value.ToString())); for (int i = e.RowIndex + 1; i <= dtGridCurrentStatusGoals.Rows.Count; i++) { excessFund = double.Parse(dtGridCurrentStatusGoals.Rows[i - 1].Cells[4].Value.ToString()) - (double.Parse(dtGridCurrentStatusGoals.Rows[i].Cells[2].Value.ToString()) + (string.IsNullOrEmpty(dtGridCurrentStatusGoals.Rows[i].Cells[3].Value.ToString()) ? 0 : double.Parse(dtGridCurrentStatusGoals.Rows[i].Cells[3].Value.ToString()))); dtGridCurrentStatusGoals.Rows[i].Cells[4].Value = excessFund; if (excessFund < 0) { MessageBox.Show("Fund allocation should not be allowed more then excess fund.", "Fund Allocation", MessageBoxButtons.OK, MessageBoxIcon.Stop); dtGridCurrentStatusGoals.Rows[i].Cells[3].Value = 0; } } } } else { MessageBox.Show("Fund allocation should not be allowed more then excess fund.", "Fund Allocation", MessageBoxButtons.OK, MessageBoxIcon.Stop); dtGridCurrentStatusGoals.Rows[e.RowIndex].Cells[3].Value = 0; } } } } catch (Exception ex) { } }
private void cmbGoals_SelectedIndexChanged(object sender, EventArgs e) { setGoalId(); if (cmbGoals.Tag == "0") { dtGridGoalValue.DataSource = null; dtGridGoalCal.DataSource = null; } else { Goals goal = _goals.First(i => i.Id == int.Parse(cmbGoals.Tag.ToString())); var drs = _dtPlan.Select("ID = " + _planeId); Planner planner = convertToPlanner(drs[0]); RiskProfileInfo _riskProfileInfo = new RiskProfileInfo(); //decimal growthPercentage = _riskProfileInfo.GetRiskProfileReturnRatio(_riskProfileId, int.Parse(goal.StartYear) - planner.StartDate.Year); if (_goalCalculationInfo == null) { _goalCalculationInfo = new GoalsCalculationInfo(goal, planner, _riskProfileInfo, _riskProfileId, int.Parse(cmbPlanOption.Tag.ToString())); _goalCalculationInfo.GoalCalManager = cashFlowService.GoalCalculationMgr; } // _goalCalculationInfo.SetInvestmentInGoal(_investmentToGoal); _dtGoalValue = _goalCalculationInfo.GetGoalValue(int.Parse(cmbGoals.Tag.ToString()), _planeId, int.Parse(lblRiskProfileVal.Tag.ToString())); if (_dtGoalValue != null && _dtGoalValue.Rows.Count > 0) { lblGoalPeriodValue.Text = _dtGoalValue.Rows[0]["GoalYear"].ToString(); txtPorfolioValue.Text = _goalCalculationInfo.GetProfileValue().ToString(); setGoalValueGrid(); _dtGoalCal = _goalCalculationInfo.GetGoalCalculation(); dtGridGoalCal.DataSource = _dtGoalCal; setGoalCalGrid(); int goalComplitionPercentage = getGoalComplitionPercentage(); progGoalComplition.Value = (goalComplitionPercentage > 100) ? 100 : goalComplitionPercentage; lblGoalComplition.Text = progGoalComplition.Value.ToString() + "%"; } } }