public static void DeleteShoppingListItem(ListView shoppingList) { using (var context = new BCEntities()) { string test = shoppingList.SelectedItems[0].Text; var lista = context.ShoppingLists.Where(x => x.ParentCategory == test).ToList(); context.ShoppingLists.RemoveRange(lista); context.SaveChanges(); } }
public static void SumIncome(Label lblBudget) { using (var context = new BCEntities()) { decimal?suma = 0; var listOfIncomes = context.Incomes.ToList(); foreach (var item in listOfIncomes) { suma = suma + item.Value; } lblBudget.Text = Math.Round(Convert.ToDecimal(suma), 2).ToString() + "zł"; context.SaveChanges(); } }
public static void AddIncomeDB(TextBox name, TextBox value, RichTextBox Description) { using (var context = new BCEntities()) { var item = new Income { Name = name.Text, Value = Convert.ToDecimal(value.Text), Description = Description.Text, Date = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")) }; context.Incomes.Add(item); context.SaveChanges(); } }
public static void DisplayShoppingList(ListView shoppingList) { using (var context = new BCEntities()) { var shoppingListDb = context.ShoppingLists.ToList(); var listName = shoppingListDb.GroupBy(x => x.ParentCategory).Select(a => new { parentCategory = a.Key, count = a.Count() }).ToList(); for (int i = 0; i < listName.Count; i++) { ListViewItem listViewItem = new ListViewItem(listName[i].parentCategory); listViewItem.SubItems.Add(listName[i].count.ToString()); shoppingList.Items.Add(listViewItem); } context.SaveChanges(); } }
public static void AddShoppingListDB(ListBox shoppingList, TextBox txtListName, TextBox txtProduct) { using (var context = new BCEntities()) { for (int i = 0; i < shoppingList.Items.Count; i++) { var newShoppingList = new DataBase.ShoppingList() { ParentCategory = txtListName.Text, Product = shoppingList.Items[i].ToString() }; context.ShoppingLists.Add(newShoppingList); context.SaveChanges(); } }; }
public static void DisplayIncomeDB(ListView listView) { using (var context = new BCEntities()) { var incomeList = context.Incomes.ToList(); for (int i = 0; i < context.Incomes.Count(); i++) { ListViewItem item = new ListViewItem(incomeList[i].IncomeId.ToString()); item.SubItems.Add(incomeList[i].Name); item.SubItems.Add(Math.Round(Convert.ToDecimal(incomeList[i].Value), 2) + "zł"); item.SubItems.Add(Convert.ToDateTime(incomeList[i].Date).ToString("yyyy-MM-dd")); item.SubItems.Add(incomeList[i].Description); listView.Items.Add(item); } context.SaveChanges(); } }
public static void AddPaymentDB(RichTextBox description, TextBox shopName, TextBox invoiceNo, TextBox buyerName, Label paymentDate, Label purchaseDay, ComboBox title, Label filePath, TextBox price, string image) { if (image != "")//With image { FileStream stream = new FileStream(image, FileMode.Open, FileAccess.Read); BinaryReader brs = new BinaryReader(stream); using (var context = new BCEntities()) { var newPayment = new Payment { Description = description.Text, ShopName = shopName.Text, InvoiceNo = invoiceNo.Text, BuyerName = buyerName.Text, PaymentDay = Convert.ToDateTime(paymentDate.Text), PurchaseDate = Convert.ToDateTime(purchaseDay.Text), Title = title.Text, Price = Convert.ToDecimal(price.Text), Scan = brs.ReadBytes((int)stream.Length) }; context.Payments.Add(newPayment); context.SaveChanges(); } } else //Without image { using (var context = new BCEntities()) { var newPayment = new Payment { Description = description.Text, ShopName = shopName.Text, InvoiceNo = invoiceNo.Text, BuyerName = buyerName.Text, PaymentDay = Convert.ToDateTime(paymentDate.Text), PurchaseDate = Convert.ToDateTime(purchaseDay.Text), Title = title.Text, Price = Convert.ToDecimal(price.Text) }; context.Payments.Add(newPayment); context.SaveChanges(); } } }
public static void UpdatePaymentDB(RichTextBox description, TextBox shopName, TextBox invoiceNo, TextBox buyerName, Label paymentDate, Label purchaseDay, ComboBox title, Label filePath, TextBox price, string image, int selectedIndex) { if (filePath.Text != "") { FileStream fs = new FileStream(filePath.Text, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); using (var context = new BCEntities()) { var paymentList = context.Payments.ToList(); paymentList[selectedIndex].Title = title.Text; paymentList[selectedIndex].Price = Math.Round(Convert.ToDecimal(price.Text), 2); paymentList[selectedIndex].BuyerName = buyerName.Text; paymentList[selectedIndex].ShopName = shopName.Text; paymentList[selectedIndex].Description = description.Text; paymentList[selectedIndex].PurchaseDate = Convert.ToDateTime(purchaseDay.Text); paymentList[selectedIndex].InvoiceNo = invoiceNo.Text; paymentList[selectedIndex].PaymentDay = Convert.ToDateTime(paymentDate.Text); paymentList[selectedIndex].Scan = br.ReadBytes((int)fs.Length); context.SaveChanges(); } } else { using (var context = new BCEntities()) { var paymentList = context.Payments.ToList(); paymentList[selectedIndex].Title = title.Text; paymentList[selectedIndex].Price = Math.Round(Convert.ToDecimal(price.Text), 2); paymentList[selectedIndex].BuyerName = buyerName.Text; paymentList[selectedIndex].ShopName = shopName.Text; paymentList[selectedIndex].Description = description.Text; paymentList[selectedIndex].PurchaseDate = Convert.ToDateTime(purchaseDay.Text); paymentList[selectedIndex].InvoiceNo = invoiceNo.Text; paymentList[selectedIndex].PaymentDay = Convert.ToDateTime(paymentDate.Text); context.SaveChanges(); } } }
public static void RemoveIncomeDB(ListView listView) { using (var context = new BCEntities()) { if (listView.SelectedItems.Count > 0) { int i = listView.SelectedIndices[0]; string removeTest = listView.Items[i].Text; int removeDB = int.Parse(removeTest); listView.Items.Remove(listView.Items[i]); context.Incomes.Remove(context.Incomes.First(x => x.IncomeId == removeDB)); context.SaveChanges(); } else { string message = "Musi być zaznaczone conajmniej 1 wiersz."; string title = "Błąd usuwania"; DialogResult popUp; popUp = MessageBox.Show(message, title); } } }
public static void DisplayPaymentDB(ListView listViePayment) { using (var context = new BCEntities()) { var purchaseList = context.Payments.ToList(); for (int i = 0; i < purchaseList.Count; i++) { ListViewItem item = new ListViewItem(purchaseList[i].PaymentId.ToString()); item.SubItems.Add(purchaseList[i].Title); item.SubItems.Add(Math.Round(Convert.ToDecimal(purchaseList[i].Price), 2).ToString()); item.SubItems.Add(purchaseList[i].BuyerName); item.SubItems.Add(purchaseList[i].ShopName); item.SubItems.Add(Convert.ToDateTime(purchaseList[i].PurchaseDate).ToString("yyyy-MM-dd")); item.SubItems.Add(Convert.ToDateTime(purchaseList[i].PaymentDay).ToString("yyyy-MM-dd")); item.SubItems.Add(purchaseList[i].InvoiceNo); item.SubItems.Add(purchaseList[i].Description); listViePayment.Items.Add(item); } context.SaveChanges(); } }