Example #1
0
        public ShortcutFormPage(int id = -1)
        {
            InitializeComponent();

            Id = id;
            if (Id != -1) //Gdy formularz ma być wykorzystany do edycji skrótu
            {
                ShortcutCell = DatabaseClass.GetShortcutFromDatabase(Id);

                TextEntry.Text       = ShortcutCell.Text;
                WWWAddressEntry.Text = ShortcutCell.WWWAddress;

                Button DeleteButton = new Button()
                {
                    Text            = AppResources.DeleteShortcutFormPage,
                    BackgroundColor = Color.Red,
                    TextColor       = Color.White,
                    Margin          = new Thickness(50, 100),
                };
                DeleteButton.Clicked += DeleteButton_Clicked;
                FormStackLayout.Children.Add(DeleteButton);

                AcceptButton.Text = AppResources.ChangeShortcutFormPage;
            }
        }
Example #2
0
        public static ShortcutCell GetShortcutFromDatabase(int id) //Odczyt rekordu ze skrótem o zadanym numerze Id
        {
            if (id < 1)
            {
                return(new ShortcutCell());
            }

            try
            {
                OpenDB();
                if (DatabaseState == DatabaseState.DATABASE_OPENED)
                {
                    var existingItem = db.Get <ShortcutsTable>(id);
                    db.Close();

                    ShortcutCell shortcutCell = new ShortcutCell()
                    {
                        Id            = existingItem.Id,
                        Text          = existingItem.Text,
                        WWWAddress    = existingItem.WWWAddress,
                        Image         = existingItem.Image,
                        ButtonVisible = true,
                    };

                    DatabaseState = DatabaseState.DATABASE_OK;
                    return(shortcutCell);
                }
                else
                {
                    DatabaseState = DatabaseState.DATABASE_ERROR;
                    return(new ShortcutCell());
                }
            }
            catch (Exception ex)
            {
                exceptionText = ex.ToString();
                DatabaseState = DatabaseState.DATABASE_ERROR;
                return(new ShortcutCell());
            }
        }
Example #3
0
        public static void DeleteShortcut(ShortcutCell shortcutCell) //Usunięcie skrótu z bazy danych
        {
            try
            {
                OpenDB();
                if (DatabaseState == DatabaseState.DATABASE_OPENED)
                {
                    db.Execute("DELETE FROM ShortcutsTable WHERE Id = ?", shortcutCell.Id);
                    db.Close();

                    DatabaseState = DatabaseState.DATABASE_OK;
                }
                else
                {
                    DatabaseState = DatabaseState.DATABASE_ERROR;
                }
            }
            catch (Exception ex)
            {
                exceptionText = ex.ToString();
                DatabaseState = DatabaseState.DATABASE_ERROR;
            }
        }
Example #4
0
        public static void EditShortcut(ShortcutCell shortcutCell) //Modyfikacja skrótu znaajdującego się bazie danych
        {
            try
            {
                OpenDB();
                if (DatabaseState == DatabaseState.DATABASE_OPENED)
                {
                    db.Execute("UPDATE ShortcutsTable SET Text = ?, WWWAddress = ?, Image = ? WHERE Id = ?", shortcutCell.Text, shortcutCell.WWWAddress, shortcutCell.Image, shortcutCell.Id);
                    db.Close();

                    DatabaseState = DatabaseState.DATABASE_OK;
                }
                else
                {
                    DatabaseState = DatabaseState.DATABASE_ERROR;
                }
            }
            catch (Exception ex)
            {
                exceptionText = ex.ToString();
                DatabaseState = DatabaseState.DATABASE_ERROR;
            }
        }
Example #5
0
        public static void AddNewShortcut(ShortcutCell shortcutCell) //Dodanie nowego skrótu do bazy danych
        {
            try
            {
                OpenDB();
                if (DatabaseState == DatabaseState.DATABASE_OPENED)
                {
                    var Shortcut = new ShortcutsTable()
                    {
                        Image      = shortcutCell.Image,
                        Text       = shortcutCell.Text,
                        WWWAddress = shortcutCell.WWWAddress,
                    };

                    if (db.Insert(Shortcut) != 1)
                    {
                        DatabaseState = DatabaseState.DATABASE_ERROR;
                        db.Close();
                        return;
                    }
                    db.Close();

                    DatabaseState = DatabaseState.DATABASE_OK;
                    return;
                }
                else
                {
                    DatabaseState = DatabaseState.DATABASE_ERROR;
                    return;
                }
            }
            catch (Exception ex)
            {
                exceptionText = ex.ToString();
                DatabaseState = DatabaseState.DATABASE_ERROR;
            }
        }