SHARE
TWEET

Untitled

a guest Jan 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.OleDb;
  5. using System.ComponentModel;
  6.  
  7. namespace CustomObjects
  8. {
  9. public class Booking:ObjectBase
  10. {
  11.  
  12.     private int pBookingNo=0;
  13.     private BindingList<Loans> pCashLoans = new BindingList<Loans>();
  14.  
  15.     public int BookingNo
  16.     {
  17.         get { return pBookingNo; }
  18.         set
  19.         {
  20.             if (!value.Equals(pBookingNo))
  21.             {
  22.                 pBookingNo = value;
  23.                 PropertyHasChanged("BookingNo");
  24.             }
  25.         }
  26.     }
  27.  
  28.    public BindingList<Loans> CashLoans
  29.     {
  30.         get { return pCashLoans; }
  31.         set
  32.         {
  33.             pCashLoans = value;
  34.             //CalculateCashLoan(this,new System.ComponentModel.ListChangedEventArgs(ListChangedType.Reset,-1));
  35.             PropertyHasChanged("CashLoans");
  36.         }
  37.     }
  38.  
  39.     private decimal pTakenCashLoan = 0;
  40.     public decimal TakenCashLoan
  41.     {
  42.         get { return pTakenCashLoan; }
  43.         set
  44.         {
  45.             pTakenCashLoan = value;
  46.             PropertyHasChanged("TakenCashLoan");
  47.         }
  48.     }
  49.  
  50.       public void CalculateCashLoan(object sender, ListChangedEventArgs args)
  51.     {
  52.         decimal total = 0;
  53.         foreach (Loans loan in pCashLoans)
  54.         {
  55.             total += loan.LoanAmount;
  56.         }
  57.         this.TakenCashLoan = total;
  58.     }
  59.  
  60.     public Booking()
  61.     {
  62.         this.pCashLoans.ListChanged += this.CalculateCashLoan;
  63.     }
  64.  
  65.  
  66.     public static Booking FillEntity(OleDbDataReader Reader, OleDbConnection Connection)
  67.     {
  68.         Booking booking = new Booking();
  69.         booking.BookingNo = (int)Reader["BookingNo"];
  70.  
  71.         booking.CashLoans = Loans.GetLoanList(booking.BookingNo, 1, Connection);
  72.         booking.MarkOld();
  73.         return booking;
  74.     }
  75.  
  76.     public static Booking GetEntity(int bookingNo, string ConnectionString)
  77.     {
  78.         Booking booking =new Booking();
  79.         using (OleDbConnection Connection = new OleDbConnection(ConnectionString))
  80.         {
  81.             string sqlSelect = "SELECT BookingNo FROM tblBooking WHERE BookingNo=" + bookingNo + "";
  82.             using (OleDbCommand cmd = new OleDbCommand(sqlSelect, Connection))
  83.             {
  84.                 Connection.Open();
  85.                 OleDbDataReader bReader = cmd.ExecuteReader();
  86.                 if (bReader.HasRows)
  87.                 {
  88.                     bReader.Read();
  89.                     booking = FillEntity(bReader, Connection);
  90.                 }
  91.                 Connection.Close();
  92.  
  93.                 if (!bReader.IsClosed)
  94.                 {
  95.                     bReader.Close();
  96.                 }
  97.             }
  98.         }
  99.         return booking;
  100.     }
  101.  
  102. }
  103.  
  104. }
  105.    
  106. private void frmMain_Load(object sender, EventArgs e)
  107.     {
  108.         AddDataBindings();
  109.         cmbBookingType.DataSource = BookingType.GetSelectionList(ConnectionString.CreateConnectionStringForAccess("LOCAL", "2012"));
  110.     }
  111.  
  112.     private Booking booking=new Booking();
  113.     private void button1_Click(object sender, EventArgs e)
  114.     {
  115.         try
  116.         {
  117.            booking = Booking.GetEntity(1, ConnectionString.CreateConnectionStringForAccess("LOCAL", "2012"));
  118.             bsBooking.DataSource = booking;
  119.         }
  120.         catch (Exception Ex)
  121.         {
  122.             MessageBox.Show(Ex.Message);
  123.             MessageBox.Show(Ex.StackTrace);
  124.         }
  125.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top