public void updateEmployee(Employee employee, string surname, string firstname, DateTime dob, DateTime employedAt, int salary, Service service = null, Employee chief = null) { object[] saved =new object[7]; saved[0] = employee.Firstname; saved[1] = employee.Surname; saved[2] = employee.DOB; saved[3] = employee.EmployedAt; saved[4] = employee.Service; saved[5] = employee.Chief; saved[6] = employee.Salary; try { employee.Firstname = firstname; employee.Surname = surname; employee.DOB= dob; employee.EmployedAt = employedAt; employee.Service = service; employee.Chief = chief; employee.Salary = salary; } catch (Exception e) { employee.Firstname = (string)saved[0]; employee.Surname = (string)saved[1]; employee.DOB = (DateTime)saved[2]; employee.EmployedAt = (DateTime)saved[3]; employee.Service = (Service)saved[4]; employee.Chief = (Employee)saved[5]; employee.Salary = (int)saved[6]; throw e; } if (null != evtUpdateEmployee) evtUpdateEmployee(service, EventArgs.Empty); }
public bool deleteService(Service service) { if (null != service) { try { IDbConnection cn = Database.connection(); IDbCommand cmd = cn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "delete from services where code=@code and not exists(select * from employees where employees.service = services.Code);"; IDataParameter p = cmd.CreateParameter(); p.ParameterName = "@code"; p.DbType = DbType.String; p.Value = service.Code; cmd.Parameters.Add(p); cmd.ExecuteNonQuery(); EmployeeStore.Instance.getEmployees().RemoveAll((e) => { return e.Service.Code == service.Code; }); } catch (Exception e) { throw e; } return _lst.Remove(service); ; } return false; }
public Service addService(string code, string label) { Service service = null; try { service = new Service(code, label); IDbConnection cn = Database.connection(); IDbCommand cmd = cn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "insert into services values(@code,@label)"; IDataParameter p = cmd.CreateParameter(); p.DbType = DbType.String; p.Value = service.Code; p.ParameterName = "@code"; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@label"; p.DbType = DbType.String; p.Value = service.Label; cmd.Parameters.Add(p); if(1 == cmd.ExecuteNonQuery()) _lst.Add(service); else service =null; } catch (Exception e) { throw e; } return service; }
public Employee addEmployee(string surname, string firstname, DateTime dob, DateTime employedAt,int salary, Service service = null, Employee chief = null) { //implement storage Employee emp = EmployeeStore.Instance.addEmployee(surname, firstname, dob, employedAt, salary, service, chief); this.Employees.Add(emp); return emp; }
public static Employee addEmployee(string surname, string firstname, DateTime dob, DateTime employedAt, int salary, Service service = null, Employee chief = null) { Employee employee; //implement storage _lst.Add(employee = new Employee(surname, firstname, dob, employedAt, salary, service, chief)); return employee; }
public static bool deleteService(Service target) { Service targetService = target; if (null != targetService) { _lst.Remove(targetService); return true; } return false; }
public static Service addService(string code, string label) { Service service = null; try { _lst.Add(service = new Service(code, label)); } catch (Exception e) { throw e; } return service; }
public static void updateService(Service service, string code, string label) { try { service.memorize(); service.Code = code; service.Label = label; } catch (Exception e) { service.restore(); throw e; } }
/// <summary> /// Dedicated constructor /// throw Exception /// </summary> /// <param name="id"></param> /// <param name="surname"></param> /// <param name="firstname"></param> /// <param name="dob"></param> /// <exception cref="Exception"></exception> public Employee(Guid id, string surname, string firstname, DateTime dob, DateTime employedAt, int salary, Service service = null, Employee chief = null) : base(id, surname, firstname, dob) { try { EmployedAt = employedAt; Salary = salary; Chief = chief; Service = service; } catch (Exception e) { throw e; } }
public void updateEmployee(Employee employee, string surname, string firstname, DateTime dob, DateTime employedAt, int salary, Service service = null, Employee chief = null) { object[] saved = new object[7]; saved[0] = employee.Firstname; saved[1] = employee.Surname; saved[2] = employee.DOB; saved[3] = employee.EmployedAt; saved[4] = employee.Service; saved[5] = employee.Chief; saved[6] = employee.Salary; try { employee.Firstname = firstname; employee.Surname = surname; employee.DOB = dob; employee.EmployedAt = employedAt; employee.Service = service; employee.Chief = chief; employee.Salary = salary; } catch (Exception e) { employee.Firstname = (string)saved[0]; employee.Surname = (string)saved[1]; employee.DOB = (DateTime)saved[2]; employee.EmployedAt = (DateTime)saved[3]; employee.Service = (Service)saved[4]; employee.Chief = (Employee)saved[5]; employee.Salary = (int)saved[6]; throw e; } try { IDbConnection cn = Database.connection(); IDbCommand cmd = cn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "update employees set surname = @surname,firstname = @firstname,dob =@dob,employedAt = @employedAt,salary = @salary,service = @service,chief = @chief where id=@id"; IDataParameter p = cmd.CreateParameter(); p.ParameterName = "@id"; p.DbType = DbType.Guid; p.Value = employee.ID; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.DbType = DbType.String; p.Value = employee.Surname; p.ParameterName = "@surname"; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@firstname"; p.DbType = DbType.String; p.Value = employee.Firstname; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@dob"; p.DbType = DbType.DateTime; p.Value = employee.DOB; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@employedAt"; p.DbType = DbType.DateTime; p.Value = employee.EmployedAt; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@salary"; p.DbType = DbType.Int32; p.Value = employee.Salary; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@service"; p.DbType = DbType.StringFixedLength; if (null != employee.Service) p.Value = employee.Service.Code; else p.Value = DBNull.Value; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@chief"; p.DbType = DbType.Guid; if (null != employee.Chief) p.Value = employee.Chief.ID; else p.Value = DBNull.Value; cmd.Parameters.Add(p); cmd.ExecuteNonQuery(); } catch (Exception e) { throw e; } }
/// <summary> /// Create an employee /// throw Exception /// </summary> /// <param name="id"></param> /// <param name="surname"></param> /// <param name="firstname"></param> /// <param name="dob"></param> /// <exception cref="Exception"></exception> public Employee(string surname, string firstname, DateTime dob, DateTime employedAt,int salary, Service service = null, Employee chief = null) : this(Guid.NewGuid(), surname, firstname, dob, employedAt,salary,service,chief) { }
public Employee addEmployee(string surname, string firstname, DateTime dob, DateTime employedAt,int salary, Service service = null, Employee chief = null) { //implement storage return EmployeeStore.addEmployee(surname, firstname, dob, employedAt, salary, service, chief); ; }
public frmService() { InitializeComponent(); this.btnAdd.Tag = this.btnQuit.Tag = ScreenModes.Stateless | ScreenModes.Selection; this.btnValidate.Tag = this.btnCancel.Tag = ScreenModes.Creation | ScreenModes.Updating; this.btnNext.Tag = this.btnPrevious.Tag = ScreenModes.Selection; this.btnDel.Tag = ScreenModes.Selection; this.txtCode.Tag = this.txtLabel.Tag = ScreenModes.Selection | ScreenModes.Creation | ScreenModes.Updating; this.lstService.Tag = ScreenModes.Selection; this.lstService.MouseMove +=(object sender, MouseEventArgs e) => { if (e.Button == System.Windows.Forms.MouseButtons.Left) { System.Diagnostics.Debug.WriteLine((Service)this.lstService.SelectedItem); this.lstService.DoDragDrop((Service)this.lstService.SelectedItem, DragDropEffects.Link); } }; this.btnAdd.Click += (object sender, EventArgs e) => { this.txtCode.Text = this.txtLabel.Text = ""; _Mode = ScreenModes.Creation; }; this.btnDel.Click += (object sender, EventArgs e) => { _delete(); }; this.ep.SetIconAlignment(this.txtLabel, ErrorIconAlignment.MiddleRight); this.ep.SetIconPadding(this.txtLabel, 2); this.btnValidate.Click += (object sender, EventArgs e) => { _validate(); }; EventHandler evt = (object sender, EventArgs e) => { if(ScreenModes.Selection == _Mode) _Mode = ScreenModes.Updating; }; this.txtCode.GotFocus += evt; this.txtLabel.GotFocus += evt; this.lstService.SelectedIndexChanged += (object sender, EventArgs e) => { _selectedService = (Service)this.lstService.SelectedItem; _displayService(); }; this.btnNext.Click += (object sender, EventArgs e) => { _navigate(1); }; this.btnPrevious.Click += (object sender, EventArgs e) => { _navigate(-1); }; this.btnCancel.Click += (object sender, EventArgs e) => { _setStatelessOrSelection(); _displayService(); }; this.btnQuit.Click += (object sender, EventArgs e) => { this.Close(); }; foreach (Service s in ServiceController.Instance.Services) this.lstService.Items.Add(s); if(0<this.lstService.Items.Count) this.lstService.SetSelected(0, true); _setStatelessOrSelection(); }
public Employee addEmployee(string surname, string firstname, DateTime dob, DateTime employedAt,int salary, Service service = null, Employee chief = null) { Employee employee; this.Employees.Add(employee = new Employee(surname, firstname, dob, employedAt,salary,service, chief)); return employee; }
private void _delete() { if (null != _selectedService) { ServiceController.Instance.deleteService(_selectedService); int i = this.lstService.SelectedIndex; this.lstService.Items.Remove(_selectedService); _selectedService = null; if (0 == this.lstService.Items.Count) _displayService(); else if (this.lstService.Items.Count <= i) this.lstService.SelectedIndex = i - 1; else this.lstService.SelectedIndex = i; _setStatelessOrSelection(); } }
private void _validate() { this.ep.SetError(this.txtLabel, ""); if (_Mode == ScreenModes.Creation) { try { _selectedService = ServiceController.Instance.addService(this.txtCode.Text, this.txtLabel.Text); } catch (Exception ex) { if (ex.Message.ToLower().Contains("code")) { this.txtCode.Focus(); } else if (ex.Message.ToLower().Contains("label")) { this.txtLabel.Focus(); } this.ep.SetError(this.txtLabel, ex.Message); return; } this.lstService.Items.Insert(0, _selectedService); this.lstService.SelectedItem = _selectedService; } else { Service updatingService = _selectedService; try { ServiceController.Instance.updateService(updatingService, this.txtCode.Text, this.txtLabel.Text); } catch (Exception ex) { if (ex.Message.ToLower().Contains("code")) { this.txtCode.Focus(); } else if (ex.Message.ToLower().Contains("label")) { this.txtLabel.Focus(); } this.ep.SetError(this.txtLabel, ex.Message); return; } int pos = this.lstService.SelectedIndex; this.lstService.Items.RemoveAt(pos); this.lstService.Items.Insert(ServiceController.Instance.Services.BinarySearch(_selectedService), updatingService); this.lstService.SelectedItem = updatingService; } _Mode = ScreenModes.Selection; }
public List<Service> getServices() { if (0 >= _lst.Count) { IDbConnection cn = Database.connection(); IDbCommand cmd = cn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from services"; IDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Service service = new Service( reader.GetString(reader.GetOrdinal("code")), reader.GetString(reader.GetOrdinal("label")) ); _lst.Add(service); } } return _lst; }
public void updateEmployee(Employee employee, string surname, string firstname, DateTime dob, DateTime employedAt, int salary, Service service = null, Employee chief = null) { EmployeeStore.Instance.updateEmployee(employee,surname,firstname,dob,employedAt,salary,service,chief); if (null != evtUpdateEmployee) evtUpdateEmployee(service, EventArgs.Empty); }
public Employee addEmployee(string surname, string firstname, DateTime dob, DateTime employedAt, int salary, Service service = null, Employee chief = null) { Employee employee; //implement storage try { employee = new Employee(surname, firstname, dob, employedAt, salary, service, chief); IDbConnection cn = Database.connection(); IDbCommand cmd = cn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "insert into employees(id, surname, firstname, dob, employedAt, salary, service, chief) values(@id,@surname,@firstname,@dob,@employedAt,@salary,@service,@chief)"; IDataParameter p = cmd.CreateParameter(); p.ParameterName = "@id"; p.DbType = DbType.Guid; p.Value = employee.ID; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.DbType = DbType.String; p.Value = employee.Surname; p.ParameterName = "@surname"; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@firstname"; p.DbType = DbType.String; p.Value = employee.Firstname; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@dob"; p.DbType = DbType.DateTime; p.Value = employee.DOB; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@employedAt"; p.DbType = DbType.DateTime; p.Value = employee.EmployedAt; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@salary"; p.DbType = DbType.Int32; p.Value = employee.Salary; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@service"; p.DbType = DbType.String; if (null != employee.Service) p.Value = employee.Service.Code; else p.Value = DBNull.Value; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@chief"; p.DbType = DbType.Guid; if (null != employee.Chief) p.Value = employee.Chief.ID; else p.Value = DBNull.Value; cmd.Parameters.Add(p); if(1 == cmd.ExecuteNonQuery()) _lst.Add(employee); else employee =null; } catch (Exception e) { throw e; } return employee; }
public static void setMemento(Service service) { _service = service.Clone() as Service; }
public void updateService(Service service, string code, string label) { string targetcode = service.Code; try { service.memorize(); service.Code = code; service.Label = label; } catch (Exception e) { service.restore(); throw e; } try { IDbConnection cn = Database.connection(); IDbCommand cmd = cn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "update services set code = @code,label = @label where code=@targetcode"; IDataParameter p = cmd.CreateParameter(); p.DbType = DbType.String; p.Value = targetcode; p.ParameterName = "@targetcode"; cmd.Parameters.Add(p); p.DbType = DbType.String; p.Value = service.Code; p.ParameterName = "@code"; cmd.Parameters.Add(p); p = cmd.CreateParameter(); p.ParameterName = "@label"; p.DbType = DbType.String; p.Value = service.Label; cmd.Parameters.Add(p); if (1 == cmd.ExecuteNonQuery()) _lst.Add(service); else service = null; } catch (Exception e) { throw e; } }