Beispiel #1
0
        //Gets Product and Variation
        public static Tuple <ProductObj, ProductVariationObj> GetProduct(int id)
        {
            ProductVariationObj tmpVariation = JsonConvert.DeserializeObject <ProductVariationObj>(Get(@"http://localhost/productvariations/get/" + id.ToString()));
            string     productUrl            = @"http://localhost/products/get/" + tmpVariation.product_id;
            ProductObj tmpProduct            = JsonConvert.DeserializeObject <ProductJson>(Get(productUrl)).Product;

            return(new Tuple <ProductObj, ProductVariationObj>(tmpProduct, tmpVariation));
        }
Beispiel #2
0
        //Gets Product and Variation for a sale
        public static Tuple <ProductObj, ProductVariationObj> GetSaleItem(string barcode)
        {
            //Set Url
            string variationUrl = @"http://localhost/productvariations/barcode/" + barcode;
            //Conver Json
            ProductVariationObj tmpVariation = JsonConvert.DeserializeObject <ProductVariationJson>(Get(variationUrl)).productVariation[0];
            //Set Url
            string productUrl = @"http://localhost/products/get/" + tmpVariation.product_id;
            //Conver Json
            ProductObj tmpProduct = JsonConvert.DeserializeObject <ProductJson>(Get(productUrl)).Product;

            return(new Tuple <ProductObj, ProductVariationObj>(tmpProduct, tmpVariation));
        }
Beispiel #3
0
 //Adds item on enter
 private void CheckEnterKeyPress(object sender, KeyPressEventArgs e)
 {
     //Checks for enter press
     if (e.KeyChar == (char)Keys.Return)
     {
         //Error catching
         try
         {
             //Retreives item from API and resets textbox
             Tuple <ProductObj, ProductVariationObj> tmp = API.GetSaleItem(txt_barcodeInput.Text);
             ProductObj          product   = tmp.Item1;
             ProductVariationObj variation = tmp.Item2;
             txt_barcodeInput.Text = "";
             bool hasItem = false;
             //Checks for items existence
             foreach (SaleItem sale in pnl_items.Controls)
             {
                 //Increases quantity if item exists
                 if (sale.productAttatched.id == variation.id)
                 {
                     sale.quantity++;
                     UpdateTotal();
                     hasItem = true;
                 }
             }
             //Creates GUI sale item
             if (!hasItem)
             {
                 SaleItem item = new SaleItem();
                 item.sale             = this;
                 item.Dock             = DockStyle.Top;
                 item.productAttatched = variation;
                 item.name             = product.name + " - " + variation.name;
                 item.description      = product.description + " - " + variation.description;
                 item.price            = variation.retail_price.ToString();
                 item.total            = variation.retail_price.ToString();
                 item.quantity         = 1;
                 pnl_items.Controls.Add(item);
                 UpdateTotal();
             }
         }
         catch
         {
             txt_barcodeInput.Text = "";
             MessageBox.Show("No barcode found", "ERROR");
         }
     }
 }
Beispiel #4
0
        public SaleContents(int TransactionID)
        {
            List <SaleObj> sales = API.SalesbyTransaction(TransactionID);

            InitializeComponent();
            //Creates and initialises each sale item
            foreach (SaleObj sale in sales)
            {
                //Retrieve Products from api
                Tuple <ProductObj, ProductVariationObj> tmp = API.GetProduct(sale.product_variation_id);
                ProductObj          product   = tmp.Item1;
                ProductVariationObj variation = tmp.Item2;
                SaleContentsItem    item      = new SaleContentsItem();
                item.name     = product.name + "-" + variation.name;
                item.quantity = sale.quantity;
                item.Dock     = DockStyle.Top;
                pnl_contents.Controls.Add(item);
            }
        }