Skip to content

Commit

Permalink
Calculated Ratio is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
4o66 committed Feb 11, 2018
1 parent 0d09777 commit ae14315
Showing 1 changed file with 63 additions and 17 deletions.
80 changes: 63 additions & 17 deletions cpamvc/Models/CalculatedRatio.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,83 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;

namespace cpamvc.Models
{
public class CalculatedRatio
{
public string Name { get; set; }
public string Type { get; set; }
public int UserID { get; set; }
public List<RatioConstruct> Numerator {get; set;}
public List<RatioConstruct> Denominator {get; set;}
public Company Company { get; set; }
public Ratio Ratio { get; set; }
public decimal Value { get; set; }
public int Year { get; set; }

public Company Company {get; set;}
public CalculatedRatio(Ratio ratio, Company company, int year)
{
this.Ratio = ratio;
this.Company = company;
this.Year = year;

public long Value {get; set;}
SqlConnection sqlConn = new SqlConnection("Server=localhost;Database=cpa;Trusted_Connection=True;");

//public RatioLines<RatioLine> {get; set;}

try
{
sqlConn.Open();

public CalculatedRatio(Ratio ratio, Company company)
{
this.Numerator = ratio.Numerator;
this.Denominator = ratio.Denominator;
this.Company = company;
SqlDataReader myReader = null;
SqlCommand sqlCmd = new SqlCommand("exec getRatio", sqlConn);
sqlCmd.Parameters.AddWithValue("@companyID", this.Company.ID);
sqlCmd.Parameters.AddWithValue("@ratioID", this.Ratio.ID);
sqlCmd.Parameters.AddWithValue("@year", this.Year);
myReader = sqlCmd.ExecuteReader();
while (myReader.Read())
{
this.Value = Decimal.Parse(myReader["value"].ToString());
}

sqlConn.Close();
}
catch (Exception e) { Console.WriteLine(e.ToString()); }

//this.Value = calculated ratio
}

public static List<CalculatedRatio> GetCalculatedRatios(int ratioID, int companyID)
public static List<CalculatedRatio> GetCalculatedRatios(Ratio ratio, Company company)
{
//given ratioid, cID return calculated ratio for every year (4) )
return null;
//given ratio, company return calculated ratio for every year (4) )

//get the most recent years, up to 4

List<int> years = null;

SqlConnection sqlConn = new SqlConnection("Server=localhost;Database=cpa;Trusted_Connection=True;");

try
{
sqlConn.Open();

SqlDataReader myReader = null;
SqlCommand sqlCmd = new SqlCommand("select distinct top 4 year from statement where company_id = @companyID order by year desc", sqlConn);
sqlCmd.Parameters.AddWithValue("@companyID", company.ID);
myReader = sqlCmd.ExecuteReader();
while (myReader.Read())
{
years.Add(Int32.Parse(myReader["year"].ToString()));
}

sqlConn.Close();
}
catch (Exception e) { Console.WriteLine(e.ToString()); }

List<CalculatedRatio> ratios = null;

foreach (int year in years)
{
ratios.Add(new CalculatedRatio(ratio, company, year));
}

return ratios;
}
}
}

0 comments on commit ae14315

Please sign in to comment.