コード例 #1
0
        /// <summary>
        /// Xác định chuyến đi theo ID
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns>Chuyến đi</returns>
        private Journey journeyIdentification(int id)
        {
            Journey result = new Journey();

            foreach (Journey journey in Global.data.journeys)
            {
                if (id == journey.id)
                {
                    result = journey;
                }
            }

            return(result);
        }
コード例 #2
0
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            newJourney         = new Journey();
            newJourney.members = new List <Member>();

            newJourney.id = currentJourney.id;
            if (string.IsNullOrEmpty(journeyNameBox.Text) || string.IsNullOrWhiteSpace(journeyNameBox.Text))
            {
                journeyNameBox.Text = "(Chưa cập nhật)";
            }
            newJourney.journeyName = journeyNameBox.Text;

            if (string.IsNullOrEmpty(placeBox.Text) || string.IsNullOrWhiteSpace(placeBox.Text))
            {
                placeBox.Text = "(Chưa cập nhật)";
            }
            newJourney.place = placeBox.Text;

            newJourney.stage = stageBox.SelectedIndex;

            newJourney.images = createRelativePaths(imageAbsolutePaths);
            copyImages(imageAbsolutePaths);

            for (int i = 0; i < membersPanel.Children.Count; i++)
            {
                Member member = new Member();
                member.expenses = new List <Expense>();

                StackPanel panel1 = membersPanel.Children[i] as StackPanel;
                StackPanel panel2 = panel1.Children[0] as StackPanel;
                StackPanel panel3 = panel1.Children[1] as StackPanel;
                StackPanel panel4 = panel3.Children[0] as StackPanel;
                TextBox    box1   = panel2.Children[1] as TextBox;

                if (string.IsNullOrEmpty(box1.Text) || string.IsNullOrWhiteSpace(box1.Text))
                {
                    box1.Text = "(Chưa cập nhật)";
                }
                member.memberName = box1.Text;

                for (int j = 0; j < panel4.Children.Count; j++)
                {
                    StackPanel panel5 = panel4.Children[j] as StackPanel;
                    StackPanel panel6 = panel5.Children[0] as StackPanel;
                    StackPanel panel7 = panel5.Children[1] as StackPanel;
                    TextBox    box2   = panel6.Children[1] as TextBox;
                    TextBox    box3   = panel7.Children[1] as TextBox;

                    if (string.IsNullOrEmpty(box2.Text) || string.IsNullOrWhiteSpace(box2.Text))
                    {
                        box2.Text = "(Chưa cập nhật)";
                    }

                    if (string.IsNullOrEmpty(box3.Text) || string.IsNullOrWhiteSpace(box3.Text))
                    {
                        box3.Text = "0";
                    }
                    member.expenses.Add(new Expense {
                        spendingName = box2.Text, cost = int.Parse(box3.Text)
                    });
                }

                newJourney.members.Add(member);
            }

            if (saveCommand == 0)
            {
                newJourney.id = searchValidID();
                saveID        = newJourney.id;
                Global.data.journeys.Add(newJourney);
            }

            else if (saveCommand == 1)
            {
                int index = Global.data.journeys.IndexOf(currentJourney);
                Global.data.journeys[index] = newJourney;
            }

            NotificationScreen notificationScreen = new NotificationScreen(saveCommand);

            notificationScreen.Owner = Window.GetWindow(this);
            notificationScreen.Show();

            commandExecutionHandler?.Invoke(4, saveID);
        }