Exemplo n.º 1
0
        private void BtnInserir_Click(object sender, EventArgs e)
        {
            bd = new StarDBContainer();

            if (textboxKms.Text.Equals("") || textboxKms.Text.Equals("KMS") && textboxKms.Enabled == true)
            {
                MessageBox.Show("KMS: Campo Obrigatório!");
                return;
            }


            if (globalUser != null)
            {
                Aluguer aluguer = new Aluguer();
                aluguer.DataInicio = DatepickerEntrada.Value;
                aluguer.DataFim    = DatepickerSaida.Value;
                aluguer.UtilizadoresIdUtilizador = globalUser.IdUtilizador;
                aluguer.CarroAluguerId           = globalCarro.IdCarro;
                bd.AluguerSet.Add(aluguer);
                bd.SaveChanges();
                CarroAluguer carroAluguer = bd.CarrosSet.OfType <CarroAluguer>().Single(a => a.IdCarro == globalCarro.IdCarro);
                carroAluguer.Estado          = "Alugado";
                bd.Entry(carroAluguer).State = EntityState.Modified;
                bd.SaveChanges();
            }
            else
            {
                int     id      = globalCarro.Aluguer.OrderByDescending(a => a.IdAluguer).Select(a => a.IdAluguer).First();
                Aluguer aluguer = bd.AluguerSet.Single(a => a.IdAluguer == id);
                aluguer.DataFim         = DatepickerSaida.Value;
                aluguer.Kms             = int.Parse(textboxKms.Text);
                aluguer.Valor           = decimal.Parse(textboxTotal.Text.Replace("€", ""));
                bd.Entry(aluguer).State = EntityState.Modified;
                bd.SaveChanges();

                CarroAluguer carroAluguer = bd.CarrosSet.OfType <CarroAluguer>().Single(a => a.IdCarro == globalCarro.IdCarro);
                carroAluguer.Estado          = "Disponível";
                bd.Entry(carroAluguer).State = EntityState.Modified;
                bd.SaveChanges();
                DialogResult result = MessageBox.Show("Deseja fatura?", "Faturação", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    faturacao(aluguer);
                }
            }
            this.Close();
        }
Exemplo n.º 2
0
        private void btnRemoveClientes_Click(object sender, EventArgs e)
        {
            int             index       = dgv_Clientes.CurrentCell.RowIndex;
            DataGridViewRow selectedRow = dgv_Clientes.Rows[index];
            Utilizadores    user        = (Utilizadores)selectedRow.DataBoundItem;

            bd.Entry(user).State = EntityState.Deleted;
            bd.SaveChanges();
            lerdados();
        }
