private void Pay_Btn_Click(object sender, RoutedEventArgs e) { var itemname = ItemName_TextBox.Text; float price; float.TryParse(ItemPrice_TextBox.Text, out price); if (itemname == "" || price == 0 || Categories_CB.SelectedItem == null) { MessageBox.Show("Entrer un prix ou nom non vide svp"); } else { var item = new Item(); item.Date = DateTime.Now; item.ItemName = itemname; item.ItemPrice = price; item.Category = (Categories)Enum.Parse(typeof(Categories), Categories_CB.SelectedValue.ToString()); SQLiteDataAccess.SaveItem(item); var finances = SQLiteDataAccess.GetBalance().FirstOrDefault(); finances.Balance -= price; SQLiteDataAccess.LoadSalary(finances); Balance_Label.Content = $"Balance:{finances.Balance} TND"; } ItemName_TextBox.Text = ""; ItemPrice_TextBox.Text = ""; RefreshHistoryDataGrid(); }
private void SetBalance() { var x = SQLiteDataAccess.GetBalance().FirstOrDefault(); if (x != null) { Balance_Label.Content = $"Balance:{x.Balance} TND"; } else { Balance_Label.Content = $"Balance:0 TND"; } }
private void Salary_Btn_Click(object sender, RoutedEventArgs e) { float input; float.TryParse(Salary_TextBox.Text, out input); if (input == 0) { MessageBox.Show("Entrer un entier"); } else { //adjusting balance var finances = SQLiteDataAccess.GetBalance().FirstOrDefault(); float x; if (finances.Balance != 0) { x = float.Parse(Salary_TextBox.Text) + finances.Balance; Balance_Label.Content = $"Balance:{x} TND"; } else { x = float.Parse(Salary_TextBox.Text); Balance_Label.Content = $"Balance:0 TND"; } finances.Balance = x; SQLiteDataAccess.LoadSalary(finances); //setting values for new item var item = new Item(); item.Date = DateTime.Now; item.ItemName = "Salaire"; item.ItemPrice = input; item.Category = Categories.Misc; //saving to db SQLiteDataAccess.SaveItem(item); } Salary_TextBox.Text = ""; RefreshHistoryDataGrid(); }