コード例 #1
0
        public static void StoreCorp(PublicCorp data)
        {
            bool newRow = false;
            EMMADataSet.PublicCorpsDataTable table = new EMMADataSet.PublicCorpsDataTable();
            EMMADataSet.PublicCorpsRow row;

            tableAdapter.FillByID(table, data.ID);
            if (table.Count > 0)
            {
                row = table[0];
            }
            else
            {
                row = table.NewPublicCorpsRow();
                newRow = true;
            }

            row.CorpName = data.Name;
            row.Ticker = data.Ticker;
            row.Description = data.Description;
            row.CEO = data.CEO;
            row.EstimatedNAV = data.NAV;
            row.NAVTakenAt = data.NAVDate;
            row.ValuePerShare = data.ShareValue;
            row.ExpectedPayoutPerShare = data.ExpectedPayout;
            row.PayoutPeriodID = (short)data.PayoutPeriod;
            row.Bank = data.Bank;
            row.RiskRatingID = (short)data.CorpRiskRating;

            if (newRow)
            {
                table.AddPublicCorpsRow(row);
            }

            tableAdapter.Update(table);
        }
コード例 #2
0
        public static void LoadOldEmmaXML(string filename, ref Dictionary<int, int> IDChanges)
        {
            EMMADataSet.PublicCorpsDataTable table = new EMMADataSet.PublicCorpsDataTable();
            XmlDocument xml = new XmlDocument();
            xml.Load(filename);

            XmlNodeList nodes = xml.SelectNodes("/DocumentElement/PublicCorps");

            int counter = 0;
            //UpdateStatus(0, 0, "", "Extracting data from XML", false);
            foreach (XmlNode node in nodes)
            {
                string corpName = node.SelectSingleNode("CorpName").FirstChild.Value;
                PublicCorp existingCorp = null;
                int oldID = int.Parse(node.SelectSingleNode("CorpID").FirstChild.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                decimal nav = decimal.Parse(node.SelectSingleNode("EstimatedNAV").FirstChild.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                DateTime navDate = DateTime.Parse(node.SelectSingleNode("NAVTakenAt").FirstChild.Value);
                string payoutPeriod = node.SelectSingleNode("PayoutPeriod").FirstChild.Value;
                CorpPayoutPeriod period = CorpPayoutPeriod.Unspecified;
                if (payoutPeriod.Equals("Monthly"))
                {
                    period = CorpPayoutPeriod.Monthly30;
                }
                else if (payoutPeriod.Equals("BiMonthly"))
                {
                    period = CorpPayoutPeriod.BiMonthly;
                }
                else if (payoutPeriod.Equals("Weekly"))
                {
                    period = CorpPayoutPeriod.Weekly;
                }
                else if (payoutPeriod.Equals("Dayley") || payoutPeriod.Equals("Dailey"))
                {
                    period = CorpPayoutPeriod.Dailey;
                }
                else if (payoutPeriod.Equals("Quaterly"))
                {
                    period = CorpPayoutPeriod.Quaterly;
                }
                decimal shareValue = decimal.Parse(node.SelectSingleNode("ValuePerShare").FirstChild.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                decimal expectedPayout = decimal.Parse(node.SelectSingleNode("ExpectedPayoutPerShare").FirstChild.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                XmlNode tickerNode = node.SelectSingleNode("Ticker");
                string ticker = "";
                if (tickerNode.FirstChild != null)
                {
                    ticker = tickerNode.FirstChild.Value;
                }
                XmlNode descNode = node.SelectSingleNode("Description");
                string description = "";
                if (descNode.FirstChild != null)
                {
                    description = descNode.FirstChild.Value;
                }
                XmlNode ceoNode = node.SelectSingleNode("CEO");
                string ceo = "";
                if (ceoNode.FirstChild != null)
                {
                    ceo = ceoNode.FirstChild.Value;
                }

                try
                {
                    existingCorp = GetCorp(corpName);
                    if (existingCorp.NAV == 0)
                    {
                        existingCorp.NAV = nav;
                        existingCorp.NAVDate = navDate;
                    }
                    if (existingCorp.PayoutPeriod == CorpPayoutPeriod.Unspecified) {
                        existingCorp.PayoutPeriod = period; }
                    if (existingCorp.ShareValue == 0) { existingCorp.ShareValue = shareValue; }
                    if (existingCorp.Ticker.Length == 0) { existingCorp.Ticker = ticker; }
                    if (existingCorp.Description.Length == 0) { existingCorp.Description = description; }
                    if (existingCorp.CEO.Length == 0) { existingCorp.CEO = ceo; }
                    if (existingCorp.ExpectedPayout == 0) { existingCorp.ExpectedPayout = expectedPayout; }
                    StoreCorp(existingCorp);
                }
                catch (EMMADataMissingException)
                {
                    EMMADataSet.PublicCorpsRow corp = table.NewPublicCorpsRow();
                    corp.CorpName = corpName;
                    corp.Description = description;
                    corp.CEO = ceo;
                    corp.Ticker = ticker;
                    corp.EstimatedNAV = nav;
                    corp.NAVTakenAt = navDate;
                    corp.ExpectedPayoutPerShare = expectedPayout;
                    corp.ValuePerShare = shareValue;
                    corp.PayoutPeriodID = (short)period;
                    corp.Bank = false;
                    table.AddPublicCorpsRow(corp);
                    lock (tableAdapter)
                    {
                        tableAdapter.Update(corp);
                        corp.AcceptChanges();
                    }
                }

                PublicCorp newCorp = GetCorp(corpName);
                IDChanges.Add(oldID, newCorp.ID);

                counter++;
                //UpdateStatus(counter, nodes.Count, "", "", false);
            }
            //UpdateStatus(1, 1, "", "Complete", false);

            //UpdateStatus(0, 0, "", "Updating database", false);
            lock (tableAdapter)
            {
                tableAdapter.Update(table);
            }
            //UpdateStatus(1, 1, "", "Complete", false);
        }