Example #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();
     }
 }