Ejemplo n.º 1
0
        // Add a new bill to the database
        public void Add(Bill bill)
        {
            string query = "INSERT INTO [dbo].[Bills] ([date], [tableId], [employeeId], [Payed]) VALUES (@date, @tableId, @employeeId, @payed)";

            SqlParameter[] parameters = new SqlParameter[4]
            {
                new SqlParameter("@date", bill.Date),
                new SqlParameter("@tableId", bill.Table.Number),
                new SqlParameter("@employeeId", bill.Employee.Id),
                new SqlParameter("@payed", bill.Payed),
            };

            foreach (Order order in bill.Orders)
            {
                if (order.Id == 0)
                {
                    Order_DAO order_dao = new Order_DAO();

                    order_dao.Add(order);
                }
            }

            ExecuteEditQuery(query, parameters);
            bill.Id = GetLastBillId();

            AddBillHasOrder(bill);
        }
Ejemplo n.º 2
0
        // Convert the raw database data into an Bill object
        private Bill Read(DataRow dataRow)
        {
            int          id       = (int)dataRow["Id"];
            DateTime     date     = (DateTime)dataRow["date"];
            Table        table    = new Table_DAO().GetWithId((int)dataRow["tableId"]);
            List <Order> orders   = new Order_DAO().GetAllForBill(id);
            Employee     employee = new Employee_DAO().GetWithId((int)dataRow["employeeId"]);
            bool         payed    = (bool)dataRow["Payed"];

            return(new Bill(id, date, table, orders, employee, payed));
        }