Esempio n. 1
0
        /// <summary>
        /// Gets the vocatin details.
        /// </summary>
        /// <param name="staffId">The staff id.</param>
        public List <LeaveDetails> GetVacationDetails(int staffId)
        {
            int                 yearNow       = currentDate.Year;
            DateTime            startDate     = Convert.ToDateTime("1990-1-1");
            DateTime            endDate       = Convert.ToDateTime(yearNow + 1 + "-12-31");
            LeaveDetailsService detailService = new LeaveDetailsService();
            LeaveDetails        ld            = new LeaveDetails
            {
                StaffId   = staffId,
                StartDate = startDate,
                EndDate   = endDate
            };

            allDetails = detailService.ObtainLeaveDetailsByStaffId(ld);

            thisyearUALF         = 0;
            thisyearUALS         = 0;
            sickLeaveCounter     = 0;
            nopayLeaveCounter    = 0;
            marriageLeaveCounter = 0;
            maternityCounter     = 0;
            compassionateCounter = 0;
            paternityCounter     = 0;
            othersCounter        = 0;

            for (int i = 0; i < allDetails.Count; i++)
            {
                int      ID        = allDetails.ElementAt(i).LeaveTypeId;
                Single   dur       = allDetails.ElementAt(i).Duration;
                DateTime startdate = allDetails.ElementAt(i).StartDate;
                switch (ID)
                {
                case 1:
                    if (startdate >= janOneYear && startdate < MarOneYear)
                    {
                        thisyearUALF += dur;
                    }
                    else if (startdate >= MarOneYear && startdate < janOneYearAfter)
                    {
                        thisyearUALS += dur;
                    }
                    break;

                case 2:
                    if (startdate >= janOneYear && startdate < janOneYearAfter)
                    {
                        sickLeaveCounter += dur;
                    }
                    else if (startdate >= janOneLastYear && startdate < janOneYear)
                    {
                        lastyearUSL += dur;
                    }
                    break;

                case 3:
                    if (startdate >= janOneYear && startdate < janOneYearAfter)
                    {
                        nopayLeaveCounter += dur;
                    }
                    break;

                case 4:
                    marriageLeaveCounter += dur;
                    break;

                case 5:
                    maternityCounter += dur;
                    break;

                case 6:
                    compassionateCounter += dur;
                    break;

                case 7:
                    paternityCounter += dur;
                    break;

                case 8:
                    othersCounter += dur;
                    break;

                default:
                    break;
                }
            }
            return(allDetails);
        }
Esempio n. 2
0
        /// <summary>
        /// Prints all.
        /// </summary>
        /// <param name="dt">The dt.</param>
        public void printAll()
        {
            if (showStaffInfo.StaffId != 0)
            {
                try
                {
                    string         saveFileName = "";
                    SaveFileDialog saveDialog   = new SaveFileDialog();
                    saveDialog.DefaultExt = "xlsx";
                    saveDialog.FileName   = showStaffInfo.EmployeeId + "(" + showStaffInfo.StaffName + ")" + " Vacation Details" + DateTime.Today.ToString("yyyy-MM-dd");
                    saveDialog.ShowDialog();
                    saveFileName = saveDialog.FileName;
                    if (saveFileName.IndexOf(":") < 0)
                    {
                        return;
                    }

                    LeaveDetailsService leaveDetailsService = new LeaveDetailsService();

                    Excel.Application myExcel = new Excel.Application();
                    if (myExcel == null)
                    {
                        MessageBox.Show("Can not Create a Sheet! Make Sure your computer has installed the Excel!");
                        return;
                    }

                    myExcel.Application.Workbooks.Add(true);
                    myExcel.Visible = false;

                    Excel.Workbook  myBook  = myExcel.Workbooks[1];
                    Excel.Worksheet mySheet = myBook.Worksheets[1];
                    mySheet.Name = "Vacation Details";

                    for (int i = 1; i <= 5; i++)
                    {
                        mySheet.Columns[i].ColumnWidth         = 20;
                        mySheet.Columns[i].HorizontalAlignment = Excel.Constants.xlCenter;
                        mySheet.Columns[i].VerticalAlignment   = Excel.Constants.xlCenter;
                    }

                    mySheet.Range[mySheet.Cells[1, 1], mySheet.Cells[2, 5]].MergeCells = true;
                    mySheet.Range[mySheet.Cells[3, 4], mySheet.Cells[3, 5]].MergeCells = true;
                    mySheet.Range[mySheet.Cells[4, 4], mySheet.Cells[4, 5]].MergeCells = true;
                    mySheet.Cells[1, 1]           = showStaffInfo.StaffName + "'s Vacation Details";
                    mySheet.Cells[1, 1].Font.Size = 18;

                    mySheet.Cells[3, 1] = "EmployeeID:";
                    mySheet.Cells[3, 2] = showStaffInfo.EmployeeId;
                    mySheet.Cells[3, 3] = "Staff Name:";
                    mySheet.Cells[3, 4] = showStaffInfo.StaffName + "(" + showStaffInfo.ChineseName + ")";

                    mySheet.Cells[4, 1] = "Onboard Date:";
                    mySheet.Cells[4, 2] = showStaffInfo.OnboardDate;
                    mySheet.Cells[4, 3] = "Title:";
                    mySheet.Cells[4, 4] = showStaffInfo.Title;

                    int row = 5;
                    for (int i = yearNow; i >= showStaffInfo.OnboardDate.Year; i--)
                    {
                        Excel.Range range = mySheet.Range[mySheet.Cells[row, 1], mySheet.Cells[row + 1, 5]];
                        range.MergeCells                = true;
                        mySheet.Cells[row, 1]           = "Detailed records in " + i;
                        mySheet.Cells[row, 1].Font.Size = 16;


                        row = row + 2;

                        mySheet.Cells[row, 1] = "Leaving Type";
                        mySheet.Cells[row, 2] = "Start Date";
                        mySheet.Cells[row, 3] = "End Date";
                        mySheet.Cells[row, 4] = "Days Taken";
                        mySheet.Cells[row, 5] = "Remark";

                        DateTime     startDate = Convert.ToDateTime(i + "-1-1");
                        DateTime     endDate   = Convert.ToDateTime(i + 1 + "-1-1");
                        LeaveDetails ld        = new LeaveDetails
                        {
                            StaffId   = CurrentStaffId,
                            StartDate = startDate,
                            EndDate   = endDate
                        };

                        OneYearDetails = leaveDetailsService.ObtainLeaveDetailsByStaffId(ld);
                        AddLeavingsAttributetoList(OneYearDetails);

                        for (int j = 0; j < OneYearDetails.Count; j++)
                        {
                            int      ID        = OneYearDetails.ElementAt(j).LeaveTypeId;
                            Single   dur       = OneYearDetails.ElementAt(j).Duration;
                            DateTime startdate = OneYearDetails.ElementAt(j).StartDate;
                            DateTime enddate   = OneYearDetails.ElementAt(j).EndDate;
                            string   remarks   = OneYearDetails.ElementAt(j).Remark;
                            string   name      = OneYearDetails.ElementAt(j).Leavings.LeaveTypeName;

                            row += 1;
                            mySheet.Cells[row, 1] = name;
                            mySheet.Cells[row, 2] = startdate;
                            mySheet.Cells[row, 3] = enddate;
                            mySheet.Cells[row, 4] = dur;
                            mySheet.Cells[row, 5] = remarks;
                        }
                        row += 1;
                    }

                    myBook.SaveCopyAs(saveFileName);
                    myBook.Close(false, Type.Missing, Type.Missing);

                    myExcel.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);
                    mySheet = null;
                    myBook  = null;
                    myExcel = null;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "error" + ex);
                }
                finally
                {
                    GC.Collect();
                }
            }
            else
            {
                MessageBox.Show("StaffId error!");
            }
        }