Exemplo n.º 3
0
        private void BtnSubmeter_Click(object sender, EventArgs e)
        {
            //Campos Obrigatórios
            if (textBoxMarca.Text.Equals("") || textBoxMarca.Text.Equals("Marca"))
            {
                MessageBox.Show("Marca: Campo Obrigatório!");
                return;
            }

            if (TextBoxModelo.Text.Equals("") || TextBoxModelo.Text.Equals("Modelo"))
            {
                MessageBox.Show("Modelo: Campo Obrigatório!");
                return;
            }

            if (TextboxMatricula.Text.Equals("") || TextboxMatricula.Text.Equals("Matricula"))
            {
                MessageBox.Show("Matricula: Campo Obrigatório!");
                return;
            }

            //Validações
            if (comboboxCombustivel.Text.Equals("Combustível"))
            {
                MessageBox.Show("Comustível: Selecione um tipo de combustível!");
                return;
            }

            if (Globalcarro != null)
            {
                Utilizadores user  = bd.UtilizadoresSet.Single(Utilizadores => Utilizadores.IdUtilizador == idUtilizador);
                CarroOficina carro = user.CarroOficina.Single(carros => carros.IdCarro == Globalcarro.IdCarro);
                carro.Marca           = textBoxMarca.Text.Trim();
                carro.Modelo          = TextBoxModelo.Text.Trim();
                carro.Matricula       = TextboxMatricula.Text.Trim();
                carro.Combustivel     = comboboxCombustivel.SelectedText.Trim();
                bd.Entry(carro).State = EntityState.Modified;
            }
            else
            {
                CarroOficina carro = new CarroOficina();
                carro.Marca       = textBoxMarca.Text.Trim();
                carro.Modelo      = TextBoxModelo.Text.Trim();
                carro.Matricula   = TextboxMatricula.Text.Trim();
                carro.Combustivel = comboboxCombustivel.SelectedText.Trim();
                carro.Kms         = 1;
                carro.UtilizadoresIdUtilizador = idUtilizador;
                bd.CarrosSet.Add(carro);
            }

            bd.SaveChanges();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 4
0
 private void BtnRemoveCarros_Click(object sender, EventArgs e)
 {
     if (listBoxHist.list.SelectedIndex != -1)
     {
         Aluguer aluguer = listBoxHist.list.SelectedItem as Aluguer;
         bd.AluguerSet.Remove(aluguer);
         bd.SaveChanges();
         CarroAluguer carro = (CarroAluguer)bd.CarrosSet.Where(id => id.IdCarro == aluguer.CarroAluguerId).First();
         carro.Estado          = "Disponível";
         bd.Entry(carro).State = EntityState.Modified;
         bd.SaveChanges();
         lerdadosAluguer();
     }
     else
     {
         MessageBox.Show("Tem de selecionar um aluguer");
     }
 }
Exemplo n.º 5
0
 private void BtnRemoveClientes_Click(object sender, EventArgs e)
 {
     if (listboxClientes.list.SelectedIndex != -1)
     {
         DialogResult dialog = MessageBox.Show("Tem a certeza que quere eliminar", "Comfimação", MessageBoxButtons.YesNo);
         if (dialog == DialogResult.Yes)
         {
             Utilizadores user = listboxClientes.list.SelectedItem as Utilizadores;
             bd.Entry(user).State = EntityState.Deleted;
             bd.SaveChanges();
             lerdadosclientes();
         }
     }
     else
     {
         MessageBox.Show("Tem de selecionar um cliente");
     }
 }
Exemplo n.º 6
0
        private void BtnSwitch_Click(object sender, EventArgs e)
        {
            CarroAluguer carroAluguer = listboxCarros.list.SelectedItem as CarroAluguer;

            carroAluguer = (CarroAluguer)bd.CarrosSet.Single(id => id.IdCarro == carroAluguer.IdCarro);

            if (btnSwitch.Value == true)
            {
                carroAluguer.Estado = "Disponível";
            }
            else
            {
                carroAluguer.Estado = "Indisponivel";
            }

            bd.Entry(carroAluguer).State = EntityState.Modified;
            bd.SaveChanges();
            lerdadosClientes();
            lerdadosCarro();
            mostrarDado();
        }
Exemplo n.º 7
0
        //Adicionar clientes
        private void btnSubmeter_Click(object sender, EventArgs e)
        {
            if (textboxNIF.Text.Length < 9)
            {
                MessageBox.Show("Introduza 9 digitos no campo do NIF!");
                return;
            }
            if (textboxNIF.Text.Length > 9)
            {
                MessageBox.Show("Introduziu mais que 9 digitos!");
                return;
            }

            int          convnif = int.Parse(textboxNIF.Text);
            Utilizadores nif     = bd.UtilizadoresSet.FirstOrDefault(x => x.NIF == convnif);

            if (nif != null)
            {
                MessageBox.Show("O NIF introduzido já existe!");
            }

            if (textboxNome.Text.Count(c => !char.IsLetter(c) && !char.IsWhiteSpace(c)) > 0)
            {
                MessageBox.Show("Nome: Este campo só pode conter letras!");
                return;
            }

            if (!textboxEmail.Text.Contains("@"))
            {
                MessageBox.Show("Email: Campo incorreto!");
                return;
            }
            if (textboxTelemovel.Text.Count(c => char.IsDigit(c)) == 0)
            {
                MessageBox.Show("Telemóvel: Obrigatório digitos!");
                return;
            }

            if (textboxTelemovel.Text.Count(c => char.IsLetter(c)) > 0)
            {
                MessageBox.Show("Telemóvel: Este campo não permite letras!");
                return;
            }

            if (textboxTelemovel.Text.Count(c => !char.IsSymbol(c)) == 0)
            {
                MessageBox.Show("Telemóvel: Este campo não permite letras!");
                return;
            }


            //Campos para preencher obrigatóriamente!
            if (textboxNome.Text.Equals(""))
            {
                MessageBox.Show("Nome: Campo Obrigatório!");
                return;
            }

            if (textboxNIF.Text.Equals(""))
            {
                MessageBox.Show("NIF: Campo Obrigatório!");
                return;
            }

            if (textboxTelemovel.Text.Equals(""))
            {
                MessageBox.Show("Telemóvel: Campo Obritório!");
                return;
            }

            if (textboxMorada.Text.Equals(""))
            {
                MessageBox.Show("Morada: Campo Obrigatório!");
                return;
            }

            if (btnSubmeter.Text == "Inserir")
            {
                Utilizadores user = new Utilizadores();
                user.Nome      = textboxNome.Text.Trim();
                user.NIF       = int.Parse(textboxNIF.Text.Trim());
                user.Morada    = textboxMorada.Text.Trim();
                user.Telemovel = textboxTelemovel.Text.Trim();
                user.Email     = textboxEmail.Text.Trim();
                bd.UtilizadoresSet.Add(user);
            }
            else
            {
                Utilizadores user = bd.UtilizadoresSet.Single(Utilizadores => Utilizadores.IdUtilizador == idUser);
                user.Nome            = textboxNome.Text.Trim();
                user.NIF             = int.Parse(textboxNIF.Text.Trim());
                user.Morada          = textboxMorada.Text.Trim();
                user.Telemovel       = textboxTelemovel.Text.Trim();
                user.Email           = textboxEmail.Text.Trim();
                bd.Entry(user).State = EntityState.Modified;
            }

            //Verificações ao tentar submeter
            //Restrições


            bd.SaveChanges();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 8
0
        private void btnInserir_Click(object sender, EventArgs e)
        {
            //Campos Obrigatórios
            if (textboxMarca.Text.Equals("") || textboxMarca.Text.Equals("Marca"))
            {
                MessageBox.Show("Marca: Campo Obrigatório!");
                return;
            }


            if (textboxModelo.Text.Equals("") || textboxModelo.Text.Equals("Modelo"))
            {
                MessageBox.Show("Modelo: Campo Obrigatório!");
                return;
            }

            if (textboxValorBase.Text.Equals("") || textboxValorBase.Text.Equals("Valor Base"))
            {
                MessageBox.Show("Valor Base: Campo Obrigatório!");
                return;
            }

            //Validações
            if (comboboxCombustivel.Text.Equals("Combustível"))
            {
                MessageBox.Show("Comustível: Selecione um tipo de combustível!");
                return;
            }


            if (globalCarro == null)
            {
                CarroAluguer aluguer = new CarroAluguer();
                aluguer.Marca  = textboxMarca.Text.Trim();
                aluguer.Modelo = textboxModelo.Text.Trim();
                try
                {
                    aluguer.ValorBase = decimal.Parse(textboxValorBase.Text.Replace(".", ","));
                }
                catch (FormatException)
                {
                    MessageBox.Show("So pode inserir numeros e '.' ou ','");
                    textboxValorBase.Text = "";

                    setplaceholder(textboxValorBase, VALBASE);
                    return;
                }

                aluguer.Matricula   = "StarStand";
                aluguer.Combustivel = comboboxCombustivel.Text;
                aluguer.Estado      = "Disponível";
                bd.CarrosSet.Add(aluguer);
            }
            else
            {
                CarroAluguer aluguer = (CarroAluguer)bd.CarrosSet.OfType <CarroAluguer>().Where(id => id.IdCarro == globalCarro.IdCarro).First();
                aluguer.Marca  = textboxMarca.Text.Trim();
                aluguer.Modelo = textboxModelo.Text.Trim();
                try
                {
                    aluguer.ValorBase = decimal.Parse(textboxValorBase.Text.Replace(".", ","));
                }
                catch (FormatException)
                {
                    MessageBox.Show("So pode inserir numeros e '.' ou ','");
                    textboxValorBase.Text = "";

                    setplaceholder(textboxValorBase, VALBASE);
                    return;
                }
                aluguer.Combustivel     = comboboxCombustivel.Text;
                bd.Entry(aluguer).State = EntityState.Modified;
            }

            bd.SaveChanges();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }