private void LoginButtonClick(object sender, RoutedEventArgs e) { try { string myConnection = @"provider=microsoft.jet.oledb.4.0;data source=..\..\Database\Login.mdb"; OleDbConnection myConn = new OleDbConnection(myConnection); imputName = this.BoxName.Text.Trim(); string imputPass = this.BoxPassword.Password; string selectString = "SELECT * FROM Login WHERE User='******' AND Pass='******'"; OleDbCommand selectCommand = new OleDbCommand(selectString, myConn); myConn.Open(); OleDbDataReader myReader = selectCommand.ExecuteReader(); int count = 0; while (myReader.Read()) { count++; } if (count == 1) { IsOpen = false; this.Hide(); MainWindow main = new MainWindow(); main.Show(); this.Close(); } else { MessageBox.Show("Username or password not correct!"); myReader.Close(); myConn.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// The information about a new order private void AddOrderButtonClick(object sender, RoutedEventArgs e) { // Takes the information from the calendar // Calendar.SelectedDate.ToString()); // Create a cashier Cashier cashier = new Cashier("Pepa"); // Export the results to Database MDB file string myConnection = @"provider=microsoft.jet.oledb.4.0;data source=..\..\Database\Orders.mdb"; OleDbConnection myConn = new OleDbConnection(myConnection); string myInsertQuery = "INSERT INTO Orders values('" + (LastOrderID() + 1) + "','" + this.Tables.Text + "','" + DateTime.Now + "','" + DateTime.Now + "','" + "closed" + "','" + this.totalPrice + "','" + this.BoxPersonName.Text + "','" + cashier.Name + "','" + Login.imputName + "')"; OleDbCommand myCommand = new OleDbCommand(myInsertQuery); myCommand.Connection = myConn; // Open connection to database myConn.Open(); try { myCommand.ExecuteNonQuery(); MessageBox.Show(String.Format("A new order {0} was created!", LastOrderID() + 1)); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } // Close connection to database myConn.Close(); this.Hide(); // Update the information in MainWindow MainWindow main = new MainWindow(); main.Show(); // Close the 1st opened MainWindow Application.Current.Windows[0].Close(); // Close the NewOrder window this.Close(); }