Exemple #1
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;

            }
        }
 partial void UpdateStock(Stock instance);
 partial void DeleteStock(Stock instance);
 partial void InsertStock(Stock instance);