Example #1
0
        public void Fill()
        {
            IDagentDatabase database = new DagentDatabase("SQLite");

            DataTable dt = new DataTable();

            database.Fill(dt, @"
                select 
                    *
                from 
                    customers c 
                inner join 
                    customerPurchases cp 
                on 
                    c.customerId = cp.customerId                 
	            order by 
                    c.customerId, cp.no");

            List <Customer> customers = new List <Customer>();
            int             id        = 0;

            foreach (DataRow row in dt.Rows)
            {
                int currentId = int.Parse(row["customerId"].ToString());

                if (currentId != id)
                {
                    customers.Add(new Customer {
                        customerId = currentId, name = row["name"].ToString()
                    });
                }

                if (customers.Last().CustomerPurchases == null)
                {
                    customers.Last().CustomerPurchases = new List <CustomerPurchase>();
                }

                customers.Last().CustomerPurchases.Add(new CustomerPurchase
                {
                    customerId = currentId,
                    no         = Convert.ToInt16(row["no"]),
                    content    = Convert.ToString(row["content"])
                });

                id = currentId;
            }

            ValidList(customers);
        }
Example #2
0
        public void Update()
        {
            IDagentDatabase database = new DagentDatabase("SQLite");

            string sql = @"
                select 
                    *
                from 
                    customers c 
                inner join 
                    customerPurchases cp 
                on 
                    c.customerId = cp.customerId                 
	            order by 
                    c.customerId, cp.no";

            DataTable dt = new DataTable();

            database.Fill(dt, sql);
            database.Update(dt, sql);

            Fill();
        }