Example #1
0
        public void BindLoans()
        {
            LoanManager oManager = new LoanManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            grdCtlLoanInfo.DataSource = oManager.GetLoans();
            grdCtlLoanInfo.Refresh();
            oManager.Close();
        }
        private void txtStatus_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                if (txtStatus.Text == "Draft")
                {

                    if (MessageBox.Show("Are you sure you want to approved this document? This action is irreversible!!!", "Post", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        LoanManager oManager = new LoanManager();

                        oManager.ConnectionString = this.ConnectionString;
                        oManager.Open();

                        oManager.Approved(txtLoanNo.Text);

                        oManager.Close();

                        MessageBox.Show("Successfully approved!!!", "Posted", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        txtStatus.Text = "Approved";
                    }
                    else
                    {
                        return;
                    }
                }
                else if (txtStatus.Text == "Approved")
                {
                    if (MessageBox.Show("Are you sure you want to post this document? This action is irreversible!!!", "Post", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        LoanManager oManager = new LoanManager();

                        oManager.ConnectionString = this.ConnectionString;
                        oManager.Open();

                        oManager.PostDocument(txtLoanNo.Text);

                        oManager.Close();

                        MessageBox.Show("Successfully posted!!!", "Posted", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        txtStatus.Text = "Posted";
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else if (e.Button.Index == 1)
            {
                if (txtStatus.Text == "Draft")
                {
                    if (MessageBox.Show("Are you sure you want to cancel this document? This action is irreversible!!!", "Post", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        LoanManager oManager = new LoanManager();

                        oManager.ConnectionString = this.ConnectionString;
                        oManager.Open();

                        oManager.CancelDocument(txtLoanNo.Text);

                        oManager.Close();

                        MessageBox.Show("Successfully cancelled!!!", "Posted", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        txtStatus.Text = "Canceled";
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (MessageBox.Show("Are you sure you want to close this document? This action is irreversible!!!", "Post", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        LoanManager oManager = new LoanManager();

                        oManager.ConnectionString = this.ConnectionString;
                        oManager.Open();

                        oManager.CloseDocument(txtLoanNo.Text);

                        oManager.Close();

                        MessageBox.Show("Successfully closed!!!", "Closed", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        txtStatus.Text = "Closed";
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
        private void txtPayment_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                if (txtStatus.Text == "Draft")
                {
                    MessageBox.Show("Your not able to add payment to draft documents!!!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (txtStatus.Text == "Approved")
                {
                    MessageBox.Show("Your not able to add payment to approved documents!!!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (txtStatus.Text == "Closed" || txtStatus.Text == "Canceled")
                {
                    MessageBox.Show("Your not able to add payment to closed documents!!!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                addCollection oform = new addCollection();
                int iFocusedRowIndex = gridView1.FocusedRowHandle;

                oform.ConnectionString = this.ConnectionString;
                oform.ActiveUserID = this.ActiveUserID;
                oform.LoanNumber = txtLoanNo.Text;

                oform.ScheduledNo = Convert.ToInt16(gridView1.GetRowCellValue(iFocusedRowIndex, gridView1.Columns["ScheduleNo"]));

                oform.ShowDialog();

                LoanManager oManager = new LoanManager();

                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();

                this.LineScheduleOfPayment = oManager.GetLoanInfoLineItems(txtLoanNo.Text);

                oManager.Close();

                gridControl1.DataSource = this.LineScheduleOfPayment;
                gridControl1.Refresh();

                BindCollections(txtLoanNo.Text);
                ComputeOutstandingBalance();
            }
            else
            {
                PaymentBreakdown oForm = new PaymentBreakdown();
                int iFocusedRowIndex = gridView1.FocusedRowHandle;

                oForm.ConnectionString = this.ConnectionString;
                oForm.ScheduleNo = Convert.ToInt16(gridView1.GetRowCellValue(iFocusedRowIndex, gridView1.Columns["ScheduleNo"]));
                oForm.DocumentNumber = txtLoanNo.Text;

                oForm.ShowDialog();
                ComputeOutstandingBalance();
            }
        }
        private void txtOtherCharges_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                if (txtStatus.Text == "Draft")
                {
                    MessageBox.Show("Your not able to add charges to draft documents!!!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (txtStatus.Text == "Approved")
                {
                    MessageBox.Show("Your not able to add charges to approved status documents!!!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (txtStatus.Text == "Closed" || txtStatus.Text == "Canceled")
                {
                    MessageBox.Show("Your not able to add charges to canceled or closed documents!!!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                addOtherCharges oForm = new addOtherCharges();

                int iFocusedRowIndex = gridView1.FocusedRowHandle;
                string sScheduleNo = gridView1.GetRowCellValue(iFocusedRowIndex, gridView1.Columns["ScheduleNo"]).ToString();
                DateTime dtDueDate = (DateTime)gridView1.GetRowCellValue(iFocusedRowIndex, gridView1.Columns["ScheduledDate"]);

                oForm.ConnectionString = this.ConnectionString;
                oForm.DocumentNumber = txtLoanNo.Text;
                oForm.ScheduleNo = sScheduleNo;
                oForm.ScheduledDate = dtDueDate;

                oForm.ShowDialog();

                LoanManager oManager = new LoanManager();

                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();
                this.LineScheduleOfPayment = oManager.GetLoanInfoLineItems(txtLoanNo.Text);
                oManager.Close();

                gridControl1.DataSource = this.LineScheduleOfPayment;
                gridControl1.Refresh();

                barSaveLoan.Caption = "Update";
                txtLoanNo.Enabled = false;

                BindCashReleased();
                BindCollections(txtLoanNo.Text);
                ComputeOutstandingBalance();
            }
            else
            {
                detailOtherCharges oForm = new detailOtherCharges();

                int iFocusedRowIndex = gridView1.FocusedRowHandle;
                string sScheduleNo = gridView1.GetRowCellValue(iFocusedRowIndex, gridView1.Columns["ScheduleNo"]).ToString();
                DateTime dtDueDate = (DateTime)gridView1.GetRowCellValue(iFocusedRowIndex, gridView1.Columns["ScheduledDate"]);

                oForm.ConnectionString = this.ConnectionString;
                oForm.DocumentNumber = txtLoanNo.Text;
                oForm.ScheduleNo = sScheduleNo;
                oForm.ShowDialog();
                ComputeOutstandingBalance();
            }
        }
        private void barSaveLoan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (barSaveLoan.Caption == "Save")
            {
                LoanManager oConnectionManager = new LoanManager();
                LoanUnit oUnit = new LoanUnit();

                if (txtCardCode.Text == "")
                {
                    MessageBox.Show("Please select borrower before saving!!!", "Loan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (Convert.ToDouble(txtLoanAmount.EditValue) <= 0)
                {
                    MessageBox.Show("Please insert loan amount and click calculate button to generate schedule of payment!!!", "Loan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (this.LineScheduleOfPayment.Rows.Count <= 0)
                {
                    MessageBox.Show("Please click calculate button to generate schedule of payment!!!", "Loan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                txtLoanNo.Text = GetSeries();

                oConnectionManager.ConnectionString = this.ConnectionString;
                oConnectionManager.Open();

                if (oConnectionManager.IsExists(txtLoanNo.Text))
                {
                    MessageBox.Show("Loan Document Number is already exists!!!", "Exists", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                oUnit.DocumentNumber = txtLoanNo.Text;
                oUnit.CardCode = txtCardCode.Text;
                oUnit.CardName = txtCardName.Text;
                oUnit.TransactionType = cboTransType.Text;
                oUnit.Guarantor = txtGuarrantor.Text;
                oUnit.LoanAmount = Convert.ToDouble(txtLoanAmount.Text.Replace(",", ""));
                oUnit.Terms = Convert.ToInt16(txtTerms.Text);
                oUnit.InterestRate = Convert.ToDouble(txtInterestRate.Text);
                oUnit.FrequencyOfPayment = cboFrequencyOfPayment.EditValue.ToString();
                oUnit.PayDayCode = cboPayDayCode.EditValue != null ? cboPayDayCode.EditValue.ToString() : "";
                oUnit.FirstDateOfPayment = (DateTime)dtStartOfPayment.EditValue;
                oUnit.ReleaseDate = (DateTime)dtDateOfRelease.EditValue;
                oUnit.MonthlyPayment = Convert.ToDouble(string.Format("{0}", txtAmortization.Text));
                oUnit.NumberOfPayment = Convert.ToInt16(txtNoOfPayments.Text);
                oUnit.TotalAmortization = Convert.ToDouble(string.Format("{0}", txtTotalAmortization.Text));
                oUnit.TotalInterest = Convert.ToDouble(txtTotalInterest.Text);

                oUnit.DocumentStatus = txtStatus.Text;
                oUnit.CreatedBy = this.ActiveUserID;
                oUnit.DateCreated = (DateTime)dtCreated.EditValue;
                oUnit.ModifiedBy = txtModifiedBy.Text;
                oUnit.DateModified = (DateTime)dtModified.EditValue;

                oConnectionManager.AddLoan(oUnit);

                oConnectionManager.AddLineItems(txtLoanNo.Text, this.LineScheduleOfPayment);
                oConnectionManager.Close();

                barSaveLoan.Caption = "Update";
                txtLoanNo.Enabled = false;

                MessageBox.Show("Adding completed successfully!!!", "Add", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                LoanManager oConnectionManager = new LoanManager();
                LoanUnit oUnit = new LoanUnit();

                oConnectionManager.ConnectionString = this.ConnectionString;
                oConnectionManager.Open();
                oUnit.DocumentNumber = txtLoanNo.Text;
                oUnit.CardCode = txtCardCode.Text;
                oUnit.CardName = txtCardName.Text;
                oUnit.TransactionType = cboTransType.Text;
                oUnit.Guarantor = txtGuarrantor.Text;
                oUnit.LoanAmount = Convert.ToDouble(txtLoanAmount.Text.Replace(",", ""));
                oUnit.Terms = Convert.ToInt16(txtTerms.Text);
                oUnit.InterestRate = Convert.ToDouble(txtInterestRate.Text);
                oUnit.FrequencyOfPayment = cboFrequencyOfPayment.EditValue.ToString();
                oUnit.PayDayCode = cboPayDayCode.EditValue != null ? cboPayDayCode.EditValue.ToString() : "";
                oUnit.FirstDateOfPayment = (DateTime)dtStartOfPayment.EditValue;
                oUnit.ReleaseDate = (DateTime)dtDateOfRelease.EditValue;
                oUnit.MonthlyPayment = Convert.ToDouble(txtAmortization.Text.Replace(",", ""));
                oUnit.NumberOfPayment = Convert.ToInt16(txtNoOfPayments.Text);
                oUnit.TotalAmortization = Convert.ToDouble(txtTotalAmortization.Text.Replace(",", ""));
                oUnit.TotalInterest = Convert.ToDouble(txtTotalInterest.Text);
                oUnit.DocumentStatus = txtStatus.Text;
                oUnit.ModifiedBy = txtModifiedBy.Text;
                oUnit.DateModified = (DateTime)dtModified.EditValue;

                oConnectionManager.UpdateLoan(oUnit);

                oConnectionManager.DeleteLineItems(txtLoanNo.Text);
                oConnectionManager.AddLineItems(txtLoanNo.Text, this.LineScheduleOfPayment);

                oConnectionManager.Close();
                MessageBox.Show("Updating completed successfully!!!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public void OpenDocument(string sDocNum)
        {
            Initializetable();
            BindPayDayCode();

            cboModeOfPayment.SelectedIndex = 0;
            cboTransType.SelectedIndex = 0;

            txtCreatedBy.Text = this.ActiveUserID;
            txtModifiedBy.Text = this.ActiveUserID;

            DateTime dtNow = System.DateTime.Now;

            dtCreated.EditValue = dtNow;
            dtModified.EditValue = dtNow;

            dtStartOfPayment.EditValue = dtNow;
            dtDateOfRelease.EditValue = dtNow;

            txtTerms.Text = "1";

            LoanManager oManager = new LoanManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable dtInfo = oManager.GetLoanInfo(sDocNum);

            DataRow oRow = dtInfo.Rows[0];

            //ounit.documentnumber = txtloanno.text;
            txtLoanNo.Text = oRow["DocNum"].ToString();
            txtCardCode.Text = oRow["CardCode"].ToString();
            txtCardName.Text = oRow["CardName"].ToString();
            cboTransType.Text = oRow["TransType"].ToString();
            txtGuarrantor.Text = oRow["Guarrantor"].ToString();
            txtLoanAmount.Text = string.Format("{0:N}", oRow["LoanAmount"].ToString());
            txtTerms.Text = string.Format("{0:N}", oRow["Terms"]);
            txtInterestRate.Text = oRow["InterestRate"].ToString();
            cboFrequencyOfPayment.Text = oRow["FreqOfPayment"].ToString();
            cboPayDayCode.EditValue = oRow["PayDayCode"].ToString();
            dtStartOfPayment.EditValue = (DateTime)oRow["FirstPaymentDate"];
            dtDateOfRelease.EditValue = (DateTime)oRow["DateOfReleasing"];
            txtAmortization.Text = string.Format("{0:N}", oRow["MonthlyPayment"]);
            txtNoOfPayments.Text = string.Format("{0}", oRow["NoOfPayment"]);
            txtTotalAmortization.Text = string.Format("{0:N}", oRow["TotalAmortization"]);
            txtTotalInterest.Text = string.Format("{0:N}", oRow["TotalInterest"]);
            txtStatus.Text = string.Format("{0:N}", oRow["DocStatus"]);

            txtCreatedBy.Text = oRow["CreatedBy"].ToString();
            dtCreated.EditValue = Convert.ToDateTime(oRow["DateCreated"]);
            txtModifiedBy.Text = oRow["ModifiedBy"].ToString();
            dtModified.EditValue = Convert.ToDateTime(oRow["DateModified"]);

            this.LineScheduleOfPayment = oManager.GetLoanInfoLineItems(sDocNum);

            gridControl1.DataSource = this.LineScheduleOfPayment;
            gridControl1.Refresh();

            barSaveLoan.Caption = "Update";
            txtLoanNo.Enabled = false;

            BindCashReleased();
            BindCollections(txtLoanNo.Text);
            ComputeOutstandingBalance();
        }