Beispiel #1
0
        private void EndClick(object sender, RoutedEventArgs e)
        {
            var select = db.trips.Where(x => x.id == selectedTrip.id).SingleOrDefault();

            select.isfinish = true;
            db.SaveChanges();
            borderButtonEnd.Visibility = Visibility.Collapsed;
            endTXT.Visibility          = Visibility.Visible;
        }
Beispiel #2
0
        private void addPlace_Click(object sender, RoutedEventArgs e)
        {
            if (namePlace.Text.Equals("") || addrPlace.Text.Equals("") || descrPlace.Text.Equals(""))
            {
                _timer.Start();
                Notif.Foreground = Brushes.Red;
                Notif.Text       = "Nhap day du cac thong tin di. Nhap thieu thong tin sao them";
                return;
            }
            var db     = new wesplitEntities();
            var _place = new place();

            _place.id          = db.places.Max(x => x.id) + 1;
            _place.name        = namePlace.Text;
            _place.address     = addrPlace.Text;
            _place.discription = descrPlace.Text;
            db.places.Add(_place);
            db.SaveChanges();
            placedata.ItemsSource = db.places.ToList();
            data            = placedata;
            namePlace.Text  = "";
            addrPlace.Text  = "";
            descrPlace.Text = "";
            Notif.Text      = "";
        }
Beispiel #3
0
        private void addThumbail_Click(object sender, RoutedEventArgs e)
        {
            if (journeyThumbnail.Source != null)
            {
                oldPath = journeyThumbnail.Source.ToString().Substring(8);
            }
            var screen = new OpenFileDialog();

            if (screen.ShowDialog() == true)
            {
                var thumbnailPath = screen.FileName;
                newPath = "Data/fakedata/" + Guid.NewGuid() + Path.GetExtension(thumbnailPath);
                var savePath = AppDomain.CurrentDomain.BaseDirectory + newPath;
                File.Copy(thumbnailPath, savePath, true);
                var thumbnail = new BitmapImage(new Uri(savePath, UriKind.Absolute));

                journeyThumbnail.Source = thumbnail;
            }
            if (idTrip != -1)
            {
                var db      = new wesplitEntities();
                var oldTrip = db.trips.Find(idTrip);
                if (!newPath.Equals(oldTrip.thumbnail))
                {
                    oldTrip.thumbnail = newPath;
                }

                db.SaveChanges();
                Err.Foreground = Brushes.Green;
                Err.Text       = "Da cap nhat thong tin chuyen di";
            }
        }
Beispiel #4
0
        private void addImageClick(object sender, RoutedEventArgs e)
        {
            List <String> FilePath = new List <string>();
            var           screen   = new OpenFileDialog();

            screen.Multiselect = true;
            if (screen.ShowDialog() == true)
            {
                var thumbnailPaths = screen.FileNames;
                foreach (var thumbnailPath in thumbnailPaths)
                {
                    var savePath = "Data/fakedata/" + Guid.NewGuid() + Path.GetExtension(thumbnailPath);
                    FilePath.Add(savePath);
                    File.Copy(thumbnailPath, AppDomain.CurrentDomain.BaseDirectory + savePath, true);
                    var thumbnail = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + savePath, UriKind.Absolute));
                    var border    = new Border();
                    border.CornerRadius = new CornerRadius(15);

                    var temp = new ImageBrush();

                    temp.ImageSource = thumbnail;


                    border.Background = temp;
                    border.Width      = 100;
                    border.Height     = 90;

                    border.Margin = new Thickness(0, 0, 3, 0);

                    carousel.Children.Add(border);
                }
            }

            foreach (var path in FilePath)
            {
                var   db     = new wesplitEntities();
                image _image = new image();
                _image.id     = db.images.Max(x => x.id) + 1;
                _image.idtrip = selectedTrip.id;
                _image.path   = path;
                db.images.Add(_image);
                db.SaveChanges();
            }
        }
