コード例 #1
0
        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            thisConnection = new connection(serverTextBox.Text);

            //save the connection to settings.

            var connection = thisConnection.connectionString;
            DbContextOptionsBuilder <COMP4952PROJECTContext> builder = new DbContextOptionsBuilder <COMP4952PROJECTContext>();

            builder.UseSqlServer(connection);

            COMP4952PROJECTContext db = new COMP4952PROJECTContext(builder.Options);

            if (db.Database.CanConnect())
            {
                SettingsFile.Default.ConnectionString = thisConnection.connectionString;
                SettingsFile.Default.Save();

                if (!db.Wall.Any())
                {
                    thisWindow.frame.Source = new Uri("FloorBuilder.xaml", UriKind.Relative);
                }
                else
                {
                    thisWindow.frame.Source = new Uri("Home.xaml", UriKind.Relative);
                }

                this.Close();
            }
            else
            {
                MessageBox.Show("Unable to connect to server, try again.", "Alert");
            }
        }
コード例 #2
0
        private void initializeDBConnection()
        {
            var connection = SettingsFile.Default.ConnectionString;

            DbContextOptionsBuilder <COMP4952PROJECTContext> builder = new DbContextOptionsBuilder <COMP4952PROJECTContext>();

            builder.UseSqlServer(connection);

            db = new COMP4952PROJECTContext(builder.Options);
        }
コード例 #3
0
        public MainWindow()
        {
            InitializeComponent();

            ServerCredentials newCredentialRequest = new ServerCredentials(this);

            if (SettingsFile.Default.ConnectionString == null || SettingsFile.Default.ConnectionString == "")
            {
                //display server credentials

                newCredentialRequest.Show();
            }
            else
            {
                var connection = SettingsFile.Default.ConnectionString;
                DbContextOptionsBuilder <COMP4952PROJECTContext> builder = new DbContextOptionsBuilder <COMP4952PROJECTContext>();
                builder.UseSqlServer(connection);

                COMP4952PROJECTContext db = new COMP4952PROJECTContext(builder.Options);

                if (db.Database.CanConnect())
                {
                    if (!db.Wall.Any())
                    {
                        frame.Source = new Uri("FloorBuilder.xaml", UriKind.Relative);
                    }
                    else
                    {
                        frame.Source = new Uri("Home.xaml", UriKind.Relative);
                    }
                }
                else
                {
                    newCredentialRequest.Show();
                }
            }
        }