public OutputInvoiceList() { // Get required services this.outputInvoiceService = DependencyResolver.Kernel.Get <IOutputInvoiceService>(); this.outputInvoiceNoteService = DependencyResolver.Kernel.Get <IOutputInvoiceNoteService>(); this.outputInvoiceDocumentService = DependencyResolver.Kernel.Get <IOutputInvoiceDocumentService>(); InitializeComponent(); this.DataContext = this; }
//public OutputInvoiceNoteListResponse GetUnSyncedNotes(int companyId) //{ // OutputInvoiceNoteListResponse response = new OutputInvoiceNoteListResponse(); // List<OutputInvoiceNoteViewModel> viewModels = new List<OutputInvoiceNoteViewModel>(); // using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) // { // db.Open(); // try // { // SqliteCommand selectCommand = new SqliteCommand( // SqlCommandSelectPart + // "FROM OutputInvoiceNotes " + // "WHERE CompanyId = @CompanyId AND IsSynced = 0 " + // "ORDER BY Id DESC;", db); // selectCommand.Parameters.AddWithValue("@CompanyId", companyId); // SqliteDataReader query = selectCommand.ExecuteReader(); // while (query.Read()) // { // int counter = 0; // OutputInvoiceNoteViewModel dbEntry = new OutputInvoiceNoteViewModel(); // dbEntry.Id = SQLiteHelper.GetInt(query, ref counter); // dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter); // dbEntry.OutputInvoice = SQLiteHelper.GetOutputInvoice(query, ref counter); // dbEntry.Note = SQLiteHelper.GetString(query, ref counter); // dbEntry.NoteDate = SQLiteHelper.GetDateTime(query, ref counter); // dbEntry.IsSynced = SQLiteHelper.GetBoolean(query, ref counter); // dbEntry.UpdatedAt = SQLiteHelper.GetDateTime(query, ref counter); // dbEntry.CreatedBy = SQLiteHelper.GetCreatedBy(query, ref counter); // dbEntry.Company = SQLiteHelper.GetCompany(query, ref counter); // viewModels.Add(dbEntry); // } // } // catch (SqliteException error) // { // MainWindow.ErrorMessage = error.Message; // response.Success = false; // response.Message = error.Message; // response.OutputInvoiceNotes = new List<OutputInvoiceNoteViewModel>(); // return response; // } // db.Close(); // } // response.Success = true; // response.OutputInvoiceNotes = viewModels; // return response; //} #endregion #region Sync public void Sync(IOutputInvoiceNoteService OutputInvoiceNoteService, Action <int, int> callback = null) { try { SyncOutputInvoiceNoteRequest request = new SyncOutputInvoiceNoteRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; OutputInvoiceNoteListResponse response = OutputInvoiceNoteService.Sync(request); if (response.Success) { toSync = response?.OutputInvoiceNotes?.Count ?? 0; List <OutputInvoiceNoteViewModel> outputInvoiceNotesFromDB = response.OutputInvoiceNotes; using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM OutputInvoiceNotes WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var outputInvoiceNote in outputInvoiceNotesFromDB) { deleteCommand.Parameters.AddWithValue("@Identifier", outputInvoiceNote.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (outputInvoiceNote.IsActive) { outputInvoiceNote.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, outputInvoiceNote); insertCommand.ExecuteNonQuery(); insertCommand.Parameters.Clear(); syncedItems++; callback?.Invoke(syncedItems, toSync); } } transaction.Commit(); } db.Close(); } } else { throw new Exception(response.Message); } } catch (Exception ex) { MainWindow.ErrorMessage = ex.Message; } }
public OutputInvoiceNoteController(IServiceProvider provider) { OutputInvoiceNoteService = provider.GetRequiredService <IOutputInvoiceNoteService>(); }