Beispiel #5
0
        private void saveRoute_Click(object sender, RoutedEventArgs e)
        {
            var db = new wesplitEntities();
            var _journeyBegDate = journeyBegDate.SelectedDate;
            var _journeyEndDate = journeyEndDate.SelectedDate;

            if (_journeyBegDate == null)
            {
                Err.Foreground = Brushes.Red;
                Err.Text       = "Hay chon ngay di";
                return;
            }

            if (_journeyEndDate == null)
            {
                Err.Foreground = Brushes.Red;
                Err.Text       = "Hay chon ngay ve";
                return;
            }

            if (journeyThumbnail.Source == null)
            {
                Err.Foreground = Brushes.Red;
                Err.Text       = "Hay them hinh cua dia diem";
                return;
            }

            Err.Text = "";

            var _jorneyThumbnail = newPath;

            if (routeMoney.Text.Equals(""))
            {
                Err.Foreground = Brushes.Red;
                Err.Text       = "Hay them chi phi lo trinh";
                return;
            }

            if (idTrip != -1)
            {
                var oldTrip = db.trips.Find(idTrip);
                if (!_journeyBegDate.Equals(oldTrip.datetogo))
                {
                    oldTrip.datetogo = _journeyBegDate;
                }

                if (!_journeyEndDate.Equals(oldTrip.returndate))
                {
                    oldTrip.returndate = _journeyEndDate;
                }

                db.SaveChanges();
                Err.Foreground = Brushes.Green;
                Err.Text       = "Da cap nhat thong tin chuyen di";


                if (routeNameEdit.Visibility == Visibility.Visible && routeNameEdit.SelectedIndex != -1)
                {
                    var id       = ((route)routeNameEdit.SelectedItem).id;
                    var oldRoute = db.routes.Find(id);
                    oldRoute.cost = int.Parse(routeMoney.Text);
                    db.SaveChanges();
                    Err.Foreground = Brushes.Green;
                    Err.Text       = "Da cap nhat thong tin lo trinh";
                }
                else if (routeNameAddNew.Visibility == Visibility.Visible)
                {
                    if (routeNameAddNew.Text.Equals(""))
                    {
                        Err.Foreground = Brushes.Red;
                        Err.Text       = "Hay them ten lo trinh";
                        return;
                    }

                    var   maxId    = db.routes.Max(x => x.id);
                    route newRoute = new route();
                    newRoute.id     = maxId + 1;
                    newRoute.idtrip = idTrip;
                    newRoute.cost   = int.Parse(routeMoney.Text);
                    newRoute.place  = routeNameAddNew.Text;
                    db.routes.Add(newRoute);
                    Err.Foreground = Brushes.Green;
                    Err.Text       = "Da them moi lo trinh";
                    db.SaveChanges();
                }
            }
            else
            {
                if (_trip == null)
                {
                    if (journeyName.Text.Equals(""))
                    {
                        Err.Foreground = Brushes.Red;
                        Err.Text       = "Hay them ten chuyen di";
                        return;
                    }

                    if (journeyPlace.SelectedItem == null)
                    {
                        Err.Foreground = Brushes.Red;
                        Err.Text       = "Hay chon dia danh";
                        return;
                    }

                    if (routeNameAddNew.Text.Equals(""))
                    {
                        Err.Foreground = Brushes.Red;
                        Err.Text       = "Hay them ten lo trinh";
                        return;
                    }

                    journeyName.IsEnabled    = false;
                    journeyPlace.IsEnabled   = false;
                    addThumbail.IsEnabled    = false;
                    journeyBegDate.IsEnabled = false;
                    journeyEndDate.IsEnabled = false;

                    var _journeyName  = journeyName.Text;
                    var _journeyPlace = journeyPlace.SelectedItem;
                    _trip              = new trip();
                    _trip.name         = _journeyName;
                    _trip.idplace      = ((place)_journeyPlace).id;
                    _trip.datetogo     = _journeyBegDate;
                    _trip.returndate   = _journeyEndDate;
                    _trip.thumbnail    = _jorneyThumbnail;
                    _trip.isfinish     = false;
                    _trip.totalrevenue = 0;
                    _trip.totalexpend  = 0;
                    _trip.id           = db.trips.Max(x => x.id) + 1;
                    db.trips.Add(_trip);
                    Err.Foreground = Brushes.Green;
                    Err.Text       = "Da them moi chuyen di";
                    db.SaveChanges();
                }
                var _routeName  = routeNameAddNew.Text;
                var _routeMoney = int.Parse(routeMoney.Text);
                //var _routeDescription = routeDescription.Text;
                route newRoute = new route();
                newRoute.id     = db.routes.Max(x => x.id) + 1;
                newRoute.idtrip = _trip.id;
                newRoute.cost   = _routeMoney;
                newRoute.place  = _routeName;
                db.routes.Add(newRoute);
                Err.Foreground = Brushes.Green;
                Err.Text       = "Da them moi lo trinh";
                db.SaveChanges();
                routeNameAddNew.Text = "";
                routeMoney.Text      = "";
            }
            _routes = new BindingList <route>(db.routes.Where(x => x.idtrip == _trip.id || x.idtrip == idTrip).ToList());
            routeList.ItemsSource = _routes;
            var tmp = routeNameEdit.SelectedIndex;

            routeNameEdit.ItemsSource   = _routes;
            routeNameEdit.SelectedIndex = tmp;
            //db.SaveChanges();
        }
