private void CheckBox_Checked(object sender, RoutedEventArgs e, AccountOption accOpt) { CheckBox chkbox = sender as CheckBox; if (chkbox != null && (bool)chkbox.IsChecked) { MessageBoxResult result = MessageBox.Show("If Exclusive is checked, only the first item with Activate True will be kept.\nAre you sure to continue?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { bool firstFound = false; foreach (var item in accOpt.Accounts) { if (item.IsActivate) { if (!firstFound) { firstFound = true; } else { item.IsActivate = false; } } } accOpt.Accounts = new ObservableCollection <ConnectionParam>(accOpt.Accounts); } } }
private void AddBtn_Click(object sender, RoutedEventArgs e) { string vendor = ((Button)sender).Name.Substring(4, 2).ToUpper(); AccountConfig ac = new AccountConfig(); AccountOption accOpt = (dynamic)settings.GetType().GetProperty(vendor + "Account").GetValue(settings); ac.chkIsEnabled.IsEnabled = CheckIfActivateEnabled(accOpt); ac.ShowDialog(); if ((bool)ac.DialogResult) { ConnectionParam ao = new ConnectionParam(); ao.AccName = ac.AccName; ao.Host = ac.Host; ao.Port = ac.Port; ao.ClientId = ac.ClientId; ao.IsActivate = ac.IsActivate; accOpt.Accounts.Add(ao); if (accOpt.IsExclusive && ac.IsActivate) { foreach (ConnectionParam cp in accOpt.Accounts) { if (cp.AccName != ao.AccName) { cp.IsActivate = false; } } accOpt.Accounts = new ObservableCollection <ConnectionParam>(accOpt.Accounts); } } }
// Remove attribute ReadOnly's value for storing the value private void RemoveRedundant() { foreach (string vendor in settings.Vendors) { AccountOption accOpt = (dynamic)settings.GetType().GetProperty(vendor + "Account").GetValue(settings); foreach (var item in accOpt.Accounts) { item.ReadOnly = false; } } }
private void CheckBox_Checked(object sender, RoutedEventArgs e, AccountOption accOpt) { CheckBox chkbox = sender as CheckBox; if (chkbox != null && (bool)chkbox.IsChecked) { MessageBoxResult result = MessageBox.Show("If Exclusive is checked, only the first item with Activate True will be kept.\nAre you sure to continue?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { bool firstFound = false; var cps = accOpt.Accounts.Where(x => x.ReadOnly); ConnectionParam cp = null; if (cps.Count() > 1) { MessageBox.Show("Exclusive cannot be checked since there are more than one using connections.", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); accOpt.IsExclusive = false; return; } else { cp = cps.ToList()[0]; } foreach (var item in accOpt.Accounts) { if (cp != null && item != cp) { item.IsActivate = false; } if (item.IsActivate && cp == null) { if (!firstFound) { firstFound = true; } else { item.IsActivate = false; } } } accOpt.Accounts = new ObservableCollection <ConnectionParam>(accOpt.Accounts); } else { accOpt.IsExclusive = false; } } }
private bool CheckIfActivateEnabled(AccountOption accOpt) { if (accOpt != null && accOpt.IsExclusive) { foreach (var item in accOpt.Accounts) { if (item.ReadOnly) { return(false); } } } return(true); }
// if Accounts are exclusive and one is being connected (ReadOnly), IsActivate checkbox should be disabled. private bool CheckIfActivateEnabled(string vendor) { AccountOption accOpt = (dynamic)settings.GetType().GetProperty(vendor + "Account").GetValue(settings); if (accOpt != null && accOpt.IsExclusive) { foreach (var item in accOpt.Accounts) { if (item.ReadOnly) { return(false); } } } return(true); }
public Setting(List <IController> ctrls) { InitializeComponent(); // set Window Icon /* * string resourceName = "AmiBroker.Controllers.images.setting.png"; * Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); * this.Icon = BitmapFrame.Create(s);*/ Uri uri = new Uri("pack://application:,,,/OrderManager;component/Controllers/images/setting.png"); BitmapImage bi = new BitmapImage(uri); this.Icon = bi; // read preference from setting string up = Properties.Settings.Default["preference"].ToString(); if (up != string.Empty) { settings = JsonConvert.DeserializeObject <UserPreference>(up); } else { settings = new UserPreference(); } this.DataContext = settings; // set CheckBox (exclusive) click event chk_ft_ex.Click += (sender, EventArgs) => { CheckBox_Checked(sender, EventArgs, settings.FTAccount); }; chk_ib_ex.Click += (sender, EventArgs) => { CheckBox_Checked(sender, EventArgs, settings.IBAccount); }; // set ReadOnly = true if the connection is being connected, so that item will be non-editable foreach (string vendor in settings.Vendors) { AccountOption accOpt = (dynamic)settings.GetType().GetProperty(vendor + "Account").GetValue(settings); foreach (var item in accOpt.Accounts) { var ctrl = ctrls.FirstOrDefault(x => x.DisplayName == vendor + "(" + item.AccName + ")"); if (ctrl != null) { item.ReadOnly = ctrl.IsConnected; } } } }
private void EditAccountConfig(string vendor) { ListView lv = (ListView)this.FindName("lv_" + vendor + "_acc"); if (lv.SelectedIndex != -1) { AccountConfig ac = new AccountConfig(); ac.txtName.IsReadOnly = true; ac.Owner = this; string prop = vendor.ToUpper() + "Account"; AccountOption accOpt = (dynamic)settings.GetType().GetProperty(prop).GetValue(settings); ac.chkIsEnabled.IsEnabled = CheckIfActivateEnabled(accOpt); ObservableCollection <ConnectionParam> aos = accOpt.Accounts; ConnectionParam ao = aos[lv.SelectedIndex]; ac.AccName = ao.AccName; ac.Host = ao.Host; ac.Port = ao.Port; ac.ClientId = ao.ClientId; ac.IsActivate = ao.IsActivate; ac.IsMulti = ao.IsMulti; ac.ShowDialog(); if ((bool)ac.DialogResult) { ao.AccName = ac.AccName; ao.Host = ac.Host; ao.Port = ac.Port; ao.ClientId = ac.ClientId; ao.IsActivate = ac.IsActivate; ao.IsMulti = ac.IsMulti; if (accOpt.IsExclusive && ac.IsActivate) { foreach (ConnectionParam cp in accOpt.Accounts) { if (cp.AccName != ao.AccName) { cp.IsActivate = false; } } } accOpt.Accounts = new ObservableCollection <ConnectionParam>(aos); } } }
private void DeleteAccountConfig(string vendor) { ListView lv = (ListView)this.FindName("lv_" + vendor + "_acc"); //ListItem li = lv.ItemContainerGenerator.ContainerFromIndex(lv.SelectedIndex); if (lv.SelectedIndex != -1) { string prop = vendor.ToUpper() + "Account"; AccountOption accOpt = (dynamic)settings.GetType().GetProperty(prop).GetValue(settings); ObservableCollection <ConnectionParam> aos = accOpt.Accounts; ConnectionParam ao = aos[lv.SelectedIndex]; MessageBoxResult result = MessageBox.Show("Are you sure to delete this configuration?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { aos.RemoveAt(lv.SelectedIndex); } } }
private void ReadSettings() { UserPreference = JsonConvert.DeserializeObject <UserPreference>(Properties.Settings.Default["preference"].ToString()); List <IController> ctrls = new List <IController>(); if (UserPreference != null) { Type t = typeof(Helper); string ns = t.Namespace; foreach (string vendor in UserPreference.Vendors) { AccountOption accOpt = (dynamic)UserPreference.GetType().GetProperty(vendor + "Account").GetValue(UserPreference); foreach (var acc in accOpt.Accounts) { if (acc.IsActivate) { string clsName = ns + "." + vendor + "Controller"; Type type = Type.GetType(clsName); IController ctrl = Activator.CreateInstance(type, this) as IController; ctrl.ConnParam = acc; // if some connection is connected, then remain unchanged IController ic = Controllers.FirstOrDefault(x => x.DisplayName == ctrl.DisplayName); if (ic != null && ic.IsConnected) { ctrls.Add(ic); } else { ctrls.Add(ctrl); } } } Controllers.Clear(); foreach (var item in ctrls) { Controllers.Add(item); } } } }