コード例 #1
0
ファイル: SellItem.aspx.cs プロジェクト: carentsen/CSharp
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Clears the dropdown menus when the page is done loading.
                DropDownCandy.Items.Clear();
                DropDownLiquid.Items.Clear();

                //Connecting to the database
                using (DataClasses1DataContext db = new DataClasses1DataContext())
                {
                    //CandyTable _candyTable = new CandyTable();

                    //Selecting all liquids
                    var liquidQuery = from c in db.CandyTables
                                where c.Kind == 2
                                select c.Product;
                    //Adding all liquids
                    foreach (var c in liquidQuery)
                    {
                        DropDownLiquid.Items.Add(c);
                    }
                    //Selecting all candies
                    var candyQuery = from c in db.CandyTables
                                     where c.Kind == 1
                                     select c.Product;
                    //Adding all candies
                    foreach (var c in candyQuery)
                    {
                        DropDownCandy.Items.Add(c);
                    }

                }
            }
        }
コード例 #2
0
ファイル: CandyFactory.cs プロジェクト: carentsen/CSharp
 //Creates a new candy and adds it to the database.
 public Candy CreateCandy(string Type, string Brand, string Product, float Price, int Weight, int MinStock, int Stock, DateTime ExpirationDate)
 {
     using (DataClasses1DataContext db = new DataClasses1DataContext())
     {
         CandyTable _candyTable = new CandyTable();
         Candy candy = new Candy(Type, Brand, Product, Price, Weight, MinStock, Stock, ExpirationDate);
         _candyTable.Type = Type;
         _candyTable.Kind = 1;
         _candyTable.Brand = Brand;
         _candyTable.Product = Product;
         _candyTable.Price = Price;
         _candyTable.Weight = Weight;
         _candyTable.Stock = Stock;
         _candyTable.MinStock = MinStock;
         _candyTable.ExpirationDate = ExpirationDate;
         db.CandyTables.InsertOnSubmit(_candyTable);
         db.SubmitChanges();
         return candy;
     }
 }
コード例 #3
0
ファイル: CandyFactory.cs プロジェクト: carentsen/CSharp
 //Creates a new liquid and adds it to the database.
 public Liquids CreateLiquid(string Type, string Brand, string Product, double Price, int Litres, int MinStock, int Stock, DateTime ExpirationDate)
 {
     using (DataClasses1DataContext db = new DataClasses1DataContext())
     {
         CandyTable _candyTable = new CandyTable();
         Liquids liquid = new Liquids(Type, Brand, Product, Price, Litres, MinStock, Stock, ExpirationDate);
         _candyTable.Type = Type;
         _candyTable.Kind = 2;
         _candyTable.Brand = Brand;
         _candyTable.Product = Product;
         _candyTable.Price = Price;
         _candyTable.Weight = Litres;
         _candyTable.Stock = Stock;
         _candyTable.MinStock = MinStock;
         _candyTable.ExpirationDate = ExpirationDate;
         db.CandyTables.InsertOnSubmit(_candyTable);
         db.SubmitChanges();
         return liquid;
     }
 }
コード例 #4
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();
            }
        }
    }
        }
コード例 #5
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();
         }
     }
 }