Example #1
0
        private void executeDeduction()
        {
            int numOfRecords = lstDeductions.Items.Count;
            int currentRecord;

            SqlConnection  conn     = ConnectDB.GetConnection();
            SqlTransaction sqlTrans = null;
            SqlCommand     cmd;

            try
            {
                conn.Open();
                sqlTrans = conn.BeginTransaction();

                cmd             = conn.CreateCommand();
                cmd.Transaction = sqlTrans;

                int selectedMonth = Convert.ToInt16(cboMonth.SelectedValue);
                int selectedYear  = Convert.ToInt16(cboYear.Text);

                #region loop through records
                //loop through records
                for (currentRecord = 0; currentRecord < numOfRecords; currentRecord++)
                {
                    cmd.Parameters.Clear();

                    memberID = Convert.ToInt16(lstDeductions.Items[currentRecord].SubItems[1].Text);
                    decimal monthlyLoanRepayment   = Convert.ToDecimal(lstDeductions.Items[currentRecord].SubItems[5].Text);
                    decimal lstAllSavingsDeduction = Convert.ToDecimal(lstDeductions.Items[currentRecord].SubItems[4].Text);
                    decimal lstAllLoansDeduction   = Convert.ToDecimal(lstDeductions.Items[currentRecord].SubItems[5].Text);
                    decimal lstTotalDeductions     = Convert.ToDecimal(lstDeductions.Items[currentRecord].SubItems[6].Text);

                    totalSavings = Convert.ToDecimal(lstDeductions.Items[currentRecord].SubItems[4].Text);

                    string transactionID = "DED" + DateTime.Now.ToString("ddMMyyhhmmss");

                    Deduction newPosting        = new Deduction();
                    string    postSavingsStatus = newPosting.postSavings(conn, cmd, sqlTrans, memberID, transactionID, totalSavings, numOfRows, errorflag, selectedMonth, selectedYear);
                    //MessageBox.Show("Post Savings Status: " + postSavingsStatus);

                    string postLoansStatus = newPosting.postLoans(conn, cmd, sqlTrans, memberID, transactionID, currentRecord, selectedMonth, selectedYear, numOfRows, errorflag, monthlyLoanRepayment);
                    //MessageBox.Show("PostLoan Status: " + postLoansStatus);

                    string recordDeductionStatus = newPosting.recordDeduction(cmd, memberID, transactionID, currentRecord, selectedMonth, selectedYear, lstAllSavingsDeduction, lstAllLoansDeduction, lstTotalDeductions, numOfRows, errorflag);
                    //MessageBox.Show("Record Deductions status: " + recordDeductionStatus);

                    string recordDeductionDetailsStatus = newPosting.recordDeductionDetails(cmd, memberID, transactionID, currentRecord, numOfRows, errorflag, lstAllSavingsDeduction, lstAllLoansDeduction, repaymentLoanType, servicingLoan, loanMoreThanSavings);
                    //MessageBox.Show("Record Deduction Detail Status: " + recordDeductionDetailsStatus);

                    if (errorflag == 0)
                    {
                        //MessageBox.Show("Posted");
                        //lstDeductions.Items[currentRecord].SubItems[7].Text = "Posted";
                    }
                }
                //end of for loop
                #endregion end of loop


                if (errorflag == 0)
                {
                    Deduction newDeductionPosting = new Deduction();
                    string    deductionDateRecord = newDeductionPosting.recordDeductionDate(selectedMonth, selectedYear);
                    if (deductionDateRecord == "1")
                    {
                        sqlTrans.Commit();
                        MessageBox.Show("Transaction has been Successfully Posted");
                        getDeductionList();
                        ActivityLog.logActivity(userId, "Post Deduction - Collective", "Deduction Posting for Month:" + selectedMonth + " " + selectedYear);
                    }
                    else
                    {
                        sqlTrans.Rollback();
                        MessageBox.Show("Posting Transaction Failed");
                    }
                }
                else
                {
                    sqlTrans.Rollback();
                    MessageBox.Show("Posting Transaction Failed");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }//end of executeDeduction
        private void executeDeduction()
        {
            int numOfRecords = lstMonthlyDeductions.Items.Count;
            int currentRecord;

            SqlConnection  conn     = ConnectDB.GetConnection();
            SqlTransaction sqlTrans = null;
            SqlCommand     cmd;

            try
            {
                conn.Open();
                sqlTrans = conn.BeginTransaction();

                cmd             = conn.CreateCommand();
                cmd.Transaction = sqlTrans;

                int selectedMonth = Convert.ToInt16(cboMonth.SelectedValue);
                int selectedYear  = Convert.ToInt16(cboYear.Text);

                #region loop through records
                //loop through records
                for (currentRecord = 0; currentRecord < numOfRecords; currentRecord++)
                {
                    cmd.Parameters.Clear();

                    memberID = Convert.ToInt16(lstMonthlyDeductions.Items[currentRecord].SubItems[1].Text);
                    decimal monthlyLoanRepayment   = Convert.ToDecimal(lstMonthlyDeductions.Items[currentRecord].SubItems[5].Text);
                    decimal lstAllSavingsDeduction = Convert.ToDecimal(lstMonthlyDeductions.Items[currentRecord].SubItems[4].Text);
                    decimal lstAllLoansDeduction   = Convert.ToDecimal(lstMonthlyDeductions.Items[currentRecord].SubItems[5].Text);
                    decimal lstTotalDeductions     = Convert.ToDecimal(lstMonthlyDeductions.Items[currentRecord].SubItems[6].Text);


                    string transactionID = "DED" + DateTime.Now.ToString("ddMMyyhhmmss");
                    totalSavings = Convert.ToDecimal(lblTotalSavings.Text);

                    Deduction newPosting        = new Deduction();
                    string    postSavingsStatus = newPosting.postSavings(conn, cmd, sqlTrans, memberID, transactionID, lstAllSavingsDeduction, numOfRows, errorflag, selectedMonth, selectedYear);
                    //MessageBox.Show("Post Savings Status: " + postSavingsStatus);

                    string postLoansStatus = newPosting.postLoans(conn, cmd, sqlTrans, memberID, transactionID, currentRecord, selectedMonth, selectedYear, numOfRows, errorflag, monthlyLoanRepayment);
                    //MessageBox.Show("PostLoan Status: " + postLoansStatus);

                    string recordDeductionStatus = newPosting.recordDeduction(cmd, memberID, transactionID, currentRecord, selectedMonth, selectedYear, lstAllSavingsDeduction, lstAllLoansDeduction, lstTotalDeductions, numOfRows, errorflag);
                    //MessageBox.Show("Record Deductions status: " + recordDeductionStatus);

                    //string recordDeductionDetailsStatus = newPosting.recordDeductionDetails(cmd, memberID, transactionID, currentRecord, numOfRows, errorflag, lstAllSavingsDeduction, lstAllLoansDeduction, repaymentLoanType, servicingLoan, loanMoreThanSavings);
                    //MessageBox.Show("Record Deduction Detail Status: " + recordDeductionDetailsStatus);
                    int recordDeductionDetailStatus = recordDeductionDetails(cmd, memberID, transactionID, errorflag, numOfRows);
                    //MessageBox.Show(recordDeductionDetailStatus.ToString());
                }
                //end of for loop
                #endregion end of loop


                if (errorflag == 0)
                {
                    sqlTrans.Commit();
                    MessageBox.Show("Member Deduction has been successfully posted.", "Deduction Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    getMonthlyDeductionsInfo(memberID);
                    getMemberPreviousDeductions(memberID);
                    getPreviousDeductionDate(memberID);


                    //Display Savings and Loan information
                    //lstMonthlyDeductions_SelectedIndexChanged(sender, e);
                    string selectedMemberID = lstMonthlyDeductions.Items[0].SubItems[1].Text;
                    getSavingsInfo(selectedMemberID);
                    getLoansInfo(selectedMemberID);

                    txtChangeSavingsAmt.Text = string.Empty;
                    txtChangeLoanAmount.Text = string.Empty;

                    ActivityLog.logActivity(UserId, "Posting Deduction - Individual", "Deduction Posting for MemberID:" + memberID + " for  Month:" + selectedMonth + " " + selectedYear);
                }
                else
                {
                    sqlTrans.Rollback();
                    MessageBox.Show("Deduction Transaction failed and is aborted!", "Deduction Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }