public FormSalariesEdit(EmployerRepository repositoryOfEmployee)
        {
            InitializeComponent();

            salRepo      = new SalaryRepository();
            ss           = new SoloSalary();
            this.empRepo = repositoryOfEmployee;
            monthCalendarUntil.SetDate(DateTime.Today.AddYears(1)); //add default end date
            comboBoxEmp.DataSource    = empRepo.getComboBoxSource();
            comboBoxEmp.DisplayMember = "Name3";                    //changing by event
            comboBoxEmp.ValueMember   = "ID";
            comboBoxEmp.SelectedIndex = -1;                         //not implicitely touch other users
        }
        public FormSalariesEdit(SalaryRepository salariesRepo, EmployerRepository employeesRepo, int v)
        {
            InitializeComponent();
            this.salRepo          = salariesRepo;
            this.empRepo          = employeesRepo;
            this.SelectedSalIndex = v;
            ss = new SoloSalary();
            ss = salRepo.SelectById(SelectedSalIndex);

            labelID.Text = String.Format("ID of salary record: {0}", SelectedSalIndex);

            comboBoxEmp.DataSource    = empRepo.getComboBoxSource();
            comboBoxEmp.DisplayMember = "Name3";                         //changing to full name by event
            comboBoxEmp.ValueMember   = "ID";
            comboBoxEmp.SelectedValue = empRepo.SelectById(ss.IDemp).ID; //select ID where sal.IDemp = emp.IDemp

            numericUpDownAm.Value = (decimal)ss.Amount;
            monthCalendarFrom.SetDate(ss.validFrom);
            monthCalendarUntil.SetDate(ss.validUntil);
        }
        public void RefreshGui()
        {
            dpmRepo.GetAll();
            List <SoloDepartment> departments = dpmRepo.GetAll().ToList();

            empRepo.GetAll();
            List <SoloEmployer> employees = empRepo.GetAll().ToList();

            salRepo.GetAll();
            List <SoloSalary> salaries = salRepo.GetAll().ToList();

            if (empRepo == null && dpmRepo == null && salRepo == null)
            {
                return; //negated protection as in other forms
            }

            int selectedRowComfortGui; //for user comfort

            try
            {
                //multiselect should be take in account
                selectedRowComfortGui = repDataGridView.CurrentCell.RowIndex;
            }
            catch
            {
                selectedRowComfortGui = 0;
            }

            repDataGridView.ClearSelection(); //cleaning previos search
            repDataGridView.Columns.Clear();  //cleaning previous content
            repDataGridView.Rows.Clear();     //cleaning previous content

            /*
             * I dont want to refactor this code, but better way how to use object model is shown in part Refresh stats
             */

            //columns headers
            DataGridViewColumn d1 = new DataGridViewTextBoxColumn();

            d1.HeaderText = "ID employee";
            d1.ReadOnly   = true;
            d1.Visible    = false;
            d1.SortMode   = DataGridViewColumnSortMode.Automatic;
            DataGridViewColumn d2 = new DataGridViewTextBoxColumn();

            d2.HeaderText = "First name";
            d2.SortMode   = DataGridViewColumnSortMode.Automatic;
            DataGridViewColumn d3 = new DataGridViewTextBoxColumn();

            d3.HeaderText = "Middle name";
            d3.SortMode   = DataGridViewColumnSortMode.Automatic;
            DataGridViewColumn d4 = new DataGridViewTextBoxColumn();

            d4.HeaderText = "Last name";
            d4.SortMode   = DataGridViewColumnSortMode.Automatic;
            DataGridViewColumn d5 = new DataGridViewTextBoxColumn();

            d5.HeaderText = "Email contact";
            d5.SortMode   = DataGridViewColumnSortMode.Automatic;
            d5.Visible    = false;
            DataGridViewColumn d6 = new DataGridViewComboBoxColumn();

            d6.HeaderText = "Department";
            d6.SortMode   = DataGridViewColumnSortMode.Automatic;

            DataGridViewColumn d7 = new DataGridViewTextBoxColumn();

            d7.HeaderText = "Salary value";
            d7.SortMode   = DataGridViewColumnSortMode.Automatic;
            DataGridViewColumn d8 = new DataGridViewTextBoxColumn();

            d8.HeaderText = "Valid from";
            d8.SortMode   = DataGridViewColumnSortMode.Automatic;

            DataGridViewColumn d9 = new DataGridViewTextBoxColumn();

            d9.HeaderText = "Valid to";
            d9.SortMode   = DataGridViewColumnSortMode.Automatic;

            repDataGridView.Columns.AddRange(d1, d2, d3, d4, d5, d6, d7, d8, d9);

            foreach (SoloEmployer emp in employees)
            {
                var row = new DataGridViewRow();
                row.Cells.Add(new DataGridViewTextBoxCell {
                    Value = emp.ID
                });
                row.Cells.Add(new DataGridViewTextBoxCell {
                    Value = emp.Name1
                });
                row.Cells.Add(new DataGridViewTextBoxCell {
                    Value = emp.Name2
                });
                row.Cells.Add(new DataGridViewTextBoxCell {
                    Value = emp.Name3
                });
                row.Cells.Add(new DataGridViewTextBoxCell {
                    Value = emp.Email
                });

                DataGridViewComboBoxCell dgvCB = new DataGridViewComboBoxCell();
                dgvCB.DataSource    = dpmRepo.getComboBoxSource();
                dgvCB.Value         = emp.IDdmp;
                dgvCB.ValueMember   = "IDdpm";
                dgvCB.DisplayMember = "Name";
                row.Cells.Add(dgvCB); //comboBox to building row

                SoloSalary sa = new SoloSalary();
                foreach (SoloSalary ssa in salaries) //woraround, SELECT WHERE IDemp is not implicitely working
                {
                    if (ssa.IDemp == emp.ID)
                    {
                        sa = ssa;
                    }
                }
                row.Cells.Add(new DataGridViewTextBoxCell {
                    Value = sa.Amount
                });

                DateTime validFrom = sa.validFrom, validTo = sa.validUntil; //parsing datetime to be showed
                string   validFromUI, validToUI;
                if (validFrom == DateTime.MinValue || validTo == DateTime.MinValue)
                {
                    validFromUI = "";
                    validToUI   = "";
                }
                else
                {
                    validFromUI = validFrom.ToString(dateTimeFormat);
                    validToUI   = validTo.ToString(dateTimeFormat);
                }

                row.Cells.Add(new DataGridViewTextBoxCell {
                    Value = validFromUI
                });
                row.Cells.Add(new DataGridViewTextBoxCell {
                    Value = validToUI
                });

                repDataGridView.Rows.Add(row); //finalize row
            }

            repDataGridView.Rows[selectedRowComfortGui].Selected = true;

            RefreshStats();
        }