protected void lvHREmployeeDetailsForMonthlyTimeSheetSummary_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                ListViewDataItem dataItem = (ListViewDataItem)e.Item;

                HREmployee_DetailedEntity ent = new HREmployee_DetailedEntity();

                TextBox txtEmployeeName      = (TextBox)e.Item.FindControl("txtEmployeeName");
                TextBox txtDesignation       = (TextBox)e.Item.FindControl("txtDesignation");
                TextBox txtEmployeeJobTypeID = (TextBox)e.Item.FindControl("txtEmployeeJobTypeID");
                TextBox txtSalaryLevel       = (TextBox)e.Item.FindControl("txtSalaryLevel");
                TextBox txtOnJob             = (TextBox)e.Item.FindControl("txtOnJob");
                TextBox txtHoliday           = (TextBox)e.Item.FindControl("txtHoliday");
                TextBox txtLCASUAL           = (TextBox)e.Item.FindControl("txtLCASUAL");
                TextBox txtLMEDICAL          = (TextBox)e.Item.FindControl("txtLMEDICAL");
                TextBox txtEARNLEAVE         = (TextBox)e.Item.FindControl("txtEARNLEAVE");
                TextBox txtLWP            = (TextBox)e.Item.FindControl("txtLWP");
                TextBox txtACTUALWORKDAYS = (TextBox)e.Item.FindControl("txtACTUALWORKDAYS");
                TextBox txtREMARKS        = (TextBox)e.Item.FindControl("txtREMARKS");
                TextBox txtNUMBEROFMEALS  = (TextBox)e.Item.FindControl("txtNUMBEROFMEALS");
                TextBox txtPROJECTACTUAL  = (TextBox)e.Item.FindControl("txtPROJECTACTUAL");
                TextBox txtOTHERLEAVE     = (TextBox)e.Item.FindControl("txtOTHERLEAVE");
                Label   employeeIDlv      = (Label)e.Item.FindControl("employeeIDlv");
                String  remarks           = String.Empty;

                txtLCASUAL.Text       = "0";
                txtLMEDICAL.Text      = "0";
                txtEARNLEAVE.Text     = "0";
                txtLWP.Text           = "0";
                txtREMARKS.Text       = String.Empty;
                txtNUMBEROFMEALS.Text = "0";
                txtPROJECTACTUAL.Text = "0";
                txtOTHERLEAVE.Text    = "0";



                IList <HREmployeeDetailsForMonthlyTimeSheetSummary_CustomEntity> entList = FCCHREmployeeDetailsForMonthlyTimeSheetSummary_Custom.GetFacadeCreate().GetIL(Int64.Parse(ddlSalarySessionID.SelectedValue));
                txtOnJob.Text          = entList[0].OnJob.ToString().Trim();
                txtHoliday.Text        = (entList[0].Holiday - entList[0].LeaveDay).ToString().Trim();
                txtACTUALWORKDAYS.Text = ((Decimal.Parse(txtOnJob.Text) + Decimal.Parse(txtHoliday.Text)) - Decimal.Parse(txtLWP.Text)).ToString().Trim();

                //Int64 leaveApplicationApplicationStatusID = 2;
                Int64   employeeID     = (Int64.Parse(employeeIDlv.Text));
                Decimal totalLeaveDays = 0;
                Decimal casual         = 0;
                Decimal medical        = 0;
                Decimal earn           = 0;
                Decimal lwp            = 0;


                String fe1 = SqlExpressionBuilder.PrepareFilterExpression("HREmployee." + HREmployee_DetailedEntity.FLD_NAME_EmployeeID, employeeID.ToString(), SQLMatchType.Equal);
                String fe2 = SqlExpressionBuilder.PrepareFilterExpression(MDSalarySessionEntity.FLD_NAME_SalarySessionID, (Int64.Parse(ddlSalarySessionID.SelectedValue)).ToString(), SQLMatchType.Equal);
                String fe3 = SqlExpressionBuilder.PrepareFilterExpression("HREmployeeLeaveApplication." + HREmployeeLeaveApplicationEntity.FLD_NAME_LeaveApplicationApplicationStatusID, MasterDataConstants.MDLeaveApplicatoinStatus.APPROVED.ToString(), SQLMatchType.Equal);
                String fe  = SqlExpressionBuilder.PrepareFilterExpression(fe1, SQLJoinType.AND, fe2);
                fe = SqlExpressionBuilder.PrepareFilterExpression(fe, SQLJoinType.AND, fe3);

                IList <HREmployeeLeaveApplication_DetailedEntity> leaveList = FCCHREmployeeLeaveApplication_Detailed.GetFacadeCreate().GetIL(1000, 1, String.Empty, fe);
                if (leaveList != null && leaveList.Count > 0)
                {
                    foreach (HREmployeeLeaveApplication_DetailedEntity entity in leaveList)
                    {
                        if (entity.LeaveCategoryID == MasterDataConstants.MDLeaveCategory.CASUAL)
                        {
                            casual += leaveList[0].TotalLeaveDays;
                        }
                        else if (entity.LeaveCategoryID == MasterDataConstants.MDLeaveCategory.MEDICAL)
                        {
                            medical += leaveList[0].TotalLeaveDays;
                        }
                        else if (entity.LeaveCategoryID == MasterDataConstants.MDLeaveCategory.EARN)
                        {
                            earn += leaveList[0].TotalLeaveDays;
                        }
                        else if (entity.LeaveCategoryID == MasterDataConstants.MDLeaveCategory.LWP)
                        {
                            lwp += leaveList[0].TotalLeaveDays;
                        }
                    }
                }
                if (lwp > 0)
                {
                    remarks += lwp + " LWP " + (lwp * 6) + " Late. ";
                }

                totalLeaveDays = casual + medical + earn;

                if (totalLeaveDays > 0)
                {
                    remarks += Decimal.Truncate(totalLeaveDays).ToString().Trim() + " Leave.";
                }
                else
                {
                    remarks += String.Empty;
                }
                txtLCASUAL.Text        = casual.ToString();
                txtLMEDICAL.Text       = medical.ToString();
                txtEARNLEAVE.Text      = earn.ToString();
                txtLWP.Text            = lwp.ToString();
                txtACTUALWORKDAYS.Text = (entList[0].ActualWorkingDay - lwp).ToString().Trim();
                txtREMARKS.Text        = remarks;

                btnSubmit.Text = "Save";

                #region CurrentEmployeeMonthlyTimeSheetSummaryInfo
                String fe4 = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.FLD_NAME_EmployeeID, employeeID.ToString(), SQLMatchType.Equal);
                String fe5 = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.FLD_NAME_SalarySessionID, (Int64.Parse(ddlSalarySessionID.SelectedValue)).ToString(), SQLMatchType.Equal);
                String fe6 = SqlExpressionBuilder.PrepareFilterExpression(fe4, SQLJoinType.AND, fe5);
                IList <HREmployeeMonthlyTimeSheetSummaryEntity> hREmployeeMonthlyTimeSheetSummarylist = FCCHREmployeeMonthlyTimeSheetSummary.GetFacadeCreate().GetIL(null, null, String.Empty, fe6, DatabaseOperationType.LoadWithFilterExpression);
                if (hREmployeeMonthlyTimeSheetSummarylist != null && hREmployeeMonthlyTimeSheetSummarylist.Count > 0)
                {
                    txtOnJob.Text          = hREmployeeMonthlyTimeSheetSummarylist[0].OnJob.ToString().Trim();
                    txtHoliday.Text        = hREmployeeMonthlyTimeSheetSummarylist[0].Holiday.ToString().Trim();
                    txtACTUALWORKDAYS.Text = hREmployeeMonthlyTimeSheetSummarylist[0].ACTUALWORKDAYS.ToString().Trim();
                    txtLCASUAL.Text        = hREmployeeMonthlyTimeSheetSummarylist[0].LCASUAL.ToString().Trim();
                    txtLMEDICAL.Text       = hREmployeeMonthlyTimeSheetSummarylist[0].LMEDICAL.ToString().Trim();
                    txtLWP.Text            = hREmployeeMonthlyTimeSheetSummarylist[0].LWP.ToString().Trim();
                    txtEARNLEAVE.Text      = hREmployeeMonthlyTimeSheetSummarylist[0].EARNLEAVE.ToString().Trim();
                    txtREMARKS.Text        = hREmployeeMonthlyTimeSheetSummarylist[0].REMARKS.ToString().Trim();
                    txtNUMBEROFMEALS.Text  = hREmployeeMonthlyTimeSheetSummarylist[0].NUMBEROFMEALS.ToString().Trim();
                    txtPROJECTACTUAL.Text  = hREmployeeMonthlyTimeSheetSummarylist[0].PROJECTACTUAL.ToString().Trim();
                    txtOTHERLEAVE.Text     = hREmployeeMonthlyTimeSheetSummarylist[0].OTHERLEAVE.ToString().Trim();

                    btnSubmit.Text = "Update";
                }

                #endregion
            }
        }
        private void GenerateAll()
        {
            try
            {
                StringBuilder xmlStr             = new StringBuilder();
                Int64         employmentStatusID = 1;
                String        fe = SqlExpressionBuilder.PrepareFilterExpression("(HREmployeeSalaryInfo.SalaryAmount is not null and HREmployeeSalaryInfo.FiscalYearID = (Select FiscalYearID from ACFiscalYear where IsClosed = 0)) and HREmployee." + HREmployee_DetailedEntity.FLD_NAME_EmploymentStatusID, employmentStatusID.ToString(), SQLMatchType.Equal);

                if (ddlDepartmentID.SelectedValue == "1")
                {
                    String fe2 = "( HREmployee.DepartmentID is null or HREmployee.DepartmentID <> 20)";
                    fe = SqlExpressionBuilder.PrepareFilterExpression(fe, SQLJoinType.AND, fe2);
                }
                else
                {
                    String fe3 = "(HREmployee.DepartmentID = 20)";
                    fe = SqlExpressionBuilder.PrepareFilterExpression(fe, SQLJoinType.AND, fe3);
                }

                IList <HREmployee_DetailedEntity> list = FCCHREmployeeMonthlyTimeSheet_Detailed.GetFacadeCreate().GetIL(1000, 1, String.Empty, fe);
                xmlStr.Append("<m>");
                if (list != null && list.Count > 0)
                {
                    foreach (HREmployee_DetailedEntity hREmployee_DetailedEntity in list)
                    {
                        HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity = new HREmployeeMonthlyTimeSheetSummaryEntity();

                        hREmployeeMonthlyTimeSheetSummaryEntity.LCASUAL       = 0;
                        hREmployeeMonthlyTimeSheetSummaryEntity.LMEDICAL      = 0;
                        hREmployeeMonthlyTimeSheetSummaryEntity.EARNLEAVE     = 0;
                        hREmployeeMonthlyTimeSheetSummaryEntity.LWP           = 0;
                        hREmployeeMonthlyTimeSheetSummaryEntity.REMARKS       = String.Empty;
                        hREmployeeMonthlyTimeSheetSummaryEntity.NUMBEROFMEALS = 0;
                        hREmployeeMonthlyTimeSheetSummaryEntity.PROJECTACTUAL = 0;
                        hREmployeeMonthlyTimeSheetSummaryEntity.OTHERLEAVE    = 0;
                        String remarks = String.Empty;

                        IList <HREmployeeDetailsForMonthlyTimeSheetSummary_CustomEntity> entList = FCCHREmployeeDetailsForMonthlyTimeSheetSummary_Custom.GetFacadeCreate().GetIL(Int64.Parse(ddlSalarySessionID.SelectedValue));
                        hREmployeeMonthlyTimeSheetSummaryEntity.OnJob          = entList[0].OnJob;
                        hREmployeeMonthlyTimeSheetSummaryEntity.Holiday        = (entList[0].Holiday - entList[0].LeaveDay);
                        hREmployeeMonthlyTimeSheetSummaryEntity.ACTUALWORKDAYS = ((hREmployeeMonthlyTimeSheetSummaryEntity.OnJob + hREmployeeMonthlyTimeSheetSummaryEntity.Holiday) - hREmployeeMonthlyTimeSheetSummaryEntity.LWP);

                        Int64   employeeID     = hREmployee_DetailedEntity.EmployeeID;
                        Decimal totalLeaveDays = 0;
                        Decimal casual         = 0;
                        Decimal medical        = 0;
                        Decimal earn           = 0;
                        Decimal lwp            = 0;

                        String fe1 = SqlExpressionBuilder.PrepareFilterExpression(" HREmployee." + HREmployee_DetailedEntity.FLD_NAME_EmployeeID, employeeID.ToString(), SQLMatchType.Equal);
                        String fe2 = SqlExpressionBuilder.PrepareFilterExpression(MDSalarySessionEntity.FLD_NAME_SalarySessionID, (Int64.Parse(ddlSalarySessionID.SelectedValue)).ToString(), SQLMatchType.Equal);
                        String fe3 = SqlExpressionBuilder.PrepareFilterExpression("HREmployeeLeaveApplication." + HREmployeeLeaveApplicationEntity.FLD_NAME_LeaveApplicationApplicationStatusID, MasterDataConstants.MDLeaveApplicatoinStatus.APPROVED.ToString(), SQLMatchType.Equal);
                        String f   = SqlExpressionBuilder.PrepareFilterExpression(fe1, SQLJoinType.AND, fe2);
                        f = SqlExpressionBuilder.PrepareFilterExpression(f, SQLJoinType.AND, fe3);

                        IList <HREmployeeLeaveApplication_DetailedEntity> leaveList = FCCHREmployeeLeaveApplication_Detailed.GetFacadeCreate().GetIL(1000, 1, String.Empty, f);
                        if (leaveList != null && leaveList.Count > 0)
                        {
                            foreach (HREmployeeLeaveApplication_DetailedEntity entity in leaveList)
                            {
                                if (entity.LeaveCategoryID == MasterDataConstants.MDLeaveCategory.CASUAL)
                                {
                                    casual += leaveList[0].TotalLeaveDays;
                                }
                                else if (entity.LeaveCategoryID == MasterDataConstants.MDLeaveCategory.MEDICAL)
                                {
                                    medical += leaveList[0].TotalLeaveDays;
                                }
                                else if (entity.LeaveCategoryID == MasterDataConstants.MDLeaveCategory.EARN)
                                {
                                    earn += leaveList[0].TotalLeaveDays;
                                }
                                else if (entity.LeaveCategoryID == MasterDataConstants.MDLeaveCategory.LWP)
                                {
                                    lwp += leaveList[0].TotalLeaveDays;
                                }
                            }
                        }
                        if (lwp > 0)
                        {
                            remarks += lwp + " LWP " + (lwp * 6) + " Late. ";
                        }

                        totalLeaveDays = casual + medical + earn;

                        if (totalLeaveDays > 0)
                        {
                            remarks += totalLeaveDays.ToString().Trim() + " Leave.";
                        }
                        else
                        {
                            remarks += String.Empty;
                        }

                        hREmployeeMonthlyTimeSheetSummaryEntity.LCASUAL         = casual;
                        hREmployeeMonthlyTimeSheetSummaryEntity.LMEDICAL        = medical;
                        hREmployeeMonthlyTimeSheetSummaryEntity.EARNLEAVE       = earn;
                        hREmployeeMonthlyTimeSheetSummaryEntity.LWP             = lwp;
                        hREmployeeMonthlyTimeSheetSummaryEntity.ACTUALWORKDAYS  = (entList[0].ActualWorkingDay - lwp);
                        hREmployeeMonthlyTimeSheetSummaryEntity.REMARKS         = remarks;
                        hREmployeeMonthlyTimeSheetSummaryEntity.SalarySessionID = Int64.Parse(ddlSalarySessionID.SelectedValue);

                        #region Already Has this employee
                        Boolean isTrue = true;

                        String fe4 = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.FLD_NAME_EmployeeID, employeeID.ToString(), SQLMatchType.Equal);
                        String fe5 = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.FLD_NAME_SalarySessionID, (Int64.Parse(ddlSalarySessionID.SelectedValue)).ToString(), SQLMatchType.Equal);
                        String fe6 = SqlExpressionBuilder.PrepareFilterExpression(fe4, SQLJoinType.AND, fe5);
                        IList <HREmployeeMonthlyTimeSheetSummaryEntity> hREmployeeMonthlyTimeSheetSummarylist = FCCHREmployeeMonthlyTimeSheetSummary.GetFacadeCreate().GetIL(null, null, String.Empty, fe6, DatabaseOperationType.LoadWithFilterExpression);

                        if (hREmployeeMonthlyTimeSheetSummarylist != null && hREmployeeMonthlyTimeSheetSummarylist.Count > 0)
                        {
                            isTrue = false;
                        }

                        #endregion

                        if (isTrue)
                        {
                            String subXmlStr = null;
                            subXmlStr = subXmlStr + "<i><a>" + hREmployee_DetailedEntity.EmployeeID + "</a><b>" + hREmployee_DetailedEntity.DesignationID + "</b><c>" + hREmployee_DetailedEntity.EmployeeJobTypeID + "</c><d>" + hREmployee_DetailedEntity.SalaryLevel + "</d><e>" + hREmployeeMonthlyTimeSheetSummaryEntity.SalarySessionID + "</e><f>" + hREmployeeMonthlyTimeSheetSummaryEntity.OnJob + "</f><g>" + hREmployeeMonthlyTimeSheetSummaryEntity.Holiday + "</g><h>" + hREmployeeMonthlyTimeSheetSummaryEntity.LCASUAL + "</h><i1>" + hREmployeeMonthlyTimeSheetSummaryEntity.LMEDICAL + "</i1><j>" + hREmployeeMonthlyTimeSheetSummaryEntity.EARNLEAVE + "</j><k>" + hREmployeeMonthlyTimeSheetSummaryEntity.LWP + "</k><l>" + hREmployeeMonthlyTimeSheetSummaryEntity.ACTUALWORKDAYS + "</l><m>" + hREmployeeMonthlyTimeSheetSummaryEntity.REMARKS + "</m><n>" + hREmployeeMonthlyTimeSheetSummaryEntity.NUMBEROFMEALS + "</n><o>" + hREmployeeMonthlyTimeSheetSummaryEntity.PROJECTACTUAL + "</o><p>" + hREmployeeMonthlyTimeSheetSummaryEntity.OTHERLEAVE + "</p><q>" + hREmployee_DetailedEntity.DepartmentID + "</q></i>";
                            xmlStr.Append(subXmlStr.ToString());
                        }
                    }
                }
                xmlStr.Append("</m>");

                FCCBulkInsertXML.GetFacadeCreate().GetIL(xmlStr.ToString(), CommonConstants.HREmployeeMonthlyTimeSheetSummary);

                MiscUtil.ShowMessage(lblMessage, "Time Sheet Has been Generated Successfully.", false);
            }
            catch (Exception ex)
            {
                MiscUtil.ShowMessage(lblMessage, "An Error Occoured.", true);
            }
        }