//================================================================ /// <summary> /// Разбиение строки из файла в структуру Docs /// </summary> private Docs SplitString(string str) { Docs doc = new Docs(); string patt = @"^[^;]+|[^;]+|[^;]+$"; Regex reg = new Regex(patt); MatchCollection coll = reg.Matches(str); doc.Name = coll[0].Value; doc.Path = coll[1].Value; doc.Ext = coll[2].Value; try { DateTime.TryParse(coll[3].Value, out doc.OpenTime); } //catch (Exception e) catch (Exception) { doc.OpenTime = DateTime.Now; } //foreach (Match match in coll) //{ // //doc.Name = match.Groups["Name"].Value; // //doc.Path = match.Groups["Path"].Value; // //doc.Ext = match.Groups["Ext"].Value; // //DateTime.TryParse(match.Groups["Date"].Value, out doc.OpenTime); //} return(doc); }
//=============================================================== /// <summary> /// Добавить новый документ /// </summary> public bool AddNewDocument(Docs doc) { //bool bOk = true; foreach (Docs dc in docs) { if (dc.Path == doc.Path) { return(false); } } docs.Add(doc); return(true); }
//======================================================================== /// <summary> /// Открыть файл с помощью программы, переданной в качестве параметра /// </summary> public bool OpenDocumentWith(string Doc, string Prog) { bool Ok = false; string OpenDoc = "\"" + Doc + "\""; Process OpenProg = Process.Start(Prog, OpenDoc); if (OpenProg != null) { Ok = true; int ind = GetDocIndex(Doc); if (ind != -1) { docs[ind] = new Docs(Doc); } } return(Ok); }
//============================================================== public int CompareTo(object obj) { Docs _file = (Docs)obj; int result; if (this.OpenTime < _file.OpenTime) { result = -1; } else if (this.OpenTime > _file.OpenTime) { result = 1; } else { result = 0; } return(result); }
//=================================================================== //----------------------------------------------------AddDoc_funtion() -- private bool AddDoc_funtion(string fileName) { Docs dc = new Docs(fileName); if (documents.AddNewDocument(dc)) { dGrid.Rows.Add(dc.Name, dc.Path, dc.Ext, dc.OpenTime); // Открытие документа, если стоит флажок if (cbOpen.Checked) { documents.OpenDocument(dc.Path, dc.Ext); } dGrid.Sort(dGrid.Columns["Date"], ListSortDirection.Descending); dGrid.CurrentCell = dGrid["Name", 0]; // Установка курсора GetProgData(dGrid["Ext", dGrid.CurrentRow.Index].Value.ToString()); return(true); } return(false); }
//=============================================================== /// <summary> /// Открыть документ из списка /// </summary> public short OpenDocument(string Doc, string Ext) { short Ok = -1; // -1 - нет расширения в списке if (progs.ContainsKey(Ext)) // 0 - нет программы в списке { // 1 - файл открыт string doc = "\"" + Doc + "\""; string prg = progs[Ext]; if (prg != null && prg != "") { //Process newProc = Process.Start(progs[Ext], doc); // можно (doc); Process newProc = Process.Start(prg, doc); // можно (doc); if (newProc != null) { int ind = GetDocIndex(Doc); if (ind != -1) { docs[ind] = new Docs(Doc, Ext); } Ok = 1; } else { Ok = 0; } } else { Ok = 0; } } //else //{ MessageBox.Show("Нет программы, которая смогла бы открыть данный файл."); } return(Ok); }