Diff of /MainWindow.xaml.cs [569eeb] .. [c5a3d1]  Maximize  Restore

  Switch to side-by-side view

--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -1,16 +1,6 @@
 ďťżusing System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.Diagnostics;
 using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
 using MySql.Data.MySqlClient;
 using System.ComponentModel;
 
@@ -18,7 +8,7 @@
     public partial class MainWindow : Window, INotifyPropertyChanged {
         public string lblstatuscolor { get; set; }
 
-        MySqlConnection connection;
+        readonly MySqlConnection connection;
 
         public MainWindow() {
             Com.GetImagePath();
@@ -41,13 +31,15 @@
         }
 
         void connection_StateChange( object sender, System.Data.StateChangeEventArgs e ) {
-            if( connection.State == System.Data.ConnectionState.Open ) {
-                btnlogin.IsEnabled = true;
-                btnregister.IsEnabled = true;
-                lblstatus.Content = "Server is on!";
-                lblstatuscolor = "#FF337E17";
-                OnPropertyChanged( "lblstatuscolor" );
-            }
+            if ( connection.State != System.Data.ConnectionState.Open ) return;
+
+            btnlogin.IsEnabled = true;
+            btnregister.IsEnabled = true;
+            lblstatus.Content = "Server is on!";
+            lblstatuscolor = "#FF337E17";
+            OnPropertyChanged( "lblstatuscolor" );
+
+            connection.Close();
         }
 
         private void btnlogin_Click( object sender, RoutedEventArgs e ) {
@@ -60,10 +52,13 @@
             btnlogin.IsEnabled = false;
             this.UpdateLayout();
 
-            try {
-               string query = "SELECT * FROM users WHERE `name` =  '" + tbusername.Text + "' AND `password` =  '" +
+            //try {
+                string query = "SELECT * FROM users WHERE `name` =  '" + tbusername.Text + "' AND `password` =  '" +
                     tbpassword.Password + "' LIMIT 1";
-                var cmd = new MySqlCommand(query, connection);
+                var con = new MySqlConnection( Com.connStr );
+                con.Open();
+                Debug.Write(con.State);
+                var cmd = new MySqlCommand(query, con);
                 var reader = cmd.ExecuteReader();
 
                 if( reader.Read() ){
@@ -72,6 +67,7 @@
 
                     reader.Close();
                     cmd.Dispose();
+                    con.Close();
 
                     new wMenu().Show();
                     this.Close();
@@ -83,15 +79,15 @@
                 }
 
                 reader.Close();
-            }
+            /*}
             catch (Exception ex) {
                 MessageBox.Show( "Critical login error!\n" + ex.Source +": "+ ex.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error );
                 Application.Current.Shutdown();
-            }
+            }*/
         }
 
-        private void Window_Closing( object sender, System.ComponentModel.CancelEventArgs e ) {
-            connection.Close();
+        private void Window_Closing( object sender, CancelEventArgs e ) {
+            //connection.Close();
         }
 
         public event PropertyChangedEventHandler PropertyChanged;

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks