I have a project that I'm developing in layers, so far I have the following: Access to data, presentation, business and transfer objects. The question is:
Example: I have form
to register a legal entity in the database. To save the data that the user entered in form
would be correct in this form
that the user entered the data I create a pessoaJuridica
object and pass this object to a class in the business layer with the name SalvaPessoaJuridica.cs
by example, does this in turn access the data access layer and write to the bank?
For every form
would I have to create a class to hold the data or would I already use the data access layer directly on the form and would I already keep the data without creating a class specific to each type of operation?
Example:
private void button1_Click(object sender, EventArgs e)
{
if (txtNome.Text == string.Empty || txtIdade.Text == string.Empty || txtEmail.Text == string.Empty)
{
MessageBox.Show("Informe os valores para nome, idade e email do aluno.");
return;
}
else
{
try
{
string sqlInsert = "Insert into Alunos (Nome,Idade,Email) values (@Nome,@Idade,@Email)";
string[] campos = { "@Nome", "@Idade", "@Email" };
string[] valores = { txtNome.Text, txtIdade.Text, txtEmail.Text };
accDB.Salvar(campos, valores, sqlInsert);
gdvDados.DataSource = accDB.getRegistro(sqlSelect);
}
catch (Exception ex)
{
MessageBox.Show("Erro " + ex.Message);
}
}
}
Or:
private void button1_Click(object sender, EventArgs e)
{
try
{
Alunos aluno = new Alunos();
aluno.Nome = "Teste";
aluno.Idade = 22;
aluno.Email = "[email protected]"
SalvaAluno salva = new SalvaAluno();
salva.Manter(aluno);
}
catch (Exception ex)
{
MessageBox.Show("Erro " + ex.Message);
}
}
}