Exemplo n.º 1
0
        private void saveLoanApplication()
        {
            SqlConnection conn     = ConnectDB.GetConnection();
            string        strQuery = "Insert into LoanApplication(AppMonth,AppYear,MemberID,LoanCategoryID,LoanTypeID," +
                                     "LoanAmount,FormFee,StartRepaymentMonth,StartRepaymentYear,SuretyMemberID1,SuretyMemberID2,WitnessMemberID," +
                                     "NonMemberSurety1,NonMemberSurety2,NonMemberWitness,LoanDuration,InterestRate,InterestAmount," +
                                     "TotalRepayment,MonthlyRepayment,TransactionID)values(@AppMonth,@AppYear,@MemberID,@LoanCategoryID,@LoanTypeID," +
                                     "@LoanAmount,@FormFee,@StartRepaymentMonth,@StartRepaymentYear,@SuretyMemberID1,@SuretyMemberID2,@WitnessMemberID," +
                                     "@NonMemberSurety1,@NonMemberSurety2,@NonMemberWitness,@LoanDuration,@InterestRate,@InterestAmount," +
                                     "@TotalRepayment,@MonthlyRepayment,@TransactionID)";

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

            SqlCommand cmd = new SqlCommand(strQuery, conn);

            #region parameters
            cmd.Parameters.Add("@AppMonth", SqlDbType.Int);
            cmd.Parameters["@AppMonth"].Value = DateFunction.getMonthByDate(cboMonth.Text);


            cmd.Parameters.Add("@AppYear", SqlDbType.Int);
            cmd.Parameters["@AppYear"].Value = Convert.ToInt32(cboYear.Text);

            cmd.Parameters.Add("@MemberID", SqlDbType.Int);
            cmd.Parameters["@MemberID"].Value = memberID;

            cmd.Parameters.Add("@LoanCategoryID", SqlDbType.Int);
            cmd.Parameters["@LoanCategoryID"].Value = Convert.ToInt32(cboCategory.SelectedValue.ToString());

            cmd.Parameters.Add("@LoanTypeID", SqlDbType.Int);
            cmd.Parameters["@LoanTypeID"].Value = Convert.ToInt32(cboType.SelectedValue.ToString());

            cmd.Parameters.Add("@LoanAmount", SqlDbType.Decimal);
            cmd.Parameters["@LoanAmount"].Value = Convert.ToDecimal(txtAmount.Text);

            cmd.Parameters.Add("@FormFee", SqlDbType.Decimal);
            cmd.Parameters["@FormFee"].Value = Convert.ToDecimal(txtFormFee.Text);

            int startRepaymentMonth = 0;
            int startRepaymentYear  = 0;
            if ((chkStartRepayment.Checked == true) && (cboStartRepaymentMonth.Text != string.Empty) && (cboStartRepaymentYear.Text != string.Empty))
            {
                startRepaymentMonth = DateFunction.getMonthByDate(cboStartRepaymentMonth.Text);
                startRepaymentYear  = Convert.ToInt32(cboStartRepaymentYear.Text);
            }
            else
            {
                //DateTime currentDate = DateTime.Now;
                //int currentMonth = currentDate.Month;
                string   strAppDate = cboMonth.Text + " " + cboYear.Text;
                DateTime appDate    = DateTime.Parse(strAppDate);
                DateTime nextMonth  = appDate.AddMonths(1);
                startRepaymentMonth = nextMonth.Month;
                startRepaymentYear  = nextMonth.Year;
            }

            cmd.Parameters.Add("@StartRepaymentMonth", SqlDbType.Int);
            cmd.Parameters["@StartRepaymentMonth"].Value = startRepaymentMonth;

            cmd.Parameters.Add("@StartRepaymentYear", SqlDbType.Int);
            cmd.Parameters["@StartRepaymentYear"].Value = startRepaymentYear;

            cmd.Parameters.Add("@SuretyMemberID1", SqlDbType.NVarChar, 10);
            cmd.Parameters["@SuretyMemberID1"].Value = lblSuretyMemberID_1.Text;

            cmd.Parameters.Add("@SuretyMemberID2", SqlDbType.NVarChar, 10);
            cmd.Parameters["@SuretyMemberID2"].Value = lblSuretyMemberID_2.Text;

            cmd.Parameters.Add("@WitnessMemberID", SqlDbType.NVarChar, 10);
            cmd.Parameters["@WitnessMemberID"].Value = lblSuretyMemberID_3.Text;

            cmd.Parameters.Add("@NonMemberSurety1", SqlDbType.NVarChar, 100);
            cmd.Parameters["@NonMemberSurety1"].Value = txtSuretyName1.Text;

            cmd.Parameters.Add("@NonMemberSurety2", SqlDbType.NVarChar, 100);
            cmd.Parameters["@NonMemberSurety2"].Value = txtSuretyName2.Text;

            cmd.Parameters.Add("@NonMemberWitness", SqlDbType.NVarChar, 100);
            cmd.Parameters["@NonMemberWitness"].Value = txtWitnessName.Text;

            cmd.Parameters.Add("@LoanDuration", SqlDbType.Int);
            cmd.Parameters["@LoanDuration"].Value = Convert.ToInt32(txtLoanDuration.Text);

            cmd.Parameters.Add("@InterestRate", SqlDbType.Decimal);
            cmd.Parameters["@InterestRate"].Value = Convert.ToDecimal(txtLoanInterestRate.Text);

            cmd.Parameters.Add("@InterestAmount", SqlDbType.Decimal);
            cmd.Parameters["@InterestAmount"].Value = Convert.ToDecimal(txtInterestAmount.Text);

            cmd.Parameters.Add("@TotalRepayment", SqlDbType.Decimal);
            cmd.Parameters["@TotalRepayment"].Value = Convert.ToDecimal(txtTotalRepaymentAmount.Text);

            cmd.Parameters.Add("@MonthlyRepayment", SqlDbType.Decimal);
            cmd.Parameters["@MonthlyRepayment"].Value = Convert.ToDecimal(txtMonthRepayment.Text);

            cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar, 50);
            cmd.Parameters["@TransactionID"].Value = transactionID;
            #endregion


            try
            {
                conn.Open();
                int rowAffected = cmd.ExecuteNonQuery();

                if (rowAffected > 0)
                {
                    MessageBox.Show("Loan Application has been Successfully saved.", "Loan Application", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Hide();
                    clearAllFields();

                    string ActivityType = "Loan Application";
                    string Description  = "Loan Application of " + cboType.Text + ". Amount: " + txtAmount.Text + " for " + cboFileNo.Text + " with TransactionID: " + transactionID;
                    ActivityLog.logActivity(userId, ActivityType, Description);
                }
                else
                {
                    MessageBox.Show("An error has occurred!", "Loan Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }finally
            {
                conn.Close();
            }
        }
Exemplo n.º 2
0
 private void logUserActivity(string userId, string ActivityType, string Description)
 {
     ActivityLog.logActivity(userId, ActivityType, Description);
 }
Exemplo n.º 3
0
        private void btnSingleUnpost_Click(object sender, EventArgs e)
        {
            int memberID;

            if (dtGrdSingleDeductions.SelectedRows.Count > 0)
            {
                selDeductionId      = Convert.ToInt16(dtGrdSingleDeductions.SelectedRows[0].Cells[0].Value.ToString());
                selDelMonth         = dtGrdSingleDeductions.SelectedRows[0].Cells[1].Value.ToString();
                selDelYear          = Convert.ToInt16(dtGrdSingleDeductions.SelectedRows[0].Cells[2].Value.ToString());
                memberID            = Convert.ToInt16(dtGrdSingleDeductions.SelectedRows[0].Cells[3].Value.ToString());
                selDedTransactionId = dtGrdSingleDeductions.SelectedRows[0].Cells[8].Value.ToString();

                //MessageBox.Show("ID: " + selDeductionId.ToString() + "Month: " + selDelMonth.ToString() + " Year: " + selDelYear.ToString() + "MemberID: " + memberID.ToString() + "TransactionID: " + selDedTransactionId);
            }
            else
            {
                MessageBox.Show("Choose a Member Deduction Record to Delete", "Unpost Deduction", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            DialogResult res = MessageBox.Show("Do you wish to Unpost the Selected Record?", "Unpost", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res == DialogResult.Yes)
            {
                SqlConnection conn = ConnectDB.GetConnection();
                SqlCommand    cmd  = conn.CreateCommand();


                try
                {
                    conn.Open();
                    SqlTransaction sqlTrans = conn.BeginTransaction();
                    cmd.CommandType = CommandType.Text;
                    cmd.Transaction = sqlTrans;

                    Cl_UnpostDeductions deletePosting = new Cl_UnpostDeductions();
                    string savingsDelStatus           = deletePosting.unpostSavingsDeductions(conn, cmd, memberID, selDedTransactionId);
                    string loanDelStatus             = deletePosting.unpostLoansDeduction(conn, cmd, memberID, selDedTransactionId);
                    string deductionDelStatus        = deletePosting.unpostDeductions(conn, cmd, memberID, selDedTransactionId, selDelMonth, selDelYear);
                    string deductionDetailsDelStatus = deletePosting.unpostDeductionDetails(conn, cmd, memberID, selDedTransactionId);

                    //MessageBox.Show("Savings Status: " + savingsDelStatus + "\nLoans Status: " + loanDelStatus + "\nDeductions: " + deductionDelStatus + "\nDeduction Detials: " + deductionDetailsDelStatus);

                    if ((Convert.ToInt16(savingsDelStatus) != 0) || (Convert.ToInt16(deductionDetailsDelStatus) != 0) || (Convert.ToInt16(deductionDelStatus) != 0))
                    {
                        sqlTrans.Commit();
                        ActivityLog.logActivity(UserId, "Unpost Deduction - Single", "Unpost Deduction for MemberID:" + memberID + " for " + selDelMonth + " " + selDelYear);
                        MessageBox.Show("Selected record has been Successfully Deleted.", "Unpost Deduction", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        UnpostDeductions unpostDeductions = new UnpostDeductions(UserId);
                        unpostDeductions.MdiParent = this.ParentForm;
                        unpostDeductions.Show();
                        this.Close();
                    }
                    else
                    {
                        sqlTrans.Rollback();
                        MessageBox.Show("An error has occurred.", "Unpost Deduction", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Exemplo n.º 4
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
Exemplo n.º 5
0
        private void btnPost_Click(object sender, EventArgs e)
        {
            if (CheckForNumber.isNumeric(txtWithdrawAmt.Text) && (Convert.ToDecimal(txtWithdrawAmt.Text) > 0))
            {
                DialogResult res = MessageBox.Show("Do you wish to post this Transaction?", "Withdrawal", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res == DialogResult.Yes)
                {
                    #region ExecutePost
                    string strMonth = dateTimePicker1.Value.Month.ToString();
                    string strYear  = dateTimePicker1.Value.Year.ToString();

                    string        transactionID = "WIT" + DateTime.Now.ToString("ddMMyyhhmmss");
                    SqlConnection conn          = ConnectDB.GetConnection();

                    conn.Open();
                    SqlTransaction mySqlTrans = conn.BeginTransaction();

                    string strInsertSavings = "Insert into Savings(MemberID,SavingSource,Amount,Month,Year,TransactionID)values(@MemberID," +
                                              "@SavingSource,@Amount,@Month,@Year,@TransactionID)";
                    string strInsertSavingsWithdrawal = "Insert into SavingsWithdrawal(SavingsID,MemberID,SavingsTypeID,Amount," +
                                                        "WithdrawAmount,Balance)values(@SavingsID,@MemberID,@SavingsTypeID,@Amount,@WithdrawalAmount,@Balance)";

                    string strQuery = "Select SavingsID from Savings where TransactionID=@TransactionID";

                    SqlCommand cmd = conn.CreateCommand();
                    cmd.Transaction = mySqlTrans;

                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = strInsertSavings;

                    #region cmdParameters
                    cmd.Parameters.Add("@MemberID", SqlDbType.Int);
                    cmd.Parameters["@MemberID"].Value = memberID;

                    cmd.Parameters.Add("@SavingSource", SqlDbType.NVarChar, 50);
                    cmd.Parameters["@SavingSource"].Value = "Withdrawal";

                    cmd.Parameters.Add("@Amount", SqlDbType.Decimal);
                    cmd.Parameters["@Amount"].Value = "-" + txtWithdrawAmt.Text;

                    cmd.Parameters.Add("@Month", SqlDbType.NVarChar, 50);
                    cmd.Parameters["@Month"].Value = strMonth;

                    cmd.Parameters.Add("@Year", SqlDbType.NVarChar, 50);
                    cmd.Parameters["@Year"].Value = strYear;

                    cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar, 30);
                    cmd.Parameters["@TransactionID"].Value = transactionID;
                    #endregion cmdParameters
                    try
                    {
                        int rowAffected = cmd.ExecuteNonQuery();

                        if (rowAffected > 0)
                        {
                            cmd.CommandText = strQuery;
                            cmd.Parameters["@TransactionID"].Value = transactionID;

                            int savingsID = Convert.ToInt16(cmd.ExecuteScalar());

                            cmd.CommandText = strInsertSavingsWithdrawal;

                            #region cmdParameters - strInsertSavingsWithrawal
                            cmd.Parameters.Add("@SavingsID", SqlDbType.Int);
                            cmd.Parameters["@SavingsID"].Value = savingsID;

                            cmd.Parameters["@MemberID"].Value = memberID;

                            cmd.Parameters.Add("@SavingsTypeID", SqlDbType.Int);
                            cmd.Parameters["@SavingsTypeID"].Value = cboSavingsType.SelectedValue;

                            cmd.Parameters["@Amount"].Value = lblAcctAmount.Text;

                            cmd.Parameters.Add("@WithdrawalAmount", SqlDbType.Decimal);
                            cmd.Parameters["@WithdrawalAmount"].Value = txtWithdrawAmt.Text;

                            cmd.Parameters.Add("@Balance", SqlDbType.Decimal);
                            cmd.Parameters["@Balance"].Value = lblAmtBalance.Text;
                            #endregion

                            rowAffected = cmd.ExecuteNonQuery();
                            if (rowAffected > 0)
                            {
                                mySqlTrans.Commit();
                                MessageBox.Show("Transaction is Successfully Posted", "Withdrawal", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                string logDescription = cboSavingsType.Text + " withdrawal of " + txtWithdrawAmt.Text +
                                                        " from Member with ID " + memberID;


                                txtWithdrawAmt.Text    = string.Empty;
                                txtWithdrawAmt.Enabled = false;
                                btnPost.Enabled        = false;
                                getPreviousWithdrawals();
                                ActivityLog.logActivity(UserID, "Withdrawal", logDescription);
                            }
                            else
                            {
                                mySqlTrans.Rollback();
                                MessageBox.Show("An error has occurred!", "Withdrawal", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            mySqlTrans.Rollback();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                    #endregion
                }
            }
            else
            {
                MessageBox.Show("Withdrawal Amount has not been Supplied", "Withdrawal", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 6
0
        private void btnBulkUnpost_Click(object sender, EventArgs e)
        {
            if (dtGrdBulkDeductions.SelectedRows.Count > 0)
            {
                selDeductionId = Convert.ToInt16(dtGrdBulkDeductions.SelectedRows[0].Cells[0].Value.ToString());
                selDelMonth    = dtGrdBulkDeductions.SelectedRows[0].Cells[1].Value.ToString();
                selDelYear     = Convert.ToInt16(dtGrdBulkDeductions.SelectedRows[0].Cells[2].Value.ToString());
                //MessageBox.Show("ID: " + selDeductionId.ToString() + "Month: " + selDelMonth.ToString() + " Year: " + selDelYear.ToString());
            }
            else
            {
                MessageBox.Show("Choose a Deduction Record to Delete", "Unpost Deduction", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            DialogResult res = MessageBox.Show("Do you wish to Unpost the Selected Deduction?", "Unpost Deduction", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res == DialogResult.Yes)
            {
                SqlConnection conn = ConnectDB.GetConnection();
                SqlCommand    cmd;


                try
                {
                    conn.Open();
                    SqlTransaction sqlTrans = conn.BeginTransaction();
                    cmd             = conn.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.Transaction = sqlTrans;
                    cmd.CommandText = "Select distinct d.TransactionID from Deductions d " +
                                      "inner join MonthByName m on m.MonthID=d.Month " +
                                      "where m.month='" + selDelMonth + "' And d.Year=" + selDelYear;

                    SqlDataReader reader = cmd.ExecuteReader();
                    selDeductionTransactionDel.Clear();
                    while (reader.Read())
                    {
                        selDeductionTransactionDel.Add(reader["TransactionID"].ToString());
                    }
                    reader.Close();

                    //MessageBox.Show(selDeductionTransactionDel.Count.ToString());

                    Cl_UnpostDeductions deletePosting = new Cl_UnpostDeductions();
                    string savingsDelStatus           = deletePosting.unpostSavingsDeductions(conn, cmd, selDeductionTransactionDel);
                    string loanDelStatus             = deletePosting.unpostLoansDeduction(conn, cmd, selDeductionTransactionDel);
                    string deductionDelStatus        = deletePosting.unpostDeductions(conn, cmd, selDeductionTransactionDel, selDelMonth, selDelYear);
                    string deductionDetailsDelStatus = deletePosting.unpostDeductionDetails(conn, cmd, selDeductionTransactionDel);
                    string deductionDatesDelStatus   = deletePosting.unpostDeductionDates(conn, cmd, selDelMonth, selDelYear);

                    //MessageBox.Show("Savings Status: " + savingsDelStatus + "\nLoans Status: " + loanDelStatus + "\nDeductions: " + deductionDelStatus + "\nDeduction Detials: " + deductionDetailsDelStatus);

                    if ((Convert.ToInt16(deductionDelStatus) != 0) && (Convert.ToInt16(deductionDetailsDelStatus) != 0) && (Convert.ToInt16(deductionDelStatus) != 0))
                    {
                        sqlTrans.Commit();
                        ActivityLog.logActivity(UserId, "Unpost Deduction - Bulk", "Unpost Deduction Record ID:" + selDeductionId + " for " + selDelMonth + " " + selDelYear);
                        MessageBox.Show("Selected record has been Successfully Deleted.", "Unpost Deduction", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        UnpostDeductions unpostDeductions = new UnpostDeductions(UserId);
                        unpostDeductions.MdiParent = this.ParentForm;
                        unpostDeductions.Show();
                        this.Close();
                    }
                    else
                    {
                        sqlTrans.Rollback();
                        MessageBox.Show("An error has occurred.", "Unpost Deduction", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Exemplo n.º 7
0
        private void executeEditLoansBF()
        {
            if (txtAmount.Text != string.Empty && txtInterest.Text != string.Empty && txtTotalRepayment.Text != string.Empty && txtAmountPaid.Text != string.Empty && txtMonthlyRepayment.Text != string.Empty)
            {
                SqlConnection conn = ConnectDB.GetConnection();
                conn.Open();

                try
                {
                    SqlTransaction sqlTrans = conn.BeginTransaction();


                    string QueryLoanApp = "Update LoanApplication set AppMonth=@AppMonth, AppYear=@AppYear,LoanCategoryID=@LoanCategoryID, " +
                                          "LoanTypeID=@LoanTypeID,LoanAmount=@LoanAmount,StartRepaymentMonth=@StartRepaymentMonth,StartRepaymentYear=@StartRepaymentYear," +
                                          "LoanDuration=@LoanDuration,InterestRate=@InterestRate,InterestAmount=@InterestAmount,TotalRepayment=@TotalRepayment, " +
                                          "MonthlyRepayment=@MonthlyRepayment where LoanApplicationID=@LoanApplicationID";

                    SqlCommand cmd = new SqlCommand(QueryLoanApp, conn);
                    cmd.Transaction = sqlTrans;

                    //MessageBox.Show("Application  ID: " + loanApplicationID.ToString());
                    #region parameters
                    cmd.Parameters.Add("@AppMonth", SqlDbType.Int);
                    cmd.Parameters["@AppMonth"].Value = dtAppDate.Value.Month.ToString();

                    cmd.Parameters.Add("@AppYear", SqlDbType.Int);
                    cmd.Parameters["@AppYear"].Value = dtAppDate.Value.Year.ToString();

                    cmd.Parameters.Add("@LoanCategoryID", SqlDbType.Int);
                    cmd.Parameters["@LoanCategoryID"].Value = cboLoanCategory.SelectedValue;

                    cmd.Parameters.Add("@LoanTypeID", SqlDbType.Int);
                    cmd.Parameters["@LoanTypeID"].Value = cboLoanType.SelectedValue;

                    cmd.Parameters.Add("@LoanAmount", SqlDbType.Decimal);
                    cmd.Parameters["@LoanAmount"].Value = txtAmount.Text;

                    cmd.Parameters.Add("@StartRepaymentMonth", SqlDbType.Int);
                    cmd.Parameters["@StartRepaymentMonth"].Value = dtStartRepayment.Value.Month.ToString();

                    cmd.Parameters.Add("@StartRepaymentYear", SqlDbType.Int);
                    cmd.Parameters["@StartRepaymentYear"].Value = dtStartRepayment.Value.Year.ToString();

                    cmd.Parameters.Add("@LoanDuration", SqlDbType.Int);
                    cmd.Parameters["@LoanDuration"].Value = lblDuration.Text;

                    cmd.Parameters.Add("@InterestRate", SqlDbType.Decimal);
                    cmd.Parameters["@InterestRate"].Value = lblInterestRate.Text;

                    cmd.Parameters.Add("@InterestAmount", SqlDbType.Decimal);
                    cmd.Parameters["@InterestAmount"].Value = txtInterest.Text;

                    cmd.Parameters.Add("@TotalRepayment", SqlDbType.Decimal);
                    cmd.Parameters["@TotalRepayment"].Value = txtTotalRepayment.Text;

                    cmd.Parameters.Add("@MonthlyRepayment", SqlDbType.Decimal);
                    cmd.Parameters["@MonthlyRepayment"].Value = txtMonthlyRepayment.Text;

                    cmd.Parameters.Add("@LoanApplicationID", SqlDbType.Int);
                    cmd.Parameters["@LoanApplicationID"].Value = loanApplicationID;
                    #endregion


                    int rowAffected_QueryLoanApp = cmd.ExecuteNonQuery();
                    MessageBox.Show("QueryLoanApp: " + rowAffected_QueryLoanApp.ToString());

                    string QueryLoans;

                    if (dateFinishedPayment != string.Empty)
                    {
                        QueryLoans = "Update Loans set RepaymentAmount=@RepaymentAmount,AmountPaid=@AmountPaid,OutstandingAmount=@OutstandingAmount, " +
                                     "PaymentStatus=@PaymentStatus,PaymentFinished=@PaymentFinished,DateFinishedPayment=@DateFinishedPayment,Remark=@Remark " +
                                     "where LoanApplicationID=@LoanApplicationID";
                    }
                    else
                    {
                        QueryLoans = "Update Loans set RepaymentAmount=@RepaymentAmount,AmountPaid=@AmountPaid,OutstandingAmount=@OutstandingAmount, " +
                                     "PaymentStatus=@PaymentStatus,PaymentFinished=@PaymentFinished,Remark=@Remark " +
                                     "where LoanApplicationID=@LoanApplicationID";
                    }

                    cmd.CommandText = QueryLoans;
                    //cmd.Transaction = sqlTrans;

                    #region parameters
                    cmd.Parameters.Add("@RepaymentAmount", SqlDbType.Decimal);
                    cmd.Parameters["@RepaymentAmount"].Value = txtTotalRepayment.Text;

                    cmd.Parameters.Add("@AmountPaid", SqlDbType.Decimal);
                    cmd.Parameters["@AmountPaid"].Value = txtAmountPaid.Text;

                    cmd.Parameters.Add("@OutstandingAmount", SqlDbType.Decimal);
                    cmd.Parameters["@OutstandingAmount"].Value = txtOutstandingAmt.Text;

                    cmd.Parameters.Add("@PaymentStatus", SqlDbType.NVarChar, 10);
                    cmd.Parameters["@PaymentStatus"].Value = paymentStatus;

                    cmd.Parameters.Add("@PaymentFinished", SqlDbType.NVarChar, 5);
                    cmd.Parameters["@PaymentFinished"].Value = paymentFinished;

                    if (dateFinishedPayment != string.Empty)
                    {
                        cmd.Parameters.Add("@DateFinishedPayment", SqlDbType.Date);
                        cmd.Parameters["@DateFinishedPayment"].Value = DateTime.Parse(dateFinishedPayment);
                    }

                    cmd.Parameters.Add("@Remark", SqlDbType.NVarChar, 1000);
                    cmd.Parameters["@Remark"].Value = txtRemark.Text;

                    cmd.Parameters["@LoanApplicationID"].Value = loanApplicationID;

                    #endregion

                    int rowAffected_QueryLoans = cmd.ExecuteNonQuery();
                    MessageBox.Show("QueryLoans: " + rowAffected_QueryLoans.ToString());

                    if ((rowAffected_QueryLoanApp > 0) && (rowAffected_QueryLoans > 0))
                    {
                        sqlTrans.Commit();
                        MessageBox.Show("Record has been successfully edited.", "Loans Forward", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ActivityLog.logActivity(userId, "LoansForward", "Edit Loans Brought Forward with LoanApplication ID of " + loanApplicationID);

                        EditLoansBroughtForward editLoansBroughtForward = new EditLoansBroughtForward(userId);
                        editLoansBroughtForward.MdiParent = this.ParentForm;
                        editLoansBroughtForward.Show();

                        this.Close();
                    }
                    else
                    {
                        sqlTrans.Rollback();
                        MessageBox.Show("An error occurred editing record.", "Loans Forward", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }//end of if statement check
        }
Exemplo n.º 8
0
        private void executePosting()
        {
            btnPost.Enabled = false;

            string appMonth         = dtAppDate.Value.Month.ToString();
            string appYear          = dtAppDate.Value.Year.ToString();
            string rePay_StartMonth = dtStartRepayment.Value.Month.ToString();
            string rePay_StartYear  = dtStartRepayment.Value.Year.ToString();

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

            SqlConnection conn = ConnectDB.GetConnection();

            conn.Open();

            try
            {
                SqlTransaction sqlTrans = conn.BeginTransaction();


                string strQuery = "Insert into LoanApplication(AppMonth,AppYear,MemberID,LoanCategoryID," +
                                  "LoanTypeID,LoanAmount,StartRepaymentMonth,StartRepaymentYear,LoanDuration,InterestRate," +
                                  "InterestAmount,TotalRepayment,MonthlyRepayment,ApprovalStatus,TransactionID)" +
                                  "values(@AppMonth,@AppYear,@MemberID,@LoanCategoryID,@LoanTypeID,@LoanAmount,@StartRepaymentMonth,@StartRepaymentYear," +
                                  "@LoanDuration,@InterestRate,@InterestAmount,@TotalRepayment,@MonthlyRepayment,@ApprovalStatus,@TransactionID)";

                SqlCommand cmd = new SqlCommand(strQuery, conn);
                cmd.Transaction = sqlTrans;

                #region Parameters
                cmd.Parameters.Add("@AppMonth", SqlDbType.Int);
                cmd.Parameters["@AppMonth"].Value = appMonth;

                cmd.Parameters.Add("@AppYear", SqlDbType.Int);
                cmd.Parameters["@AppYear"].Value = appYear;

                cmd.Parameters.Add("@MemberID", SqlDbType.Int);
                cmd.Parameters["@MemberID"].Value = memberID;

                cmd.Parameters.Add("@LoanCategoryID", SqlDbType.Int);
                cmd.Parameters["@LoanCategoryID"].Value = cboLoanCategory.SelectedValue.ToString();

                cmd.Parameters.Add("@LoanTypeID", SqlDbType.Int);
                cmd.Parameters["@LoanTypeID"].Value = cboLoanType.SelectedValue.ToString();

                cmd.Parameters.Add("@LoanAmount", SqlDbType.Decimal);
                cmd.Parameters["@LoanAmount"].Value = txtAmount.Text;

                cmd.Parameters.Add("@StartRepaymentMonth", SqlDbType.Decimal);
                cmd.Parameters["@StartRepaymentMonth"].Value = rePay_StartMonth;

                cmd.Parameters.Add("@StartRepaymentYear", SqlDbType.Decimal);
                cmd.Parameters["@StartRepaymentYear"].Value = rePay_StartYear;

                cmd.Parameters.Add("@LoanDuration", SqlDbType.Int);
                cmd.Parameters["@LoanDuration"].Value = lblDuration.Text;

                cmd.Parameters.Add("@InterestRate", SqlDbType.Decimal);
                cmd.Parameters["@InterestRate"].Value = lblInterestRate.Text;

                cmd.Parameters.Add("@InterestAmount", SqlDbType.Decimal);
                cmd.Parameters["@InterestAmount"].Value = txtInterest.Text;

                cmd.Parameters.Add("@TotalRepayment", SqlDbType.Decimal);
                cmd.Parameters["@TotalRepayment"].Value = txtTotalRepayment.Text;

                cmd.Parameters.Add("@MonthlyRepayment", SqlDbType.Decimal);
                cmd.Parameters["@MonthlyRepayment"].Value = txtMonthlyRepayment.Text;

                cmd.Parameters.Add("@ApprovalStatus", SqlDbType.NVarChar, 3);
                cmd.Parameters["@ApprovalStatus"].Value = "Yes";

                cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar, 50);
                cmd.Parameters["@TransactionID"].Value = transactionID;
                #endregion

                string strQuery1;

                if (dateFinishedPayment != string.Empty)
                {
                    strQuery1 = "Insert into Loans(LoanApplicationID,RepaymentAmount,AmountPaid,OutstandingAmount," +
                                "PaymentStatus,PaymentFinished,DateFinishedPayment,TransactionID,Remark)values(@LoanApplicationID," +
                                "@RepaymentAmount,@AmountPaid,@OutstandingAmount,@PaymentStatus,@PaymentFinished,@DateFinishedPayment," +
                                "@TransactionID,@Remark)";
                }
                else
                {
                    strQuery1 = "Insert into Loans(LoanApplicationID,RepaymentAmount,AmountPaid,OutstandingAmount," +
                                "PaymentStatus,PaymentFinished,TransactionID,Remark)values(@LoanApplicationID," +
                                "@RepaymentAmount,@AmountPaid,@OutstandingAmount,@PaymentStatus,@PaymentFinished," +
                                "@TransactionID,@Remark)";
                }

                string strQuery3 = "Select LoanApplicationID from LoanApplication where TransactionID='" + transactionID + "'";


                int rowAffected = cmd.ExecuteNonQuery();
                //MessageBox.Show(rowAffected.ToString());
                if (rowAffected > 0)
                {
                    cmd             = new SqlCommand(strQuery3, conn);
                    cmd.Transaction = sqlTrans;
                    int loanApplicationID = Convert.ToInt16(cmd.ExecuteScalar());
                    //MessageBox.Show(loanApplicationID.ToString());


                    cmd             = new SqlCommand(strQuery1, conn);
                    cmd.Transaction = sqlTrans;

                    #region parameters strQuery1
                    cmd.Parameters.Add("@LoanApplicationID", SqlDbType.Int);
                    cmd.Parameters["@LoanApplicationID"].Value = loanApplicationID;

                    cmd.Parameters.Add("@RepaymentAmount", SqlDbType.Decimal);
                    cmd.Parameters["@RepaymentAmount"].Value = txtTotalRepayment.Text;

                    cmd.Parameters.Add("@AmountPaid", SqlDbType.Decimal);
                    cmd.Parameters["@AmountPaid"].Value = txtAmountPaid.Text;

                    cmd.Parameters.Add("@OutstandingAmount", SqlDbType.Decimal);
                    cmd.Parameters["@OutstandingAmount"].Value = txtOutstandingAmt.Text;

                    cmd.Parameters.Add("@PaymentStatus", SqlDbType.NVarChar, 10);
                    cmd.Parameters["@PaymentStatus"].Value = paymentStatus;

                    cmd.Parameters.Add("@PaymentFinished", SqlDbType.NVarChar, 3);
                    cmd.Parameters["@PaymentFinished"].Value = paymentFinished;


                    if (dateFinishedPayment != string.Empty)
                    {
                        cmd.Parameters.Add("@DateFinishedPayment", SqlDbType.NVarChar, 40);
                        cmd.Parameters["@DateFinishedPayment"].Value = dateFinishedPayment;
                    }

                    cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar, 50);
                    cmd.Parameters["@TransactionID"].Value = transactionID;

                    cmd.Parameters.Add("@Remark", SqlDbType.NVarChar, 1000);
                    cmd.Parameters["@Remark"].Value = txtRemark.Text;

                    #endregion

                    //Execute strQuery1
                    rowAffected = cmd.ExecuteNonQuery();

                    if (rowAffected > 0)
                    {
                        sqlTrans.Commit();
                        MessageBox.Show("Transaction has been successfully posted.", "Loans", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ActivityLog.logActivity(userId, "LoansForward", "Added a new Loans Brought Forward record with TransactionID of " + transactionID);
                    }
                    else
                    {
                        sqlTrans.Rollback();
                        MessageBox.Show("An error has occurred! Operation has been aborted.", "Loans", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }



                    //Close existing form and reopen active form

                    NewLoanBroughtForward newLoanBroughtForward = new NewLoanBroughtForward(userId);
                    newLoanBroughtForward.MdiParent = this.ParentForm;
                    newLoanBroughtForward.Show();

                    this.Close();
                }
                else
                {
                    MessageBox.Show("An error has occurred!", "Loans", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }
Exemplo n.º 9
0
        private void UpdateSavings()
        {
            int  rowAffected = 0;
            bool errorflag   = false;

            int     savingsTypeID    = 0;
            int     savingsForwardID = 0;
            string  temp             = string.Empty;
            decimal amount           = 0;
            string  comment          = string.Empty;
            string  strQuery         = string.Empty;


            SqlConnection conn = ConnectDB.GetConnection();

            strQuery = "Update Savings set Amount=@Amount where TransactionID=@TransactionID";

            conn.Open();
            SqlTransaction sqlTrans = conn.BeginTransaction();

            SqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = strQuery;

            cmd.Parameters.Add("@Amount", SqlDbType.Decimal);
            cmd.Parameters["@Amount"].Value = Convert.ToDecimal(lblSavingsTotal.Text);

            cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar, 100);
            cmd.Parameters["@TransactionID"].Value = lblSavingsID.Text;

            cmd.Transaction = sqlTrans;

            try
            {
                rowAffected = cmd.ExecuteNonQuery();

                if (rowAffected > 0)
                {
                    for (int i = 0; i < lstVwSavingDetails.Items.Count; i++)
                    {
                        strQuery = "Update SavingsForward set SavingsTypeID=@SavingsTypeID,Amount=@Amount,Comment=@Comment where SavingsForwardID=@SavingsForwardID" +
                                   " and TransactionID=@TransactionID";
                        cmd.CommandText = strQuery;

                        #region cmd parameters
                        savingsForwardID = Convert.ToInt16(lstVwSavingDetails.Items[i].SubItems[0].Text.ToString());
                        savingsTypeID    = Convert.ToInt16(lstVwSavingDetails.Items[i].SubItems[1].Text.ToString());
                        temp             = lstVwSavingDetails.Items[i].SubItems[3].Text.ToString();
                        amount           = Convert.ToDecimal(temp);
                        comment          = lstVwSavingDetails.Items[i].SubItems[4].Text.ToString();

                        cmd.Parameters.Clear();
                        //MessageBox.Show("Savings TypeID - " + savingsTypeID.ToString() + " - " + amount.ToString());

                        cmd.Parameters.Add("@SavingsTypeID", SqlDbType.Int);
                        cmd.Parameters["@SavingsTypeID"].Value = savingsTypeID;

                        cmd.Parameters.Add("@Amount", SqlDbType.Decimal);
                        cmd.Parameters["@Amount"].Value = amount;

                        cmd.Parameters.Add("@Comment", SqlDbType.NVarChar, 400);
                        cmd.Parameters["@Comment"].Value = comment;

                        cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar, 400);
                        cmd.Parameters["@TransactionID"].Value = lblSavingsID.Text;

                        cmd.Parameters.Add("@SavingsForwardID", SqlDbType.Int);
                        cmd.Parameters["@SavingsForwardID"].Value = savingsForwardID;


                        #endregion


                        rowAffected = cmd.ExecuteNonQuery();

                        if (rowAffected == 0)
                        {
                            errorflag = true;
                        }
                    }
                }
                else
                {
                    errorflag = true;
                }


                //check if there was no error and commit, if there is error rollback
                if (errorflag == false)
                {
                    sqlTrans.Commit();
                    ActivityLog.logActivity(userId, "SavingsForward", "Update Savings Record " + lblSavingsID.Text);
                    MessageBox.Show("Savings has been successfully Updated", "Savings", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    sqlTrans.Rollback();
                    MessageBox.Show("An error occurred! Update has been cancelled.", "Savings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //reset view
                loadDataSetSavingsForward();
                lstVwSavingDetails.Items.Clear();
                cboSavingsType.SelectedIndex = 0;
                txtAmount.Text       = string.Empty;
                txtComment.Text      = string.Empty;
                lblSavingsTotal.Text = "0.00";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }
Exemplo n.º 10
0
        private void ExecuteSave()
        {
            SqlConnection conn      = null;
            SqlCommand    cmd       = null;
            bool          errorFlag = false;
            int           rowAffected;
            string        strQuery;

            if ((lstVwSavings.Items.Count != 0) && (totalAmount > 0) && (cboMonth.Text != string.Empty) && (cboYear.Text != string.Empty))
            {
                conn = ConnectDB.GetConnection();

                conn.Open();
                SqlTransaction sqlTrans = conn.BeginTransaction();

                cmd = conn.CreateCommand();

                cmd.Transaction = sqlTrans;

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

                strQuery = "Insert into Savings(MemberID,SavingSource,Amount,Month,Year,TransactionID)" +
                           "values(@MemberID,@SavingSource,@Amount,@Month,@Year,@TransactionID)";
                #region cmd parameters
                cmd.Parameters.Add("@MemberID", SqlDbType.Int);
                cmd.Parameters["@MemberID"].Value = memberID;

                cmd.Parameters.Add("@SavingSource", SqlDbType.NVarChar, 40);
                cmd.Parameters["@SavingSource"].Value = "SavingsForward";

                cmd.Parameters.Add("@Amount", SqlDbType.Decimal);
                cmd.Parameters["@Amount"].Value = totalAmount;

                cmd.Parameters.Add("@Month", SqlDbType.Int);
                cmd.Parameters["@Month"].Value = Convert.ToInt16(cboMonth.SelectedIndex);

                cmd.Parameters.Add("@Year", SqlDbType.Int);
                cmd.Parameters["@Year"].Value = Convert.ToInt16(cboYear.Text);

                cmd.Parameters.Add("@TransactionID", SqlDbType.NVarChar, 50);
                cmd.Parameters["@TransactionID"].Value = transactionID;

                #endregion

                cmd.CommandText = strQuery;

                try
                {
                    rowAffected = cmd.ExecuteNonQuery();

                    #region if Statement of rowAffected
                    if (rowAffected > 0)
                    {
                        //Get SavingsID from the savings Table
                        strQuery        = "Select SavingsID from Savings where TransactionID='" + transactionID + "'";
                        cmd.CommandText = strQuery;

                        SqlDataReader reader = cmd.ExecuteReader();
                        reader.Read();
                        string SavingsID = reader["SavingsID"].ToString();
                        reader.Close();

                        cmd.Parameters.Add("@SavingsID", SqlDbType.Int);
                        cmd.Parameters.Add("@SavingsTypeID", SqlDbType.Int);
                        cmd.Parameters.Add("@Comment", SqlDbType.NVarChar, 400);

                        for (int i = 0; i < lstVwSavings.Items.Count; i++)
                        {
                            strQuery = "Insert into SavingsForward(SavingsID,Month,Year,SavingsTypeID,Amount,Comment,TransactionID)" +
                                       "values(@SavingsID,@Month,@Year,@SavingsTypeID,@Amount,@Comment,@TransactionID)";

                            #region cmd parameters

                            cmd.Parameters["@SavingsID"].Value = SavingsID;

                            cmd.Parameters["@Month"].Value = Convert.ToInt16(cboMonth.SelectedIndex);

                            cmd.Parameters["@Year"].Value = Convert.ToInt16(cboYear.Text);

                            cmd.Parameters["@SavingsTypeID"].Value = Convert.ToInt16(lstVwSavings.Items[i].SubItems[0].Text.ToString());

                            cmd.Parameters["@Amount"].Value = Convert.ToDecimal(lstVwSavings.Items[i].SubItems[2].Text.ToString());

                            cmd.Parameters["@Comment"].Value = txtComment.Text.Trim();

                            cmd.Parameters["@TransactionID"].Value = transactionID;

                            #endregion

                            cmd.CommandText = strQuery;
                            rowAffected     = cmd.ExecuteNonQuery();

                            if (rowAffected == 0)
                            {
                                MessageBox.Show("An error has occurred", "Savings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                errorFlag = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        errorFlag = true;
                    }
                    #endregion end of if statement

                    //Check if Transaction has been successful without error and commit or rollback

                    if (errorFlag == false)
                    {
                        sqlTrans.Commit();
                        ActivityLog.logActivity(userId, "SavingsForward", "Added a new Savings record with TransactionID of " + transactionID);
                        MessageBox.Show("Savings has been successfully posted", "Savings", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        loadDataSetSavingsForward();
                        loadDataSetMemberSavings();
                    }
                    else
                    {
                        sqlTrans.Rollback();
                        MessageBox.Show("An error has occurred posting savings", "Savings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    clearFields();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                MessageBox.Show("Month, Year and Amount are required", "Savings", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 11
0
        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();
            }
        }