public static List<Portfolio> read() { if (!File.Exists(fileName)) createDefaultInitFile(); String[] lines = File.ReadAllLines(fileName); List<Portfolio> portfolios = new List<Portfolio>(); Portfolio portfolio = null; foreach (var line in lines) { if (String.IsNullOrEmpty(line)) continue; String[] attrs = line.Split(';'); int value; if (!Int32.TryParse(attrs[0], out value)) { portfolio = new Portfolio(attrs[0], attrs[1], Double.Parse(attrs[2].Replace('.', ',')), Int32.Parse(attrs[3])); portfolios.Add(portfolio); continue; } portfolio.add(new Machine(value, attrs[1], (Int32.Parse(attrs[2]) == 1))); } return portfolios; }
private AddPortfolioForm(Portfolio portfolio) { InitializeComponent(); this.portfolio = portfolio; sieveParamBox.Text = portfolio.sieveParam.ToString().Replace(",", "."); fillingGapsNumberBox.Text = portfolio.fillingGapsNumber.ToString(); securityBox.Text = portfolio.security; strategyComboBox.Items.AddRange(Enum.GetNames(typeof(Portfolio.Strategy))); strategyComboBox.SelectedItem = portfolio.strategy; }
public static List<MachineForm> build(Portfolio portfolio) { List<MachineForm> machinesForms = new List<MachineForm>(); int index = 0; Dictionary<Int32, List<Machine>> map = collect(portfolio); foreach (var depth in map.Keys) { List<Machine> machines; map.TryGetValue(depth, out machines); machinesForms.Add(MachineForm.createFrom(depth, index++, machines)); } return machinesForms; }
private static Dictionary<Int32, List<Machine>> collect(Portfolio portfolio) { Dictionary<Int32, List<Machine>> map = new Dictionary<int, List<Machine>>(); foreach (var machine in portfolio.machines) { if (!map.ContainsKey(machine.depth)) map.Add(machine.depth, new List<Machine>()); List<Machine> list; map.TryGetValue(machine.depth, out list); list.Add(machine); } return map; }
public static AddPortfolioForm edit(Portfolio portfolio) { return new AddPortfolioForm(portfolio); }