示例#1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ItemList_Drop(object sender, DragEventArgs e)
 {
     if (!(e.Data.GetData(DataFormats.FileDrop) is string[] files))
     {
         return;
     }
     using (var table = new ItemsTable(this._profileDatabase)) {
         table.OpenDatabase();
         table.BeginTrans();
         foreach (var file in files)
         {
             var fileUtil = FileUtil.Create(file);
             var model    = new ItemModel();
             if (fileUtil.IsFile)
             {
                 model.DisplayName = ((FileOperator)fileUtil).NameWithoutExtension;
             }
             else
             {
                 model.DisplayName = fileUtil.Name;
             }
             if (fileUtil.Exists())
             {
                 if (fileUtil.IsDirectory)
                 {
                     model.Icon = CustomImage.GetDirectoryIcon(fileUtil.FilePath);
                 }
                 else
                 {
                     model.Icon = CustomImage.GetAppIcon(fileUtil.FilePath);
                 }
             }
             model.FilePath   = file;
             model.CategoryId = ((CategoryModel)this.cCategoryList.SelectedItem).Id;
             model.Id         = table.Insert(model);
             if (model.Id < 0)
             {
                 AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToInsert, "item"));
                 return;
             }
             this._itemList.Add(model);
         }
         table.CommitTrans();
     }
 }
示例#2
0
        /// <summary>
        /// item context menu add click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ItemContextMenuAdd_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new EditItem(this);

            if (true != dialog.ShowDialog())
            {
                return;
            }
            using (var table = new ItemsTable(this._profileDatabase)) {
                var model = dialog.Model;
                model.CategoryId = ((CategoryModel)this.cCategoryList.SelectedItem).Id;
                model.RowOrder   = this._itemList.Count + 1;
                model.Id         = table.Insert(model);
                if (model.Id < 0)
                {
                    AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToInsert, "item"));
                    return;
                }
                this._itemList.Add(model);
            }
        }