public Documents_Mailing_List()
        {
            InitializeComponent();

            this.DataContext = this;

            FilterBusinessPartnerDocuments = new BusinessPartnerDocumentViewModel();
            FilterBusinessPartnerDocuments.PropertyChanged += FilterBusinessPartnerDocuments_PropertyChanged;

            FilterConstructionSiteDocuments = new ConstructionSiteDocumentViewModel();
            FilterConstructionSiteDocuments.PropertyChanged += FilterConstructionSiteDocuments_PropertyChanged;

            FilterEmployeeDocuments = new EmployeeDocumentViewModel();
            FilterEmployeeDocuments.PropertyChanged += FilterEmployeeDocuments_PropertyChanged;

            FilterPhysicalPersonDocuments = new PhysicalPersonDocumentViewModel();
            FilterPhysicalPersonDocuments.PropertyChanged += FilterPhysicalPersonDocuments_PropertyChanged;

            DocumentsForMail = new ObservableCollection <DocumentForMailViewModel>();

            Thread td = new Thread(() => {
                DisplayBusinessPartnerDocumentData();

                DisplayConstructionSiteDocumentData();

                DisplayEmployeeDocumentData();

                DisplayPhysicalPersonDocumentData();
            });

            td.IsBackground = true;
            td.Start();
        }
        public ConstructionSiteDocumentResponse Create(ConstructionSiteDocumentViewModel constructionSiteDocument)
        {
            ConstructionSiteDocumentResponse response = new ConstructionSiteDocumentResponse();

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

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, constructionSiteDocument);
                    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 ConstructionSiteDocumentSQLiteRepository().SetStatusDeleted(CurrentConstructionSiteDocumentDG.Identifier);

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

                CurrentConstructionSiteDocumentForm            = new ConstructionSiteDocumentViewModel();
                CurrentConstructionSiteDocumentForm.Identifier = Guid.NewGuid();
                CurrentConstructionSiteDocumentForm.ItemStatus = ItemStatus.Added;

                CurrentConstructionSiteDocumentDG = null;

                ConstructionSiteCreatedUpdated();

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

            if (CurrentConstructionSiteDocumentForm.Name == null)
            {
                MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Obavezno_polje_naziv"));
                return;
            }

            #endregion
            Thread th = new Thread(() =>
            {
                SubmitButtonEnabled = false;
                CurrentConstructionSiteDocumentForm.ConstructionSite = CurrentConstructionSite;

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

                new ConstructionSiteDocumentSQLiteRepository().Delete(CurrentConstructionSiteDocumentForm.Identifier);

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

                    CurrentConstructionSiteDocumentForm            = new ConstructionSiteDocumentViewModel();
                    CurrentConstructionSiteDocumentForm.Identifier = Guid.NewGuid();
                    CurrentConstructionSiteDocumentForm.ItemStatus = ItemStatus.Added;
                    CurrentConstructionSiteDocumentForm.IsSynced   = false;
                    return;
                }

                CurrentConstructionSiteDocumentForm            = new ConstructionSiteDocumentViewModel();
                CurrentConstructionSiteDocumentForm.Identifier = Guid.NewGuid();
                CurrentConstructionSiteDocumentForm.ItemStatus = ItemStatus.Added;
                CurrentConstructionSiteDocumentForm.IsSynced   = false;

                ConstructionSiteCreatedUpdated();
                DisplayConstructionSiteDocumentData();

                Application.Current.Dispatcher.BeginInvoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(() =>
                {
                    txtDocumentName.Focus();
                })
                    );
                SubmitButtonEnabled = true;
            });
            th.IsBackground = true;
            th.Start();
        }
        private void btnEditDocument_Click(object sender, RoutedEventArgs e)
        {
            CurrentConstructionSiteDocumentForm            = new ConstructionSiteDocumentViewModel();
            CurrentConstructionSiteDocumentForm.Identifier = CurrentConstructionSiteDocumentDG.Identifier;
            CurrentConstructionSiteDocumentForm.ItemStatus = ItemStatus.Edited;

            CurrentConstructionSiteDocumentForm.Name       = CurrentConstructionSiteDocumentDG.Name;
            CurrentConstructionSiteDocumentForm.CreateDate = CurrentConstructionSiteDocumentDG.CreateDate;
            CurrentConstructionSiteDocumentForm.Path       = CurrentConstructionSiteDocumentDG.Path;
            CurrentConstructionSiteDocumentForm.IsSynced   = CurrentConstructionSiteDocumentDG.IsSynced;
            CurrentConstructionSiteDocumentForm.UpdatedAt  = CurrentConstructionSiteDocumentDG.UpdatedAt;
        }
        public ConstructionSiteDocumentListResponse GetFilteredConstructionSiteDocuments(int companyId, ConstructionSiteDocumentViewModel filterObject)
        {
            ConstructionSiteDocumentListResponse     response = new ConstructionSiteDocumentListResponse();
            List <ConstructionSiteDocumentViewModel> ConstructionSiteDocuments = new List <ConstructionSiteDocumentViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM ConstructionSiteDocuments " +
                        "WHERE (" +
                        "   (@ConstructionSiteName IS NULL OR @ConstructionSiteName = '' OR ConstructionSiteName LIKE @ConstructionSiteName) OR " +
                        "   (@ConstructionSiteName IS NULL OR @ConstructionSiteName = '' OR Name LIKE @ConstructionSiteName) " +
                        ") " +
                        "AND (@ConstructionSiteInternalCode IS NULL OR @ConstructionSiteInternalCode = '' OR ConstructionSiteInternalCode LIKE @ConstructionSiteInternalCode) " +
                        "AND (@DateFrom IS NULL OR @DateFrom = '' OR DATE(CreateDate) >= DATE(@DateFrom)) " +
                        "AND (@DateTo IS NULL OR @DateTo = '' OR DATE(CreateDate) <= DATE(@DateTo)) " +
                        "ORDER BY IsSynced, Id DESC;", db);

                    selectCommand.Parameters.AddWithValue("@ConstructionSiteName", (String.IsNullOrEmpty(filterObject.Search_Name) ? "" : "%" + filterObject.Search_Name + "%"));
                    selectCommand.Parameters.AddWithValue("@ConstructionSiteInternalCode", (String.IsNullOrEmpty(filterObject.Search_Code) ? "" : "%" + filterObject.Search_Code + "%"));
                    selectCommand.Parameters.AddWithValue("@DateFrom", ((object)filterObject.Search_DateFrom) ?? DBNull.Value);
                    selectCommand.Parameters.AddWithValue("@DateTo", ((object)filterObject.Search_DateTo) ?? DBNull.Value);
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        ConstructionSiteDocumentViewModel dbEntry = Read(query);
                        ConstructionSiteDocuments.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage            = error.Message;
                    response.Success                   = false;
                    response.Message                   = error.Message;
                    response.ConstructionSiteDocuments = new List <ConstructionSiteDocumentViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.ConstructionSiteDocuments = ConstructionSiteDocuments;
            return(response);
        }
        private static ConstructionSiteDocumentViewModel Read(SqliteDataReader query)
        {
            int counter = 0;
            ConstructionSiteDocumentViewModel dbEntry = new ConstructionSiteDocumentViewModel();

            dbEntry.Id               = SQLiteHelper.GetInt(query, ref counter);
            dbEntry.Identifier       = SQLiteHelper.GetGuid(query, ref counter);
            dbEntry.ConstructionSite = SQLiteHelper.GetConstructionSiteWithInternalCode(query, ref counter);
            dbEntry.Name             = SQLiteHelper.GetString(query, ref counter);
            dbEntry.CreateDate       = 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 ConstructionSiteDocumentListResponse GetConstructionSiteDocumentsByConstructionSite(int companyId, Guid ConstructionSiteIdentifier)
        {
            ConstructionSiteDocumentListResponse     response = new ConstructionSiteDocumentListResponse();
            List <ConstructionSiteDocumentViewModel> ConstructionSiteDocuments = new List <ConstructionSiteDocumentViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM ConstructionSiteDocuments " +
                        "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())
                    {
                        ConstructionSiteDocumentViewModel dbEntry = Read(query);
                        ConstructionSiteDocuments.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage            = error.Message;
                    response.Success                   = false;
                    response.Message                   = error.Message;
                    response.ConstructionSiteDocuments = new List <ConstructionSiteDocumentViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.ConstructionSiteDocuments = ConstructionSiteDocuments;
            return(response);
        }
Esempio n. 9
0
        public static ConstructionSiteDocumentViewModel ConvertToConstructionSiteDocumentViewModelLite(this ConstructionSiteDocument constructionSiteDocument)
        {
            ConstructionSiteDocumentViewModel constructionSiteDocumentViewModel = new ConstructionSiteDocumentViewModel()
            {
                Id         = constructionSiteDocument.Id,
                Identifier = constructionSiteDocument.Identifier,

                Name       = constructionSiteDocument.Name,
                CreateDate = constructionSiteDocument.CreateDate,
                Path       = constructionSiteDocument.Path,
                ItemStatus = constructionSiteDocument.ItemStatus,

                IsActive = constructionSiteDocument.Active,

                UpdatedAt = constructionSiteDocument.UpdatedAt,
                CreatedAt = constructionSiteDocument.CreatedAt
            };

            return(constructionSiteDocumentViewModel);
        }
        private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, ConstructionSiteDocumentViewModel constructionSiteDocument)
        {
            insertCommand.Parameters.AddWithValue("@ServerId", constructionSiteDocument.Id);
            insertCommand.Parameters.AddWithValue("@Identifier", constructionSiteDocument.Identifier);
            insertCommand.Parameters.AddWithValue("@ConstructionSiteId", ((object)constructionSiteDocument.ConstructionSite.Id) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ConstructionSiteIdentifier", ((object)constructionSiteDocument.ConstructionSite.Identifier) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ConstructionSiteCode", ((object)constructionSiteDocument.ConstructionSite.Code) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ConstructionSiteName", ((object)constructionSiteDocument.ConstructionSite.Name) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ConstructionSiteInternalCode", ((object)constructionSiteDocument.ConstructionSite.InternalCode) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Name", ((object)constructionSiteDocument.Name) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@CreateDate", ((object)constructionSiteDocument.CreateDate) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Path", ((object)constructionSiteDocument.Path) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ItemStatus", ((object)constructionSiteDocument.ItemStatus) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@IsSynced", constructionSiteDocument.IsSynced);
            insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)constructionSiteDocument.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 ConstructionSite_Document_AddEdit(ConstructionSiteViewModel constructionSite)
        {
            constructionSiteService         = DependencyResolver.Kernel.Get <IConstructionSiteService>();
            constructionSiteDocumentService = DependencyResolver.Kernel.Get <IConstructionSiteDocumentService>();

            InitializeComponent();

            this.DataContext = this;

            CurrentConstructionSite                        = constructionSite;
            CurrentConstructionSiteDocumentForm            = new ConstructionSiteDocumentViewModel();
            CurrentConstructionSiteDocumentForm.Identifier = Guid.NewGuid();
            CurrentConstructionSiteDocumentForm.ItemStatus = ItemStatus.Added;


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

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

            btnAddDocument.Focus();
        }
        public ConstructionSiteDocumentResponse GetConstructionSiteDocument(Guid identifier)
        {
            ConstructionSiteDocumentResponse  response = new ConstructionSiteDocumentResponse();
            ConstructionSiteDocumentViewModel ConstructionSiteDocument = new ConstructionSiteDocumentViewModel();

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

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        ConstructionSiteDocumentViewModel dbEntry = Read(query);
                        ConstructionSiteDocument = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage           = error.Message;
                    response.Success                  = false;
                    response.Message                  = error.Message;
                    response.ConstructionSiteDocument = new ConstructionSiteDocumentViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.ConstructionSiteDocument = ConstructionSiteDocument;
            return(response);
        }
 private void btnCancelDocument_Click(object sender, RoutedEventArgs e)
 {
     CurrentConstructionSiteDocumentForm            = new ConstructionSiteDocumentViewModel();
     CurrentConstructionSiteDocumentForm.Identifier = Guid.NewGuid();
     CurrentConstructionSiteDocumentForm.ItemStatus = ItemStatus.Added;
 }