Esempio n. 1
0
        private void btnApplyBonus_Click(object sender, EventArgs e)
        {
            try
            {
                //Gets the employee IDs selected in the grid
                var empIdList = new List <int>();
                foreach (DataGridViewRow row in dgvEmployees.Rows)
                {
                    if (row.Cells["Chk"].Value != null && (bool)row.Cells["Chk"].Value == true)
                    {
                        empIdList.Add(employeeList[row.Index].EmployeeId);
                    }
                }

                if (empIdList.Count == 0)
                {
                    throw new DataException("No employees selected.");
                }

                //Validates the entry
                checkBonusEntry();

                //Create Bonus
                var BonusObj = Bonus.Create();

                //Get the effective date
                var effectiveDate = Convert.ToDateTime(cmbEffectiveDate.SelectedItem);
                BonusObj.EffectiveDate = effectiveDate;

                if (cmbBonusType.SelectedIndex == 0) //Percent
                {
                    //Gets the percent increase amount
                    var increasePercent = nudPercent.Value / 100;
                    BonusObj.PercentBonus = increasePercent;
                }
                else
                {
                    //Gets the fixed amount
                    var fixedAmount = Convert.ToDecimal(txtFixedBonus.Text);
                    BonusObj.FixedBonus = fixedAmount;
                }

                //Apply increase
                if (BonusCUD.Create(empIdList, BonusObj))
                {
                    MessageBox.Show("Bonus applied successful.");
                    bonusPending.Add(BonusObj);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }