Esempio n. 1
0
        public void DisplayData()
        {
            ConstructionSiteDataLoading = true;

            ConstructionSiteListResponse response = new ConstructionSiteSQLiteRepository()
                                                    .GetConstructionSitesByPage(MainWindow.CurrentCompanyId, ConstructionSiteSearchObject, currentPage, itemsPerPage);

            if (response.Success)
            {
                ConstructionSitesFromDB = new ObservableCollection <ConstructionSiteViewModel>(response?.ConstructionSites ?? new List <ConstructionSiteViewModel>());
                totalItems = response.TotalItems;
            }
            else
            {
                ConstructionSitesFromDB = new ObservableCollection <ConstructionSiteViewModel>();
                totalItems = 0;
                MainWindow.ErrorMessage = response.Message;
            }

            int itemFrom = totalItems != 0 ? (currentPage - 1) * itemsPerPage + 1 : 0;
            int itemTo   = currentPage * itemsPerPage < totalItems ? currentPage * itemsPerPage : totalItems;

            PaginationDisplay = itemFrom + " - " + itemTo + " od " + totalItems;

            ConstructionSiteDataLoading = false;
        }
        public ConstructionSite_ReportWindow(ConstructionSiteViewModel constructionSiteView)
        {
            InitializeComponent();
            rdlcConstructionSiteReport.LocalReport.DataSources.Clear();

            List <ConstructionSitesReportViewModel> constructionSites     = new List <ConstructionSitesReportViewModel>();
            List <ConstructionSiteViewModel>        ConstructionSiteItems = new ConstructionSiteSQLiteRepository().GetConstructionSitesByPage(MainWindow.CurrentCompanyId, ConstructionSiteSearchObject, 1, 50).ConstructionSites;
            int counter = 1;

            foreach (var ConstructionSiteItem in ConstructionSiteItems)
            {
                constructionSites.Add(new ConstructionSitesReportViewModel()
                {
                    OrderNumbersForConstructionSites = counter++,
                    ConstructionSiteCode             = ConstructionSiteItem?.Code ?? "",
                    InternalCode        = ConstructionSiteItem?.InternalCode ?? "",
                    Name                = ConstructionSiteItem?.Name ?? "",
                    CityName            = ConstructionSiteItem?.City?.Name ?? "",
                    CountryName         = ConstructionSiteItem?.Country?.Name ?? "",
                    BusinessPartnerName = ConstructionSiteItem?.BusinessPartner?.Name ?? "",
                    StatusName          = ConstructionSiteItem?.Status?.Name ?? "",
                    Address             = ConstructionSiteItem?.Address ?? "",
                    MaxWorkers          = ConstructionSiteItem?.MaxWorkers.ToString() ?? "",
                    ProContractDate     = ConstructionSiteItem?.ProContractDate.ToString("dd.MM.yyyy") ?? "",
                    ContractStart       = ConstructionSiteItem?.ContractStart.ToString("dd.MM.yyyy") ?? "",
                    ContractExpiration  = ConstructionSiteItem?.ContractExpiration.ToString("dd.MM.yyyy") ?? "",
                });
            }
            var rpdsModel = new ReportDataSource()
            {
                Name  = "DataSet1",
                Value = constructionSites
            };

            rdlcConstructionSiteReport.LocalReport.DataSources.Add(rpdsModel);

            //List<ReportParameter> reportParams = new List<ReportParameter>();
            //string parameterText = "Dana " + (CurrentConstructionSite?.InvoiceDate.ToString("dd.MM.yyyy") ?? "") + " na stočni depo klanice Bioesen primljeno je:";
            //reportParams.Add(new ReportParameter("txtConstructionSiteDate", parameterText));


            //var businessPartnerList = new List<InvoiceBusinessPartnerViewModel>();
            //businessPartnerList.Add(new InvoiceBusinessPartnerViewModel() { Name = "Pera peric " });
            //var businessPartnerModel = new ReportDataSource() { Name = "DataSet2", Value = businessPartnerList };
            //rdlcOutputNoteReport.LocalReport.DataSources.Add(businessPartnerModel);

            string exeFolder    = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            string ContentStart = System.IO.Path.Combine(exeFolder, @"RdlcReports\ConstructionSites\ConstructionSitesReport.rdlc");

            rdlcConstructionSiteReport.LocalReport.ReportPath = ContentStart;
            // rdlcConstructionSiteReport.LocalReport.SetParameters(reportParams);
            rdlcConstructionSiteReport.SetDisplayMode(DisplayMode.PrintLayout);
            rdlcConstructionSiteReport.Refresh();
            rdlcConstructionSiteReport.ZoomMode    = ZoomMode.Percent;
            rdlcConstructionSiteReport.ZoomPercent = 100;
            rdlcConstructionSiteReport.RefreshReport();
        }
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            ConstructionSiteListResponse constructionSiteList = new ConstructionSiteSQLiteRepository()
                                                                .GetConstructionSites(MainWindow.CurrentCompanyId, "");

            var ConstructionSitesFromDB = new ObservableCollection <ConstructionSiteViewModel>(constructionSiteList.ConstructionSites ?? new List <ConstructionSiteViewModel>());

            #region Validation

            if (CurrentConstructionSite?.Name == null)
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Naziv_gradilista"));
                return;
            }

            if (ConstructionSitesFromDB.Any(p => p.InternalCode == CurrentConstructionSite?.InternalCode) && CurrentConstructionSite.Code == null)
            {
                MainWindow.WarningMessage = (string)Application.Current.FindResource("Šifra_već_postoji_uzvičnik");
                return;
            }

            #endregion

            Thread td = new Thread(() => {
                SubmitButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke"));
                SubmitButtonEnabled = false;

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

                ConstructionSiteResponse response = new ConstructionSiteSQLiteRepository().Create(CurrentConstructionSite);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_lokalnog_čuvanjaUzvičnik"));
                    SubmitButtonContent     = ((string)Application.Current.FindResource("Proknjiži"));
                    SubmitButtonEnabled     = true;
                }

                response = constructionSiteService.Create(CurrentConstructionSite);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Podaci_su_sačuvani_u_lokaluUzvičnikTačka_Greška_kod_čuvanja_na_serveruUzvičnik")) + response.Message;
                    SubmitButtonContent     = ((string)Application.Current.FindResource("Proknjiži"));
                    SubmitButtonEnabled     = true;
                }

                if (response.Success)
                {
                    MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik"));
                    SubmitButtonContent       = ((string)Application.Current.FindResource("Proknjiži"));
                    SubmitButtonEnabled       = true;

                    new ConstructionSiteSQLiteRepository().Sync(constructionSiteService);

                    ConstructionSiteCreatedUpdated();

                    Application.Current.Dispatcher.BeginInvoke(
                        System.Windows.Threading.DispatcherPriority.Normal,
                        new Action(() =>
                    {
                        FlyoutHelper.CloseFlyout(this);
                    })
                        );
                }
            });
            td.IsBackground = true;
            td.Start();
        }