Beispiel #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);
            }
        }
Beispiel #2
0
 private void dgvBonusPending_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.ColumnIndex == dgvBonusPending.Columns["DeleteBonus"].Index)
         {
             DialogResult = MessageBox.Show("Are you sure you want to remove this bonus?", "Confirm", MessageBoxButtons.OKCancel);
             if (DialogResult == DialogResult.OK)
             {
                 //Delete the bonus
                 if (BonusCUD.DeleteSingleBonusByEmpId(
                         Convert.ToInt32(txtEmpIdDisplay.Text), bonusPending[e.RowIndex].BonusId))
                 {
                     bonusPending.RemoveAt(e.RowIndex);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }