private void Accept_Click(object sender, RoutedEventArgs e) { #region SQLite var optionsBuilder = new DbContextOptionsBuilder <DataBaseUsingEF.DataBaseInFile>(); optionsBuilder.UseSqlite("Filename=" + PathDataBase + BaseName); if (CostOrIncome) { using (var dataBase = new DataBaseUsingEF.DataBaseInFile(optionsBuilder.Options)) { DataBaseUsingEF.Cost cost = (from c in dataBase.Costs where c.Id == ID select c).SingleOrDefault(); cost.NameOfCost = textBox.Text; dataBase.SaveChanges(); } } else { using (var dataBase = new DataBaseUsingEF.DataBaseInFile(optionsBuilder.Options)) { DataBaseUsingEF.Income income = (from c in dataBase.Incomes where c.Id == ID select c).SingleOrDefault(); income.NameOfIncome = textBox.Text; dataBase.SaveChanges(); } } Close(); #endregion #region SQLServer //if (CostOrIncome) //{ // using (var dataBase = new DataBaseUsingEF.DataBaseUsingEF(BaseName)) // { // DataBaseUsingEF.Cost cost = (from c in dataBase.Costs where c.Id == ID select c).SingleOrDefault(); // cost.NameOfCost = textBox.Text; // dataBase.SaveChanges(); // } //} //else //{ // using (var dataBase = new DataBaseUsingEF.DataBaseUsingEF(BaseName)) // { // DataBaseUsingEF.Income income = (from c in dataBase.Incomes where c.Id == ID select c).SingleOrDefault(); // income.NameOfIncome = textBox.Text; // dataBase.SaveChanges(); // } //} //Close(); #endregion }
private void addBtn_Click(object sender, RoutedEventArgs e) { #region SQLite try { decimal preis; if (string.IsNullOrWhiteSpace(nameTxBxAdd.Text) || string.IsNullOrWhiteSpace(priceTxBxAdd.Text)) { if (string.IsNullOrWhiteSpace(nameTxBxAdd.Text)) { nameTxBxAdd.Focus(); } else { priceTxBxAdd.Focus(); } DatenUpdateSourсe(); lblError.Content = "Fehler! Sie haben nicht alle Daten eingegeben."; } else { if (this.Title == "Ausgabe hinzufügen") { if (decimal.TryParse(priceTxBxAdd.Text, out preis)) { decimal tempPreisDecimal = Convert.ToDecimal(priceTxBxAdd.Text, CultureInfo.CreateSpecificCulture("de-DE")); //Add Euro to end string tempPreisString = tempPreisDecimal.ToString("C", CultureInfo.CreateSpecificCulture("de-DE")); var optionsBuilder = new DbContextOptionsBuilder <DataBaseUsingEF.DataBaseInFile>(); optionsBuilder.UseSqlite("Filename=" + PathUser + @"\" + baseName); using (var dataBase = new DataBaseUsingEF.DataBaseInFile(optionsBuilder.Options)) { var cost = new DataBaseUsingEF.Cost { CategoryOfCost = comboBoxCostCategory.Text, CategoryUnderOfCost = tempComboBox.Text, NameOfCost = nameTxBxAdd.Text, PreisOfCost = tempPreisString, DateOfCost = dataPickerAdd.SelectedDate.Value.Date }; dataBase.Costs.Add(cost); dataBase.SaveChanges(); } DialogResult = true; //SerialCryptoDate(); cancelBtn_Click(sender, e); } else { priceTxBxAdd.Text = string.Empty; DatenUpdateSourсe(); priceTxBxAdd.Focus(); lblError.Content = "Fehler! Sie haben wahrscheinlich Buchstaben eingeben"; } } else if (this.Title == "Einkommen hinzufügen") { if (decimal.TryParse(priceTxBxAdd.Text, out preis)) { decimal tempPreisDecimal = Convert.ToDecimal(priceTxBxAdd.Text, CultureInfo.CreateSpecificCulture("de-DE")); //Add Euro to end string tempPreisString = tempPreisDecimal.ToString("C", CultureInfo.CreateSpecificCulture("de-DE")); var optionsBuilder = new DbContextOptionsBuilder <DataBaseUsingEF.DataBaseInFile>(); optionsBuilder.UseSqlite("Filename=" + PathUser + @"\" + baseName); using (var dataBase = new DataBaseUsingEF.DataBaseInFile(optionsBuilder.Options)) { var income = new DataBaseUsingEF.Income { CategoryOfIncome = comboBoxIncomeCategory.Text, CategoryUnderOfIncome = tempComboBox.Text, NameOfIncome = nameTxBxAdd.Text, PreisOfIncome = tempPreisString, DateOfIncome = dataPickerAdd.SelectedDate.Value.Date }; dataBase.Incomes.Add(income); dataBase.SaveChanges(); } DialogResult = true; //SerialCryptoDate(); cancelBtn_Click(sender, e); } else { priceTxBxAdd.Text = string.Empty; DatenUpdateSourсe(); priceTxBxAdd.Focus(); lblError.Content = "Fehler! Sie haben wahrscheinlich Buchstaben eingeben"; } } } } catch (Exception em) { MessageBox.Show(em.Message); } #endregion #region SQLServer //decimal preis; //if (string.IsNullOrWhiteSpace(nameTxBxAdd.Text) || string.IsNullOrWhiteSpace(priceTxBxAdd.Text)) //{ // if (string.IsNullOrWhiteSpace(nameTxBxAdd.Text)) // { // nameTxBxAdd.Focus(); // } // else // { // priceTxBxAdd.Focus(); // } // DatenUpdateSourсe(); // lblError.Content = "Ошибка! Вы ввели не все данные"; //} //else //{ // if (this.Title == "Добавить расходы") // { // if (decimal.TryParse(priceTxBxAdd.Text, out preis)) // { // using (var dataBase = new DataBaseUsingEF.DataBaseUsingEF(baseName)) // { // var cost = new DataBaseUsingEF.Cost // { // CategoryOfCost = comboBoxCostCategory.Text, // CategoryUnderOfCost = tempComboBox.Text, // NameOfCost = nameTxBxAdd.Text, // PreisOfCost = Convert.ToDecimal(priceTxBxAdd.Text, CultureInfo.InvariantCulture), // DateOfCost = dataPickerAdd.SelectedDate.Value.Date // }; // dataBase.Costs.Add(cost); // dataBase.SaveChanges(); // } // DialogResult = true; // SerialCryptoDate(); // cancelBtn_Click(sender, e); // } // else // { // priceTxBxAdd.Text = string.Empty; // DatenUpdateSourсe(); // priceTxBxAdd.Focus(); // lblError.Content = "Ошибка! Возможно вы ввели букву"; // } // } // else if (this.Title == "Добавить доходы") // { // if (decimal.TryParse(priceTxBxAdd.Text, out preis)) // { // using (var dataBase = new DataBaseUsingEF.DataBaseUsingEF(baseName)) // { // var income = new DataBaseUsingEF.Income // { // CategoryOfIncome = comboBoxIncomeCategory.Text, // CategoryUnderOfIncome = tempComboBox.Text, // NameOfIncome = nameTxBxAdd.Text, // PreisOfIncome = Convert.ToDecimal(priceTxBxAdd.Text, CultureInfo.InvariantCulture), // DateOfIncome = dataPickerAdd.SelectedDate.Value.Date // }; // dataBase.Incomes.Add(income); // dataBase.SaveChanges(); // } // DialogResult = true; // SerialCryptoDate(); // cancelBtn_Click(sender, e); // } // else // { // priceTxBxAdd.Text = string.Empty; // DatenUpdateSourсe(); // priceTxBxAdd.Focus(); // lblError.Content = "Ошибка! Возможно вы ввели букву"; // } // } //} #endregion }