Example #1
0
 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);
 }
Example #2
0
 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;
 }
Example #3
0
 public bool deleteEmployee(Employee target)
 {
     if (null != target)
     {
         return EmployeeStore.deleteEmployee(target);
     }
     return false;
 }
Example #4
0
 public bool deleteEmployee(Employee target)
 {
     if (null != target)
     {
         return this.Employees.Remove(target);
     }
     return false;
 }
Example #5
0
 public static bool deleteEmployee(Employee target)
 {
     if (null != target)
     {
         return _lst.Remove(target);
     }
     return false;
 }
Example #6
0
 public void addEmployee(Employee employee)
 {
     if (_cursor >= _employees.Length)
     {
         throw new Exception("No space left in the array of employees");
     }
     _employees[_cursor++] = employee;
 }
Example #7
0
        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;
        }
Example #8
0
 public bool deleteEmployee(Employee target)
 {
     if (null != target)
     {
         this.Employees.Remove(target);
         return EmployeeStore.Instance.deleteEmployee(target);
     }
     return false;
 }
Example #9
0
        /// <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;
            }
        }
Example #10
0
        private void _delete()
        {
            if (null != _selectedEmployee)
            {
                EmployeeController.Instance.deleteEmployee(_selectedEmployee);
                if (_cursor > EmployeeController.Instance.Employees.Count - 1)
                    _cursor--;
                if(-1<_cursor)_selectedEmployee = EmployeeController.Instance.Employees.ElementAt(_cursor);

                _setStatelessOrSelection();

            }
        }
Example #11
0
        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;
            }
        }
Example #12
0
 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;
 }
Example #13
0
 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);
 }
Example #14
0
        public List<Employee> getEmployees()
        {
            if (0 >= _lst.Count)
            {
                IDbConnection cn = Database.connection();
                IDbCommand cmd = cn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from employees order by id asc;";
                IDataReader reader = cmd.ExecuteReader();
                List<Service> services = ServiceStore.Instance.getServices();
                List<Guid> chiefs = new List<Guid>();
                while (reader.Read())
                {
                    Service service = reader.IsDBNull(reader.GetOrdinal("service")) ? null : services.Find((Service s) =>
                    {
                        return (s.Code == reader.GetString(reader.GetOrdinal("service")));
                    });
                    Employee emp = new Employee(
                        reader.GetGuid(reader.GetOrdinal("id")),
                        reader.GetString(reader.GetOrdinal("surname")),
                        reader.IsDBNull(reader.GetOrdinal("firstname")) ? null : reader.GetString(reader.GetOrdinal("firstname")),
                        reader.GetDateTime(reader.GetOrdinal("dob")),
                        reader.GetDateTime(reader.GetOrdinal("employedAt")),
                        (int)reader.GetDecimal(reader.GetOrdinal("salary")),
                        service,
                        null
                        );

                    chiefs.Add(reader.IsDBNull(reader.GetOrdinal("chief")) ? Guid.NewGuid() : reader.GetGuid(reader.GetOrdinal("chief")));
                    _lst.Add(emp);
                }
                //link chief with employee objects
                int cpt = 0;
                foreach (Employee emp in _lst)
                {
                    emp.Chief = _lst.Find((Employee e) =>
                    {
                        return e.ID == chiefs.ElementAt(cpt);
                    });
                    cpt++;
                }

            }
            return _lst;
        }
Example #15
0
        private void _switchScreenMode()
        {
            foreach (ToolStripItem it in this.tsEmployee.Items)
                if (it is ToolStripButton) it.Enabled = ((ScreenModes)it.Tag & _Mode) > 0;
            this.navBar.LinkEnabled = ((ScreenModes)this.navBar.Tag & _Mode) > 0;
            this.lblServiceValue.AllowDrop = this.lblService.Enabled;

            switch (_Mode)
            {
                case ScreenModes.Selection:
                    _selectedEmployee = EmployeeController.Instance.Employees.ElementAt(_cursor);
                    this.navBar.Focus();
                break;
                case ScreenModes.Stateless:
                case ScreenModes.Creation:
                    _selectedEmployee = null;
                    break;
                case ScreenModes.Updating:
                    break;
                default:
                    break;
            }
            _displayEmployee();
        }
Example #16
0
        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); ;
        }
Example #17
0
 /// <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)
 {
 }
