public PhysicalPersonNoteResponse Create(PhysicalPersonNoteViewModel PhysicalPersonNote)
        {
            PhysicalPersonNoteResponse response = new PhysicalPersonNoteResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                SqliteCommand insertCommand = db.CreateCommand();
                insertCommand.CommandText = SqlCommandInsertPart;

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, PhysicalPersonNote);
                    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 PhysicalPersonNoteSQLiteRepository().SetStatusDeleted(CurrentPhysicalPersonNoteDG.Identifier);

            if (response.Success)
            {
                MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Stavka_je_uspešno_obrisanaUzvičnik"));

                CurrentPhysicalPersonNoteForm            = new PhysicalPersonNoteViewModel();
                CurrentPhysicalPersonNoteForm.Identifier = Guid.NewGuid();
                CurrentPhysicalPersonNoteForm.ItemStatus = ItemStatus.Added;

                CurrentPhysicalPersonNoteDG = null;

                PhysicalPersonCreatedUpdated();

                Thread displayThread = new Thread(() => DisplayPhysicalPersonNoteData());
                displayThread.IsBackground = true;
                displayThread.Start();
            }
            else
            {
                MainWindow.ErrorMessage = response.Message;
            }
        }
        private void btnAddNote_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (CurrentPhysicalPersonNoteForm.Note == null)
            {
                MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Napomena"));
                return;
            }

            #endregion
            Thread th = new Thread(() =>
            {
                SubmitButtonEnabled = false;
                CurrentPhysicalPersonNoteForm.PhysicalPerson = CurrentPhysicalPerson;

                CurrentPhysicalPersonNoteForm.Company = new CompanyViewModel()
                {
                    Id = MainWindow.CurrentCompanyId
                };
                CurrentPhysicalPersonNoteForm.CreatedBy = new UserViewModel()
                {
                    Id = MainWindow.CurrentUserId
                };

                new PhysicalPersonNoteSQLiteRepository().Delete(CurrentPhysicalPersonNoteForm.Identifier);

                var response = new PhysicalPersonNoteSQLiteRepository().Create(CurrentPhysicalPersonNoteForm);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = response.Message;

                    CurrentPhysicalPersonNoteForm            = new PhysicalPersonNoteViewModel();
                    CurrentPhysicalPersonNoteForm.Identifier = Guid.NewGuid();
                    CurrentPhysicalPersonNoteForm.ItemStatus = ItemStatus.Added;
                    CurrentPhysicalPersonNoteForm.IsSynced   = false;
                    return;
                }

                CurrentPhysicalPersonNoteForm            = new PhysicalPersonNoteViewModel();
                CurrentPhysicalPersonNoteForm.Identifier = Guid.NewGuid();
                CurrentPhysicalPersonNoteForm.ItemStatus = ItemStatus.Added;
                CurrentPhysicalPersonNoteForm.IsSynced   = false;

                PhysicalPersonCreatedUpdated();
                DisplayPhysicalPersonNoteData();

                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)
        {
            CurrentPhysicalPersonNoteForm            = new PhysicalPersonNoteViewModel();
            CurrentPhysicalPersonNoteForm.Identifier = CurrentPhysicalPersonNoteDG.Identifier;
            CurrentPhysicalPersonNoteForm.ItemStatus = ItemStatus.Edited;

            CurrentPhysicalPersonNoteForm.Note      = CurrentPhysicalPersonNoteDG.Note;
            CurrentPhysicalPersonNoteForm.NoteDate  = CurrentPhysicalPersonNoteDG.NoteDate;
            CurrentPhysicalPersonNoteForm.IsSynced  = CurrentPhysicalPersonNoteDG.IsSynced;
            CurrentPhysicalPersonNoteForm.UpdatedAt = CurrentPhysicalPersonNoteDG.UpdatedAt;
        }
        private static PhysicalPersonNoteViewModel Read(SqliteDataReader query)
        {
            int counter = 0;
            PhysicalPersonNoteViewModel dbEntry = new PhysicalPersonNoteViewModel();

            dbEntry.Id             = SQLiteHelper.GetInt(query, ref counter);
            dbEntry.Identifier     = SQLiteHelper.GetGuid(query, ref counter);
            dbEntry.PhysicalPerson = SQLiteHelper.GetPhysicalPerson(query, ref counter);
            dbEntry.Note           = SQLiteHelper.GetString(query, ref counter);
            dbEntry.NoteDate       = SQLiteHelper.GetDateTime(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);
        }
Exemplo n.º 6
0
        public static PhysicalPersonNoteViewModel ConvertToPhysicalPersonNoteViewModelLite(this PhysicalPersonNote PhysicalPersonNote)
        {
            PhysicalPersonNoteViewModel PhysicalPersonNoteViewModel = new PhysicalPersonNoteViewModel()
            {
                Id         = PhysicalPersonNote.Id,
                Identifier = PhysicalPersonNote.Identifier,

                Note       = PhysicalPersonNote.Note,
                NoteDate   = PhysicalPersonNote.NoteDate,
                ItemStatus = PhysicalPersonNote.ItemStatus,

                IsActive = PhysicalPersonNote.Active,

                UpdatedAt = PhysicalPersonNote.UpdatedAt,
                CreatedAt = PhysicalPersonNote.CreatedAt
            };

            return(PhysicalPersonNoteViewModel);
        }
        public PhysicalPersonNoteListResponse GetPhysicalPersonNotesByPhysicalPerson(int companyId, Guid PhysicalPersonIdentifier)
        {
            PhysicalPersonNoteListResponse     response            = new PhysicalPersonNoteListResponse();
            List <PhysicalPersonNoteViewModel> PhysicalPersonNotes = new List <PhysicalPersonNoteViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM PhysicalPersonNotes " +
                        "WHERE PhysicalPersonIdentifier = @PhysicalPersonIdentifier " +
                        "AND CompanyId = @CompanyId " +
                        "ORDER BY IsSynced, Id DESC;", db);

                    selectCommand.Parameters.AddWithValue("@PhysicalPersonIdentifier", PhysicalPersonIdentifier);
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        PhysicalPersonNoteViewModel dbEntry = Read(query);
                        PhysicalPersonNotes.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage      = error.Message;
                    response.Success             = false;
                    response.Message             = error.Message;
                    response.PhysicalPersonNotes = new List <PhysicalPersonNoteViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success             = true;
            response.PhysicalPersonNotes = PhysicalPersonNotes;
            return(response);
        }
        private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, PhysicalPersonNoteViewModel PhysicalPersonNote)
        {
            insertCommand.Parameters.AddWithValue("@ServerId", PhysicalPersonNote.Id);
            insertCommand.Parameters.AddWithValue("@Identifier", PhysicalPersonNote.Identifier);
            insertCommand.Parameters.AddWithValue("@PhysicalPersonId", ((object)PhysicalPersonNote.PhysicalPerson.Id) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@PhysicalPersonIdentifier", ((object)PhysicalPersonNote.PhysicalPerson.Identifier) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@PhysicalPersonCode", ((object)PhysicalPersonNote.PhysicalPerson.Code) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@PhysicalPersonName", ((object)PhysicalPersonNote.PhysicalPerson.Name) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Note", PhysicalPersonNote.Note);
            insertCommand.Parameters.AddWithValue("@NoteDate", ((object)PhysicalPersonNote.NoteDate) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ItemStatus", ((object)PhysicalPersonNote.ItemStatus) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@IsSynced", PhysicalPersonNote.IsSynced);
            insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)PhysicalPersonNote.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 PhysicalPerson_Note_AddEdit(PhysicalPersonViewModel physicalPerson)
        {
            physicalPersonService     = DependencyResolver.Kernel.Get <IPhysicalPersonService>();
            physicalPersonNoteService = DependencyResolver.Kernel.Get <IPhysicalPersonNoteService>();

            InitializeComponent();

            this.DataContext = this;

            CurrentPhysicalPerson                    = physicalPerson;
            CurrentPhysicalPersonNoteForm            = new PhysicalPersonNoteViewModel();
            CurrentPhysicalPersonNoteForm.Identifier = Guid.NewGuid();
            CurrentPhysicalPersonNoteForm.ItemStatus = ItemStatus.Added;

            Thread displayThread = new Thread(() => DisplayPhysicalPersonNoteData());

            displayThread.IsBackground = true;
            displayThread.Start();

            btnAddNote.Focus();
        }
Exemplo n.º 10
0
        public static PhysicalPersonNote ConvertToPhysicalPersonNote(this PhysicalPersonNoteViewModel PhysicalPersonNoteViewModel)
        {
            PhysicalPersonNote PhysicalPersonNote = new PhysicalPersonNote()
            {
                Id         = PhysicalPersonNoteViewModel.Id,
                Identifier = PhysicalPersonNoteViewModel.Identifier,

                PhysicalPersonId = PhysicalPersonNoteViewModel.PhysicalPerson?.Id ?? null,

                Note       = PhysicalPersonNoteViewModel.Note,
                NoteDate   = PhysicalPersonNoteViewModel.NoteDate,
                ItemStatus = PhysicalPersonNoteViewModel.ItemStatus,

                CreatedById = PhysicalPersonNoteViewModel.CreatedBy?.Id ?? null,
                CompanyId   = PhysicalPersonNoteViewModel.Company?.Id ?? null,

                CreatedAt = PhysicalPersonNoteViewModel.CreatedAt,
                UpdatedAt = PhysicalPersonNoteViewModel.UpdatedAt
            };

            return(PhysicalPersonNote);
        }
        public PhysicalPersonNoteResponse GetPhysicalPersonNote(Guid identifier)
        {
            PhysicalPersonNoteResponse  response           = new PhysicalPersonNoteResponse();
            PhysicalPersonNoteViewModel PhysicalPersonNote = new PhysicalPersonNoteViewModel();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM PhysicalPersonNotes " +
                        "WHERE Identifier = @Identifier;", db);
                    selectCommand.Parameters.AddWithValue("@Identifier", identifier);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        PhysicalPersonNoteViewModel dbEntry = Read(query);
                        PhysicalPersonNote = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage     = error.Message;
                    response.Success            = false;
                    response.Message            = error.Message;
                    response.PhysicalPersonNote = new PhysicalPersonNoteViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success            = true;
            response.PhysicalPersonNote = PhysicalPersonNote;
            return(response);
        }
Exemplo n.º 12
0
        public static PhysicalPersonNoteViewModel ConvertToPhysicalPersonNoteViewModel(this PhysicalPersonNote PhysicalPersonNote)
        {
            PhysicalPersonNoteViewModel PhysicalPersonNoteViewModel = new PhysicalPersonNoteViewModel()
            {
                Id         = PhysicalPersonNote.Id,
                Identifier = PhysicalPersonNote.Identifier,

                PhysicalPerson = PhysicalPersonNote.PhysicalPerson?.ConvertToPhysicalPersonViewModelLite(),

                Note       = PhysicalPersonNote.Note,
                NoteDate   = PhysicalPersonNote.NoteDate,
                ItemStatus = PhysicalPersonNote.ItemStatus,

                IsActive = PhysicalPersonNote.Active,

                CreatedBy = PhysicalPersonNote.CreatedBy?.ConvertToUserViewModelLite(),
                Company   = PhysicalPersonNote.Company?.ConvertToCompanyViewModelLite(),

                UpdatedAt = PhysicalPersonNote.UpdatedAt,
                CreatedAt = PhysicalPersonNote.CreatedAt
            };

            return(PhysicalPersonNoteViewModel);
        }
 private void btnCancelNote_Click(object sender, RoutedEventArgs e)
 {
     CurrentPhysicalPersonNoteForm            = new PhysicalPersonNoteViewModel();
     CurrentPhysicalPersonNoteForm.Identifier = Guid.NewGuid();
     CurrentPhysicalPersonNoteForm.ItemStatus = ItemStatus.Added;
 }