Beispiel #1
0
 public void AddPath(PathEntity path)
 {
     if (path != null)
     {
         path.CreatedOn = DateTime.Now;
     }
     _connection.Insert(path);
 }
Beispiel #2
0
        // create more path
        private Grid MakeNewPath(PathEntity pathEntity)
        {
            Grid pathCtn = new Grid
            {
                HorizontalOptions    = LayoutOptions.FillAndExpand,
                Margin               = new Thickness(20, 0),
                MinimumHeightRequest = 40
            };

            Label lblItemPath = new Label
            {
                Text = pathEntity.Path
            };
            Label lblTop = new Label
            {
                Text = pathEntity.Parent != null ? pathEntity.Parent:"No Parent"
            };

            Button btnEdit = new Button
            {
                Text            = "Edit",
                FontSize        = 12,
                HeightRequest   = 40,
                BackgroundColor = Color.White
            };

            btnEdit.Clicked         += OnEditClicked;
            btnEdit.CommandParameter = pathEntity;

            //Button btnDelete = new Button() { Text = "Delete" };
            //btnDelete.Clicked += OnDeleteClicked;

            //entryItemPath.Unfocused += ItemFieldUnfocus;
            //entryItemPath.TextChanged += PathChanging;

            //pathCtn.Children.Add(name, 0, 0);
            pathCtn.Children.Add(lblItemPath, 0, 0);
            // add choose top button
            pathCtn.Children.Add(lblTop, 1, 0);
            pathCtn.Children.Add(btnEdit, 2, 0);


            pathUIlist.Add(pathCtn);
            return(pathCtn);
        }
Beispiel #3
0
        async void OnSaveAsync(object sender, EventArgs e)
        {
            string pathStr = PathEntry.Text;

            // edit exist one
            if (pathEntity != null)
            {
                if (string.IsNullOrEmpty(pathStr))
                {
                    //empty warning
                    messageLabel.Text = "Please fill the name with path";
                }
                else
                {
                    if (TopLevelSelector.SelectedItem != null)
                    {
                        pathEntity.Parent = TopLevelSelector.SelectedItem.ToString();
                    }
                    pathEntity.Path = PathEntry.Text;
                    _database.UpdatePath(pathEntity);
                    App.PathList = _database.GetPaths(App.UserEntity.ID);
                    await Navigation.PopAsync();
                }
            }
            // save new one
            else
            {
                PathEntity pe = new PathEntity();
                pe.UserID = App.UserEntity.ID;
                if (TopLevelSelector.SelectedItem != null)
                {
                    pe.Parent = TopLevelSelector.SelectedItem.ToString();
                }
                pe.Path = PathEntry.Text;
                _database.AddPath(pe);
                App.PathList = _database.GetPaths(App.UserEntity.ID);
                await Navigation.PopAsync();
            }
        }
Beispiel #4
0
 public void DeletePath(PathEntity path)
 {
     _connection.Delete(path);
 }
Beispiel #5
0
 public void UpdatePath(PathEntity path)
 {
     _connection.Update(path);
 }
Beispiel #6
0
        public AddPathCS(PathEntity pathEntity)
        {
            this.pathEntity      = pathEntity;
            this.BackgroundColor = Color.FromHex("BBDEFB");

            _database    = new YangDb();
            App.PathList = _database.GetPaths(App.UserEntity.ID);

            Title     = "Custom Paths";
            PathEntry = new Entry
            {
                Margin   = new Thickness(20, 5),
                Keyboard = Keyboard.Create(KeyboardFlags.None)
            };
            TopLevelSelector = new Picker
            {
                Margin = new Thickness(20, 5),
                Title  = "Top Level",
            };
            // fill parents picker
            // firstly add a No Parent option
            TopLevelSelector.Items.Add(NO_PARENT);

            foreach (var item in App.PathList)
            {
                TopLevelSelector.Items.Add(item.Path);
                // itself can not be its parent
                if (pathEntity != null && pathEntity.Path.Equals(item.Path))
                {
                    TopLevelSelector.Items.Remove(item.Path);
                }
            }

            if (pathEntity != null && pathEntity.Parent != null)
            {
                TopLevelSelector.SelectedItem = pathEntity.Parent;
            }


            // Grid container for buttons
            Grid btnCtn = new Grid
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Margin            = new Thickness(20, 5),
            };

            // warnging label
            messageLabel = new Label()
            {
                TextColor = Color.Red, Margin = new Thickness(20, 5)
            };

            Button btnSave = new Button()
            {
                Text = "Save", BackgroundColor = Color.White
            };

            btnSave.Clicked += OnSaveAsync;
            btnCtn.Children.Add(btnSave, 0, 0);

            // only when editing the path, there is delete option
            if (pathEntity != null)
            {
                PathEntry.Text = pathEntity.Path;

                Button btnDelete = new Button()
                {
                    Text = "Delete", BackgroundColor = Color.White
                };
                btnDelete.Clicked += OnDelete;
                btnCtn.Children.Add(btnDelete, 0, 1);
            }

            Content = new StackLayout()
            {
                BackgroundColor = Color.FromHex("BBDEFB"),
                VerticalOptions = LayoutOptions.StartAndExpand,
                Children        =
                {
                    new Label {
                        Text = "Path", Margin = new Thickness(20, 15, 0, 5)
                    },
                    PathEntry,
                    new Label {
                        Text = "Choose a Top Level", Margin = new Thickness(20, 5)
                    },
                    TopLevelSelector,
                    btnCtn,
                }
            };
        }