コード例 #1
0
 void УдалитьToolStripMenuItemClick(object sender, EventArgs e)
 {
     try {
         if (this.ActiveControl.Name == "lbDirs")             //delete Directory
         {
             if (lbDirs.SelectedItems.Count != 0)
             {
                 CONSTS.RemoveDirFromfilter(lbDirs.SelectedItem.ToString());
             }
             lbDirs.Items.Remove(lbDirs.SelectedItem);
             lbWords.Items.Clear();
         }
         else if (this.ActiveControl.Name == "lbWords")              //delete word-filter
         {
             if (lbWords.SelectedItems.Count != 0)
             {
                 CONSTS.Filters.Find(x => x.directory == lbDirs.SelectedItem.ToString()).
                 words.Remove(lbWords.SelectedItem.ToString());
             }
             lbWords.Items.Remove(lbWords.SelectedItem);
         }
     } catch (Exception ex) {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path">Full file path</param>
        /// <param name="filter">{0} - filer word
        /// {1} - target Dir</param>
        public QFile(string path, List <CONSTS.Filter> filters, List <string> exceptions)
        {
            if (!File.Exists(path))
            {
                FileName       = "";
                FilePath       = "";
                DestinationDir = "";
                DateEvent      = new DateTime(0);
                Copy           = false;
                Score          = -1;
            }

            FilePath  = path;
            FileName  = path.Split('\\').Last();
            Copy      = false;
            DateEvent = CONSTS.ParseDate(FileName);
            if (DateEvent != new DateTime(0) && DateEvent < DateTime.Today)           //DateEvent filter
            {
                Copy = true;
            }
            DestinationDir = Filter(FileName, filters);
            if (String.IsNullOrWhiteSpace(DestinationDir))
            {
                Copy = false;
            }
            if (exceptions.Contains(FilePath))
            {
                Copy = false;
            }
            Score = -1;
        }
コード例 #3
0
        //Переместить выбранные файлы
        void Button1Click(object sender, EventArgs e)
        {
            var oldtext = button1.Text;

            try {
                button1.Text = "Файлы перемещаются...";
                CONSTS.invokeStatusInfo(statusStrip1, "Перемещение файлов...");
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if ((bool)row.Cells[0].Value)                    //MOVE
                    {
                        if (String.IsNullOrWhiteSpace(row.Cells[2].Value.ToString()))
                        {
                            continue;
                        }
                        button1.Enabled = false;
                        var SourceFile = IncomingDir + "\\" + row.Cells[1].Value.ToString();
                        var TargetFile = row.Cells[2].Value.ToString().TrimEnd('\\') + "\\" + row.Cells[1].Value.ToString();

                        Writelog.WriteLog(row.Cells[1].Value.ToString() + " перемещен --> " + row.Cells[2].Value, "history.txt");

                        if (File.Exists(SourceFile))
                        {
                            if (File.Exists(TargetFile))                            //overwrite
                            {
                                File.Delete(TargetFile);
                            }

                            File.Move(SourceFile, TargetFile);
                        }
                        CONSTS.invokeStatusInfo(statusStrip1, "Переносится файл " + row.Cells[1].Value.ToString());
                    }
                    else                     //SKIP
                    {
                        //Writelog.WriteLog(row.ToString(),"Uchecked.txt");
                    }
                }
                ReadAndDisplayFilesInDGV(IncomingDir, filters, checkBox1.Checked, false);
                button1.Enabled = true;
                button1.Text    = oldtext;
                CONSTS.invokeStatusInfo(statusStrip1, "Выполнено");
            } catch (Exception ex) {
                button1.Enabled = true;
                button1.Text    = oldtext;
                MessageBox.Show(ex.Message);
                CONSTS.invokeStatusInfo(statusStrip1, "Ошибка в процессе перемещения файла");
            }
        }
コード例 #4
0
        /// <summary>
        /// Read and filtering files from incDir directory
        /// and display it into datagridview1
        /// </summary>
        /// <param name="incDir"></param>
        void ReadAndDisplayFilesInDGV(string incDir, List <CONSTS.Filter> filters, bool HideUncheked, bool rebuildModel)
        {
            if (!Directory.Exists(incDir))
            {
                return;
            }
            (dataGridView1.Columns[2] as DataGridViewComboBoxColumn).Items.Clear();
            (dataGridView1.Columns[2] as DataGridViewComboBoxColumn).Items.AddRange(CONSTS.DIRS());
            var filepaths = Directory.GetFiles(incDir);

            if (UseFilter)
            {
                AllFiles = new QueueFiles(filepaths, filters, CONSTS.FilesExceptions);                //отфильтрованный список файлов
                if (UseML)
                {
                    var predictedFiles = new QueueFiles(filepaths, filters, CONSTS.FilesExceptions, rebuildModel, MinScore); //отфильтрованный список файлов
                    for (int i = 0; i < AllFiles.Files.Count; i++)                                                           //для всех нераспознанных файлов применяем результаты нейросети
                    {
                        if (String.IsNullOrWhiteSpace(AllFiles.Files[i].DestinationDir))
                        {
                            AllFiles.Files[i] = predictedFiles.Files.First(x => x.FileName == AllFiles.Files[i].FileName);
                        }
                    }
                }
            }
            else if (UseML)
            {
                AllFiles = new QueueFiles(filepaths, filters, CONSTS.FilesExceptions, rebuildModel, MinScore);             //отфильтрованный список файлов
            }
            AllFiles.Files.Sort(new QFileComparer());
            if (HideUncheked)
            {
                bindingSource1.DataSource = AllFiles.Files.Where(x => x.Copy);
            }
            else
            {
                bindingSource1.DataSource = AllFiles.Files;
            }
            dataGridView1.DataSource = bindingSource1;
            SetStatus(AllFiles.Files.Count(x => x.Copy), AllFiles.Files.Count());
        }
コード例 #5
0
        private int MinScore;          //minimal level of prediction
        public MainForm()
        {
            InitializeComponent();
            if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Data")))
            {
                Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "Data"));
            }
            this.FormClosing += formClosingMethod;
            dataGridView1.DataBindingComplete += DataGridView1_DataBindingComplete;
            dataGridView1.CellContentClick    += cellClick;
            dataGridView1.CellClick           += dataGridView1_CellClick;
            dataGridView1.CellDoubleClick     += dataGridView1_CellDoubleClick;
            comboFilters.SelectedIndexChanged += comboFilters_SelectedIndexChanged;
            dataGridView1.DataError           += dataGridView1_DataError;
            tbSearch.TextChanged += tbSearch_TextChanged;
            filters = CONSTS.Filters;
            QueueFiles.QueueEvent += QueueFiles_QueueEvent;

            #region Read config

            cfg = new IniFile(ConfigFile);
            ReadFiltersCfg(cfg);
            ReadSettings(cfg);
            ReadFilesExceptions(cfg);
            tsMenuUseML.Checked = UseML;
            #endregion
            dataGridView1.AllowUserToAddRows = false;
            (dataGridView1.Columns[2] as DataGridViewComboBoxColumn).Items.AddRange(CONSTS.DIRS());
            #region ComboFilters
            comboFilters.Items.AddRange(namesFilters());
            comboFilters.Items.Add("Все фильтры");
            comboFilters.SelectedItem = "Все фильтры";

            #endregion
            if (IncomingDir != null && Directory.Exists(IncomingDir))
            {
                ReadAndDisplayFilesInDGV(IncomingDir, filters, checkBox1.Checked, false);
            }
        }
コード例 #6
0
        public QFile(string path, string dest, List <string> exceptions, float score)
        {
            if (!File.Exists(path))
            {
                FileName       = "";
                FilePath       = "";
                DestinationDir = "";
                DateEvent      = new DateTime(0);
                Copy           = false;
            }

            FilePath  = path;
            FileName  = path.Split('\\').Last();
            Copy      = false;
            DateEvent = CONSTS.ParseDate(FileName);
            if (DateEvent != new DateTime(0) && DateEvent < DateTime.Today)             //DateEvent filter
            {
                Copy = true;
            }
            if (Directory.Exists(dest))
            {
                DestinationDir = dest;
            }
            else
            {
                DestinationDir = "";
            }
            if (String.IsNullOrWhiteSpace(DestinationDir))
            {
                Copy = false;
            }
            if (exceptions.Contains(FilePath))
            {
                Copy = false;
            }
            Score = (float)Math.Round(score * 100, 2);
        }
コード例 #7
0
 private void QueueFiles_QueueEvent(string msg)
 {
     CONSTS.InvokeLog(tbLog, msg);
 }