private void DeleteAllCurrentData()
        {
            try
            {
                Int64 result = -1;

                String fe = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.FLD_NAME_SalarySessionID, (Int64.Parse(ddlSalarySessionID.SelectedValue)).ToString(), SQLMatchType.Equal);

                HREmployeeMonthlyTimeSheetSummaryEntity HhEmployeeMonthlyTimeSheetSummaryEntity = new HREmployeeMonthlyTimeSheetSummaryEntity();


                result = FCCHREmployeeMonthlyTimeSheetSummary.GetFacadeCreate().Delete(HhEmployeeMonthlyTimeSheetSummaryEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                if (result == 0)
                {
                    _EmployeeMonthlyTimeSheetID = 0;
                    _HREmployeeMonthlyTimeSheetSummaryEntity = new HREmployeeMonthlyTimeSheetSummaryEntity();
                    PrepareInitialView();

                    MiscUtil.ShowMessage(lblMessage, "Time Sheet has been successfully deleted.", true);
                }
                else
                {
                    MiscUtil.ShowMessage(lblMessage, "Failed to delete Time Sheet.", true);
                }
            }
            catch (Exception ex)
            {
                MiscUtil.ShowMessage(lblMessage, ex.Message, true);
            }
        }
        Int64 IHREmployeeMonthlyTimeSheetSummaryDataAccess.Add(HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

                switch (reqTran)
                {
                case TransactionRequired.No:
                {
                    retValues = Add(hREmployeeMonthlyTimeSheetSummaryEntity, option);
                    break;
                }

                case TransactionRequired.Yes:
                {
                    retValues = AddTran(hREmployeeMonthlyTimeSheetSummaryEntity, option);
                    break;
                }

                default:
                {
                    retValues = -99;
                    break;
                }
                }

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void SaveHREmployeeMonthlyTimeSheetSummaryEntity()
        {
            if (IsValid)
            {
                try
                {
                    HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity = new HREmployeeMonthlyTimeSheetSummaryEntity();//BuildHREmployeeMonthlyTimeSheetSummaryEntity();

                    Int64 result = -1;

                    if (hREmployeeMonthlyTimeSheetSummaryEntity.IsNew)
                    {
                        result = FCCHREmployeeMonthlyTimeSheetSummary.GetFacadeCreate().Add(hREmployeeMonthlyTimeSheetSummaryEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.FLD_NAME_EmployeeMonthlyTimeSheetID, hREmployeeMonthlyTimeSheetSummaryEntity.EmployeeMonthlyTimeSheetID.ToString(), SQLMatchType.Equal);
                        result = FCCHREmployeeMonthlyTimeSheetSummary.GetFacadeCreate().Update(hREmployeeMonthlyTimeSheetSummaryEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _EmployeeMonthlyTimeSheetID = 0;
                        _HREmployeeMonthlyTimeSheetSummaryEntity = new HREmployeeMonthlyTimeSheetSummaryEntity();
                        PrepareInitialView();
                        BindHREmployeeMonthlyTimeSheetSummaryList();

                        if (hREmployeeMonthlyTimeSheetSummaryEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Employee Monthly Time Sheet Summary Information has been added successfully.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Employee Monthly Time Sheet Summary Information has been updated successfully.", false);
                        }
                    }
                    else
                    {
                        if (hREmployeeMonthlyTimeSheetSummaryEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to add Employee Monthly Time Sheet Summary Information.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to update Employee Monthly Time Sheet Summary Information.", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }
        private Int64 DeleteTran(HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.HREmployeeMonthlyTimeSheetSummary_SET";

            Database db = DatabaseFactory.CreateDatabase();


            using (DbCommand cmd = db.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd, db);
                AddFilterExpressionParameter(cmd, filterExpression, db);


                DbConnection connection = db.CreateConnection();
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();

                try
                {
                    using (IDataReader reader = db.ExecuteReader(cmd, transaction))
                    {
                        returnCode = GetReturnCodeFromParameter(cmd);
                    }

                    if (returnCode >= 0)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        throw new ArgumentException("Error Code." + returnCode.ToString());
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    transaction.Dispose();
                    connection.Close();
                    connection = null;
                }
            }

            return(returnCode);
        }
        private Int64 Delete(HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.HREmployeeMonthlyTimeSheetSummary_SET";

            using (DbCommand cmd = Database.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd);
                AddFilterExpressionParameter(cmd, filterExpression);


                using (IDataReader reader = Database.ExecuteReader(cmd))
                {
                    returnCode = GetReturnCodeFromParameter(cmd);

                    switch (returnCode)
                    {
                    case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST:
                    {
                        throw new ArgumentException("HREmployeeMonthlyTimeSheetSummaryEntity already exists. Please specify another HREmployeeMonthlyTimeSheetSummaryEntity.");
                    }

                    case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION:
                    {
                        throw new ArgumentException("HREmployeeMonthlyTimeSheetSummaryEntity data already updated from different session.");
                    }

                    case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION:
                    {
                        throw new ArgumentException("HREmployeeMonthlyTimeSheetSummaryEntity already exists. Please specify another HREmployeeMonthlyTimeSheetSummaryEntity.");
                    }
                    }
                }
            }

            return(returnCode);
        }
 Int64 IHREmployeeMonthlyTimeSheetSummaryFacade.Delete(HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateHREmployeeMonthlyTimeSheetSummaryDataAccess().Delete(hREmployeeMonthlyTimeSheetSummaryEntity, filterExpression, option, reqTran));
 }
 Int64 IHREmployeeMonthlyTimeSheetSummaryFacade.Add(HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateHREmployeeMonthlyTimeSheetSummaryDataAccess().Add(hREmployeeMonthlyTimeSheetSummaryEntity, option, reqTran));
 }
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _EmployeeMonthlyTimeSheetID = 0;
     _HREmployeeMonthlyTimeSheetSummaryEntity = new HREmployeeMonthlyTimeSheetSummaryEntity();
     PrepareInitialView();
 }
        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);
            }
        }
        private void UpdateHREmployeeDetailsForMonthlyTimeSheetSummary()
        {
            try
            {
                IList <ListViewDataItem> list = lvHREmployeeDetailsForMonthlyTimeSheetSummary.Items;

                if (list != null && list.Count > 0)
                {
                    Int32 tempDataItemIndex = 0;

                    foreach (ListViewDataItem lvdi in list)
                    {
                        DataKey currentDataKey = lvHREmployeeDetailsForMonthlyTimeSheetSummary.DataKeys[tempDataItemIndex++];
                        Int64   _employeeID    = (Int64)currentDataKey["EmployeeID"];

                        Boolean isSaveFlag = true;

                        String fe1 = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.FLD_NAME_EmployeeID, _employeeID.ToString(), SQLMatchType.Equal);
                        String fe2 = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.FLD_NAME_SalarySessionID, ddlSalarySessionID.SelectedValue.ToString(), SQLMatchType.Equal);
                        String fe  = SqlExpressionBuilder.PrepareFilterExpression(fe1, SQLJoinType.AND, fe2);

                        IList <HREmployeeMonthlyTimeSheetSummaryEntity> lstHREmployeeMonthlyTimeSheetSummary = FCCHREmployeeMonthlyTimeSheetSummary.GetFacadeCreate().GetIL(null, null, String.Empty, fe, DatabaseOperationType.LoadWithFilterExpression);

                        if (lstHREmployeeMonthlyTimeSheetSummary != null && lstHREmployeeMonthlyTimeSheetSummary.Count > 0)
                        {
                            isSaveFlag = false;
                        }


                        //String fe = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.em)
                        HREmployee_DetailedEntity employeeEntity = GetHREmployeeInfo(_employeeID);

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

                        Decimal totalLeave        = Decimal.Parse(txtLCASUAL.Text) + Decimal.Parse(txtLMEDICAL.Text) + Decimal.Parse(txtEARNLEAVE.Text);
                        Decimal actualWorkingdays = (Decimal.Parse(txtOnJob.Text) + Decimal.Parse(txtHoliday.Text)) - Decimal.Parse(txtLWP.Text);

                        if (txtLWP.Text.IsNotNullOrEmpty() && Decimal.Parse(txtLWP.Text) > 0)
                        {
                            remarks += txtLWP.Text + " LWP for " + (Decimal.Parse(txtLWP.Text) * 6) + " Late. ";
                        }

                        if (totalLeave > 0)
                        {
                            remarks += totalLeave + " Leave";
                        }
                        txtREMARKS.Text = remarks;

                        HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity = new HREmployeeMonthlyTimeSheetSummaryEntity();

                        hREmployeeMonthlyTimeSheetSummaryEntity.EmployeeID        = employeeEntity.EmployeeID;
                        hREmployeeMonthlyTimeSheetSummaryEntity.DesignationID     = employeeEntity.DesignationID;
                        hREmployeeMonthlyTimeSheetSummaryEntity.EmployeeJobTypeID = employeeEntity.EmployeeJobTypeID;
                        hREmployeeMonthlyTimeSheetSummaryEntity.OnJob             = Decimal.Parse(txtOnJob.Text);
                        hREmployeeMonthlyTimeSheetSummaryEntity.Holiday           = Decimal.Parse(txtHoliday.Text);
                        hREmployeeMonthlyTimeSheetSummaryEntity.LCASUAL           = Decimal.Parse(txtLCASUAL.Text);
                        hREmployeeMonthlyTimeSheetSummaryEntity.LMEDICAL          = Decimal.Parse(txtLMEDICAL.Text);
                        hREmployeeMonthlyTimeSheetSummaryEntity.LWP             = Decimal.Parse(txtLWP.Text);
                        hREmployeeMonthlyTimeSheetSummaryEntity.EARNLEAVE       = Decimal.Parse(txtEARNLEAVE.Text);
                        hREmployeeMonthlyTimeSheetSummaryEntity.ACTUALWORKDAYS  = actualWorkingdays;
                        hREmployeeMonthlyTimeSheetSummaryEntity.REMARKS         = txtREMARKS.Text.ToString().Trim();
                        hREmployeeMonthlyTimeSheetSummaryEntity.NUMBEROFMEALS   = Decimal.Parse(txtNUMBEROFMEALS.Text);
                        hREmployeeMonthlyTimeSheetSummaryEntity.PROJECTACTUAL   = Decimal.Parse(txtPROJECTACTUAL.Text);
                        hREmployeeMonthlyTimeSheetSummaryEntity.OTHERLEAVE      = Decimal.Parse(txtOTHERLEAVE.Text);
                        hREmployeeMonthlyTimeSheetSummaryEntity.SalarySessionID = Int64.Parse(ddlSalarySessionID.SelectedValue);
                        hREmployeeMonthlyTimeSheetSummaryEntity.DepartmentID    = Int64.Parse(lbldepartmentID.Text);

                        if (txtSalaryLevel.Text.IsNotNullOrEmpty())
                        {
                            hREmployeeMonthlyTimeSheetSummaryEntity.SalaryLevel = Int32.Parse(txtSalaryLevel.Text);
                        }
                        else
                        {
                            hREmployeeMonthlyTimeSheetSummaryEntity.SalaryLevel = null;
                        }


                        if (isSaveFlag)
                        {
                            FCCHREmployeeMonthlyTimeSheetSummary.GetFacadeCreate().Add(hREmployeeMonthlyTimeSheetSummaryEntity, DatabaseOperationType.Add, TransactionRequired.No);
                            MiscUtil.ShowMessage(lblMessage, "Employee Monthly Time Sheet Summary Information has been saved successfully.", false);
                        }
                        else
                        {
                            String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeMonthlyTimeSheetSummaryEntity.FLD_NAME_EmployeeMonthlyTimeSheetID, lstHREmployeeMonthlyTimeSheetSummary[0].EmployeeMonthlyTimeSheetID.ToString(), SQLMatchType.Equal);
                            FCCHREmployeeMonthlyTimeSheetSummary.GetFacadeCreate().Update(hREmployeeMonthlyTimeSheetSummaryEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                            MiscUtil.ShowMessage(lblMessage, "Employee Monthly Time Sheet Summary Information has been updated successfully.", false);
                        }


                        BindList();
                        //PrepareInitialView();
                    }
                }
            }
            catch (Exception ex)
            {
                MiscUtil.ShowMessage(lblMessage, "Failed to Employee Monthly Time Sheet Summary Information.", true);
            }
        }
        private Int64 Add(HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.HREmployeeMonthlyTimeSheetSummary_SET";

            using (DbCommand cmd = Database.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd);
                AddNullPrimaryKeyParameter(cmd, "EmployeeMonthlyTimeSheetID");

                Database.AddInParameter(cmd, "@EmployeeID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.EmployeeID);
                Database.AddInParameter(cmd, "@DesignationID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.DesignationID);
                Database.AddInParameter(cmd, "@EmployeeJobTypeID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.EmployeeJobTypeID);
                Database.AddInParameter(cmd, "@SalaryLevel", DbType.Int32, hREmployeeMonthlyTimeSheetSummaryEntity.SalaryLevel);
                Database.AddInParameter(cmd, "@SalarySessionID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.SalarySessionID);
                Database.AddInParameter(cmd, "@OnJob", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.OnJob);
                Database.AddInParameter(cmd, "@Holiday", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.Holiday);
                Database.AddInParameter(cmd, "@LCASUAL", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.LCASUAL);
                Database.AddInParameter(cmd, "@LMEDICAL", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.LMEDICAL);
                Database.AddInParameter(cmd, "@EARNLEAVE", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.EARNLEAVE);
                Database.AddInParameter(cmd, "@LWP", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.LWP);
                Database.AddInParameter(cmd, "@ACTUALWORKDAYS", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.ACTUALWORKDAYS);
                Database.AddInParameter(cmd, "@REMARKS", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.REMARKS);
                Database.AddInParameter(cmd, "@NUMBEROFMEALS", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.NUMBEROFMEALS);
                Database.AddInParameter(cmd, "@PROJECTACTUAL", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.PROJECTACTUAL);
                Database.AddInParameter(cmd, "@OTHERLEAVE", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.OTHERLEAVE);
                Database.AddInParameter(cmd, "@Field1", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.Field1);
                Database.AddInParameter(cmd, "@Field11", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field11);
                Database.AddInParameter(cmd, "@Field12", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field12);
                Database.AddInParameter(cmd, "@Field13", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field13);
                Database.AddInParameter(cmd, "@Field14", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field14);
                Database.AddInParameter(cmd, "@Field15", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field15);
                Database.AddInParameter(cmd, "@DepartmentID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.DepartmentID);

                using (IDataReader reader = Database.ExecuteReader(cmd))
                {
                    returnCode = GetReturnCodeFromParameter(cmd);

                    switch (returnCode)
                    {
                    case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST:
                    {
                        throw new ArgumentException("HREmployeeMonthlyTimeSheetSummaryEntity already exists. Please specify another HREmployeeMonthlyTimeSheetSummaryEntity.");
                    }

                    case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION:
                    {
                        throw new ArgumentException("HREmployeeMonthlyTimeSheetSummaryEntity data already updated from different session.");
                    }

                    case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION:
                    {
                        throw new ArgumentException("HREmployeeMonthlyTimeSheetSummaryEntity already exists. Please specify another HREmployeeMonthlyTimeSheetSummaryEntity.");
                    }
                    }
                }
            }

            return(returnCode);
        }
        private Int64 UpdateTran(HREmployeeMonthlyTimeSheetSummaryEntity hREmployeeMonthlyTimeSheetSummaryEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.HREmployeeMonthlyTimeSheetSummary_SET";

            Database db = DatabaseFactory.CreateDatabase();

            using (DbCommand cmd = db.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option, db);
                AddOutputParameter(cmd, db);
                AddFilterExpressionParameter(cmd, filterExpression, db);

                db.AddInParameter(cmd, "@EmployeeMonthlyTimeSheetID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.EmployeeMonthlyTimeSheetID);
                db.AddInParameter(cmd, "@EmployeeID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.EmployeeID);
                db.AddInParameter(cmd, "@DesignationID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.DesignationID);
                db.AddInParameter(cmd, "@EmployeeJobTypeID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.EmployeeJobTypeID);
                db.AddInParameter(cmd, "@SalaryLevel", DbType.Int32, hREmployeeMonthlyTimeSheetSummaryEntity.SalaryLevel);
                db.AddInParameter(cmd, "@SalarySessionID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.SalarySessionID);
                db.AddInParameter(cmd, "@OnJob", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.OnJob);
                db.AddInParameter(cmd, "@Holiday", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.Holiday);
                db.AddInParameter(cmd, "@LCASUAL", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.LCASUAL);
                db.AddInParameter(cmd, "@LMEDICAL", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.LMEDICAL);
                db.AddInParameter(cmd, "@EARNLEAVE", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.EARNLEAVE);
                db.AddInParameter(cmd, "@LWP", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.LWP);
                db.AddInParameter(cmd, "@ACTUALWORKDAYS", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.ACTUALWORKDAYS);
                db.AddInParameter(cmd, "@REMARKS", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.REMARKS);
                db.AddInParameter(cmd, "@NUMBEROFMEALS", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.NUMBEROFMEALS);
                db.AddInParameter(cmd, "@PROJECTACTUAL", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.PROJECTACTUAL);
                db.AddInParameter(cmd, "@OTHERLEAVE", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.OTHERLEAVE);
                db.AddInParameter(cmd, "@Field1", DbType.Decimal, hREmployeeMonthlyTimeSheetSummaryEntity.Field1);
                db.AddInParameter(cmd, "@Field11", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field11);
                db.AddInParameter(cmd, "@Field12", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field12);
                db.AddInParameter(cmd, "@Field13", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field13);
                db.AddInParameter(cmd, "@Field14", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field14);
                db.AddInParameter(cmd, "@Field15", DbType.String, hREmployeeMonthlyTimeSheetSummaryEntity.Field15);
                db.AddInParameter(cmd, "@DepartmentID", DbType.Int64, hREmployeeMonthlyTimeSheetSummaryEntity.DepartmentID);

                DbConnection connection = db.CreateConnection();
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();

                try
                {
                    using (IDataReader reader = db.ExecuteReader(cmd, transaction))
                    {
                        returnCode = GetReturnCodeFromParameter(cmd);
                    }

                    if (returnCode > 0)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        throw new ArgumentException("Error Code." + returnCode.ToString());
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    transaction.Dispose();
                    connection.Close();
                    connection = null;
                }
            }

            return(returnCode);
        }