Esempio n. 1
0
        private TreeNode GetMonth(int month)
        {
            //month -1 because january is 0
            String   actualMonthString = Months.GetMonth(month - 1);
            TreeNode result            = new TreeNode()
            {
                Title = actualMonthString, children = new List <TreeNode>()
            };

            foreach (TreeNode actualMonth in months)
            {
                if (actualMonth != null && actualMonth.Title.Equals(actualMonthString))
                {
                    result = actualMonth;
                }
            }
            return(result);
        }
        private void InitializeList()
        {
            int mount = Months.WhichMonth(parentTitle);
            int to    = 0;

            if (mount == 1)
            {
                //TODO szökőév?
                to = 29;
            }
            else if (mount == 0 || mount == 2 || mount == 4 || mount == 6 || mount == 7 || mount == 9 || mount == 11)
            {
                to = 32;
            }
            else
            {
                to = 31;
            }
            for (int i = 1; i < 32; i++)
            {
                days.Add(i);
            }
            ComboBoxDays.ItemsSource = days;
        }
        private void AddItem_Click(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem actual = sender as TreeViewItem;

            if (actual == null)
            {
                return;
            }
            TreeViewItem parent = ItemsControl.ItemsControlFromItemContainer(actual) as TreeViewItem;

            if (parent == null)
            {
                return;
            }
            TreeNode node       = actual.Tag as TreeNode;
            TreeNode parentNode = node.parent;

            if (parentNode == null)
            {
                return;
            }
            int day = -1;
            //NodeItem nodeItem = node as NodeItem;
            //if (nodeItem == null)
            //    return;
            TreeViewItem newItem = new TreeViewItem();

            if (!Int32.TryParse(node.Title.ToString(), out day) && !Months.IsMonth(node.Title))
            {
                //new item
                DialogSetShoppingItem dialog = new DialogSetShoppingItem(reader);
                Nullable <bool>       result = dialog.ShowDialog();
                if (result == true)
                {
                    AddNewNode(dialog.GetItem(), newItem, parentNode, parent);
                }
            }
            else if (!Months.IsMonth(node.Title))
            {
                //new day
                DialogNewCostDay dialog = new DialogNewCostDay(node.Title, reader);
                Nullable <bool>  result = dialog.ShowDialog();
                if (result == true)
                {
                    AddNewNode(dialog.GetItem(), newItem, parentNode, parent);
                }
            }
            else
            {
                //new month
                DialogNewMonth  dialog = new DialogNewMonth(head.children, parentNode);
                Nullable <bool> result = dialog.ShowDialog();
                if (result == true)
                // AddNewNode(dialog.GetItem(), newItem, parentNode, parent);
                {
                    var newNode = dialog.GetItem();
                    newItem.Tag    = newNode;
                    newItem.Header = newNode.Title;
                    parentNode.children.Add(newNode);
                    parent.Items.Add(newItem);
                    newItem.MouseRightButtonDown += AddItem_Click;
                    newItem.MouseDoubleClick     += TreeNodeItem_DoubleClick;
                    TreeItemViewMain.Items.Refresh();
                }
            }
            e.Handled = true;
        }