Example #1
0
        public static Fund CreateFromLine(string line)
        {
            Fund res; int temp_i; DateTime temp_d; float temp_f;

            char[]   splitters = new char[] { ',' };
            string[] parts     = line.Split(splitters, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length > 0 && int.TryParse(parts[0], out temp_i))
            {
                res = new Fund {
                    Id = temp_i
                }
            }
            ;
            else
            {
                return(null);
            }

            if (parts.Length > 1 && !parts[1].StartsWith(CommonGroupName))
            {
                res.GroupName = parts[1];
            }
            else
            {
                res.GroupName = CommonGroupName;
            }

            if (parts.Length > 2 && DateTime.TryParseExact(parts[2], NeDateFormat, null, DateTimeStyles.None, out temp_d))
            {
                res.BuyDate = temp_d;
            }

            if (parts.Length > 3 && int.TryParse(parts[3], out temp_i))
            {
                res.BuyCount = temp_i;
            }

            if (parts.Length > 4 && float.TryParse(parts[4], NumberStyles.Any, CultureInfo.InvariantCulture, out temp_f))
            {
                res.BuyCash = temp_f;
            }

            return(res);
        }
Example #2
0
        // public Fund Clone(string groupName)
        // {
        //     return new Fund
        //     {
        //         Id = this.Id,
        //         GroupName = groupName ?? this.GroupName,
        //         BuyDate = this.BuyDate,
        //         BuyCount = this.BuyCount,
        //         BuyCash = this.BuyCash,

        //     };
        // }
        public Fund Clone(string groupName)
        {
            Fund res = null;

            return(Clone(ref res, groupName));
        }
Example #3
0
        public static List <FundGroup> LoadFundGroups(string NeFileName, out string ErrMes)
        {
            ErrMes = null;
            List <FundGroup> res = null;

            if (!File.Exists(NeFileName))
            {
                ErrMes = "File '" + NeFileName + "' not found";
                return(res);
            }

            string[] lines     = File.ReadAllLines(NeFileName);
            char[]   splitters = new char[] { ',' };
            if (lines.Length == 0)
            {
                return(res);
            }

            res = new List <FundGroup>();
            FundGroup allGroup = new FundGroup()
            {
                Name = Fund.AllGroupName
            };

            res.Add(allGroup);
            for (int i = 1; i < lines.Length; i++)
            {
                Fund curFund = Fund.CreateFromLine(lines[i]);
                if (curFund != null)
                {
                    if (allGroup.Funds.FirstOrDefault(x => x.Id == curFund.Id) != null)
                    {
                        continue;
                    }
                    FundGroup curGroup = res.FirstOrDefault(x => x.Name == curFund.GroupName);
                    if (curGroup == null)
                    {
                        res.Add((curGroup = new FundGroup()
                        {
                            Name = curFund.GroupName
                        }));
                    }
                    curGroup.Funds.Add(curFund);
                    allGroup.Funds.Add(curFund);
                }
            }
            FundGroup CommonGroup = res.FirstOrDefault(x => x.Name == Fund.CommonGroupName);

            if (CommonGroup != null)
            {
                //split the "Common" group
                int CommonGroupSize = 8;

                //!!! CommonGroup.Funds = CommonGroup.Funds.OrderBy(x => x.Id).ToList();

                // int CurSubGroupIndex = 0;
                // while(CommonGroup.Funds.Count>0)
                // {
                //     FundGroup curGroup = new FundGroup() { Name = Fund.CommonGroupName +"_"+CurSubGroupIndex.ToString()};
                //     curGroup.Funds = CommonGroup.Funds.Take(CommonGroupSize).ToList();
                //     res.Add(curGroup);
                //     foreach (Fund f in curGroup.Funds)
                //     {
                //         CommonGroup.Funds.Remove(f);
                //         f.GroupName = curGroup.Name;
                //     }
                //     CurSubGroupIndex++;
                // }
                for (int CurSubGroupIndex = 0;
                     CurSubGroupIndex <= CommonGroup.Funds.Count / CommonGroupSize; CurSubGroupIndex++)
                {
                    FundGroup curGroup = new FundGroup()
                    {
                        Name  = Fund.CommonGroupName + "_" + CurSubGroupIndex.ToString(),
                        Funds = new List <Fund>(),
                    };
                    res.Add(curGroup);
                    for (int i = CurSubGroupIndex * CommonGroupSize;
                         i < CommonGroup.Funds.Count && i < (CurSubGroupIndex + 1) * CommonGroupSize; i++)
                    {
                        curGroup.Funds.Add(CommonGroup.Funds[i].Clone(curGroup.Name));
                    }
                }
            }
            //res.SaveToFile();
            return(res);
        }