private void readAllTaxesPayedByNatPersonsFromDatabase(SQLiteCommand sqlite_cmd, out SQLiteDataReader sqlite_datareader) { sqlite_datareader = sqlite_cmd.ExecuteReader(); try { sqlite_cmd.CommandText = "SELECT * FROM TaxesPayedByNatPersons"; while (sqlite_datareader.Read()) { int id = int.Parse(sqlite_datareader["Id"].ToString()); int taxId = int.Parse(sqlite_datareader["TaxId"].ToString()); int payerId = int.Parse(sqlite_datareader["PayerId"].ToString()); string taxName = sqlite_datareader["TaxName"].ToString(); string payerName = sqlite_datareader["PayerName"].ToString(); string payerSurname = sqlite_datareader["PayerSurname"].ToString(); int amount = int.Parse(sqlite_datareader["Amount"].ToString()); DateTime date = Extensions.Tools.GetDateTimeFromSql(sqlite_datareader["OnPayedDate"].ToString()); TaxPayedByNaturalPerson newTax = new TaxPayedByNaturalPerson(id, taxId, payerId, taxName, payerName, payerSurname, date, amount); ((App)Application.Current).TaxesPayedByNatPersons.Add(newTax); } if (((App)Application.Current).TaxesPayedByNatPersons.Count > 0) { Tax.MaxId = ((App)Application.Current).TaxesPayedByNatPersons[((App)Application.Current).TaxesPayedByNatPersons.Count - 1].TaxId + 1; } } catch (Exception e) { Logger.Log.Info(e.ToString()); } }
private void AddNewPerson(object sender, RoutedEventArgs e) { Tax tax = null; foreach (var item in ((App)Application.Current).Taxes) { if (item.TaxName == TaxNamesBox.autoTextBox.Text) { tax = item; } } if (!this.checkIfTaxIsValid(tax)) { return; } NaturalPerson natPerson = null; string[] personName = PayersNamesBox.autoTextBox.Text.Split(' '); foreach (var item in ((App)Application.Current).NaturalPersons) { if (item.Name == personName[0] && item.Surname == personName[1]) { natPerson = item; } } if (natPerson == null) { MessageBox.Show("Фізичної особи з таким іменем не існує!"); return; } TaxPayedByNaturalPerson newTax = new TaxPayedByNaturalPerson(TaxPayedByNaturalPerson.MaxId++, tax.TaxId, natPerson.Id, tax.TaxName, natPerson.Name, natPerson.Surname, PayDate.SelectedDate.Value, int.Parse(Amount.Text)); string date = Extensions.Tools.ConvertDayTimeToSqlDate(PayDate.SelectedDate.Value); string query = "INSERT INTO TaxesPayedByNatPersons(Id, TaxId, PayerId, TaxName, PayerName, PayerSurname, OnPayedDate, Amount) VALUES (" + newTax.Id + ", " + newTax.TaxId + ", " + newTax.PayerId + ", '" + newTax.TaxName + "', '" + newTax.PayerName + "', '" + newTax.PayerSurname + "', '" + date + "', " + newTax.Amount + ");"; Tools.ExecuteQuery(query); ((App)Application.Current).TaxesPayedByNatPersons.Add(newTax); }