public static void Delete(int corpID)
 {
     EMMADataSet.PublicCorpsDataTable table = new EMMADataSet.PublicCorpsDataTable();
     lock (tableAdapter)
     {
         tableAdapter.FillByID(table, corpID);
     }
     table.FindByCorpID(corpID).Delete();
     tableAdapter.Update(table);
 }
 public static PublicCorpsList GetAll(bool includeBanks, bool includeNonBanks)
 {
     PublicCorpsList retVal = new PublicCorpsList();
     EMMADataSet.PublicCorpsDataTable table = new EMMADataSet.PublicCorpsDataTable();
     tableAdapter.Fill(table);
     foreach (EMMADataSet.PublicCorpsRow row in table)
     {
         if ((row.Bank && includeBanks) || (!row.Bank && includeNonBanks))
         {
             retVal.Add(new PublicCorp(row));
         }
     }
     return retVal;
 }
        public static PublicCorp GetCorp(string corpName)
        {
            PublicCorp retVal = null;
            EMMADataSet.PublicCorpsDataTable table = new EMMADataSet.PublicCorpsDataTable();
            EMMADataSet.PublicCorpsRow rowData = null;

            lock (tableAdapter)
            {
                tableAdapter.FillByName(table, corpName);
            }
            if (table.Count == 1)
            {
                rowData = table[0];
            }
            else
            {
                lock (tableAdapter)
                {
                    tableAdapter.FillByName(table, "%" + corpName + "%");
                }

                if (table.Count < 1)
                {
                    throw new EMMADataMissingException(ExceptionSeverity.Error, "No public corp found " +
                        "matching '" + corpName + "'", "PublicCorps", corpName);
                }
                else if (table.Count > 1)
                {
                    SortedList<object, string> options = new SortedList<object, string>();
                    foreach (EMMADataSet.PublicCorpsRow corp in table)
                    {
                        options.Add(corp.CorpID, corp.CorpName);
                    }
                    OptionPicker picker = new OptionPicker("Select Corp (" + corpName + ")",
                        "Choose the specific corp you want from those listed below.", options);
                    if (picker.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
                    {
                        rowData = table.FindByCorpID((int)picker.SelectedItem);
                    }
                }
                else
                {
                    rowData = table[0];
                }
            }

            if (rowData != null) { retVal = new PublicCorp(rowData); }
            return retVal;
        }
 static void Cache_DataUpdateNeeded(object myObject, DataUpdateNeededArgs<int, PublicCorp> args)
 {
     PublicCorp data = null;
     EMMADataSet.PublicCorpsDataTable table =new EMMADataSet.PublicCorpsDataTable();
     tableAdapter.FillByID(table, args.Key);
     if (table.Count > 0)
     {
         data = new PublicCorp(table[0]);
     }
     args.Data = data;
 }
        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);
        }
        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);
        }