예제 #1
0
        private async void updateProductsList()
        {
            FirebaseResponse resp = await client.GetTaskAsync("products/");

            Dictionary <string, Products_class> dict = resp.ResultAs <Dictionary <string, Products_class> >();



            //Adding product keys to Array Keys
            foreach (KeyValuePair <string, Products_class> ele1 in dict)
            {
                keys.Add(ele1.Key);
                // Console.WriteLine("{0} and {1}",
                //  ele1.Key, ele1.Value);
            }

            //traversing list keys to fetch product details
            for (int i = 0; i < keys.Count; i++)
            {
                FirebaseResponse resp2 = await client.GetTaskAsync("products/" + keys[i]);

                Products_class product = resp2.ResultAs <Products_class>();
                products_list.Items.Add(product.name);
                productList.Add(product);
                //Console.WriteLine(product.name+" : "+product.price);
            }
        }
예제 #2
0
        private async void updateProductsList()
        {
            try
            {
                FirebaseResponse resp = await client.GetTaskAsync("products/");

                Dictionary <string, Products_class> dict = resp.ResultAs <Dictionary <string, Products_class> >();



                //Adding product keys to Array Keys
                foreach (KeyValuePair <string, Products_class> ele1 in dict)
                {
                    keys.Add(ele1.Key);
                    // Console.WriteLine("{0} and {1}",
                    //  ele1.Key, ele1.Value);
                }

                //traversing list keys to fetch product details
                for (int i = 0; i < keys.Count; i++)
                {
                    FirebaseResponse resp2 = await client.GetTaskAsync("products/" + keys[i]);

                    Products_class product = resp2.ResultAs <Products_class>();
                    productList.Add(product);
                    product_list.Items.Add(product.name);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Cant connect to FIREBASE. Check your internet connection!");
            }
        }
예제 #3
0
        private async void updateProductList()
        {
            FirebaseResponse resp = await client.GetTaskAsync("products/");

            Dictionary <string, Products_class> dict = resp.ResultAs <Dictionary <string, Products_class> >();

            Console.WriteLine("received prods keys");



            //Adding product keys to Array Keys
            foreach (KeyValuePair <string, Products_class> ele1 in dict)
            {
                keys.Add(ele1.Key);
                // Console.WriteLine(+"{0} and {1}",
                //  ele1.Key, ele1.Value);
            }

            Console.WriteLine("starting recieving prods");

            //traversing list keys to fetch product details
            for (int i = 0; i < keys.Count; i++)
            {
                FirebaseResponse resp2 = await client.GetTaskAsync("products/" + keys[i]);

                Products_class product = resp2.ResultAs <Products_class>();
                productList.Add(product);
            }
            Console.WriteLine("received prods successfykkt");

            for (int i = 0; i < productList.Count; i++)
            {
                DataRow row = dt.NewRow();
                row["Name"]         = productList[i].name;
                row["Price"]        = productList[i].price;
                row["Quantity"]     = productList[i].quantity;
                row["Discount"]     = productList[i].discount;
                row["Description"]  = productList[i].description;
                row["Featured"]     = productList[i].featured;
                row["Prescription"] = productList[i].prescription;
                row["Date"]         = productList[i].timestamp;

                dt.Rows.Add(row);
            }
        }
예제 #4
0
        private async void add_btn_Click(object sender, EventArgs e)
        {
            if (name_editText.Text == "" || name_editText == null)
            {
                MessageBox.Show("Fill Name field first.");
            }

            else if (price_editText.Text == "" || price_editText == null)
            {
                MessageBox.Show("Fill price field first.");
            }

            else if (description_editText.Text == "" || description_editText == null)
            {
                MessageBox.Show("Fill description field first.");
            }

            else if (quantity_editText.Text == "" || quantity_editText == null)
            {
                MessageBox.Show("Fill quantity field first.");
            }

            else
            {
                bool check = false;

                for (int i = 0; i < productList.Count; i++)
                {
                    if (name_editText.Text.ToLower() == productList[i].name.ToLower())
                    {
                        check = true;
                        break;
                    }
                }

                if (!check)
                {
                    bool temp1, temp2;
                    if (featured_list.GetItemText(featured_list.SelectedItem) == "false")
                    {
                        temp1 = false;
                    }
                    else
                    {
                        temp1 = true;
                    }

                    if (prescription_list.GetItemText(prescription_list.SelectedItem) == "false")
                    {
                        temp2 = false;
                    }
                    else
                    {
                        temp2 = true;
                    }

                    //Adding product to firebase
                    Products_class product = new Products_class(description_editText.Text, discount_editText.Text, temp1, image_editText.Text + "", name_editText.Text, temp2, double.Parse(price_editText.Text), int.Parse(quantity_editText.Text), DateTime.Now.ToString());

                    PushResponse response = await client.PushTaskAsync("products", product);

                    productList.Add(product);

                    FirebaseResponse resp = await client.GetTaskAsync("products/");

                    Dictionary <string, Products_class> dict = resp.ResultAs <Dictionary <string, Products_class> >();

                    //Adding new key to keys array
                    foreach (KeyValuePair <string, Products_class> ele1 in dict)
                    {
                        if (!keys.Contains(ele1.Key))
                        {
                            keys.Add(ele1.Key);
                            break;
                        }
                    }


                    //Console.WriteLine("response: "+response.Result.ToString());

                    //adding new row to DT
                    DataRow row = dt.NewRow();
                    row["Name"]         = product.name;
                    row["Price"]        = product.price;
                    row["Quantity"]     = product.quantity;
                    row["Discount"]     = product.discount;
                    row["Description"]  = product.description;
                    row["Featured"]     = product.featured;
                    row["Prescription"] = product.prescription;
                    row["Date"]         = product.timestamp;

                    dt.Rows.Add(row);
                }

                else
                {
                    MessageBox.Show("Product already exists in the inventory.");
                }
            }
        }
예제 #5
0
        private async void update_btn_Click(object sender, EventArgs e)
        {
            try
            {
                Products_class product = productList[selectedRow];
                if (product.name != name_editText.Text)
                {
                    product.name = name_editText.Text;
                    inventory_datagrid.Rows[selectedRow].Cells[0].Value = product.name;
                }

                if (product.price + "" != price_editText.Text)
                {
                    product.price = double.Parse(price_editText.Text);
                    inventory_datagrid.Rows[selectedRow].Cells[1].Value = product.price;
                }

                if (product.quantity != int.Parse(quantity_editText.Text))
                {
                    product.quantity = int.Parse(quantity_editText.Text);
                    inventory_datagrid.Rows[selectedRow].Cells[2].Value = product.quantity;
                }

                if (product.discount != discount_editText.Text)
                {
                    product.discount = discount_editText.Text;
                    inventory_datagrid.Rows[selectedRow].Cells[3].Value = product.discount;
                }

                if (product.description != description_editText.Text)
                {
                    product.description = description_editText.Text;
                    inventory_datagrid.Rows[selectedRow].Cells[4].Value = product.description;
                }

                bool temp1, temp2;
                if (featured_list.GetItemText(featured_list.SelectedItem) == "false")
                {
                    temp1 = false;
                }
                else
                {
                    temp1 = true;
                }

                if (prescription_list.GetItemText(prescription_list.SelectedItem) == "false")
                {
                    temp2 = false;
                }
                else
                {
                    temp2 = true;
                }

                product.image        = image_editText.Text;
                product.featured     = temp1;
                product.prescription = temp2;
                inventory_datagrid.Rows[selectedRow].Cells[5].Value = product.featured;
                inventory_datagrid.Rows[selectedRow].Cells[6].Value = product.prescription;
                try
                {
                    FirebaseResponse response = await client.UpdateTaskAsync("products/" + keys[selectedRow], product);

                    //setting values to default
                    name_editText.Text              = "";
                    price_editText.Text             = "";
                    description_editText.Text       = "";
                    prescription_list.SelectedIndex = 0;
                    featured_list.SelectedIndex     = 0;
                    discount_editText.Text          = "0";
                    quantity_editText.Text          = "";
                    image_editText.Text             = "";

                    MessageBox.Show("Updated Successfully!");
                }

                catch (Exception)
                {
                    MessageBox.Show("Update Failed");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please select an item to edit");
            }
        }
예제 #6
0
        private void add_btn_Click(object sender, EventArgs e)
        {
            if (products_list.GetItemText(products_list.SelectedItem) != null && products_list.GetItemText(products_list.SelectedItem) != string.Empty)
            {
                string text = products_list.GetItemText(products_list.SelectedItem);
                int    temp = 0;
                for (int i = 0; i < productList.Count; i++)
                {
                    if (productList[i].name == text)
                    {
                        temp = i;
                        break;
                    }
                }

                if (Int32.Parse(productList[temp].quantity) < Int32.Parse(quantity_editText.Text))
                {
                    MessageBox.Show("Insufficient Stocks. You only have " + productList[temp].quantity + " of stocks available in the inventory.");
                }
                else
                {
                    DataRow row = dt.NewRow();
                    row["Name"]  = text;
                    row["Price"] = productList[temp].price;

                    row["Quantity"]    = quantity_editText.Text;
                    row["Discount"]    = productList[temp].discount;
                    row["Description"] = productList[temp].description;

                    int tempPrice       = Int32.Parse(productList[temp].price);
                    int tempDisc        = Int32.Parse(productList[temp].discount);
                    int discountedPrice = tempPrice - ((tempDisc * tempPrice) / 100);

                    row["Total"] = "" + discountedPrice * Int32.Parse(quantity_editText.Text);

                    totalBill_label.Text = "" + (double)(double.Parse(totalBill_label.Text) + discountedPrice * Int32.Parse(quantity_editText.Text));

                    dt.Rows.Add(row);

                    //adding to selectedProdList
                    Products_class product = new Products_class
                    {
                        name         = productList[temp].name,
                        price        = productList[temp].price,
                        quantity     = quantity_editText.Text,
                        discount     = productList[temp].discount,
                        featured     = productList[temp].featured,
                        prescription = productList[temp].prescription,
                        avgReviews   = productList[temp].avgReviews,
                        description  = productList[temp].description,
                        image        = productList[temp].image,
                        timestamp    = productList[temp].timestamp,
                        totalReviews = productList[temp].totalReviews
                    };
                    // selectedProductList.Add(productList[temp]);
                    selectedProductList.Add(product);
                    selectedKeys.Add(keys[temp]);
                    selectedQuantity.Add(productList[temp].quantity);
                }
            }
            else
            {
                MessageBox.Show("Please select a product first!");
            }
        }
예제 #7
0
 public async void AddProductToInventory(Products_class product)
 {
     PushResponse response = await client.PushTaskAsync("products", product);
 }
예제 #8
0
        private async void createOrder_btn_Click(object sender, EventArgs e)
        {
            if (products_grid.Rows[0].Cells[0].Value == null)
            {
                MessageBox.Show("Please select a product first");
            }
            else
            {
                try
                {
                    Vendor_class v = vendorList[vendor_list.SelectedIndex];

                    List <Products_class> newList = new List <Products_class>();

                    newList = selectedProductsList.Concat(newProductList).ToList();

                    PurchaseOrder_class po = new PurchaseOrder_class
                    {
                        vendor      = v,
                        orderNo     = orderNo_editText.Text,
                        orderDate   = orderDate_editText.Text,
                        totalBill   = totalBill_label.Text,
                        productList = newList,
                        punchedBy   = Form1.loggedInUser.name
                    };

                    try
                    {
                        PushResponse response = await client.PushTaskAsync("purchases", po);

                        PurchaseOrder_class p2 = response.ResultAs <PurchaseOrder_class>();
                        for (int i = 0; i < newProductList.Count; i++)
                        {
                            PushResponse res = await client.PushTaskAsync("products", newProductList[i]);

                            Products_class pp = res.ResultAs <Products_class>();
                        }

                        for (int i = 0; i < selectedProductsListUPDATE.Count; i++)
                        {
                            FirebaseResponse response2 = await client.UpdateTaskAsync("products/" + keysUPDATE[i], selectedProductsListUPDATE[i]);

                            Products_class product = response2.ResultAs <Products_class>();
                        }
                    }

                    catch (Exception)
                    {
                        MessageBox.Show("Error connecting to FIREBASE. Please check your internet connection!");
                    }

                    MessageBox.Show("Order added successfully");

                    this.Hide();
                    Purchasing p = new Purchasing();
                    p.Show();
                }
                catch (Exception)
                {
                    MessageBox.Show("Please Select a vendor first!");
                }
            }
        }
예제 #9
0
        private async void addToOrder_btn_Click(object sender, EventArgs e)
        {
            if (name_editText.Text == "" || name_editText == null)
            {
                MessageBox.Show("Fill Name field first.");
            }

            else if (price_editText.Text == "" || price_editText == null)
            {
                MessageBox.Show("Fill price field first.");
            }



            else if (quantity_editText.Text == "" || quantity_editText == null)
            {
                MessageBox.Show("Fill quantity field first.");
            }

            else
            {
                bool check      = false;
                int  indexFound = -1;

                for (int i = 0; i < productList.Count; i++)
                {
                    if (name_editText.Text.ToLower() == productList[i].name.ToLower())
                    {
                        check      = true;
                        indexFound = i;
                        break;
                    }
                }

                if (!check)
                {
                    //Adding product to firebase if it doesn't exist
                    Products_class product = new Products_class(description_editText.Text, discount_editText.Text, false, image_editText.Text + "", name_editText.Text, false, double.Parse(price_editText.Text), int.Parse(quantity_editText.Text), DateTime.Now.ToString());

                    //PushResponse response = await client.PushTaskAsync("products", product);

                    //productList.Add(product);
                    //product_list.Items.Add(product.name);

                    newProductList.Add(product);

                    //FirebaseResponse resp = await client.GetTaskAsync("products/");
                    //Dictionary<string, Products_class> dict = resp.ResultAs<Dictionary<string, Products_class>>();

                    //Adding new key to keys array

                    /*  foreach (KeyValuePair<string, Products_class> ele1 in dict)
                     * {
                     *    if (!keys.Contains(ele1.Key))
                     *    {
                     *        keys.Add(ele1.Key);
                     *        break;
                     *    }
                     *
                     * }*/

                    //adding new row to DT
                    DataRow row = dt.NewRow();
                    row["Name"]         = product.name;
                    row["Price"]        = product.price;
                    row["Quantity"]     = product.quantity;
                    row["Discount"]     = product.discount;
                    row["Total"]        = "" + product.quantity * product.price;
                    row["Description"]  = product.description;
                    row["Featured"]     = product.featured;
                    row["Prescription"] = product.prescription;
                    row["Date"]         = product.timestamp;

                    dt.Rows.Add(row);

                    totalBill_label.Text = "" + (double.Parse(totalBill_label.Text) + product.quantity * product.price);

                    name_editText.Text = "";
                }

                else
                {
                    //MessageBox.Show("Product already exists in the inventory.");
                    Products_class product  = new Products_class(description_editText.Text, discount_editText.Text, false, image_editText.Text + "", name_editText.Text, false, double.Parse(price_editText.Text), Int32.Parse(quantity_editText.Text) + productList[indexFound].quantity, DateTime.Now.ToString());
                    Products_class product2 = new Products_class(description_editText.Text, discount_editText.Text, false, image_editText.Text + "", name_editText.Text, false, double.Parse(price_editText.Text), int.Parse(quantity_editText.Text), DateTime.Now.ToString());

                    //adding new row to DT
                    DataRow row = dt.NewRow();
                    row["Name"]         = product.name;
                    row["Price"]        = product.price;
                    row["Quantity"]     = quantity_editText.Text;
                    row["Discount"]     = product.discount;
                    row["Total"]        = "" + double.Parse(quantity_editText.Text) * product.price;
                    row["Description"]  = product.description;
                    row["Featured"]     = product.featured;
                    row["Prescription"] = product.prescription;
                    row["Date"]         = product.timestamp;


                    dt.Rows.Add(row);

                    totalBill_label.Text = "" + (double.Parse(totalBill_label.Text) + double.Parse(quantity_editText.Text) * product.price);

                    selectedProductsListUPDATE.Add(product);
                    keysUPDATE.Add(keys[indexFound]);
                    selectedProductsList.Add(product2);

                    //FirebaseResponse resp = await client.SetTaskAsync<Products_class>("products/"+keys[indexFound],product);
                    //Products_class result = resp.ResultAs<Products_class>();

                    //MessageBox.Show("Updated SUCCESSFULLY");
                    name_editText.Text = "";
                }
            }
        }