Exemplo n.º 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var db = new wesplitEntities();

            if (idTrip == -1)
            {
                journeyPlace.ItemsSource = new BindingList <place>(db.places.ToList());
                addRouteAddNew_Click(sender, e);
                addRouteEdit.IsEnabled = false;
            }
            else
            {
                journeyName.IsEnabled    = false;
                journeyName.Foreground   = Brushes.Gray;
                journeyPlace.IsEnabled   = false;
                journeyPlace.Foreground  = Brushes.Gray;
                journeyBegDate.IsEnabled = false;
                journeyEndDate.IsEnabled = false;
                _trip = db.trips.Find(idTrip);
                journeyPlace.ItemsSource    = new BindingList <place>(db.places.Where(x => x.id == _trip.idplace).ToList());
                journeyPlace.SelectedIndex  = 0;
                journeyName.Text            = _trip.name;
                journeyBegDate.SelectedDate = _trip.datetogo;
                journeyEndDate.SelectedDate = _trip.returndate;
                _routes = new BindingList <route>(_trip.routes.ToList());
                routeNameEdit.ItemsSource = _routes;
                routeList.ItemsSource     = _routes;
                journeyThumbnail.Source   = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + _trip.thumbnail, UriKind.Absolute));
                journeyEndDate.BlackoutDates.Add(new CalendarDateRange(new DateTime(1, 1, 1), (DateTime)journeyBegDate.SelectedDate));
            }
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }