private void readAllTaxesPayedByJurPersonsFromDatabase(SQLiteCommand sqlite_cmd, out SQLiteDataReader sqlite_datareader) { sqlite_datareader = sqlite_cmd.ExecuteReader(); try { sqlite_cmd.CommandText = "SELECT * FROM TaxesPayedByJurPersons"; 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(); int amount = int.Parse(sqlite_datareader["Amount"].ToString()); DateTime date = Extensions.Tools.GetDateTimeFromSql(sqlite_datareader["OnPayedDate"].ToString()); TaxPayedByJuridicalPerson newTax = new TaxPayedByJuridicalPerson(id, taxId, payerId, taxName, payerName, date, amount); ((App)Application.Current).TaxesPayedByJurPersons.Add(newTax); } if (((App)Application.Current).TaxesPayedByJurPersons.Count > 0) { TaxPayedByJuridicalPerson.MaxId = ((App)Application.Current).TaxesPayedByJurPersons[((App)Application.Current).TaxesPayedByJurPersons.Count - 1].Id + 1; } } catch (Exception e) { Logger.Log.Info(e.ToString()); } }
private void button_Click(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; } JuridicalPerson jurPerson = null; foreach (var item in ((App)Application.Current).JuridicalPersons) { if (item.Name == PayersNamesBox.autoTextBox.Text) { jurPerson = item; } } if (jurPerson == null) { MessageBox.Show("Юридичної особи з такою назвою не існує!"); return; } TaxPayedByJuridicalPerson newTax = new TaxPayedByJuridicalPerson(TaxPayedByJuridicalPerson.MaxId++, tax.TaxId, jurPerson.Id, tax.TaxName, jurPerson.Name, PayDate.SelectedDate.Value, int.Parse(Amount.Text)); string date = Extensions.Tools.ConvertDayTimeToSqlDate(PayDate.SelectedDate.Value); string query = "INSERT INTO TaxesPayedByJurPersons (Id, TaxId, PayerId, TaxName, PayerName, OnPayedDate, Amount) VALUES (" + newTax.Id + ", " + newTax.TaxId + ", " + newTax.PayerId + ", '" + newTax.TaxName + "', '" + newTax.PayerName + "', '" + date + "', " + newTax.Amount + ");"; Extensions.Tools.ExecuteQuery(query); ((App)Application.Current).TaxesPayedByJurPersons.Add(newTax); }