Exemple #1
0
        private void addSiteButton_Click(object sender, RoutedEventArgs e)
        {
            Site site = new Site();

            site.ID_Site       = _databaseUtilities.GetMaxIDSite() + 1;
            site.ID_Province   = ((Province)startProvinceComboBox.SelectedItem).ID_Province;
            site.Province_Name = ((Province)startProvinceComboBox.SelectedItem).Province_Name;

            site.Site_Name = siteNameTextBox.Text;
            if (site.Site_Name.Length == 0)
            {
                return;
            }
            site.Standard_Site_Name = _appUtilities.getStandardName(site.Site_Name, 25);

            site.Site_Address = siteAddressTextBox.Text;
            if (site.Site_Address.Length == 0)
            {
                return;
            }
            site.Standard_Site_Address = _appUtilities.getStandardName(site.Site_Address, 28);

            if (_srcAvatarSite == "")
            {
                return;
            }

            site.Site_Description = siteDescriptionTextBox.Text;
            if (site.Site_Description.Length == 0)
            {
                return;
            }
            site.Standard_Site_Description = _appUtilities.getStandardName(site.Site_Description, 50);

            site.Site_Link_Avt = _appUtilities.getTypeOfImage(_srcAvatarSite);

            //Add
            _databaseUtilities.AddNewSite(site.ID_Site, site.ID_Province, site.Site_Name, site.Site_Description, site.Site_Link_Avt, site.Site_Address);

            _appUtilities.createSitesDirectory();
            _appUtilities.copyImageToIDirectory(site.ID_Site, _srcAvatarSite, "", true);

            site.Site_Link_Avt = $"Images/Sites/{site.ID_Site}.{site.Site_Link_Avt}";
            _sites.Add(site);

            notiMessageSnackbar.MessageQueue.Enqueue($"Đã thêm thành công địa danh \"{site.Site_Name}\"", "OK", () => { });

            //Reset Input
            siteNameTextBox.Text        = "";
            siteAddressTextBox.Text     = "";
            siteDescriptionTextBox.Text = "";

            sitesListView.ItemsSource = null;
            sitesListView.ItemsSource = _sites;

            avatarImage.Visibility              = Visibility.Collapsed;
            addSiteAvatarButton.Visibility      = Visibility.Visible;
            startProvinceComboBox.SelectedIndex = 0;
        }
Exemple #2
0
        private void saveJourneyButton_Click(object sender, RoutedEventArgs e)
        {
            //Get Data
            _journey.Journey_Name = journeyNameTextBox.Text;
            if (_journey.Journey_Name.Length == 0)
            {
                notiMessageSnackbar.MessageQueue.Enqueue($"Không được bỏ trống tên chuyến đi", "OK", () => {  });
                return;
            }

            _journey.Start_Place = journeyStartPlaceTextBox.Text;
            if (_journey.Start_Place.Length == 0)
            {
                notiMessageSnackbar.MessageQueue.Enqueue($"Không được bỏ trống địa điểm xuất phát", "OK", () => { });
                return;
            }

            _journey.Start_Province = ((Province)startProvinceComboBox.SelectedItem).Province_Name;

            if (isCurrentJourneyCheckBox.IsChecked.Value)
            {
                _journey.Status = 0;

                _databaseUtilities.FinishCurrentJourney();
            }
            else
            {
            }

            Route startRoute = new Route();

            startRoute.Place    = _journey.Start_Place;
            startRoute.Province = _journey.Start_Province;

            if (endSiteComboBox.SelectedIndex == -1)
            {
                notiMessageSnackbar.MessageQueue.Enqueue($"Hiện tại chưa có địa điểm nào được thêm ở tỉnh {((Province)endProvinceComboBox.SelectedItem).Province_Name}", "OK", () => { });
                notiMessageSnackbar.MessageQueue.Enqueue($"Vui lòng chọn địa điểm khác hoặc thêm địa điểm mới vào tỉnh {((Province)endProvinceComboBox.SelectedItem).Province_Name} và thử lại", "OK", () => { });
                return;
            }

            Route endRoute = new Route();

            endRoute.Place    = ((Site)endSiteComboBox.SelectedItem).Site_Name;
            endRoute.Province = ((Province)endProvinceComboBox.SelectedItem).Province_Name;
            _journey.ID_Site  = ((Site)endSiteComboBox.SelectedItem).ID_Site;

            _journey.StartDate = startDatePicker.SelectedDate;
            _journey.EndDate   = endDatePicker.SelectedDate;

            //Get distance
            var routeForCalcDistance = (from r in Route_For_Binding
                                        where r.Is_Active == 1
                                        select r).ToList();

            _journey.Distance = _googleMapUtilities.GetDistanceByRoutes(routeForCalcDistance, startRoute, endRoute);

            //Insert
            _databaseUtilities.UpdateJourney(
                _journey.ID_Journey,
                _journey.Journey_Name,
                _journey.ID_Site,
                _journey.Start_Place,
                _journey.Start_Province,
                _journey.Status,
                _journey.StartDate,
                _journey.EndDate,
                _journey.Distance);

            foreach (var expense in Expens_For_Binding)
            {
                _databaseUtilities.UpdateExpense(expense.ID_Expenses, expense.ID_Journey, expense.Expenses_Money, expense.Expenses_Description, expense.Is_Active ?? 0);
            }

            foreach (var route in Route_For_Binding)
            {
                _databaseUtilities.UpdateRoute(route.ID_Journey, route.Ordinal_Number, route.Place, route.Province, route.Route_Description, route.Route_Status, route.Is_Active ?? 0);
            }

            foreach (var member in JourneyAttendances)
            {
                _databaseUtilities.UpdateJourneyAttendance(member.ID_Member, member.ID_Journey, member.Member_Name, member.Phone_Number, member.Receivables_Money, member.Role, member.Is_Active ?? 0);
            }

            _appUtilities.createIDDirectory(_journey.ID_Journey);
            foreach (var image in Images_For_Binding)
            {
                _databaseUtilities.UpdateJourneyImage(_journey.ID_Journey, image.Ordinal_Number, _appUtilities.getTypeOfImage(image.Link_Image), image.Is_Active);

                _appUtilities.copyImageToIDirectory(_journey.ID_Journey, image.Link_Image, $"{image.Ordinal_Number}", false);
            }

            foreach (var advance in Advances_For_Binding)
            {
                _databaseUtilities.UpdateAdvance(advance.ID_Journey, advance.ID_Borrower, advance.ID_Lender, advance.Advance_Money, advance.Is_Active);
            }

            notiMessageSnackbar.MessageQueue.Enqueue($"Đã update thành công chuyến đi \"{_journey.Journey_Name}\"", "BACK", () => { BackCurentJourney?.Invoke(_journey.ID_Journey); });

            //Reset
            //journeyNameTextBox.Text = "";
            //journeyStartPlaceTextBox.Text = "";
            //startProvinceComboBox.SelectedIndex = 0;
            //startDatePicker.Text = "";
            //endSiteComboBox.SelectedIndex = 0;
            //endProvinceComboBox.SelectedIndex = 0;
            //endDatePicker.Text = "";
            //startProvinceRouteComboBox.SelectedIndex = 0;
            //routesListView.ItemsSource = null;
            //membersListView.ItemsSource = null;
            //expensesListView.ItemsSource = null;
        }