-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |