本文整理汇总了C#中QDMS.Instrument.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Instrument.Clone方法的具体用法?C# Instrument.Clone怎么用?C# Instrument.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDMS.Instrument
的用法示例。
在下文中一共展示了Instrument.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddInstrumentManuallyWindow
/// <summary>
///
/// </summary>
/// <param name="instrument">If we're updating or cloning an instrument, pass it here.</param>
/// <param name="addingNew">True if adding a new instrument. False if we're updating an instrument.</param>
/// <param name="addingContFut">True if adding a continuous futures instrument.</param>
public AddInstrumentManuallyWindow(Instrument instrument = null, bool addingNew = true, bool addingContFut = false)
{
InitializeComponent();
//If it's a continuous future, make the continuous future tab visible
if ((instrument != null && instrument.IsContinuousFuture) ||
addingContFut)
{
ContFutTabItem.Visibility = Visibility.Visible;
TypeComboBox.IsEnabled = false;
}
else
{
ContFutTabItem.Visibility = Visibility.Hidden;
}
DataContext = this;
_addingNew = addingNew;
_context = new MyDBContext();
if (instrument != null)
{
_context.Instruments.Attach(instrument);
_context.Entry(instrument).Reload();
if (instrument.Exchange != null)
_context.Entry(instrument.Exchange).Reload();
if (instrument.ContinuousFuture != null)
{
_context.ContinuousFutures.Attach(instrument.ContinuousFuture);
_context.Entry(instrument.ContinuousFuture).Reload();
}
if (!addingNew)
{
if (instrument.Tags != null)
{
foreach (Tag tag in instrument.Tags)
{
_context.Tags.Attach(tag);
}
}
if (instrument.Sessions != null)
{
foreach (InstrumentSession session in instrument.Sessions)
{
_context.InstrumentSessions.Attach(session);
}
}
}
TheInstrument = addingNew ? (Instrument)instrument.Clone() : instrument;
if (TheInstrument.Tags == null) TheInstrument.Tags = new List<Tag>();
if (TheInstrument.Sessions == null) TheInstrument.Sessions = new List<InstrumentSession>();
TheInstrument.Sessions = TheInstrument.Sessions.OrderBy(x => x.OpeningDay).ThenBy(x => x.OpeningTime).ToList();
_originalSessions = new List<InstrumentSession>(TheInstrument.Sessions);
}
else
{
TheInstrument = new Instrument
{
Tags = new List<Tag>(),
Sessions = new List<InstrumentSession>()
};
//need to do some extra stuff if it's a continuous future
if (addingContFut)
{
TheInstrument.ContinuousFuture = new ContinuousFuture();
TheInstrument.Type = InstrumentType.Future;
TheInstrument.IsContinuousFuture = true;
}
CustomRadioBtn.IsChecked = true;
}
//Tags
Tags = new ObservableCollection<CheckBoxTag>();
foreach (Tag t in _context.Tags)
{
Tags.Add(new CheckBoxTag(t, TheInstrument.Tags.Contains(t)));
}
//Sessions
SelectedSessions = new ObservableCollection<InstrumentSession>(TheInstrument.Sessions);
//Window title
if (addingNew)
{
Title = "Add New Instrument";
//.........这里部分代码省略.........
示例2: AddInstrumentManuallyWindow
/// <summary>
///
/// </summary>
/// <param name="instrument">If we're updating or cloning an instrument, pass it here.</param>
/// <param name="addingNew">True if adding a new instrument. False if we're updating an instrument.</param>
public AddInstrumentManuallyWindow(Instrument instrument = null, bool addingNew = true)
{
InitializeComponent();
DataContext = this;
_addingNew = addingNew;
var context = new MyDBContext();
if (instrument != null)
{
context.Instruments.Attach(instrument);
context.Entry(instrument).Reload();
context.Entry(instrument.Exchange).Reload();
TheInstrument = (Instrument)instrument.Clone();
if (TheInstrument.Tags == null) TheInstrument.Tags = new List<Tag>();
if (TheInstrument.Sessions == null) TheInstrument.Sessions = new List<InstrumentSession>();
TheInstrument.Sessions = TheInstrument.Sessions.OrderBy(x => x.OpeningDay).ThenBy(x => x.OpeningTime).ToList();
}
else
{
TheInstrument = new Instrument
{
Tags = new List<Tag>(),
Sessions = new List<InstrumentSession>()
};
}
Tags = new ObservableCollection<CheckBoxTag>();
foreach (Tag t in context.Tags)
{
Tags.Add(new CheckBoxTag(t, TheInstrument.Tags.Contains(t)));
}
if (addingNew)
{
Title = "Add New Instrument";
AddBtn.Content = "Add";
}
else
{
Title = "Modify Instrument";
AddBtn.Content = "Modify";
_originalInstrument = instrument;
}
Exchanges = new ObservableCollection<Exchange>();
var exchangeList = context.Exchanges.AsEnumerable().OrderBy(x => x.Name);
foreach (Exchange e in exchangeList)
{
Exchanges.Add(e);
}
//fill template box
var templates = context.SessionTemplates.Include("Sessions").ToList();
foreach (SessionTemplate t in templates)
{
TemplateComboBox.Items.Add(t);
}
if (TheInstrument.SessionsSource == SessionsSource.Template)
{
TemplateComboBox.SelectedItem = templates.First(x => x.ID == TheInstrument.SessionTemplateID);
}
//set the right radio button...
CustomRadioBtn.IsChecked = TheInstrument.SessionsSource == SessionsSource.Custom;
TemplateRadioBtn.IsChecked = TheInstrument.SessionsSource == SessionsSource.Template;
ExchangeRadioBtn.IsChecked = TheInstrument.SessionsSource == SessionsSource.Exchange;
//populate instrument type combobox with enum values
var instrumentTypeValues = MyUtils.GetEnumValues<InstrumentType>();
foreach (InstrumentType t in instrumentTypeValues)
{
TypeComboBox.Items.Add(t);
}
//populate option type combobox with enum values
var optionTypeValues = MyUtils.GetEnumValues<OptionType>();
foreach (OptionType t in optionTypeValues)
{
OptionTypeComboBox.Items.Add(t);
}
var dataSources = context.Datasources.AsEnumerable();
foreach (Datasource d in dataSources)
{
DatasourceComboBox.Items.Add(d);
}
//sort the sessions so they're ordered properly...
SessionsGrid.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("OpeningDay", System.ComponentModel.ListSortDirection.Ascending));
context.Dispose();
}