Beispiel #6
0
        private void saveMember_Click(object sender, RoutedEventArgs e)
        {
            var db = new wesplitEntities();
            var _journeyBegDate = journeyBegDate.SelectedDate;
            var _journeyEndDate = journeyEndDate.SelectedDate;

            if (_journeyBegDate == null)
            {
                Err.Foreground = Brushes.Red;
                Err.Text       = "Hay chon ngay di";
                return;
            }

            if (_journeyEndDate == null)
            {
                Err.Foreground = Brushes.Red;
                Err.Text       = "Hay chon ngay ve";
                return;
            }

            if (journeyThumbnail.Source == null)
            {
                Err.Foreground = Brushes.Red;
                Err.Text       = "Hay them hinh cua dia diem";
                return;
            }

            Err.Text = "";

            var _jorneyThumbnail = newPath;

            if (memberMoney.Text.Equals(""))
            {
                Err.Foreground = Brushes.Red;
                Err.Text       = "Hãy bổ sung trường tiền thu";
                return;
            }

            if (memberPhone.Text.Equals(""))
            {
                Err.Foreground = Brushes.Red;
                Err.Text       = "Hãy bổ sung trường số điện thoại";
                return;
            }

            if (idTrip != -1)
            {
                var oldTrip = db.trips.Find(idTrip);
                if (!_journeyBegDate.Equals(oldTrip.datetogo))
                {
                    oldTrip.datetogo = _journeyBegDate;
                }

                if (!_journeyEndDate.Equals(oldTrip.returndate))
                {
                    oldTrip.returndate = _journeyEndDate;
                }

                db.SaveChanges();
                Err.Foreground = Brushes.Green;
                Err.Text       = "Đã cập nhật thông tin chuyến đi";


                if (memberNameEdit.Visibility == Visibility.Visible && memberNameEdit.SelectedIndex != -1)
                {
                    var id        = ((member)memberNameEdit.SelectedItem).id;
                    var oldMember = db.members.Find(id);
                    oldMember.collectedmoney = int.Parse(memberMoney.Text);
                    oldMember.phonenumber    = memberPhone.Text;
                    db.SaveChanges();
                    Err.Foreground = Brushes.Green;
                    Err.Text       = "Da cap nhat thong tin thanh vien";
                }
                else if (memberNameAddNew.Visibility == Visibility.Visible)
                {
                    if (memberNameAddNew.Text.Equals(""))
                    {
                        Err.Foreground = Brushes.Red;
                        Err.Text       = "Hay them ten thanh vien";
                        return;
                    }

                    var    maxId     = db.members.Max(x => x.id);
                    member newMember = new member();
                    newMember.id             = maxId + 1;
                    newMember.idtrip         = idTrip;
                    newMember.collectedmoney = int.Parse(memberMoney.Text);
                    newMember.name           = memberNameAddNew.Text;
                    newMember.phonenumber    = memberPhone.Text;
                    db.members.Add(newMember);
                    Err.Foreground = Brushes.Green;
                    Err.Text       = "Da them moi thanh vien";
                    db.SaveChanges();
                }
            }
            else
            {
                if (_trip == null)
                {
                    if (journeyName.Text.Equals(""))
                    {
                        Err.Foreground = Brushes.Red;
                        Err.Text       = "Hay them ten chuyen di";
                        return;
                    }

                    if (journeyPlace.SelectedItem == null)
                    {
                        Err.Foreground = Brushes.Red;
                        Err.Text       = "Hay chon dia danh";
                        return;
                    }

                    if (memberNameAddNew.Text.Equals(""))
                    {
                        Err.Foreground = Brushes.Red;
                        Err.Text       = "Hay them ten lo trinh";
                        return;
                    }

                    journeyName.IsEnabled    = false;
                    journeyPlace.IsEnabled   = false;
                    addThumbail.IsEnabled    = false;
                    journeyBegDate.IsEnabled = false;
                    journeyEndDate.IsEnabled = false;

                    var _journeyName  = journeyName.Text;
                    var _journeyPlace = journeyPlace.SelectedItem;
                    _trip              = new trip();
                    _trip.name         = _journeyName;
                    _trip.idplace      = ((place)_journeyPlace).id;
                    _trip.datetogo     = _journeyBegDate;
                    _trip.returndate   = _journeyEndDate;
                    _trip.thumbnail    = _jorneyThumbnail;
                    _trip.isfinish     = false;
                    _trip.totalrevenue = 0;
                    _trip.totalexpend  = 0;
                    _trip.id           = db.trips.Max(x => x.id) + 1;
                    db.trips.Add(_trip);
                    Err.Foreground = Brushes.Green;
                    Err.Text       = "Da them moi chuyen di";
                    db.SaveChanges();
                }
                var _memberName  = memberNameAddNew.Text;
                var _memberMoney = int.Parse(memberMoney.Text);
                //var _routeDescription = routeDescription.Text;
                member newMember = new member();
                newMember.id             = db.routes.Max(x => x.id) + 1;
                newMember.idtrip         = _trip.id;
                newMember.collectedmoney = _memberMoney;
                newMember.name           = _memberName;
                db.members.Add(newMember);
                Err.Foreground = Brushes.Green;
                Err.Text       = "Da them moi thanh vien";
                db.SaveChanges();
                memberNameAddNew.Text = "";
                memberMoney.Text      = "";
            }
            _members = new BindingList <member>(db.members.Where(x => x.idtrip == _trip.id || x.idtrip == idTrip).ToList());
            memberList.ItemsSource = _members;
            var tmp = memberNameEdit.SelectedIndex;

            memberNameEdit.ItemsSource   = _members;
            memberNameEdit.SelectedIndex = tmp;
            //db.SaveChanges();
        }