Example #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            if (rbtLocal.Checked)
            {
                if (cboInstanceConnection.SelectedIndex > -1)
                {
                    Settings.Default["Local"]    = rbtLocal.Checked ? "True" : "False";
                    Settings.Default["Instance"] = cboInstanceConnection.Text;
                    Settings.Default.Save();

                    if (BUser.GetCountAllUsers() > 0)
                    {
                        MessageBox.Show("The connection test was done successfully.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        objForm_002.Show();
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("The connection could not be established. We ask that:\r\n• Verify that the SQL Server engine is turned on\r\n• Verify that the data structure is correctly installed.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        cboInstanceConnection.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("There isn't any instance selected.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                if (mskIP.Text.Split('.')[0].Length > 0 && mskIP.Text.Split('.')[1].Length > 0 && mskIP.Text.Split('.')[2].Length > 0 && mskIP.Text.Split('.')[3].Length > 0)
                {
                    Settings.Default["Local"] = rbtLocal.Checked ? "True" : "False";
                    Settings.Default["IP"]    = mskIP.Text.Split('.')[0].Trim().PadLeft(3, '0') + "." + mskIP.Text.Split('.')[1].Trim().PadLeft(3, '0') + "." + mskIP.Text.Split('.')[2].Trim().PadLeft(3, '0') + "." + mskIP.Text.Split('.')[3].Trim().PadLeft(3, '0');
                    Settings.Default["Port"]  = nupdPort.Value.ToString();
                    Settings.Default.Save();


                    if (BUser.GetCountAllUsers() > 0)
                    {
                        MessageBox.Show("The connection test was done successfully.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        objForm_002.Show();
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("The connection could not be established. We ask that:\r\n• Verify that the SQL Server engine on the server is turned on\r\n• Verify that the data structure is correctly installed on the server.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        mskIP.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("The selected ip is not correct.", Preferences.TitleSoftware, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    mskIP.Focus();
                }
            }

            Cursor = Cursors.Default;
        }