コード例 #1
0
        private void SubmitClipboardObjectForm(object sender, MouseButtonEventArgs e)
        {
            if (ClipboardObjectName.Text.Trim() == "")
            {
                ClipboardObjectName.BorderBrush = (SolidColorBrush) new BrushConverter().ConvertFrom(ColorSet.ERROR);
                NameErrorText.Content           = "Name is required";
            }
            else if (NameErrorText.Content.ToString().Trim() == "")
            {
                // TODO: display loading overlay
                try
                {
                    string name = ClipboardObjectName.Text.Trim();

                    if (FormType == FormType.CREATE)
                    {
                        long   categoryId = category.Id;
                        string type       = clipboardObject.GetType().Name;
                        string content    = clipboardObject.GenerateContentString();
                        long   id         = DBManager.Instance.AddClipboardObject(categoryId, name, type, content);
                        category.AddClipboardObject(ClipboardObjectUtils.CreateClipboardObjectByType(ParentWindow, id, name, type, content));
                    }
                    else if (clipboardObject != null)
                    {
                        DBManager.Instance.UpdateClipboardObject(clipboardObject.Id, name);
                        category.RemoveClipboardObject(clipboardObject);
                        clipboardObject.Name = name;
                        category.AddClipboardObject(clipboardObject);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("could not save/update clipboard object: " + ex.Message);
                    // TODO: show error in overlay
                }
                CloseForm(sender, e);
                // TODO: close loading overlay
            }
        }
コード例 #2
0
        public SortedSet <ClipboardObject> GetClipboardObjects(MainWindow parentWindow, long categoryId)
        {
            SortedSet <ClipboardObject> clipboardObjects = new SortedSet <ClipboardObject>();

            using (SQLiteConnection connection = new SQLiteConnection(CONNECTION_URI))
            {
                connection.Open();

                SQLiteCommand cmd = new SQLiteCommand(connection)
                {
                    CommandText = "SELECT * FROM clips WHERE category_id=@category_id"
                                  //CommandText = "SELECT * FROM clips WHERE category_id=@category_id ORDER BY name COLLATE NOCASE"
                };
                cmd.Parameters.AddWithValue("@category_id", categoryId);
                cmd.Prepare();

                SQLiteDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    clipboardObjects.Add(ClipboardObjectUtils.CreateClipboardObjectByType(parentWindow, reader.GetInt64(0), reader.GetString(2), reader.GetString(3), reader.GetString(4)));
                }
            }
            return(clipboardObjects);
        }