public List<CSSaleItem> removeByCSSale(CSSale CSSale)
        {
            List<CSSaleItem> CSSaleItemList = null;
            using (context = new CSFPOSWareContext())
            {
                var query = from si in context.CSSaleItems
                            where si.CSSaleID == CSSale.CSSaleID
                            select si;
                CSSaleItemList = query.ToList();
            }

            using (context = new CSFPOSWareContext())
            {
                foreach (CSSaleItem CSSaleItem in CSSaleItemList)
                {
                    context.CSSaleItems.Remove(CSSaleItem);
                    context.SaveChanges();
                }
            }
            return CSSaleItemList;
        }
        private CSSale _buildCSSale(Sale sale)
        {
            CSSale csSale = null;
            maintenanceDAO = new MaintenanceDAO();
            int totalItems = 0;
            SaleInfo saleInfo = new SaleInfo();
            saleInfo.seats = new List<Seat>();
            SaleItemDAO saleItemDAO = new SaleItemDAO();
            Seat currentSeat = new Seat();
            foreach (SaleItem saleItem in saleItemDAO.find(sale.SaleID.ToString()))
            {
                Console.WriteLine(saleItem.ToString());
                if (saleItem.Flags == 4 || saleItem.Flags == 20)//it's a seat!
                {
                    Seat seat = new Seat();
                    currentSeat = seat;
                    seat.saleItems = new List<SaleItem>();
                    seat.number = saleItem.BasePrice;
                    saleInfo.seats.Add(seat);
                    Logger.log.Debug("seat #" + seat.number + " added");
                    if (saleItem.Flags == 20)
                        currentSeat.ignorePrint = true;
                }
                else//it's an item
                {
                    if (!currentSeat.ignorePrint)
                    {
                        currentSeat.saleItems.Add(saleItem);
                        totalItems++;
                        Logger.log.Debug("item " + saleItem.ItemName + " added to seat #" + currentSeat.number);
                    }
                }
            }

            if (totalItems > 0)
            {
                csSale = new CSSale();
                csSale.CSSaleID = sale.SaleID;
                csSale.CheckNo = sale.CheckNumber;
                csSale.EndDate = DateTime.Now;
                //replace csSale data
                _clearCSSale(csSale);
                _buildCSSaleItem(saleInfo.seats);
                CSSaleDAO csSaleDAO = new CSSaleDAO();
                csSaleDAO.add(csSale);
                //build CSSale data
                //1. TOTALS
                int totalDisc = 0;
                foreach (Seat seat in saleInfo.seats)
                {
                    foreach (CSSaleItem csSaleItem in seat.csSaleItems)
                    {
                        //1.1. discounts
                    }
                }
            }
            else
            {
                Logger.log.Info("No Items found.");
            }
            return csSale;
        }
 private void _clearCSSale(CSSale csSale)
 {
     CSSaleDAO csSaleDAO = new CSSaleDAO();
     csSaleDAO.remove(csSale);
     CSSaleItemDAO csSaleItemDAO = new CSSaleItemDAO();
     List<CSSaleItem> CSSaleItemList = csSaleItemDAO.removeByCSSale(csSale);
     CSSaleItemDiscountDAO CSSaleItemDiscountDAO = new CSSaleItemDiscountDAO();
     CSSaleItemTaxDAO CSSaleItemTaxDAO = new CSSaleItemTaxDAO();
     foreach (CSSaleItem csSaleItem in CSSaleItemList)
     {
         CSSaleItemDiscountDAO.removeBySaleItem(csSaleItem);
         CSSaleItemTaxDAO.removeBySaleItem(csSaleItem);
     }
 }
 public SettleCheckForm(CSSale csSale)
 {
     InitializeComponent();
     this.csSale = csSale;
     helper = new SettleCheckFormHelper(this);
 }