private void addDirPathButton_Click(object sender, EventArgs e)
        {
            try
            {
                //Install the following NuGet package to get the required assemblies (Tools->Library Package Manager->Package Manager Console): https://www.nuget.org/packages/Windows7APICodePack-Shell/
                var dlg = new CommonOpenFileDialog();
                dlg.AllowNonFileSystemItems = false;
                dlg.Multiselect             = true;
                dlg.IsFolderPicker          = true;

                if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    foreach (var f in dlg.FileNames)
                    {
                        JAttachment at = new JAttachment();
                        at.Path = f;
                        this.listView.AddObject(at);
                    }
                }

                /* very ugly dialog
                 * FolderBrowserDialog fbd = new FolderBrowserDialog();
                 * DialogResult result = fbd.ShowDialog();
                 * if (!string.IsNullOrWhiteSpace(fbd.SelectedPath))
                 * {
                 *    string[] files = Directory.GetFiles(fbd.SelectedPath);
                 *    System.Windows.Forms.MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
                 * }
                 */
            }
            catch (Exception ex)
            {
                Log.ShowError(ex);
            }
        }
        private void addFilePathButton_Click(object sender, EventArgs e)
        {
            try
            {
                //Install the following NuGet package to get the required assemblies (Tools->Library Package Manager->Package Manager Console): https://www.nuget.org/packages/Windows7APICodePack-Shell/
                var dlg = new CommonOpenFileDialog();
                dlg.AllowNonFileSystemItems = false;
                dlg.Multiselect             = true;
                dlg.IsFolderPicker          = false;

                if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    foreach (var f in dlg.FileNames)
                    {
                        JAttachment at = new JAttachment();
                        at.Path = f;
                        this.listView.AddObject(at);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.ShowError(ex);
            }
        }
Beispiel #3
0
 static public JHelp MakeFromJAttachment(JAttachment attachment, object sourceObject)
 {
     return(new JHelp()
     {
         Path = Dm.Instance.GetRealPath(attachment.Path, sourceObject)
     });
 }
        private void ListView_HyperlinkClicked(object sender, HyperlinkClickedEventArgs e)
        {
            JAttachment item = (JAttachment)e.Model;

            if (item.Path != null && item.Path.StartsWith(Dm.STORAGE_PREFIX))
            {
                string         path = Dm.Instance.GetRealPath(item.Path, SourceObject);
                FileSystemInfo x    = GetFileSystemInfo(path);
                if (x != null)
                {
                    e.Url = x.FullName;
                }
            }
        }
 private void addURLButton_Click(object sender, EventArgs e)
 {
     try
     {
         SimpleTextDialog dlg = new SimpleTextDialog();
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             JAttachment at = new JAttachment();
             at.Path = dlg.TextToEdit;
             this.listView.AddObject(at);
         }
     }
     catch (Exception ex)
     {
         Log.ShowError(ex);
     }
 }
 private void addFileButton_Click(object sender, EventArgs e)
 {
     try
     {
         //Install the following NuGet package to get the required assemblies (Tools->Library Package Manager->Package Manager Console): https://www.nuget.org/packages/Windows7APICodePack-Shell/
         var dlg = new CommonOpenFileDialog();
         dlg.AllowNonFileSystemItems = false;
         dlg.Multiselect             = true;
         dlg.IsFolderPicker          = false;
         if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
         {
             foreach (var f in dlg.FileNames)
             {
                 //copy file
                 string objectStorageDir = Dm.Instance.GetStorageFullPathForObject(SourceObject);
                 string fileName         = (new FileInfo(f)).Name;
                 string random           = DataUtils.genKey(null);
                 string newDiskDir       = Path.Combine(objectStorageDir, random);
                 string newDiskFileName  = Path.Combine(newDiskDir, fileName);
                 if (!Directory.Exists(newDiskDir))
                 {
                     Directory.CreateDirectory(newDiskDir);
                 }
                 string newStoreFileName = Path.Combine(Path.Combine(Dm.STORAGE_PREFIX, random), fileName);
                 Cursor cursor           = Cursor.Current;
                 try
                 {
                     Cursor.Current = Cursors.WaitCursor;
                     File.Copy(f, newDiskFileName);
                 }
                 finally
                 {
                     Cursor.Current = cursor;
                 }
                 //new path
                 JAttachment at = new JAttachment();
                 at.Path = newStoreFileName;
                 this.listView.AddObject(at);
             }
         }
     }
     catch (Exception ex)
     {
         Log.ShowError(ex);
     }
 }
 private void openFileOrFolder(bool openAsFolder)
 {
     try
     {
         if (listView.SelectedObjects != null && listView.SelectedObjects.Count > 1)
         {
             MessageBox.Show(FrwCRUDRes.List_Selected_More_Than_On_record);
         }
         else if (listView.SelectedObjects == null || listView.SelectedObjects.Count == 0)
         {
             MessageBox.Show(FrwCRUDRes.List_No_Selected_Records);
         }
         else
         {
             JAttachment selectedObject = null;
             if (listView.SelectedIndex > -1)
             {
                 selectedObject = listView.GetItem(listView.SelectedIndex).RowObject as JAttachment;
             }
             string path = Dm.Instance.GetRealPath(selectedObject.Path, SourceObject);
             if (openAsFolder)
             {
                 if (Directory.Exists(path) == false)
                 {
                     FileInfo fi = new FileInfo(path);
                     path = fi.Directory.FullName;
                 }
             }
             ProcessUtils.OpenFile(path);
         }
     }
     catch (Exception ex)
     {
         Log.ShowError(ex);
     }
 }
        public SimpleAttachmentsDialog()
        {
            InitializeComponent();
            this.Text = FrwCRUDRes.SimpleAttachmentsDialog_Attachments;

            ((System.ComponentModel.ISupportInitialize)(listView)).BeginInit();
            //ovl settings
            listView.EmptyListMsg     = FrwCRUDRes.List_No_Records;
            listView.EmptyListMsgFont = new Font("Tahoma", 9);//todo;
            listView.FullRowSelect    = true;
            listView.UseCompatibleStateImageBehavior = false;
            listView.View                        = System.Windows.Forms.View.Details;
            listView.UseFiltering                = true;
            listView.UseFilterIndicator          = true;
            listView.AllowColumnReorder          = true;
            listView.TriStateCheckBoxes          = false;
            listView.CellEditUseWholeCell        = false;
            listView.TintSortColumn              = true;
            listView.ShowItemToolTips            = true;
            listView.UseHotItem                  = true;
            listView.UseHyperlinks               = true;
            listView.HyperlinkClicked           += ListView_HyperlinkClicked;
            listView.ShowCommandMenuOnRightClick = true;
            listView.TintSortColumn              = true;
            //special for selection list
            //listView.CheckBoxes = true;
            listView.CellEditActivation  = ObjectListView.CellEditActivateMode.None;
            listView.CellToolTipShowing += delegate(object sender, ToolTipShowingEventArgs e) {
                if (e.Column.Text == FrwCRUDRes.SimpleAttachmentsDialog_Path)
                {
                    JAttachment    item = (JAttachment)e.Model;
                    string         path = Dm.Instance.GetRealPath(item.Path, SourceObject);
                    FileSystemInfo x    = GetFileSystemInfo(path);
                    if (x != null)
                    {
                        e.Text = x.FullName;
                    }
                    //e.Text = String.Format("Tool tip for '{0}', column '{1}'\r\nValue shown: '{2}'", e.Model, e.Column.Text, e.SubItem.Text);
                }
                //else e.Text =
            };
            SysImageListHelper helper = new SysImageListHelper(this.listView);//todo вынести в кешируемый уровень

            OLVColumn column = null;

            column                = new OLVColumn();
            column.AspectName     = "Path";
            column.Text           = FrwCRUDRes.SimpleAttachmentsDialog_Path;
            column.Width          = 350;
            column.Hyperlink      = true;
            column.FillsFreeSpace = true;
            column.AspectGetter   = delegate(object xx)
            {
                JAttachment item = (JAttachment)xx;
                if (item.Path != null && item.Path.StartsWith(Dm.STORAGE_PREFIX))
                {
                    string         path = Dm.Instance.GetRealPath(item.Path, SourceObject);
                    FileSystemInfo x    = GetFileSystemInfo(path);
                    if (x == null)
                    {
                        return(null);
                    }
                    return(x.Name);
                }
                else
                {
                    return(item.Path);
                }
            };
            column.ImageGetter = delegate(object x)
            {
                try
                {
                    JAttachment    item = (JAttachment)x;
                    string         path = Dm.Instance.GetRealPath(item.Path, SourceObject);
                    FileSystemInfo fi   = GetFileSystemInfo(path);
                    if (fi == null)
                    {
                        return(null);
                    }
                    return(helper.GetImageIndex((fi).FullName));
                }
                catch (Exception)
                {
                    return(null);
                }
            };
            AddColumnToList(column);

            column                 = new OLVColumn();
            column.AspectName      = "Path";
            column.Text            = FrwCRUDRes.SimpleAttachmentsDialog_Size;
            column.ButtonPadding   = new Size(10, 10);
            column.HeaderTextAlign = HorizontalAlignment.Right;
            column.TextAlign       = HorizontalAlignment.Right;
            column.Width           = 80;
            column.AspectGetter    = delegate(object xx) {
                JAttachment    item = (JAttachment)xx;
                string         path = Dm.Instance.GetRealPath(item.Path, SourceObject);
                FileSystemInfo x    = GetFileSystemInfo(path);
                if (x == null)
                {
                    return(null);
                }

                if (x is DirectoryInfo)
                {
                    return((long)-1);
                }

                try
                {
                    return(((FileInfo)x).Length);
                }
                catch (System.IO.FileNotFoundException)
                {
                    // Mono 1.2.6 throws this for hidden files
                    return((long)-2);
                }
            };
            column.AspectToStringConverter = delegate(object x) {
                if (x == null)
                {
                    return(null);           //file not exist
                }
                long sizeInBytes = (long)x;
                if (sizeInBytes < 0) // folder or error
                {
                    return("");
                }
                return(FormatUtils.FormatFileSize(sizeInBytes));
            };
            AddColumnToList(column);

            column              = new OLVColumn();
            column.AspectName   = "Path";
            column.Text         = FrwCRUDRes.SimpleAttachmentsDialog_CreationDate;
            column.Width        = 130;
            column.AspectGetter = delegate(object xx) {
                JAttachment    item = (JAttachment)xx;
                string         path = Dm.Instance.GetRealPath(item.Path, SourceObject);
                FileSystemInfo x    = GetFileSystemInfo(path);
                if (x == null)
                {
                    return(null);
                }
                return(x.CreationTime);
            };
            AddColumnToList(column);

            column              = new OLVColumn();
            column.AspectName   = "Path";
            column.Text         = FrwCRUDRes.SimpleAttachmentsDialog_ModificationDate;
            column.Width        = 130;
            column.AspectGetter = delegate(object xx) {
                JAttachment    item = (JAttachment)xx;
                string         path = Dm.Instance.GetRealPath(item.Path, SourceObject);
                FileSystemInfo x    = GetFileSystemInfo(path);
                if (x == null)
                {
                    return(null);
                }
                return(x.LastWriteTime);
            };
            AddColumnToList(column);

            column              = new OLVColumn();
            column.AspectName   = "Path";
            column.Text         = FrwCRUDRes.SimpleAttachmentsDialog_FileType;
            column.Width        = 130;
            column.AspectGetter = delegate(object xx) {
                JAttachment    item = (JAttachment)xx;
                string         path = Dm.Instance.GetRealPath(item.Path, SourceObject);
                FileSystemInfo x    = GetFileSystemInfo(path);
                if (x == null)
                {
                    return(null);
                }

                return(ShellApi.GetFileType(((FileSystemInfo)x).FullName));
            };
            AddColumnToList(column);

            ((System.ComponentModel.ISupportInitialize)(listView)).EndInit();
        }