Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (radClient.Checked)
            {
                try
                {
                    Cursor = Cursors.WaitCursor;

                    Properties.Settings.Default.DbName     = txtDbName.Text.Trim();
                    Properties.Settings.Default.DbUsername = txtUsername.Text.Trim();
                    Properties.Settings.Default.DbPassword = txtPassword.Text.Trim();
                    Properties.Settings.Default.ServerIP   = txtIP.Text.Trim();
                    Properties.Settings.Default.ServerName = txtName.Text.Trim();
                    Properties.Settings.Default.AppType    = "client";

                    Properties.Settings.Default.ImagePath = @"\\" + Path.Combine(Properties.Settings.Default.ServerName, @"spk\");

                    var constring = $"SERVER={txtIP.Text.Trim()}; DATABASE={txtDbName.Text.Trim()}; USER ID={txtUsername.Text.Trim()}; PASSWORD={txtPassword.Text.Trim()};";
                    var db        = new Model1();
                    db.AdjustConfigConString(constring);
                    db.Dispose();
                }
                catch (Exception ex)
                {
                    Cursor = Cursors.Arrow;
                    MessageBox.Show("An error occured. Please contact support.");
                    Utilities.Utils.LogException(ex);
                    return;
                }
            }
            else
            {
                Cursor = Cursors.WaitCursor;

                try
                {
                    var appPath = @"\\" + Path.Combine(Environment.MachineName, @"spk");
                    File.Copy(Path.Combine(Environment.CurrentDirectory, "small.png"), Path.Combine(appPath, "small.png"), true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Please create the shared spk folder first.");
                    Utilities.Utils.LogException(ex);
                    Cursor = Cursors.Arrow;
                    return;
                }

                if (!Directory.Exists(@"c:/spk/admin") || !Directory.Exists(@"c:/spk/image"))
                {
                    MessageBox.Show("Please Create the sub folders in the spk folder.");
                    return;
                }

                try
                {
                    Properties.Settings.Default.DbName     = txtDbName.Text;
                    Properties.Settings.Default.DbUsername = txtUsername.Text;
                    Properties.Settings.Default.DbPassword = txtPassword.Text;
                    Properties.Settings.Default.ServerIP   = "127.0.0.1";
                    Properties.Settings.Default.ServerName = txtServerName.Text;
                    Properties.Settings.Default.AppType    = "server";

                    Properties.Settings.Default.ImagePath = @"c:/spk/";

                    var constring = $"SERVER=Localhost; DATABASE={txtDbName.Text.Trim()}; USER ID={txtUsername.Text.Trim()}; PASSWORD={txtPassword.Text.Trim()};";
                    var db        = new Model1();
                    db.AdjustConfigConString(constring);
                    db.Dispose();
                }
                catch (Exception ex)
                {
                    Cursor = Cursors.Arrow;
                    MessageBox.Show("An error occured. Please contact support.");
                    Utilities.Utils.LogException(ex);
                    return;
                }
            }

            Properties.Settings.Default.SetupDone = true;
            Properties.Settings.Default.Save();

            MessageBox.Show("Configuration was saved successfully.");

            Cursor = Cursors.Arrow;

            if (_from == "main")
            {
                Close();
            }
            else
            {
                LoginForm frm = new LoginForm();
                frm.Show();
                Close();
            }
        }