Example #1
0
        private void serviceFinish_Click(object sender, RoutedEventArgs e)
        {
            Boolean setTime = false;

            String          query;
            MySqlCommand    cmd;
            MySqlConnection con = null;


            //Crear servicio
            try
            {
                ConfigurationHandler Config = new ConfigurationHandler();
                String host     = Config.getSetting("host", "Connection");
                String port     = Config.getSetting("port", "Connection");
                String database = Config.getSetting("database", "Connection");
                String user     = Config.getSetting("username", "Connection");
                String pass     = Config.getSetting("password", "Connection");
                String ruta     = "Data Source=" + host + ";port=" + port + ";Database=" + database + ";Uid=" + user + ";Password="******"UPDATE `services` SET `end` = CURRENT_TIMESTAMP WHERE `services`.`id` = (SELECT actualServiceID FROM tables where id = ?selectedTableID)";
                cmd   = new MySqlCommand(query, con);
                cmd.Parameters.AddWithValue("?selectedTableID", SelectedTable.ToString());
                System.Data.IDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    // error
                    MessageBox.Show("Error al cerrar el servicio.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    setTime = true;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Hubo un error al crear el pedido: \n" + exc.Message.ToString() + ".", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }

            //Asignar a mesa actual
            if (setTime)
            {
                try
                {
                    ConfigurationHandler Config = new ConfigurationHandler();
                    String host     = Config.getSetting("host", "Connection");
                    String port     = Config.getSetting("port", "Connection");
                    String database = Config.getSetting("database", "Connection");
                    String user     = Config.getSetting("username", "Connection");
                    String pass     = Config.getSetting("password", "Connection");
                    String ruta     = "Data Source=" + host + ";port=" + port + ";Database=" + database + ";Uid=" + user + ";Password="******"UPDATE `tables` SET `actualServiceID` = null WHERE `tables`.`id` = ?selectedTableID;";
                    cmd   = new MySqlCommand(query, con);
                    cmd.Parameters.AddWithValue("?selectedTableID", SelectedTable.ToString());
                    System.Data.IDataReader dr;
                    dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        MessageBox.Show("Error al limpiar la mesa.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        //TODO OK
                        //Recargar la vista
                        SelectedService = false;
                        updateTables();
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show("Hubo un error al cerrar el pedido: \n" + exc.Message.ToString() + ".", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                finally
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                }
            }
            updateProductsList();
        }
Example #2
0
 private void productAdd_Click(object sender, RoutedEventArgs e)
 {
     new products_selection(SelectedTable.ToString()).ShowDialog();
     updateTables();
     updateProductsList();
 }
Example #3
0
        private void serviceStart_Click(object sender, RoutedEventArgs e)
        {
            Boolean alreadyWorking = false;
            int     serviceID      = -1;

            String          query;
            MySqlCommand    cmd;
            MySqlConnection con = null;

            //Comprobar si existe
            try
            {
                ConfigurationHandler Config = new ConfigurationHandler();
                String host     = Config.getSetting("host", "Connection");
                String port     = Config.getSetting("port", "Connection");
                String database = Config.getSetting("database", "Connection");
                String user     = Config.getSetting("username", "Connection");
                String pass     = Config.getSetting("password", "Connection");
                String ruta     = "Data Source=" + host + ";port=" + port + ";Database=" + database + ";Uid=" + user + ";Password="******"SELECT `actualServiceID` FROM tables WHERE id = ?selectedTableID;";
                cmd   = new MySqlCommand(query, con);
                cmd.Parameters.AddWithValue("?selectedTableID", SelectedTable.ToString());
                System.Data.IDataReader dr;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    if (!dr.IsDBNull(0))
                    {
                        alreadyWorking = true;
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Hubo un error al comrpobar la existencia de un pedido en esta mesa: \n" + exc.Message.ToString() + ".", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
            Console.WriteLine(alreadyWorking.ToString());

            if (alreadyWorking == false)
            {
                //Crear servicio
                try
                {
                    ConfigurationHandler Config = new ConfigurationHandler();
                    String host     = Config.getSetting("host", "Connection");
                    String port     = Config.getSetting("port", "Connection");
                    String database = Config.getSetting("database", "Connection");
                    String user     = Config.getSetting("username", "Connection");
                    String pass     = Config.getSetting("password", "Connection");
                    String ruta     = "Data Source=" + host + ";port=" + port + ";Database=" + database + ";Uid=" + user + ";Password="******"INSERT INTO services (start) values (CURRENT_TIMESTAMP); SELECT id FROM `services` WHERE `start`= CURRENT_TIMESTAMP;";
                    cmd   = new MySqlCommand(query, con);

                    System.Data.IDataReader dr;
                    dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        serviceID = Int32.Parse(dr.GetString(0));
                    }
                    else
                    {
                        MessageBox.Show("Error al crear el servicio.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show("Hubo un error al añadir el usuario: \n" + exc.Message.ToString() + ".", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                finally
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                }

                //Asignar a mesa actual
                if (serviceID != -1)
                {
                    try
                    {
                        ConfigurationHandler Config = new ConfigurationHandler();
                        String host     = Config.getSetting("host", "Connection");
                        String port     = Config.getSetting("port", "Connection");
                        String database = Config.getSetting("database", "Connection");
                        String user     = Config.getSetting("username", "Connection");
                        String pass     = Config.getSetting("password", "Connection");
                        String ruta     = "Data Source=" + host + ";port=" + port + ";Database=" + database + ";Uid=" + user + ";Password="******"UPDATE `tables` SET `actualServiceID` = ?serviceID WHERE `tables`.`id` = ?selectedTableID;";
                        cmd   = new MySqlCommand(query, con);
                        cmd.Parameters.AddWithValue("?serviceID", serviceID);
                        cmd.Parameters.AddWithValue("?selectedTableID", SelectedTable.ToString());
                        System.Data.IDataReader dr;
                        dr = cmd.ExecuteReader();
                        if (dr.Read())
                        {
                            MessageBox.Show("Error al asignar el servicio a esta mesa.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            //TODO OK
                            //Recargar la vista
                            SelectedService = true;
                            updateTables();
                        }
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show("Hubo un error al añadir el usuario: \n" + exc.Message.ToString() + ".", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    finally
                    {
                        if (con != null)
                        {
                            con.Close();
                        }
                    }
                }
            }
        }