Commit 61966d53 authored by Fedepa's avatar Fedepa
Browse files

boton que conecta, lanzamiento de excepciones en logica

parent 30ae042a
Pipeline #183 skipped
......@@ -19,7 +19,14 @@ namespace BusinessLogicLayer
public void AddEmployee(Employee emp)
{
_dal.AddEmployee(emp);
try
{
_dal.AddEmployee(emp);
}
catch(Exception ex)
{
throw ex;
}
}
public void DeleteEmployee(int id)
......
......@@ -9,8 +9,22 @@ namespace DataAccessLayer
{
public class DALEmployeesEF : IDALEmployees
{
protected void controlEmployeeArguments(Employee emp)
{
var error = "";
if (emp.Name == null || emp.Name.Trim() == String.Empty)
{
error += "- El nombre no puede ser vacío\n";
}
if (emp.StartDate == null)
error += "- La fecha no puede ser vacía\n";
if (error != "")
throw new ArgumentNullException(error);
}
public void AddEmployee(Employee emp)
{
controlEmployeeArguments(emp);
using (var context = new Model.tsi_pr1Entities())
{
Model.Employee e = this.toModel(emp);
......
......@@ -31,25 +31,30 @@ namespace PresentationLayerWinform
private void button1_Click(object sender, EventArgs e)
{
Employee newemp = null;
if (medioT.Checked) {
newemp = new PartTimeEmployee();
((PartTimeEmployee)newemp).HourlyRate = (double) empSal.Value;
}
else if (compT.Checked) {
newemp = new FullTimeEmployee();
((FullTimeEmployee)newemp).Salary = (int)empSal.Value;
try {
if (medioT.Checked) {
newemp = new PartTimeEmployee();
((PartTimeEmployee)newemp).HourlyRate = (double)empSal.Value;
}
else if (compT.Checked) {
newemp = new FullTimeEmployee();
((FullTimeEmployee)newemp).Salary = (int)empSal.Value;
}
if (newemp != null)
{
newemp.Name = empNom.Text;
newemp.StartDate = empDate.Value;
IBLEmployees i = new BLEmployees(new DALEmployeesEF());
i.AddEmployee(newemp);
this.Close();
_e.ListEmployees();
}
}
if(newemp != null)
catch(Exception ex)
{
newemp.Name = empNom.Text;
newemp.StartDate = empDate.Value;
IBLEmployees i = new BLEmployees(new DALEmployeesEF());
i.AddEmployee(newemp);
this.Close();
_e.ListEmployees();
}
}
private void Bback_Click(object sender, EventArgs e)
......
......@@ -31,6 +31,7 @@
this.components = new System.ComponentModel.Container();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.employeeBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.AddEmpBtn = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.employeeBindingSource)).BeginInit();
this.SuspendLayout();
......@@ -40,11 +41,12 @@
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(26, 82);
this.dataGridView1.Location = new System.Drawing.Point(11, 30);
this.dataGridView1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.ReadOnly = true;
this.dataGridView1.RowTemplate.Height = 24;
this.dataGridView1.Size = new System.Drawing.Size(952, 292);
this.dataGridView1.Size = new System.Drawing.Size(714, 237);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
//
......@@ -52,13 +54,23 @@
//
this.employeeBindingSource.DataSource = typeof(Shared.Entities.Employee);
//
// AddEmpBtn
//
this.AddEmpBtn.Location = new System.Drawing.Point(428, 292);
this.AddEmpBtn.Name = "AddEmpBtn";
this.AddEmpBtn.Size = new System.Drawing.Size(75, 23);
this.AddEmpBtn.TabIndex = 1;
this.AddEmpBtn.Text = "Agregar empleado";
this.AddEmpBtn.UseVisualStyleBackColor = true;
this.AddEmpBtn.Click += new System.EventHandler(this.AddEmpBtn_Click);
//
// EmployeeList
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1021, 401);
this.ClientSize = new System.Drawing.Size(766, 345);
this.Controls.Add(this.AddEmpBtn);
this.Controls.Add(this.dataGridView1);
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.Name = "EmployeeList";
this.Text = "EmployeeList";
this.Load += new System.EventHandler(this.EmployeeList_Load);
......@@ -72,6 +84,7 @@
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.BindingSource employeeBindingSource;
private System.Windows.Forms.Button AddEmpBtn;
}
}
......@@ -55,5 +55,15 @@ namespace PresentationLayerWinform
{
}
private void AddEmpBtn_Click(object sender, EventArgs e)
{
var frm = new EmployeeAddEdit(this);
frm.Show();
frm.Location = this.Location;
frm.StartPosition = FormStartPosition.Manual;
frm.FormClosing += delegate { this.Show(); };
this.Hide();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment