コード例 #1
0
ファイル: Vendor.cs プロジェクト: carentsen/CSharp
        //Restocks the items that are below the minStock value.
        //Code is there, but the function does not work properly.
        protected virtual void OnRestockReached(RestockReachedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(e.ReachedRestock);
            if (RestockReached != null)
            {
                using (DataClasses1DataContext db = new DataClasses1DataContext())
                {
                    System.Diagnostics.Debug.WriteLine("Lort");
                    if (e.ReachedRestockKind == 1)
                    {
                        System.Diagnostics.Debug.WriteLine(" og lagkage");
                        CandyTable _candyTable = new CandyTable();
                        var candyQuery = from c in db.CandyTables
                                         where c.Product == e.ReachedRestock
                                         select c;
                        foreach (var c in candyQuery)
                        {
                            System.Diagnostics.Debug.WriteLine("Min mor vil have mere");
                            System.Diagnostics.Debug.WriteLine(c.Product);
                            c.Stock += RestockAmount;
                            RestockReached(this, e);//Raise the event
                        }
                        db.SubmitChanges();

                    }
            else if (e.ReachedRestockKind == 2)
            {
                CandyTable _candyTable = new CandyTable();
                var liquidQuery = from l in db.CandyTables
                                  where l.Product == e.ReachedRestock
                                  select l;
                foreach (var l in liquidQuery)
                {
                    l.Stock += RestockAmount;
                    RestockReached(this, e);//Raise the event
                }
                db.SubmitChanges();
            }
        }
    }
        }
コード例 #2
0
ファイル: Vendor.cs プロジェクト: carentsen/CSharp
 //Selling items from the store.
 public void SellItem(int kind, string product, int sales)
 {
     using (DataClasses1DataContext db = new DataClasses1DataContext()) {
         if (kind == 1)
         {
             CandyTable _candyTable = new CandyTable();
             var candyQuery = from c in db.CandyTables
                              where c.Product == product
                              select c;
             foreach (var c in candyQuery) {
                 c.Stock -= sales;
                 if (c.Stock < c.MinStock)
                 {
                     System.Diagnostics.Debug.WriteLine("Min mor er en flot kvinde <3");
                     RestockReachedEventArgs e = new RestockReachedEventArgs(
                     c.Product, kind);
                     OnRestockReached(e);
                 }
             }
             db.SubmitChanges();
         }
         else if (kind == 2)
         {
             CandyTable _candyTable = new CandyTable();
             var liquidQuery = from l in db.CandyTables
                               where l.Product == product
                               select l;
             foreach (var l in liquidQuery)
             {
                 l.Stock -= sales;
                 if (l.Stock < l.MinStock)
                 {
                     RestockReachedEventArgs e = new RestockReachedEventArgs(
                     l.Product, kind);
                     OnRestockReached(e);
                 }
             }
             db.SubmitChanges();
         }
     }
 }