Click here to Skip to main content
15,886,637 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear sirs,
on debug the application is working normally but while we deploy it on server it is not working no error happened but also no records saved in DB knowing that i debug it on server and it is working normally on deployment...it is not working can any one help me

regards

this is the code that must run correctly :

C#
using System;
using System.Collections.Generic;
using System.Data;
using System.Transactions;
using BatchPackage;
using Microsoft.SqlServer.Server;

public partial class CLRGeneratePayroll
{
    public CLRGeneratePayroll(string connectionString)
    {
        _ConnectionString = connectionString;
    }

    string _ConnectionString;

    public string proc_GeneratePayroll(string payProcessId)
    {
        //CultureInfo CurrentCulture = new CultureInfo("ar-sa");
        //Calendar CurrentCalendar = CurrentCulture.Calendar;

        //MMH+BOB version 1.0
        #region Declare Variables
        int processType = 0; //(1-Normal / 2-Extra / 3-Special / 4-Bonus / 5-Pay Simulation / 6-Pay without Calculation...)
        int netShowPage = 0;
        int ruleType = 0;
        int sequenceNumber = 0;
        //int EmployeeRejected = 0;


        string payRegulationId = string.Empty;
        string payMonth = string.Empty;
        string personId = string.Empty;
        string netPayElement = string.Empty;
        string payelement = string.Empty;

        DateTime processStartDate;
        DateTime processEndDate;

        bool isEducationGenerated = false;
        int educationyear = 0;
        bool isLoanGenerated = false;
        bool isInsuranceGenerated = false;
        bool isProvisionGenerated = false;
        bool isBonusGenerated = false;//Phase II
        bool isStampGenerated = false;
        bool isReverseAccrual = false;
        bool isCloseFile = false;
        //bool isBillGenerated = false;//Phase II

        string CurrencySystem = GetSystemCurrency();
        #endregion Declare Variables

        #region Get Process Detail
        DataRow processdetail = GetPayProcessDetail(payProcessId);

        payMonth = processdetail["PayMonth"].ToString();
        processType = int.Parse(processdetail["PayProcessTypeID"].ToString());
        processStartDate = DateTime.Parse(processdetail["PayStartDate"].ToString());
        processEndDate = DateTime.Parse(processdetail["PayEndDate"].ToString());
        isEducationGenerated = bool.Parse(processdetail["IsGeneratedEducation"].ToString());
        if (isEducationGenerated == true)
            educationyear = int.Parse(processdetail["EducationYear"].ToString());

        isLoanGenerated = bool.Parse(processdetail["IsGeneratedLoan"].ToString());
        isInsuranceGenerated = bool.Parse(processdetail["IsGeneratedInsurance"].ToString());
        isProvisionGenerated = bool.Parse(processdetail["IsGeneratedProvision"].ToString());
        isBonusGenerated = bool.Parse(processdetail["IsGeneratedBonus"].ToString());  //Phase II
        isStampGenerated = bool.Parse(processdetail["IsGeneratedStamp"].ToString());
        isReverseAccrual = bool.Parse(processdetail["IsReverseAccrual"].ToString());
        isCloseFile = bool.Parse(processdetail["IsCloseFile"].ToString());
        //isBillGenerated = bool.Parse(processdetail["IsGeneratedBill"].ToString());  //Phase II
        #endregion Get Process Detail

        #region Prepare Data
        DataTable employeesInProcess = GetEmployeesforProcess(payProcessId);

        List<string> employeeIds = new List<string>();
        for (int i = 0; i < employeesInProcess.Rows.Count; i++)
        {
            if (i == 0)
                employeeIds.Add("'" + employeesInProcess.Rows[i]["PersonID"].ToString() + "'");
            else
                employeeIds.Add(", '" + employeesInProcess.Rows[i]["PersonID"].ToString() + "'");
        }

        if (employeeIds.Count > 0)
        {
            DataTable payModification = GetPayModification(payProcessId, false, employeeIds.ToArray());
            DataTable fixedTransportation = GetFixedTransport(payProcessId, employeeIds.ToArray());
            DataTable transportPayModification = GetPayModification(payProcessId, true, employeeIds.ToArray());

            DataTable educationAllowanceInProcess = new DataTable();
            DataTable loansInProcess = new DataTable();
            DataTable insuranceInProcess = new DataTable();
            if (isEducationGenerated && processType != 6)
                educationAllowanceInProcess = GetPersonEligibleToEducation(payProcessId, processEndDate, employeeIds.ToArray());

            if ((isLoanGenerated || isCloseFile) && processType != 6)

                loansInProcess = GetPersonEligibleToLoan(payProcessId, processType, processStartDate, processEndDate, employeeIds.ToArray());

            if (isInsuranceGenerated && processType != 6)
                insuranceInProcess = GetPersonEligibleToInsurance(payProcessId, processStartDate, processEndDate, employeeIds.ToArray());

            DataTable regulationsInProcess = GetRegulationsInProcess(payProcessId, employeeIds.ToArray());

        #endregion Prepare Data

            LockProcess(payProcessId, true);

            #region Generate Payroll

            Batch batch = new Batch(_ConnectionString);
            //batch.clearBatchByProcessID(payProcessId);
            batch.batchID = Guid.NewGuid().ToString();
            batch.description = processdetail["Description"].ToString();
            batch.executionStartTime = DateTime.Now;
            batch.transactionID = payProcessId;

            List<BatchDetail> lstBatchDetails = new List<BatchDetail>();
            foreach (DataRow employeeRow in employeesInProcess.Rows)
            {
                personId = employeeRow["PersonID"].ToString();

                BatchDetail _btchDetail = new BatchDetail(_ConnectionString);
                _btchDetail.batchDetailID = Guid.NewGuid().ToString();
                _btchDetail.BatchID = batch.batchID;
                _btchDetail.batchDetailDate = DateTime.Now;
                _btchDetail.personID = personId;

                try
                {

                    #region Delete Employee from PayEmployeeRejected
                    SetEmployeeRejected(null, payProcessId, personId, null, false);
                    #endregion Delete Employee from PayEmployeeRejected

                    TransactionOptions tso = new TransactionOptions();
                    tso.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, tso))
                    {
                        #region Update Employee Sequence
                        sequenceNumber = GetLastSequenceforEmployee(personId, processEndDate);
                        sequenceNumber += 1;//Update Sequence in PayEmployee for each Employee by incrementing his last Sequence by 1
                        SetEmployeeSequence(personId, payProcessId, sequenceNumber);
                        #endregion Update Employee Sequence

                        #region Update DOM
                        if (processType == 1)
                        {
                            string payparam = employeeRow["PayrollParameterID"].ToString();
                            SetDOM(payProcessId, personId, payparam, processStartDate, processEndDate);
                        }
                        #endregion Update DOM

                        #region Insert Data from previous process in PayYearTransaction
                        //Get Data from Previous Process related to the employee and set it in PayYearTransaction
                        SetPayYearTransactionFromPrevious(payProcessId, personId);

                        //Copy Rounding Amount from PayYearTransaction to PayMonthTransaction if there is Rounding on NET PayElement
                        SetRoundingNetToMonth(payProcessId, personId);
                        #endregion Get Data from previous

                        #region Compute Salary and Working Days
                        ComputeSalary(payProcessId, personId, payMonth, processType, CurrencySystem, processStartDate, processEndDate, isCloseFile);
                        #endregion

                        #region Compute PayModification
                        DataRow[] payModificationRows = payModification.Select("PersonID = '" + personId + "'");
                        if (payModificationRows.Length > 0)
                            ComputePayModification(payProcessId, personId, payMonth, processType, processStartDate, processEndDate, CurrencySystem, isCloseFile, payModificationRows);
                        #endregion (Retrieve PayModification)

                        #region Compute Fixed Transportation
                        if (processType == 1)
                        {
                            DataRow[] fixedTransportationRows = fixedTransportation.Select("PersonID = '" + personId + "'");
                            if (fixedTransportationRows.Length > 0)
                                GenerateFixedTransport(payProcessId, personId, payMonth, processType, processStartDate, processEndDate, CurrencySystem, fixedTransportationRows);
                        }
                        #endregion

                        #region Compute Transportation
                        DataRow[] transportPayModificationRows = transportPayModification.Select("PersonID = '" + personId + "'");
                        if (transportPayModificationRows.Length > 0)
                            GenerateTransportation(payProcessId, personId, payMonth, processType, processStartDate, processEndDate, CurrencySystem, isCloseFile, transportPayModificationRows);
                        #endregion

                        #region Compute Educational Allowance
                        if (isEducationGenerated && processType != 6)
                        {
                            DataRow[] employeeeducAllowanceRows = educationAllowanceInProcess.Select("PersonID = '" + personId + "'");
                            if (employeeeducAllowanceRows.Length > 0)
                                ComputeEducationalAllowance(payProcessId, personId, processEndDate, payMonth, educationyear, employeeeducAllowanceRows);
                        }
                        #endregion Compute Educational Allowance

                        #region Compute loan
                        if ((isLoanGenerated || isCloseFile) && processType != 6)
                        {
                            DataRow[] employeeLoansRows = loansInProcess.Select("PersonID = '" + personId + "'");
                            if (employeeLoansRows.Length > 0)
                                ComputeLoan(payProcessId, personId, processType, payMonth, processStartDate, processEndDate, isCloseFile, employeeLoansRows);
                        }
                        #endregion compute loan

                        #region Compute Insurance
                        if (isInsuranceGenerated && processType != 6)
                        {
                            DataRow[] employeeInsuranceRows = insuranceInProcess.Select("PersonID = '" + personId + "'");
                            if (employeeInsuranceRows.Length > 0)
                                ComputeInsurance(payProcessId, personId, processStartDate, processEndDate, employeeInsuranceRows);
                        }
                        #endregion compute Insurance

                        #region To DO Next Release
                        //if (isBonusGenerated && processType != 6)
                        //    Call function to compute the Bonus Month

                        //if (isStampGenerated == true)       //it is preferrable to call this function after the update
                        //    GenerateStamp(payProcessId, processEndDate);

                        //if (isBillGenerated == true && processType != 6)
                        //    Call function to compute the Bills in Month
                        #endregion To DO Next Release

                        #region Copy Data from PayMonthTransaction to PayYearTransaction
                        SetPayYearFromPayMonth(payProcessId, personId);
                        #endregion Copy Data from PayMonthTransaction to PayYearTransaction

                        #region Generate Part(II)
                        //JACKY version (1.0)

                        payRegulationId = employeeRow["PayRegulationHeaderID"].ToString();
                        //presenceFactor = presenceFactor = decimal.Parse(employeeRow["PresencePayFactor"].ToString());

                        if (processType != 6) //"Pay without Calculation"
                        {
                            #region Compute Accrual
                            if (isReverseAccrual == false && isCloseFile == false)
                                ComputeAccrual(payProcessId, processStartDate, processEndDate, personId, processStartDate, processEndDate, true);
                            #endregion Compute Accrual

                            #region Compute Rules in Employee Regulation
                            int ruleSequence = 0, tempSequence = 0;
                            //Get Rules order by Sequence and Starting date
                            //Before: DataTable regulationDetail = GetRegulationRuleByType(payRegulationId, 0); //All Rules
                            //Before: for (int i = 0; i < regulationDetail.Rows.Count; i++)

                            DataRow[] regulationDetailRows = regulationsInProcess.Select("PayRegulationHeaderID = '" + payRegulationId + "'", "sequence asc, StartingDate asc");
                            foreach (DataRow regulationDetailRow in regulationDetailRows)
                            {
                                //Before: DataRow regulationDetailRow = regulationDetail.Rows[i];
                                ruleType = (int)regulationDetailRow["RuleTypeID"];
                                ruleSequence = (int)regulationDetailRow["Sequence"];
                                if (tempSequence == ruleSequence)
                                    continue;

                                switch (ruleType)
                                //1=Family Allowance;    2=TAX;   3=Social Security;   4=EOS & Provision;   5=User Defined;
                                {
                                    case 1: //Family Allowance
                                        ComputeFamilyAllowance(payProcessId, personId, processType, processStartDate, processEndDate);
                                        tempSequence = ruleSequence;
                                        break;

                                    case 2: //Tax
                                        ComputeTaxProcedure(payProcessId, personId, processType, processStartDate, processEndDate);
                                        tempSequence = ruleSequence;
                                        break;

                                    case 3: //Social Security & EOS Contributions
                                        ComputeSocialSecurityProcedure(payProcessId, personId, processType, processStartDate, processEndDate);
                                        tempSequence = ruleSequence;
                                        break;

                                    case 4: //EOS & Provision
                                        if (isProvisionGenerated == true)
                                        {
                                            ComputeProvisionProcedure(payProcessId, personId, processType, processStartDate, processEndDate);
                                            tempSequence = ruleSequence;
                                        }
                                        break;

                                    //case ?: //Pension (future Release)
                                    //    break;

                                    default:
                                        break;
                                }
                            }
                            #endregion Compute Rules in Employee Regulation

                            #region Compute/Reverse Accrual
                            if (isReverseAccrual == true || isCloseFile == true)
                                ReverseAccrual(payProcessId, processStartDate, processEndDate, personId, processStartDate, processEndDate);
                            else
                                ComputeAccrual(payProcessId, processStartDate, processEndDate, personId, processStartDate, processEndDate, false);
                            #endregion Compute/Reverse Accrual
                        }

                        #region Compute UserRule before-NET
                        DataTable userRule = new DataTable();
                        userRule = GetRegulationUserRule(payRegulationId, 5); //"Before Net"
                        foreach (DataRow userRuleRow in userRule.Rows)
                        {
                            ComputeUserDefinedRule(payProcessId, processEndDate, personId, userRuleRow["UserRuleHeaderID"].ToString(), processStartDate, processEndDate);
                        }
                        #endregion Compute UserRule before-NET

                        #region Compute NET
                        DataTable regulationNet = new DataTable();
                        regulationNet = GetRegulationNet(payRegulationId);
                        foreach (DataRow netRow in regulationNet.Rows)
                        {
                            netPayElement = netRow["PayElementID"].ToString();
                            netShowPage = int.Parse(netRow["ShowOnPageID"].ToString());

                            ComputePersonNet(payProcessId, personId, processEndDate, netRow["PayRegulationNetID"].ToString(), int.Parse(netRow["ShowOnPageID"].ToString()));
                        }
                        #endregion Compute NET

                        #region Compute UserRule after-NET
                        userRule = GetRegulationUserRule(payRegulationId, 6); //"After Net"
                        foreach (DataRow userRuleRow in userRule.Rows)
                        {
                            ComputeUserDefinedRule(payProcessId, processEndDate, personId, userRuleRow["UserRuleHeaderID"].ToString(), processStartDate, processEndDate);
                        }
                        #endregion Compute UserRule after-NET

                        #endregion Generate Part(II)

                        #region Set RuleDate = TerminationDate in case of CloseFile
                        if (isCloseFile == true)
                        {
                            DateTime terminationDate;
                            terminationDate = GetTerminationDate(personId);
                            SetTillDate(personId, terminationDate);
                        }
                        #endregion Set RuleDate = TerminationDate in case of CloseFile

                        #region Set Employee Generated and Update his LastProcessDate
                        SetProcessDate(personId, processEndDate);
                        SetEmployeeGenerated(payProcessId, personId);
                        #endregion Set Employee Generated and Update his LastProcessDate

                        ts.Complete();
                        ts.Dispose();
                    }
                    _btchDetail.logMessageID = 35;
                    //_btchDetail.remark = "Process Done";
                    lstBatchDetails.Add(_btchDetail);
                }
                catch (Exception ex)
                {
                    _btchDetail.logMessageID = 54;
                    _btchDetail.remark = ex.Message;
                    lstBatchDetails.Add(_btchDetail);
                    //SetEmployeeRejected
                    SetEmployeeRejected(Guid.NewGuid().ToString(), payProcessId, personId, ((System.Exception)(ex)).Message, true);
                    //batch.executionEndTime = DateTime.Now;
                }
                //finally
                //{
                //}
            }
            LockProcess(payProcessId, false);
            batch.executionEndTime = DateTime.Now;
            //lstBatchDetails.Sort(delegate(BatchDetail bd1, BatchDetail bd2) { return bd1.logMessageID.CompareTo(bd2.logMessageID); });
            batch.lstBatchDetail = lstBatchDetails;
            batch.insert();
            //SqlDataRecord dr = new SqlDataRecord(new SqlMetaData[] { new SqlMetaData("batchID", SqlDbType.Char, 36) });
            //dr.SetString(0, batch.batchID);    //EmployeeEosID
            //SqlContext.Pipe.Send(dr);

