Click here to Skip to main content
13,354,132 members (58,220 online)
Rate this:
Please Sign up or sign in to 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 is not working can any one help me


this is the code that must run correctly :

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() + "'");
                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.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;


                    #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);

                        #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);

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

                        #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)

                                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;

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

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

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

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

                            #endregion Compute Rules in Employee Regulation

                            #region Compute/Reverse Accrual
                            if (isReverseAccrual == true || isCloseFile == true)
                                ReverseAccrual(payProcessId, processStartDate, processEndDate, personId, processStartDate, processEndDate);
                                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

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

            #endregion Generate Payroll
            return batch.batchID;
        return string.Empty;
Posted 14-Jun-12 21:16pm
Updated 14-Jun-12 22:53pm
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 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!
youssef_123 15-Jun-12 4:14am
ok i am doing that now 10x
Stephen Hewison 15-Jun-12 12:31pm
I agree with OriginalGriff about the logging. It can be very frustrating when you get unexpected results moving from dev to production environments and as such I can't over emphasise the importance of good logging. .Net has an excellent mechanism for doing this called trace listeners. You set the trace level in your config to either None, Error, Info, Critical or Verbose. So in good times you run the application in None, or Error modes so you don't write out endless logs. If you've got a problem you just set the config to run in Info of Verbose the application starts writing out loads of information. Then log absolutely everything in your code through the trace listener but with each write you specify if it's an Error, Info or Verbose log message. The following is a good starting point for trace listener.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 15 Jun 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100