private async void Load_Invoices() { try { FirebaseResponse resp = await client.GetTaskAsync("invoices/"); Dictionary <string, Invoices_class> dict = resp.ResultAs <Dictionary <string, Invoices_class> >(); //Adding invoice keys to Array salesKeys foreach (KeyValuePair <string, Invoices_class> ele1 in dict) { salesKeys.Add(ele1.Key); } //traversing list keys to fetch invoice details for (int i = 0; i < salesKeys.Count; i++) { FirebaseResponse resp2 = await client.GetTaskAsync("invoices/" + salesKeys[i]); Invoices_class invoice = resp2.ResultAs <Invoices_class>(); salesList.Add(invoice); } } catch (Exception) { MessageBox.Show("Error connecting to the database. Check your internet connection and restart the application."); } }
private async void updateInvoice() { try { FirebaseResponse resp = await client.GetTaskAsync("invoices/"); 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); } //traversing list keys to fetch product details for (int i = 0; i < keys.Count; i++) { FirebaseResponse resp2 = await client.GetTaskAsync("invoices/" + keys[i]); Invoices_class invoice = resp2.ResultAs <Invoices_class>(); invoicesList.Add(invoice); //Adding firebase data to the data grid DataRow row = dt.NewRow(); row["Invoice #"] = invoicesList[i].invoiceNo; row["Cashier"] = invoicesList[i].cashier; row["TimeStamp"] = invoicesList[i].timestamp; row["Total Bill"] = invoicesList[i].totalBill; dt.Rows.Add(row); // Console.WriteLine("Row added"); } } catch (Exception) { MessageBox.Show("Connectivity Error.\nCheck your INTERNET and try again."); } }
private async void createInvoice_btn_Click(object sender, EventArgs e) { Invoices_class invoice = new Invoices_class { cashier = cashier_editText.Text, timestamp = invoiceDate_editText.Text, invoiceNo = invoiceNo_editText.Text, totalBill = totalBill_label.Text, productList = selectedProductList }; PushResponse response = await client.PushTaskAsync("invoices", invoice); for (int i = 0; i < selectedKeys.Count; i++) { int finalQuantity = Int32.Parse(selectedQuantity[i]) - Int32.Parse(selectedProductList[i].quantity); selectedProductList[i].quantity = "" + finalQuantity; FirebaseResponse response2 = await client.UpdateTaskAsync("products/" + keys[i], selectedProductList[i]); } MessageBox.Show("Invoice Added Successfully!"); this.Hide(); }