Beispiel #1
0
        //Requisitor de GeoLocolizacao
        public void ResquestGeoApi(Motoristas Moto)
        {
            //Mount da Request
            string         endereco    = Moto.DadosEndereco.Numero.ToString() + "+" + Moto.DadosEndereco.Rua.Replace(" ", "+") + ",+" + Moto.DadosEndereco.Cidade.Replace(" ", "+") + ",+" + Moto.DadosEndereco.Estado;
            StringBuilder  sb          = new StringBuilder();
            string         enderecoUrl = sb.AppendFormat("{0}address={1}&key={2}", APIBody, endereco, APIKey).ToString();
            WebRequest     GETURL      = WebRequest.Create(enderecoUrl);
            GoogleGeoApi   GeoApi      = new GoogleGeoApi();
            JsonSerializer serializer  = new JsonSerializer();

            try
            {
                using (Stream stream = GETURL.GetResponse().GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        var jsonTextReader = new JsonTextReader(sr);
                        GeoApi = serializer.Deserialize <GoogleGeoApi>(jsonTextReader);
                    }
                };
            }
            catch (Exception e)
            {
                GeoApi.status = $"ERRO: {e.Message}";
            }

            _googleGeo = GeoApi;
        }
        private void OnSelectExcluir(object sender, EventArgs e)
        {
            try {
                if (mouseLocation.RowIndex >= 0)
                {
                    int Id = Convert.ToInt32(gridDados.Rows[mouseLocation.RowIndex].Cells[0].Value);

                    DialogResult Excluir = MessageBox.Show("Tem certeza que excluir este Motorista?", "Excluir Motorista", MessageBoxButtons.YesNo);

                    if (Excluir == DialogResult.Yes)
                    {
                        Motoristas motoristas = new Motoristas();
                        motoristas.Id = Id;
                        motoristas.Delete();

                        if (motoristas.Success)
                        {
                            MessageBox.Show(motoristas.Message);
                            LoadList();
                        }
                        else
                        {
                            throw new Exception("Houver um erro ao excluir o motorista. (" + motoristas.Message + ")");
                        }
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
        private void LoadList()
        {
            try {
                Motoristas motoristas = new Motoristas();
                motoristas.GetAll();

                ListaDados = motoristas.Results;

                gridDados.Rows.Clear();

                foreach (dynamic motorista in ListaDados)
                {
                    gridDados.Rows.Add(
                        motorista.Id,
                        motorista.Nome,
                        motorista.RG,
                        motorista.CPF,
                        motorista.CNH,
                        motorista.Categoria,
                        motorista.Vencimento
                        );
                }
            }
            catch (Exception e) {
                MessageBox.Show("Houver um erro ao carregar a lista. (" + e.Message + ")");
            }
        }
        private void PreencherDados()
        {
            try {
                Motoristas motoristas = new Motoristas();
                motoristas.Id = Id;
                motoristas.Get();

                dynamic motorista = motoristas.Results[0];

                textNome.Text                  = motorista.Nome;
                textCPF.Text                   = motorista.CPF;
                textRG.Text                    = Convert.ToString(motorista.RG);
                combStatus.SelectedValue       = motorista.Status;
                textCNH.Text                   = Convert.ToString(motorista.CNH);
                timeVencimentoCNH.Text         = motorista.Vencimento;
                combCategoriaCNH.SelectedValue = motorista.Categoria;
                combSexo.SelectedValue         = motorista.Sexo;
                combEstadoCivil.SelectedValue  = motorista.EstadoCivil;
                textCEP.Text                   = motorista.CEP;
                textEndereco.Text              = motorista.Endereco;
                textN.Text               = Convert.ToString(motorista.N);
                textBairro.Text          = motorista.Bairro;
                textComplemento.Text     = motorista.Complemento;
                textCidade.Text          = motorista.Cidade;
                combEstado.SelectedValue = motorista.Estado;
                combCargo.SelectedValue  = motorista.Cargo;
                textTelefone.Text        = motorista.Telefone;
                textCelular.Text         = motorista.Celular;
                textEmail.Text           = motorista.Email;
            }
            catch (Exception e) {
                MessageBox.Show("Houve um erro ao preencher os dados (" + e.Message + ").");
            }
        }
Beispiel #5
0
        public IActionResult Post(string value, string model)
        {
            string result    = string.Empty;
            string exception = "Não foi possivel realizar a operação";


            if (!string.IsNullOrEmpty(model))
            {
                Motoristas moto = JsonConvert.DeserializeObject <Motoristas>(model);

                switch (value.ToUpper().ToString())
                {
                case "UP":
                    result = _context.UpadateMotorista(moto);
                    break;

                case "IN":
                    result = _context.CriarMotorista(moto);
                    break;

                default:
                    break;
                }

                return((!result.Contains("ERRO")) ? CreatedAtAction("Get", moto.Nome, moto._id) : new ObjectResult(exception));
            }
            else
            {
                return(new ObjectResult(exception));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Motoristas motoristas = db.Motoristas.Find(id);

            db.Motoristas.Remove(motoristas);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "IdMotorista,ModeloCarro,Placa,IdMotoristaUsuario")] Motoristas motoristas)
 {
     if (ModelState.IsValid)
     {
         db.Entry(motoristas).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IdMotoristaUsuario = new SelectList(db.Usuarios, "IdUsuario", "FirstName", motoristas.IdUsuario);
     return(View(motoristas));
 }
        public Motorista(Motoristas novosDados)
        {
            Id            = novosDados.Id;
            NomeMotorista = novosDados.NomeMotorista;
            TipoMotorista = novosDados.TipoMotorista;
            Ativo         = novosDados.Ativo;

            Motorista motorista = this;

            motorista.AcessosPortaria = new HashSet <AcessosPortaria>();
            this.Veiculos             = new HashSet <Veiculos>();
        }
Beispiel #9
0
        public ActionResult Create([Bind(Include = "IdMotorista,ModeloCarro,Placa,IdUsuario")] Motoristas motoristas, Usuarios usuarios, string placa, string modelo)
        {
            if (ModelState.IsValid)
            {
                db.Usuarios.Add(usuarios);
                db.Motoristas.Add(motoristas);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IdMotoristaUsuario = new SelectList(db.Usuarios, "IdUsuario", "FirstName", motoristas.IdUsuario);
            return(View(motoristas));
        }
Beispiel #10
0
        protected void BtnCadastro_Click(object sender, EventArgs e)
        {
            try
            {
                if (!formValidations())
                {
                    Usuarios           usuarios = new Usuarios();
                    UsuariosController actionResultController = new UsuariosController();

                    usuarios.FirstName = inputFirstName.Text;
                    usuarios.LastName  = inputLastName.Text;

                    var teste = inputDay.SelectedIndex.ToString();

                    var day        = inputDay.Value.ToString();
                    var month      = inputMonth.Value.ToString();
                    var year       = inputYear.Value.ToString();
                    var dateFormat = day + '/' + month + '/' + year;
                    var date       = Convert.ToDateTime(dateFormat);
                    usuarios.DataNascimento = date;

                    usuarios.Sexo     = selectSexo.Value.ToString();
                    usuarios.CPF      = inputCPF.Text;
                    usuarios.Telefone = inputPhone.Text;
                    usuarios.Status   = false;

                    if (selectTipoUsuario.Value.Contains("Passageiro"))
                    {
                        usuarios.TipoUsuario = 0;
                        actionResultController.Create(usuarios);
                    }


                    if (selectTipoUsuario.Value.Contains("Motorista"))
                    {
                        string     placa      = inputPlaca.Text;
                        string     modelo     = inputModelo.Text;
                        Motoristas motoristas = new Motoristas();
                        usuarios.TipoUsuario   = (tipo)1;
                        motoristas.ModeloCarro = inputModelo.Text;
                        motoristas.Placa       = inputPlaca.Text;
                        actionResultController.Create(motoristas, usuarios, placa, modelo);
                    }
                    clearAspTxtBox();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #11
0
        private void LoadMotoristas()
        {
            Motoristas motoristas = new Motoristas();

            motoristas.GetAll();

            if (motoristas.Results.Count > 0)
            {
                combMotorista.DisplayMember = "Nome";
                combMotorista.ValueMember   = "Id";
                combMotorista.DataSource    = new List <dynamic>(motoristas.Results);
                combMotorista.SelectedValue = -1;
            }
        }
        // GET: Motoristas/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Motoristas motoristas = db.Motoristas.Find(id);

            if (motoristas == null)
            {
                return(HttpNotFound());
            }
            return(View(motoristas));
        }
 public void InserirNoBanco()
 {
     try
     {
         Motoristas novo = this;
         using (var BancoDeDados = new produsisBDEntities())
         {
             BancoDeDados.Motoristas.Add(novo);
             BancoDeDados.SaveChanges();
         }
     }
     catch (Exception)
     {
     }
 }
        // GET: Motoristas/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Motoristas motoristas = db.Motoristas.Find(id);

            if (motoristas == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IdMotoristaUsuario = new SelectList(db.Usuarios, "IdUsuario", "FirstName", motoristas.IdUsuario);
            return(View(motoristas));
        }
Beispiel #15
0
        public IActionResult Get(string nome, string sobrenome)
        {
            Motoristas moto = new Motoristas();

            if (!string.IsNullOrEmpty(nome) && !string.IsNullOrEmpty(sobrenome))
            {
                moto = _context.ObterMotorista(nome, sobrenome);
            }
            else if (!string.IsNullOrEmpty(nome))
            {
                moto = _context.ObterMotorista(nome);
            }
            else
            {
                return(NotFound());
            }

            var res = moto.ToJson();

            return(new ObjectResult(res));
        }
Beispiel #16
0
        //Set GeoLocation Motorista
        public string SetGeoMotorista(Motoristas moto, GoogleGeoApi geoApi, out Motoristas motoOut)
        {
            string result = string.Empty;

            try
            {
                if (!geoApi.status.Contains("ERRO"))
                {
                    moto.DadosEndereco.Lat = geoApi.results[0].geometry.location.lat;
                    moto.DadosEndereco.Log = geoApi.results[0].geometry.location.lng;
                    result = $"Sucesso: Cadastro de Geolocations: lat { moto.DadosEndereco.Lat} // lng {moto.DadosEndereco.Log}";
                }

                motoOut = moto;
                return(result);
            }
            catch
            {
                motoOut = moto;
                return(result);
            }
        }
        private void onEnviar(object sender, EventArgs e)
        {
            try {
                Validate Validate = new Validate(this, ErrorProvider);

                Validate.AddRule(textNome, "Nome Completo", "required|max:100");
                Validate.AddRule(textCPF, "CPF", "required|cpf");
                Validate.AddRule(textRG, "RG", "numeric|max:12");
                Validate.AddRule(combStatus, "Status", "required|numeric|exact:1");
                Validate.AddRule(textCNH, "CNH", "numeric|max:12");
                Validate.AddRule(timeVencimentoCNH, "Vencimento", "date:dd/MM/yyyy");
                Validate.AddRule(combCategoriaCNH, "Categoria", "min:1|max:2");
                Validate.AddRule(combSexo, "Sexo", "required|in:h,m");
                Validate.AddRule(combEstadoCivil, "Estado Civil", "required|numeric|exact:1");
                Validate.AddRule(textCEP, "CEP", "cep");
                Validate.AddRule(textEndereco, "Endereco", "max:100");
                Validate.AddRule(textN, "Nº", "max:10");
                Validate.AddRule(textBairro, "Bairro", "max:60");
                Validate.AddRule(textComplemento, "Complemento", "max:100");
                Validate.AddRule(textCidade, "Cidade", "max:100");
                Validate.AddRule(combEstado, "Estado", "exact:2");
                Validate.AddRule(combCargo, "Cargo", "numeric|exact:1");
                Validate.AddRule(textTelefone, "Telefone", "telefone");
                Validate.AddRule(textCelular, "Celular", "telefone");
                Validate.AddRule(textEmail, "Email", "email|max:100");

                Validate.Validation();

                if (Validate.IsValid())
                {
                    Motoristas motoristas = new Motoristas();

                    motoristas.Nome        = textNome.Text;
                    motoristas.CPF         = textCPF.Text;
                    motoristas.RG          = textRG.Text;
                    motoristas.Status      = combStatus.SelectedValue;
                    motoristas.CNH         = textCNH.Text;
                    motoristas.Vencimento  = timeVencimentoCNH.Text;
                    motoristas.Categoria   = combCategoriaCNH.SelectedValue;
                    motoristas.Sexo        = combSexo.SelectedValue;
                    motoristas.EstadoCivil = combEstadoCivil.SelectedValue;
                    motoristas.CEP         = textCEP.Text;
                    motoristas.Endereco    = textEndereco.Text;
                    motoristas.N           = textN.Text;
                    motoristas.Bairro      = textBairro.Text;
                    motoristas.Complemento = textComplemento.Text;
                    motoristas.Cidade      = textCidade.Text;
                    motoristas.Estado      = combEstado.SelectedValue;
                    motoristas.Cargo       = combCargo.SelectedValue;
                    motoristas.Telefone    = textTelefone.Text;
                    motoristas.Celular     = textCelular.Text;
                    motoristas.Email       = textEmail.Text;

                    if (Id > 0)
                    {
                        motoristas.Id = Convert.ToInt32(Id);
                        motoristas.Update();
                    }
                    else
                    {
                        motoristas.Create();
                    }

                    if (motoristas.Success)
                    {
                        DialogResult SuccessBox = MessageBox.Show(motoristas.Message, "CADASTRADO");
                        if (SuccessBox == DialogResult.OK)
                        {
                            if (fmPrincipal != null)
                            {
                                fmPrincipal.AtivarForm(new TMSForms.List.FormMotoristas(fmPrincipal));
                            }
                            else
                            {
                                Close();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Houver um erro ao salvar o motorista (" + motoristas.Message + ")");
                    }
                }
                else
                {
                    Validate.ErrorProviderShow();
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }