示例#1
0
        public CadVencMotoristaLista ListaVencMotorista()
        {
            conexaoBancoDados     = new DB();
            cadVencMotoristaLista = new CadVencMotoristaLista();

            SQL = "SELECT tblVencimentoMotorista.ID, tblVencimentoMotorista.DataVencimento, tblVencimentoMotorista.Status, tblMotorista.Nome " +
                  "FROM tblVencimentoMotorista " +
                  "INNER JOIN tblMotorista ON tblVencimentoMotorista.ID_Motorista = tblMotorista.ID " +
                  "ORDER BY tblVencimentoMotorista.DataVencimento ASC";

            try
            {
                conexaoBancoDados.LimparParametros();
                DataTable dataTable = conexaoBancoDados.ExcutarConsulta(CommandType.Text, SQL);

                foreach (DataRow dataRow in dataTable.Rows)
                {
                    cadVencMotorista = new CadVencMototista();

                    cadVencMotorista.ID                = int.Parse(dataRow["ID"].ToString());
                    cadVencMotorista.ID_Motorista      = new CadMotorista();
                    cadVencMotorista.ID_Motorista.Nome = dataRow["Nome"].ToString();
                    cadVencMotorista.Status            = dataRow["Status"].ToString();
                    cadVencMotorista.Vencimento        = DateTime.Parse(dataRow["DataVencimento"].ToString());
                    cadVencMotoristaLista.Add(cadVencMotorista);
                }

                return(cadVencMotoristaLista);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        private void BtnSalvar_Click(object sender, EventArgs e)
        {
            // A = A vencer, V = Vencido;

            cadastroVencMotorista = new InserirCadVencMotorista();
            cadVencMotorista      = new CadVencMototista();

            char status = 'A';

            try
            {
                if (DtpVencimento.Value.Date < DateTime.Now.Date)
                {
                    status = 'V';
                }

                cadVencMotorista.ID_Motorista    = new CadMotorista();
                cadVencMotorista.ID_Motorista.ID = ID_Motorista;
                cadVencMotorista.Vencimento      = DateTime.Parse(DtpVencimento.Text);
                cadVencMotorista.Status          = status.ToString();
                cadastroVencMotorista.CadastrarVencMotorista(cadVencMotorista);
                GridListaVencimento();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName);
            }
        }
        public bool CadastrarVencMotorista(CadVencMototista cadVencMotorista)
        {
            conexaoBancoDados = new DB();
            SQL = "INSERT INTO tblVencimentoMotorista (DataVencimento, ID_Motorista, Status)" +
                  "VALUES(@DataVencimento, @ID_Motorista, @Status)";

            try
            {
                conexaoBancoDados.LimparParametros();
                conexaoBancoDados.AdicionarParametros("@DataVencimento", cadVencMotorista.Vencimento);
                conexaoBancoDados.AdicionarParametros("@ID_Motorista", cadVencMotorista.ID_Motorista.ID);
                conexaoBancoDados.AdicionarParametros("@Status", cadVencMotorista.Status);

                conexaoBancoDados.Executar(CommandType.Text, SQL);
                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }