Ejemplo n.º 1
0
        public Login()
        {
            InitializeComponent();
            this.Height = 180;

            baseFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            programmFolder = Path.Combine(baseFolder, "CRM_System");
            settingsPath = Path.Combine(programmFolder, @"Settings\ConnectSettings.json");

            if (File.Exists(settingsPath))
            {
                string connSettingsString = File.ReadAllText(settingsPath);
                ConnectSettings connectSettings = JsonSerializer.Deserialize<ConnectSettings>(connSettingsString);

                tServerHost.Text = connectSettings.Server;
                cbDataBases.Items.Clear();
                cbDataBases.Items.Add(connectSettings.DataBase);
                cbDataBases.SelectedItem = connectSettings.DataBase;
                tLogin.Text = connectSettings.UserName;
                tDbUser.Text = connectSettings.DataBaseUser;
                tDbPass.Text = connectSettings.DataBasePass;
                connectState = true;
            }

        }
Ejemplo n.º 2
0
        private void bCheckSettings_Click(object sender, EventArgs e)
        {
            if (Connect.SettingsConnect(tServerHost.Text, cbDataBases.SelectedItem.ToString(), tDbUser.Text, tDbPass.Text))
            {
                MessageBox.Show("Успешное подключение");
                try
                {
                    ConnectSettings connectSettings = new ConnectSettings() { Server = tServerHost.Text, DataBase = cbDataBases.SelectedItem.ToString(), UserName = tLogin.Text, DataBaseUser = tDbUser.Text, DataBasePass = tDbPass.Text };
                    string connectSettingsJson = JsonSerializer.Serialize<ConnectSettings>(connectSettings);

                    if (!Directory.Exists(Path.Combine(programmFolder, @"Settings")))
                    {
                        Directory.CreateDirectory(Path.Combine(programmFolder, @"Settings"));
                    }

                    File.WriteAllText(settingsPath, connectSettingsJson);
                    connectState = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Ошибка");
                }
            }
            else
            {
                MessageBox.Show("Подключение не удалось. Проверьте данные");
            }
        }
Ejemplo n.º 3
0
        private void bLogin_Click(object sender, EventArgs e)
        {
            if (connectState && Connect.SettingsConnect(tServerHost.Text, cbDataBases.SelectedItem.ToString(),tDbUser.Text,tDbPass.Text))
            {
                if (tLogin.Text != string.Empty && tPassWord.Text != string.Empty)
                {
                    if (Connect.Login(tLogin.Text, tPassWord.Text, tServerHost.Text, cbDataBases.SelectedItem.ToString()))
                    {

                        try
                        {
                            if (File.Exists(settingsPath))
                            {
                                File.Delete(settingsPath);
                            }

                            ConnectSettings connectSettings = new ConnectSettings() { Server = tServerHost.Text, DataBase = cbDataBases.SelectedItem.ToString(), UserName = tLogin.Text, DataBaseUser = tDbUser.Text, DataBasePass = tDbPass.Text };
                            string connectSettingsJson = JsonSerializer.Serialize<ConnectSettings>(connectSettings);

                            if (!Directory.Exists(Path.Combine(programmFolder, @"Settings")))
                            {
                                Directory.CreateDirectory(Path.Combine(programmFolder, @"Settings"));
                            }

                            File.WriteAllText(settingsPath, connectSettingsJson);
                            connectState = true;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Ошибка");
                        }

                        Main mainWindow = new Main(tLogin.Text, tPassWord.Text, tServerHost.Text, cbDataBases.SelectedItem.ToString());
                        mainWindow.Show();
                        this.ShowInTaskbar = false;
                        this.Hide();
                    }
                }                
                else
                {
                    MessageBox.Show("Логин или пароль не введен", "Ошибка!");
                }
            }
            else
            {
                MessageBox.Show("Проверьте параметры подключения!","Ошибка!");
            }
            
        }