コード例 #1
0
        private bool LoginToAcumatica()
        {
            _progress.Report(new MonitorMessage(String.Format(Strings.LoginNotify, Properties.Settings.Default.AcumaticaUrl)));
            _screen                 = new ScreenApi.Screen();
            _screen.Url             = Properties.Settings.Default.AcumaticaUrl + "/Soap/.asmx";
            _screen.CookieContainer = new System.Net.CookieContainer();

            try
            {
                _screen.Login(Properties.Settings.Default.Login, Settings.ToInsecureString(Settings.DecryptString(Properties.Settings.Default.Password)));
                return(true);
            }
            catch
            {
                _screen = null;
                throw;
            }
        }
コード例 #2
0
        private void okButton_Click(object sender, EventArgs e)
        {
            Uri validatedUri;

            if (!Uri.TryCreate(acumaticaUrlTextBox.Text, UriKind.Absolute, out validatedUri))
            {
                MessageBox.Show(Strings.UrlMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 0;
                acumaticaUrlTextBox.Focus();
                return;
            }

            if (String.IsNullOrEmpty(loginTextBox.Text))
            {
                MessageBox.Show(Strings.LoginMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 0;
                loginTextBox.Focus();
                return;
            }

            if (String.IsNullOrEmpty(passwordTextBox.Text))
            {
                MessageBox.Show(Strings.PasswordMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 0;
                passwordTextBox.Focus();
                return;
            }

            if (_queues.Count == 0 && String.IsNullOrEmpty(acumaticaScaleIDTextBox.Text))
            {
                MessageBox.Show(Strings.PrintQueueOrScaleConfigurationMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 1;
                return;
            }

            if (!String.IsNullOrEmpty(acumaticaScaleIDTextBox.Text) && (scalesDropDown.SelectedItem == null || (scalesDropDown.SelectedItem as ScaleDevice).VendorId == 0))
            {
                MessageBox.Show(String.Format(Strings.DeviceMissingPrompt, acumaticaScaleIDTextBox.Text), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 2;
                scalesDropDown.Focus();
                return;
            }

            PrintQueue unnamedQueue = _queues.FirstOrDefault(q => q.QueueName == NewQueueName);

            if (unnamedQueue != null)
            {
                MessageBox.Show(Strings.QueueNameMissingPrompt, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex  = 1;
                queueList.SelectedItem = unnamedQueue;
                queueName.Focus();
                return;
            }

            var screen = new ScreenApi.Screen();

            screen.Url = acumaticaUrlTextBox.Text + "/Soap/.asmx";
            try
            {
                screen.Login(loginTextBox.Text, passwordTextBox.Text);
                try
                {
                    screen.Logout();
                }
                catch { } //Ignore all errors in logout.
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format(Strings.ScreenWebServiceConnexionError, ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                mainTab.SelectedIndex = 0;
                acumaticaUrlTextBox.Focus();
                return;
            }

            Properties.Settings.Default.AcumaticaUrl = acumaticaUrlTextBox.Text;
            Properties.Settings.Default.Login        = loginTextBox.Text;
            Properties.Settings.Default.Password     = Settings.EncryptString(Settings.ToSecureString(passwordTextBox.Text));
            Properties.Settings.Default.Queues       = JsonConvert.SerializeObject(_queues);
            Properties.Settings.Default.ScaleID      = acumaticaScaleIDTextBox.Text;

            if (scalesDropDown.SelectedItem == null)
            {
                Properties.Settings.Default.ScaleDeviceVendorId  = 0;
                Properties.Settings.Default.ScaleDeviceProductId = 0;
            }
            else
            {
                var s = (ScaleDevice)scalesDropDown.SelectedItem;
                Properties.Settings.Default.ScaleDeviceVendorId  = s.VendorId;
                Properties.Settings.Default.ScaleDeviceProductId = s.ProductId;
            }

            Properties.Settings.Default.Save();

            this.DialogResult = DialogResult.OK;
        }