Beispiel #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();
        }
 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");
     }
 }
Beispiel #3
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();
        }
Beispiel #4
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();
        }
Beispiel #5
0
        private void BtnRemoveCarros_Click(object sender, EventArgs e)
        {
            if (listboxCarros.list.SelectedIndex != -1)
            {
                DialogResult result = MessageBox.Show("Tem a certeza que quere eliminar", "Confirmação", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    CarroAluguer carro = listboxCarros.list.SelectedItem as CarroAluguer;
                    carro = (CarroAluguer)bd.CarrosSet.Single(o => o.IdCarro == carro.IdCarro);

                    bd.CarrosSet.Remove(carro);
                    bd.SaveChanges();
                    lerdadosCarro();
                }
            }
            else
            {
                MessageBox.Show("Tem de selecionar um carro");
            }
        }
Beispiel #6
0
 private void BtnDeleteVendas_Click(object sender, EventArgs e)
 {
     if (listBoxHistVenda.list.SelectedIndex != -1)
     {
         DialogResult result = MessageBox.Show("Tem a certeza que quere eliminar", "Confirmação", MessageBoxButtons.YesNo);
         if (result == DialogResult.Yes)
         {
             Venda venda = listBoxHistVenda.list.SelectedItem as Venda;
             bd.VendaSet.Remove(venda);
             bd.SaveChanges();
             lerdadosHistVenda();
         }
     }
     else
     {
         MessageBox.Show("Tem de seleconar a venda");
     }
 }
Beispiel #7
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");
     }
 }
Beispiel #8
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;
             Utilizadores user_apagar = (Utilizadores)bd.UtilizadoresSet.Find(user.IdUtilizador);
             bd.UtilizadoresSet.Remove(user_apagar);
             bd.SaveChanges();
             lerdadosclientes();
             listBoxCarros.list.DataSource   = null;
             listBoxServicos.list.DataSource = null;
             listBoxParcela.list.DataSource  = null;
             panelParcela.Visible            = false;
         }
         cancelarServico();
     }
     else
     {
         MessageBox.Show("Tem de selecionar um cliente");
     }
 }
Beispiel #9
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();
        }
Beispiel #10
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();
        }
Beispiel #11
0
        private void BtnSubmeter_Click(object sender, EventArgs e)
        {
            bd = new StarDBContainer();
            if (listboxClientes.list.SelectedIndex != -1)
            {
                if (comboboxCombustivel.Text.Equals("Combustível"))
                {
                    MessageBox.Show("Comustível: Selecione um tipo de combustível!");
                    return;
                }
                if (comboBoxEstado.Text.Equals("Estado"))
                {
                    MessageBox.Show("Estado: Selecione um tipo de estado!");
                    return;
                }
                Utilizadores user = listboxClientes.list.SelectedItem as Utilizadores;

                Venda venda = new Venda();
                venda.Data   = DateTime.Now;
                venda.Estado = comboBoxEstado.Text;
                try
                {
                    venda.Valor = decimal.Parse(textboxValor.Text.Replace(".", ","));
                }
                catch (FormatException)
                {
                    MessageBox.Show("So pode inserir numeros e '.' ou ','");
                    textboxValor.Text = "";

                    setplaceholder(textboxValor, VALOR);
                    return;
                }
                venda.UtilizadoresIdUtilizador = user.IdUtilizador;
                CarroVenda carro = new CarroVenda();
                carro.Marca       = textBoxMarca.Text.Trim();
                carro.Modelo      = TextBoxModelo.Text.Trim();
                carro.Matricula   = TextboxMatricula.Text.Trim();
                carro.Combustivel = comboboxCombustivel.Text;
                if (textBoxExtras.Text == EXTRA || textBoxExtras.Text == "")
                {
                    carro.Extras = null;
                }

                else
                {
                    carro.Extras = textBoxExtras.Text;
                }
                venda.CarroVenda = carro;
                bd.CarrosSet.Add(carro);
                bd.VendaSet.Add(venda);
                bd.SaveChanges();

                CarroOficina carroOficina = new CarroOficina();
                carroOficina.Marca       = venda.CarroVenda.Marca;
                carroOficina.Modelo      = venda.CarroVenda.Modelo;
                carroOficina.Matricula   = venda.CarroVenda.Matricula;
                carroOficina.Combustivel = venda.CarroVenda.Combustivel;
                carroOficina.Kms         = 0;
                carroOficina.UtilizadoresIdUtilizador = venda.UtilizadoresIdUtilizador;
                bd.CarrosSet.Add(carroOficina);
                bd.SaveChanges();
                this.Close();
            }
        }