Esempio n. 1
0
        // 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();
        }
Esempio n. 2
0
        // 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();
        }