Esempio n. 1
0
        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;
                ao.IsMulti    = ac.IsMulti;
                ao.Password   = ac.UnlockPassword;
                ao.PwdMD5     = ac.UnlockPwdMD5;
                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);
                }
            }
        }
Esempio n. 2
0
        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;
                }
            }
        }
Esempio n. 3
0
        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);
                }
            }
        }
Esempio n. 4
0
        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);
                }
            }
        }