public ConstructionSiteNoteResponse Create(ConstructionSiteNoteViewModel constructionSiteNote) { ConstructionSiteNoteResponse response = new ConstructionSiteNoteResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; try { insertCommand = AddCreateParameters(insertCommand, constructionSiteNote); insertCommand.ExecuteNonQuery(); } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; return(response); } db.Close(); response.Success = true; return(response); } }
private void BtnDelete_Click(object sender, RoutedEventArgs e) { var response = new ConstructionSiteNoteSQLiteRepository().SetStatusDeleted(CurrentConstructionSiteNoteDG.Identifier); if (response.Success) { MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Stavka_je_uspešno_obrisanaUzvičnik")); CurrentConstructionSiteNoteForm = new ConstructionSiteNoteViewModel(); CurrentConstructionSiteNoteForm.Identifier = Guid.NewGuid(); CurrentConstructionSiteNoteForm.ItemStatus = ItemStatus.Added; CurrentConstructionSiteNoteDG = null; ConstructionSiteCreatedUpdated(); Thread displayThread = new Thread(() => DisplayConstructionSiteNoteData()); displayThread.IsBackground = true; displayThread.Start(); } else { MainWindow.ErrorMessage = response.Message; } }
private void btnAddNote_Click(object sender, RoutedEventArgs e) { #region Validation if (CurrentConstructionSiteNoteForm.Note == null) { MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Član_porodice")); return; } #endregion Thread th = new Thread(() => { SubmitButtonEnabled = false; CurrentConstructionSiteNoteForm.ConstructionSite = CurrentConstructionSite; CurrentConstructionSiteNoteForm.Company = new CompanyViewModel() { Id = MainWindow.CurrentCompanyId }; CurrentConstructionSiteNoteForm.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; new ConstructionSiteNoteSQLiteRepository().Delete(CurrentConstructionSiteNoteForm.Identifier); var response = new ConstructionSiteNoteSQLiteRepository().Create(CurrentConstructionSiteNoteForm); if (!response.Success) { MainWindow.ErrorMessage = response.Message; CurrentConstructionSiteNoteForm = new ConstructionSiteNoteViewModel(); CurrentConstructionSiteNoteForm.Identifier = Guid.NewGuid(); CurrentConstructionSiteNoteForm.ItemStatus = ItemStatus.Added; CurrentConstructionSiteNoteForm.IsSynced = false; return; } CurrentConstructionSiteNoteForm = new ConstructionSiteNoteViewModel(); CurrentConstructionSiteNoteForm.Identifier = Guid.NewGuid(); CurrentConstructionSiteNoteForm.ItemStatus = ItemStatus.Added; CurrentConstructionSiteNoteForm.IsSynced = false; ConstructionSiteCreatedUpdated(); DisplayConstructionSiteNoteData(); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { txtNote.Focus(); }) ); SubmitButtonEnabled = true; }); th.IsBackground = true; th.Start(); }
private void btnEditNote_Click(object sender, RoutedEventArgs e) { CurrentConstructionSiteNoteForm = new ConstructionSiteNoteViewModel(); CurrentConstructionSiteNoteForm.Identifier = CurrentConstructionSiteNoteDG.Identifier; CurrentConstructionSiteNoteForm.ItemStatus = ItemStatus.Edited; CurrentConstructionSiteNoteForm.Note = CurrentConstructionSiteNoteDG.Note; CurrentConstructionSiteNoteForm.NoteDate = CurrentConstructionSiteNoteDG.NoteDate; CurrentConstructionSiteNoteForm.Path = CurrentConstructionSiteNoteDG.Path; CurrentConstructionSiteNoteForm.IsSynced = CurrentConstructionSiteNoteDG.IsSynced; CurrentConstructionSiteNoteForm.UpdatedAt = CurrentConstructionSiteNoteDG.UpdatedAt; }
private static ConstructionSiteNoteViewModel Read(SqliteDataReader query) { int counter = 0; ConstructionSiteNoteViewModel dbEntry = new ConstructionSiteNoteViewModel(); dbEntry.Id = SQLiteHelper.GetInt(query, ref counter); dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter); dbEntry.ConstructionSite = SQLiteHelper.GetConstructionSite(query, ref counter); dbEntry.Note = SQLiteHelper.GetString(query, ref counter); dbEntry.NoteDate = SQLiteHelper.GetDateTime(query, ref counter); dbEntry.Path = SQLiteHelper.GetString(query, ref counter); dbEntry.ItemStatus = SQLiteHelper.GetInt(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); return(dbEntry); }
public static ConstructionSiteNoteViewModel ConvertToConstructionSiteNoteViewModelLite(this ConstructionSiteNote constructionSiteNote) { ConstructionSiteNoteViewModel constructionSiteNoteViewModel = new ConstructionSiteNoteViewModel() { Id = constructionSiteNote.Id, Identifier = constructionSiteNote.Identifier, Note = constructionSiteNote.Note, NoteDate = constructionSiteNote.NoteDate, ItemStatus = constructionSiteNote.ItemStatus, Path = constructionSiteNote.Path, IsActive = constructionSiteNote.Active, UpdatedAt = constructionSiteNote.UpdatedAt, CreatedAt = constructionSiteNote.CreatedAt }; return(constructionSiteNoteViewModel); }
public ConstructionSiteNoteListResponse GetConstructionSiteNotesByConstructionSite(int companyId, Guid ConstructionSiteIdentifier) { ConstructionSiteNoteListResponse response = new ConstructionSiteNoteListResponse(); List <ConstructionSiteNoteViewModel> ConstructionSiteNotes = new List <ConstructionSiteNoteViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM ConstructionSiteNotes " + "WHERE ConstructionSiteIdentifier = @ConstructionSiteIdentifier " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC;", db); selectCommand.Parameters.AddWithValue("@ConstructionSiteIdentifier", ConstructionSiteIdentifier); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { ConstructionSiteNoteViewModel dbEntry = Read(query); ConstructionSiteNotes.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.ConstructionSiteNotes = new List <ConstructionSiteNoteViewModel>(); return(response); } db.Close(); } response.Success = true; response.ConstructionSiteNotes = ConstructionSiteNotes; return(response); }
public ConstructionSite_Note_AddEdit(ConstructionSiteViewModel constructionSite) { constructionSiteService = DependencyResolver.Kernel.Get <IConstructionSiteService>(); constructionSiteNoteService = DependencyResolver.Kernel.Get <IConstructionSiteNoteService>(); InitializeComponent(); this.DataContext = this; CurrentConstructionSite = constructionSite; CurrentConstructionSiteNoteForm = new ConstructionSiteNoteViewModel(); CurrentConstructionSiteNoteForm.Identifier = Guid.NewGuid(); CurrentConstructionSiteNoteForm.ItemStatus = ItemStatus.Added; Thread displayThread = new Thread(() => DisplayConstructionSiteNoteData()); displayThread.IsBackground = true; displayThread.Start(); btnAddNote.Focus(); }
private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, ConstructionSiteNoteViewModel constructionSiteNote) { insertCommand.Parameters.AddWithValue("@ServerId", constructionSiteNote.Id); insertCommand.Parameters.AddWithValue("@Identifier", constructionSiteNote.Identifier); insertCommand.Parameters.AddWithValue("@ConstructionSiteId", ((object)constructionSiteNote.ConstructionSite.Id) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@ConstructionSiteIdentifier", ((object)constructionSiteNote.ConstructionSite.Identifier) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@ConstructionSiteCode", ((object)constructionSiteNote.ConstructionSite.Code) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@ConstructionSiteName", ((object)constructionSiteNote.ConstructionSite.Name) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@Note", constructionSiteNote.Note); insertCommand.Parameters.AddWithValue("@NoteDate", ((object)constructionSiteNote.NoteDate) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@Path", ((object)constructionSiteNote.Path) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@ItemStatus", constructionSiteNote.ItemStatus); insertCommand.Parameters.AddWithValue("@IsSynced", constructionSiteNote.IsSynced); insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)constructionSiteNote.UpdatedAt) ?? DBNull.Value); insertCommand.Parameters.AddWithValue("@CreatedById", MainWindow.CurrentUser.Id); insertCommand.Parameters.AddWithValue("@CreatedByName", MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName); insertCommand.Parameters.AddWithValue("@CompanyId", MainWindow.CurrentCompany.Id); insertCommand.Parameters.AddWithValue("@CompanyName", MainWindow.CurrentCompany.CompanyName); return(insertCommand); }
public static ConstructionSiteNote ConvertToConstructionSiteNote(this ConstructionSiteNoteViewModel constructionSiteNoteViewModel) { ConstructionSiteNote ConstructionSiteNote = new ConstructionSiteNote() { Id = constructionSiteNoteViewModel.Id, Identifier = constructionSiteNoteViewModel.Identifier, ConstructionSiteId = constructionSiteNoteViewModel.ConstructionSite?.Id ?? null, Note = constructionSiteNoteViewModel.Note, NoteDate = constructionSiteNoteViewModel.NoteDate, ItemStatus = constructionSiteNoteViewModel.ItemStatus, Path = constructionSiteNoteViewModel.Path, CreatedById = constructionSiteNoteViewModel.CreatedBy?.Id ?? null, CompanyId = constructionSiteNoteViewModel.Company?.Id ?? null, CreatedAt = constructionSiteNoteViewModel.CreatedAt, UpdatedAt = constructionSiteNoteViewModel.UpdatedAt }; return(ConstructionSiteNote); }
public ConstructionSiteNoteResponse GetConstructionSiteNote(Guid identifier) { ConstructionSiteNoteResponse response = new ConstructionSiteNoteResponse(); ConstructionSiteNoteViewModel ConstructionSiteNote = new ConstructionSiteNoteViewModel(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM ConstructionSiteNotes " + "WHERE Identifier = @Identifier;", db); selectCommand.Parameters.AddWithValue("@Identifier", identifier); SqliteDataReader query = selectCommand.ExecuteReader(); if (query.Read()) { ConstructionSiteNoteViewModel dbEntry = Read(query); ConstructionSiteNote = dbEntry; } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.ConstructionSiteNote = new ConstructionSiteNoteViewModel(); return(response); } db.Close(); } response.Success = true; response.ConstructionSiteNote = ConstructionSiteNote; return(response); }
private void btnCancelNote_Click(object sender, RoutedEventArgs e) { CurrentConstructionSiteNoteForm = new ConstructionSiteNoteViewModel(); CurrentConstructionSiteNoteForm.Identifier = Guid.NewGuid(); CurrentConstructionSiteNoteForm.ItemStatus = ItemStatus.Added; }