Beispiel #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            using (var context = new AlojamentoDbEntities3())
            {
                Customer queryCustomer = context.Customers
                                         .Where(s => s.nome == user)
                                         .FirstOrDefault <Customer>();

                Reserva queryReser = context.Reservas
                                     .Where(s => s.id == queryCustomer.id)
                                     .FirstOrDefault <Reserva>();

                Reserva reserva = new Reserva()
                {
                    idAlojamento = queryReser.idAlojamento,
                    dateReserva  = queryReser.dateReserva,
                    dateCheckIn  = queryReser.dateCheckIn,
                    dateCheckOut = queryReser.dateCheckOut,
                    custo        = queryReser.custo,
                    idCustomer   = queryCustomer.id
                };

                dataGridView1.DataSource = reserva;
                context.Reservas.Attach(reserva);

                //context.SaveChanges();
                Close();
            }
        }
Beispiel #2
0
        private void butonConfirmarReserva_Click(object sender, EventArgs e)
        {
            string bnum = textBoxNumBungalow.Text;

            if (bnum != "")
            {
                using (var context = new AlojamentoDbEntities3())
                {
                    Alojamento queryAloj = context.Alojamentoes
                                           .Where(s => s.num == textBoxNumBungalow.Text)
                                           .FirstOrDefault <Alojamento>();

                    Customer queryCustomer = context.Customers
                                             .Where(s => s.id == queryAloj.id) // valor estático tem de se alterar!!!!
                                             .FirstOrDefault <Customer>();

                    Reserva reserva = new Reserva()
                    {
                        idAlojamento = queryAloj.id,
                        dateReserva  = DateTime.Now,
                        dateCheckIn  = dateTimePicker1.Value,
                        dateCheckOut = dateTimePicker2.Value,
                        custo        = queryAloj.custoNoite,
                        idCustomer   = queryCustomer.id
                    };
                    context.Reservas.Add(reserva);
                    context.SaveChanges();
                    Close();
                }
            }
            else
            {
                MessageBox.Show("dados Invalidos");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Botão de login
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loginBtn_Click(object sender, EventArgs e)
        {
            string userName = textBoxUserNameLogin.Text;

            //byte passWord = Convert.ToByte( texboxPassWordLogin.Text);
            byte[] password = Encoding.ASCII.GetBytes(texboxPassWordLogin.Text);

            if (userName != "")
            {
                using (var context = new AlojamentoDbEntities3())
                {
                    User queryUser = context.Users
                                     .Where(s => s.userName == textBoxUserNameLogin.Text)
                                     .FirstOrDefault <User>();

                    User queryPassWord = context.Users
                                         .Where(s => s.passWord == password) //texboxPassWordLogin.Text convertida para byte)
                                         .FirstOrDefault <User>();
                    Close();

                    //string userName = "******";
                    //string passWord = "******";
                    Form1 menu1 = new Form1();

                    //if ((userName == queryUser.userName) && (password == queryPassWord.passWord))
                    //{
                    this.Close();
                    //Uso de Thread para fechar o form anterior e abrir um novo
                    th = new Thread(OpenForm2);
                    th.SetApartmentState(ApartmentState.STA);
                    th.Start();
                    //}
                    //else
                    //    {
                    //        MessageBox.Show("Login Invalido");

                    //    }
                }
            }
            else
            {
                MessageBox.Show("preencha login");
            }
            MinhasReservas user = new MinhasReservas(userName);
        }
Beispiel #4
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            using (var context = new AlojamentoDbEntities3())
            {
                Customer queryCustomer = context.Customers
                                         .Where(s => s.id == 1) // valor estático tem de se alterar!!!!
                                         .FirstOrDefault <Customer>();

                Customer customer = new Customer()
                {
                    nome      = queryCustomer.nome,
                    sobreNome = queryCustomer.sobreNome,
                    address   = queryCustomer.address,
                    phone     = queryCustomer.phone,
                    email     = queryCustomer.email,
                };

                //Reserva
                //context.Reserva.Add(Customer);
                //context.SaveChanges();
                Close();
            }
        }
Beispiel #5
0
        public static string Registar(string userName, string passWord, string nome, string sobreNome, string address, string phone, string email)
        {
            //ConnectDb connect = new ConnectDb();
            //SqlCommand cmd = new SqlCommand();
            //SqlCommand cmd1 = new SqlCommand();
            //SqlCommand cmd2 = new SqlCommand();
            //string mensagem;
            //int customerId = 0;

            ////comandos sql - insert, update, delete
            //cmd.CommandText = "insert into customer (nome, sobreNome, address, phone, email) values(@nome, @sobreNome, @address, @phone, @email)";
            //cmd2.CommandText = "select id from customer where email = @email";
            //cmd1.CommandText = "insert into Users (username, passWord) values(@userName, @passWord)";

            ////parametros Customer
            //cmd.Parameters.AddWithValue("@nome", nome);
            //cmd.Parameters.AddWithValue("@sobreNome", sobreNome);
            //cmd.Parameters.AddWithValue("@address", address);
            //cmd.Parameters.AddWithValue("@phone", phone);
            //cmd.Parameters.AddWithValue("@email", email);

            //cmd2.Parameters.AddWithValue("@email", email);//add do select id from customer usando o email

            ////parametros Users
            //cmd1.Parameters.AddWithValue("@userName", userName);
            //cmd1.Parameters.AddWithValue("@passWord", passWord);

            ////connectar com a db - classe connect
            //cmd.Connection = connect.Connect();
            //cmd2.Connection = connect.Connect();
            //cmd1.Connection = connect.Connect();
            //try
            //{
            //    //cmd.Connection = connect.Connect();
            //    //cmd2.Connection = connect.Connect();
            //    //cmd1.Connection = connect.Connect();

            //    //executar
            //    cmd.ExecuteNonQuery();
            //    using (SqlDataReader reader = cmd1.ExecuteReader())
            //    {
            //        if (reader.Read())
            //        {
            //            customerId = reader.GetInt32(0);
            //        }
            //    }

            //    cmd1.ExecuteNonQueryAsync();

            //    //Desconectar db
            //    connect.Disconnect();

            //    //mostrar msg de erro ou sucesso
            //    mensagem = "Registo ok";
            //}
            //catch (SqlException e)
            //{
            //    Console.WriteLine(e);
            //    mensagem =  e.ToString();
            //}
            using (AlojamentoDbEntities3 db = new AlojamentoDbEntities3())
            {
                using (var context = new AlojamentoDbEntities3())
                {
                    //Customer queryCustomer = context.Customer
                    //                   .Where(s => s.nome == user)
                    //                   .FirstOrDefault<Customer>();


                    Cliente  customer    = new Cliente(userName, passWord, nome, sobreNome, address, phone, email);
                    byte[]   pass        = Encoding.ASCII.GetBytes(passWord);
                    Customer newcustomer = new Customer()
                    {
                        nome      = customer.Nome,
                        sobreNome = customer.Sobrenome,
                        address   = customer.Address,
                        phone     = customer.Phone,
                        email     = customer.Email
                    };
                    context.Customers.Add(newcustomer);

                    context.SaveChanges();

                    User user = new User()
                    {
                        userName   = customer.Username,
                        passWord   = pass,
                        idCustomer = newcustomer.id,
                        idStaff    = null
                    };

                    context.Users.Add(user);
                    context.SaveChanges();
                }
            }
            return(userName);
        }