コード例 #1
0
        public void PayBill(String customer_id, double customer_balance, double bill_amount, int bill_id, String type)
        {
            int j;

            try
            { connection.openConnection();
              double       updated_balance = customer_balance - bill_amount;
              MySqlCommand command         = new MySqlCommand("DELETE FROM bill WHERE Bill_ID =@Id ", connection.mysqlconnect);
              command.Parameters.AddWithValue("@Id", bill_id);
              int         i           = command.ExecuteNonQuery();
              CustomerDal customerDal = new CustomerDal();

              if (type == "loan")
              {
                  double debt         = customerDal.getCustomerCreditDebt(customer_id);
                  double updated_debt = debt - bill_amount;

                  MySqlCommand command2 = new MySqlCommand("Update customer set creditDebt=@updated_debt where customer_id=@Id", connection.mysqlconnect);
                  command2.Parameters.AddWithValue("@Id", customer_id);
                  command2.Parameters.AddWithValue("@updated_debt", updated_debt);
                  j = command2.ExecuteNonQuery();


                  int k = customerDal.updateBalance(customer_id, updated_balance);
              }
              else
              {
                  j = customerDal.updateBalance(customer_id, updated_balance);
              }



              if (i > 0 && j > 00)
              {
                  MessageBox.Show("Bill was paid succesfully");
              }
              else
              {
                  MessageBox.Show("Operation could not complete please try again");
              } }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            connection.closeConnection();
        }
コード例 #2
0
        private Boolean applyLoan(double totalPayment, double monthlyPayment, int creditPeriod, int loanAmount)
        {
            //MessageBox.Show(String.Format("{0:C}", totalPayment));

            DialogResult dialogResult = MessageBox.Show("Monthly Payment: " + String.Format(new CultureInfo("en-US"), "{0:C}", monthlyPayment) + "\n" + "\n" +
                                                        "Total Payment: " + String.Format(new CultureInfo("en-US"), "{0:C}", totalPayment), "onaylıyor musunuz", MessageBoxButtons.YesNo);
            double updated_balance = customerDal.getBalance(customer_id) + loanAmount;

            if (dialogResult == DialogResult.Yes)
            {
                customerDal.setCreditDebt(customer_id, totalPayment);

                customerDal.updateBalance(customer_id, updated_balance);
                List <String> list      = new List <string>();
                DateTime      startDate = DateTime.Now.AddMonths(1);
                DateTime      endDate   = DateTime.Now.AddYears(creditPeriod / 12).AddMonths(1);
                for (DateTime dt = startDate; dt < endDate; dt = dt.AddMonths(1))
                {
                    String lastday = dt.ToString("dd/MM/yyyy");

                    list.Add(lastday);
                }

                MessageBox.Show("Your loan request has been received.");



                //Çok fazla insert işlemi yaptığı için çok vakit alıyor diğer işlemleri engelliyordu bu yüzden thread kullandık.
                //İşlem bitene kadar bill tablosu connecton açık kaldığı için kredi çeker çekmez fatura sorgulama kısmına girerseniz hata verebilir.
                Thread t = new Thread(() => billDal.AddBill(customer_id, list, monthlyPayment));
                t.Start();



                MessageBox.Show("Your loan request has been approved.");

                ShowMonthlyPayment showMonthlyPayment = new ShowMonthlyPayment(list, monthlyPayment);
                showMonthlyPayment.Show();
                tbx_loanAmount.Clear();
                lbl_customerCreditDebt.Text    = ($" Your Remaining Loan Debt is  {String.Format(new CultureInfo("en-US"), "{0:C}", totalPayment)} $.");
                lbl_customerCreditDebt.Visible = true;
                lbl_customerBalance.Text       = String.Format(new CultureInfo("en-US"), "{0:C}", customerDal.getBalance(customer_id));
            }
            return(false);
        }