Example #18
0
        private static XmlElement buildEmployeeNode(Employee emp,XmlDocument doc)
        {
            XmlElement e= doc.CreateElement("Employee");
            XmlAttribute attr = doc.CreateAttribute("ID");
            attr.Value = emp.ID.ToString();
            e.Attributes.Append(attr);
            if (null != emp.Chief)
            {
                attr = doc.CreateAttribute("Chief");
                attr.Value = emp.Chief.ID.ToString();
                e.Attributes.Append(attr);
            }

            attr = doc.CreateAttribute("Service");
            attr.Value = emp.Service.Code;
            e.Attributes.Append(attr);

            e.InnerXml = "<Surname>" + emp.Firstname.escapeXmlString() + "</Surname>"
                + "<Firstname>" + emp.Firstname.escapeXmlString() +  "</Firstname>"
                + "<DOB>" + emp.DOB.ToString().escapeXmlString() + "</DOB>"
                + "<EmployedAt>" + emp.EmployedAt.ToString().escapeXmlString() + "</EmployedAt>"
                + "<Salary>" + emp.Salary.ToString().escapeXmlString() + "</Salary>"
            ;

            return e;
        }
Example #19
0
        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;
        }
Example #20
0
        public frmEmployee()
        {
            InitializeComponent();
            this.navBar.Focus();
            if (0 < EmployeeController.Instance.Employees.Count)
            {
                _cursor = 0;
            }

            this.cmbChief.DataSource = EmployeeController.Instance.Employees;
            this.cmbChief.DisplayMember = "Fullname";

            this.tsbAdd.Tag = this.tsbClose.Tag = ScreenModes.Stateless | ScreenModes.Selection;
            this.tsbValidate.Tag = this.tsbCancel.Tag = ScreenModes.Creation | ScreenModes.Updating;
            this.navBar.Tag = ScreenModes.Selection;
            this.tsbDel.Tag = ScreenModes.Selection;
            this.nudSalary.Tag = this.lblService.Tag = this.txtFirstname.Tag = this.txtSurname.Tag = this.dtDOB.Tag = this.dtEmployedAt.Tag = ScreenModes.Selection | ScreenModes.Creation | ScreenModes.Updating;
            this.lblServiceValue.AllowDrop = true;
            this.lblServiceValue.DragEnter += (object sender, DragEventArgs e) =>
            {
                e.Effect = DragDropEffects.Link;
            };

            this.lblServiceValue.DragDrop += (object sender, DragEventArgs e) =>
            {
                Service item = (Service)e.Data.GetData(typeof(Service));
                ((Label)sender).Text = item.ToString();
                ((Label)sender).Tag = item;
                if (ScreenModes.Selection == _Mode) _Mode = ScreenModes.Updating;
            };

            EventHandler evt = (object sender, EventArgs e) =>
            {
                if (ScreenModes.Selection == _Mode) _Mode = ScreenModes.Updating;
            };
            this.txtSurname.GotFocus += evt;
            this.txtFirstname.GotFocus += evt;
            this.cmbChief.GotFocus += evt;
            this.dtDOB.GotFocus += evt;
            this.dtEmployedAt.GotFocus += evt;
            this.nudSalary.GotFocus += evt;

            this.tsbAdd.Click += (object sender, EventArgs e) =>
            {
                _Mode = ScreenModes.Creation;
            };
            this.tsbDel.Click += (object sender, EventArgs e) =>
            {
                _delete();
            };
            this.tsbValidate.Click += (object sender, EventArgs e) =>
            {
                _validate();
            };
            this.tsbCancel.Click += (object sender, EventArgs e) =>
            {
                _setStatelessOrSelection();
                _displayEmployee();
            };
            this.tsbClose.Click += (object sender, EventArgs e) =>
            {
                this.Close();
            };

            this.navBar.Navigation += (object sender, NavigationBar.NavigationBarEventArgs e) =>
            {
                switch (e.NavigationBarEvent)
                {
                    case NavigationBar.NavigationBarEvent.First:
                        _cursor = 0;
                        break;
                    case NavigationBar.NavigationBarEvent.Prev:
                        _cursor = _cursor > 0 ? --_cursor : EmployeeController.Instance.Employees.Count - 1;
                        break;
                    case NavigationBar.NavigationBarEvent.Next:
                        _cursor = _cursor < EmployeeController.Instance.Employees.Count - 1 ? ++_cursor : 0;
                        break;
                    case NavigationBar.NavigationBarEvent.Last:
                        _cursor = EmployeeController.Instance.Employees.Count - 1;
                        break;
                    default:
                        break;
                }
                _selectedEmployee = EmployeeController.Instance.Employees.ElementAt(_cursor);
                _displayEmployee();
            };
            _setStatelessOrSelection();
        }
Example #21
0
        public bool deleteEmployee(Employee employee)
        {
            if (null != employee)
            {
                IDbConnection cn = Database.connection();
                IDbCommand cmd = cn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "update employees set chief = null where id=@id;delete from employees where id=@id;";
                IDataParameter p = cmd.CreateParameter();
                p.ParameterName = "@id";
                p.DbType = DbType.Guid;
                p.Value = employee.ID;
                cmd.Parameters.Add(p);

                return _lst.Remove(employee);
            }

            return false;
        }