Example #1
0
        /****************************************************
        *
        * Ticker focus has been lost
        *
        *****************************************************/

        private void tbTicker_Leave (object sender, EventArgs e)
        {
            string exchange;

            using (dbOptionsDataContext dc = new dbOptionsDataContext ())
            {
                exchange = (from s in dc.Stocks
                            where s.Ticker == tbTicker.Text
                            select s.Exchange).FirstOrDefault ();
                if (string.IsNullOrEmpty (exchange))
                {
                    exchange = "";
                }
            }
            tbExchange.Text = exchange;
        }
Example #2
0
        private void btnSave_Click (object sender, EventArgs e)
        {
            ContractDetail cd = (ContractDetail) lbItems.SelectedItem;

            using (dbOptionsDataContext dc = new dbOptionsDataContext ())
            {
                var query = (from s1 in dc.Stocks
                             where s1.Ticker == cd.LocalSymbol
                             select s1).SingleOrDefault ();

                if (query != null)
                {
                    query.Company = cd.LongName;
                    query.Exchange = cd.Exchange;
                    try
                    {
                        dc.SubmitChanges ();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show (string.Format ("Failed to update existing record {0}. {1}", cd.ToString (), ex.Message));
                    }
                    return;
                }
                Stock s = new Stock ();
                s.Ticker = cd.Ticker;
                s.Company = cd.LongName;
                s.Exchange = cd.Exchange;
                s.SecType = (string) lbSecType.SelectedValue;
                s.FutureExpiry = cd.Expiry;
                dc.Stocks.InsertOnSubmit (s);
                try
                {
                    dc.SubmitChanges ();
                }
                catch (Exception ex)
                {
                    MessageBox.Show (string.Format ("Failed to insert new record {0}. {1}", cd.ToString (), ex.Message));
                }
                return;

            }
        }