Exemple #1
0
        /// <summary>
        /// add new item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddOthers_Click(object sender, EventArgs e)
        {
            int    vacationId = 0;
            string vacationName;
            int    otherVacationId = Convert.ToInt32(this.OthersCombo.SelectedValue);
            int    commonVactionId = Convert.ToInt32(this.CommonCombo.SelectedValue);

            if ((otherVacationId >= 0 && commonVactionId < 0) || (commonVactionId >= 0 && otherVacationId < 0))
            {
                if (otherVacationId >= 0)
                {
                    vacationId   = Convert.ToInt32(this.OthersCombo.SelectedValue);
                    vacationName = this.OthersCombo.Text.ToString();
                }
                else
                {
                    vacationId   = Convert.ToInt32(this.CommonCombo.SelectedValue);
                    vacationName = this.CommonCombo.Text.ToString();
                }

                double   startCounter;
                double   endCounter;
                string   startDate = PickerforStart.Value.Date.ToShortDateString();
                string   endDate   = PickerforEnd.Value.Date.ToShortDateString();
                DateTime start     = Convert.ToDateTime((startDate + " " + StartTimeCombo.Text).ToString());
                DateTime end       = Convert.ToDateTime((endDate + " " + EndTimeCombo.Text).ToString());
                if (StartTimeCombo.SelectedIndex == 0)
                {
                    startCounter = 0;
                }
                else
                {
                    startCounter = -0.5;
                }

                if (EndTimeCombo.SelectedIndex == 0)
                {
                    endCounter = 0.5;
                }
                else
                {
                    endCounter = 1;
                }
                Single   day           = Convert.ToSingle(endCounter + startCounter);// LeaveDetails.Duration
                TimeSpan duration      = end.Date.Subtract(start.Date);
                Single   span          = 0;
                Single   totalday      = day + Convert.ToSingle(duration.TotalDays);
                Single   inputDuration = Convert.ToSingle(numericUpDownDuration.Value);
                Single   testForAnnualLeaveRemainDay = annualLeaveRemainDay;
                Single   testForSickLeaveRemainDay   = sickLeaveRemainDay;
                if (totalday > 0 || inputDuration != 0)
                {
                    switch (vacationId)
                    {
                    case 1:
                        if (inputDuration == 0)
                        {
                            testForAnnualLeaveRemainDay = annualLeaveRemainDay - totalday;
                            span = totalday;
                        }
                        else
                        {
                            testForAnnualLeaveRemainDay = annualLeaveRemainDay - inputDuration;
                            span = inputDuration;
                        }
                        break;

                    case 2:
                        if (inputDuration == 0)
                        {
                            testForSickLeaveRemainDay = sickLeaveRemainDay - totalday;
                            span = totalday;
                        }
                        else
                        {
                            testForSickLeaveRemainDay = sickLeaveRemainDay - inputDuration;
                            span = inputDuration;
                        }
                        break;

                    case 3:
                        if (inputDuration == 0)
                        {
                            span = totalday;
                        }
                        else
                        {
                            span = inputDuration;
                        }
                        showStaffInfo.Married = true;
                        StaffService staffService = new StaffService();
                        staffService.UpdateStaffInfor(showStaffInfo);
                        break;

                    case 4:
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                    default:
                        if (inputDuration == 0)
                        {
                            span = totalday;
                        }
                        else
                        {
                            span = inputDuration;
                        }
                        break;
                    }
                    if (testForAnnualLeaveRemainDay < -5 || testForSickLeaveRemainDay < 0)
                    {
                        MessageBox.Show("The vacation exceeds its limit", "Warning");
                    }
                    else
                    {
                        annualLeaveRemainDay = testForAnnualLeaveRemainDay;
                        sickLeaveRemainDay   = testForSickLeaveRemainDay;
                        LeaveType vacation = new LeaveType {
                            LeaveTypeId = vacationId, LeaveTypeName = vacationName
                        };
                        LeaveDetails newDetail = new LeaveDetails
                        {
                            StaffId     = showStaffInfo.StaffId,
                            LeaveTypeId = vacationId,
                            StartDate   = start,
                            EndDate     = end,
                            Duration    = span,
                            Remark      = textBoxRemark.Text.ToString(),
                            Leavings    = vacation,
                        };
                        LeaveDetailsService detailService = new LeaveDetailsService();
                        detailService.AddNewDetails(newDetail);
                        RequestHistory.DataSource = null;
                        allDetails.Clear();
                        detailsBindingList.Clear();

                        AssignDatatoList();
                        AddLeavingsAttributetoList(allDetails);
                        BindVactionDetails();
                        nCurrent    = 0;
                        pageCurrent = 0;
                        InitPagingList();
                    }
                }
                else
                {
                    MessageBox.Show("Please adjust the interval to fit with the requirement", "Error");
                }
            }
            else
            {
                MessageBox.Show("Please select a vacation type", "Warning");
            }
        }