            #endregion Generate Payroll
            return batch.batchID;
        }
        return string.Empty;
    }
};
Posted
Updated 14-Jun-12 21:53pm
v2
Comments
Stephen Hewison 15-Jun-12 2:20am    
Can you provide a bit more information about the application? Is it a windows form, wpf, service? Is the db sql, my sql, oracle, db2? What is the query it's trying to execute?
youssef_123 15-Jun-12 2:29am    
ok man it is a web application using ADO.net and T-sql and the function include many functions that run one by one and all these functions are written inside TransactionScope(the function that are inside this function for example: insert this,delete this, update this and this and .. it is very big but it is working normally before i am sure and i edit it a little bit only
thnx )
Sandeep Mewara 15-Jun-12 3:15am    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.

Do add the error you get.
youssef_123 15-Jun-12 4:01am    
there is no error!!!
OriginalGriff 15-Jun-12 4:08am    
Of course there is an error! Just you don't know where, and we don't know what.

Rather than dumping your entire program on use and expecting us to wade through it and work out what is supposed to be going on, why not try adding some logging information to find out what is happening and what isn't? Run it so it fails, and look at your logs. What is the data like? Add more logging and remove others, until you can get a clearer picture of what is happening, and what isn't.
Then ask for help if you need it, but with a targeted problem instead of "here it is, I dunno what's going on" - which doesn't help us to help you at all!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900