Пример #1
0
        //private void exportExcel(string excelFile)
        //{
        //    var selectedUser = this.CodeListBox.SelectedItem as Person;            
        //    var excelApp = new Microsoft.Office.Interop.Excel.Application();
        //    var books = (Microsoft.Office.Interop.Excel.Workbooks)excelApp.Workbooks;
        //    var book = (Microsoft.Office.Interop.Excel._Workbook)(books.Add(System.Type.Missing));
        //    var sheets = (Microsoft.Office.Interop.Excel.Sheets)book.Worksheets;
        //    var sheet = (Microsoft.Office.Interop.Excel._Worksheet)(sheets.get_Item(1));
        //    sheet.Name = "TDB Records";
        //    Microsoft.Office.Interop.Excel._Worksheet screensheet;
        //    if (sheets.Count > 1)
        //    {
        //        screensheet = (Microsoft.Office.Interop.Excel._Worksheet)(sheets.get_Item(2));
        //    }
        //    else
        //    {
        //        screensheet = sheets.Add(System.Type.Missing, sheet, System.Type.Missing, System.Type.Missing);                
        //    }
        //    screensheet.Name = "Screening Records";
        //    patientList.Clear();
        //    ListFiles(new DirectoryInfo(App.reportSettingModel.DataBaseFolder));
            
        //    //tdb文件統計數據
        //    Microsoft.Office.Interop.Excel.Range range = (Microsoft.Office.Interop.Excel.Range)sheet.get_Range("A1", "A100");
        //    range.ColumnWidth = 15;
        //    range = (Microsoft.Office.Interop.Excel.Range)sheet.get_Range("B1", "B100");
        //    range.ColumnWidth = 30;
        //    range = (Microsoft.Office.Interop.Excel.Range)sheet.get_Range("C1", "C100");
        //    range.ColumnWidth = 20;
        //    range = (Microsoft.Office.Interop.Excel.Range)sheet.get_Range("D1", "D100");
        //    range.ColumnWidth = 100;
        //    sheet.Cells[1, 1] = App.Current.FindResource("Excel1").ToString();
        //    sheet.Cells[1, 2] = App.Current.FindResource("Excel2").ToString();
        //    sheet.Cells[1, 3] = App.Current.FindResource("Excel4").ToString();
        //    sheet.Cells[1, 4] = App.Current.FindResource("Excel3").ToString();
        //    for (int i = 0; i < patientList.Count; i++)
        //    {
        //        Patient item = patientList[i];
        //        sheet.Cells[i + 2, 1] = item.Code;
        //        sheet.Cells[i + 2, 2] = item.Name;
        //        sheet.Cells[i + 2, 3] = item.ScreenDate;
        //        sheet.Cells[i + 2, 4] = item.Desc;
        //    }

        //    //启动MEIK设备次数
        //    Microsoft.Office.Interop.Excel.Range range1 = (Microsoft.Office.Interop.Excel.Range)screensheet.get_Range("A1", "A100");
        //    range1.ColumnWidth = 100;
        //    range1 = (Microsoft.Office.Interop.Excel.Range)screensheet.get_Range("B1", "B100");
        //    range1.ColumnWidth = 30;
            
        //    screensheet.Cells[1, 1] = App.Current.FindResource("Excel5").ToString();
        //    screensheet.Cells[1, 2] = App.Current.FindResource("Excel6").ToString();
        //    int row = 1;
        //    foreach (KeyValuePair<string, List<long>> item in App.countDictionary)                            
        //    {
        //        screensheet.Cells[row + 1, 1] = item.Key;                
        //        foreach (var tick in item.Value)
        //        {
        //            DateTime screeningTime = new DateTime(tick);
        //            screensheet.Cells[row + 1, 2] = screeningTime.ToString("yyyy-MM-dd HH:mm:ss");                    
        //            row++; 
        //        }                            
        //    }

        //    book.SaveAs(excelFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
        //    book.Close();
        //    excelApp.Quit();
            
        //}

        private void ListFiles(FileSystemInfo info)
        {
            try
            {
                if (!info.Exists) return;
                IFormatProvider culture = new System.Globalization.CultureInfo("en-US", true);
                DirectoryInfo dir = info as DirectoryInfo;
                //不是目录 
                if (dir == null) return;
                if (!dir.Name.Equals("NORM"))
                {
                    FileSystemInfo[] files = dir.GetFileSystemInfos();
                    for (int i = 0; i < files.Length; i++)
                    {
                        FileInfo file = files[i] as FileInfo;
                        //是文件 
                        if (file != null)
                        {
                            DateTime beginDate = DateTime.Now;
                            if (".tdb".Equals(file.Extension, StringComparison.OrdinalIgnoreCase))
                            {
                                DateTime fileTime = file.LastWriteTime;
                                beginDate = beginDate.AddMonths(-1);
                                if (beginDate < fileTime)
                                {

                                    FileStream fsRead = new FileStream(file.FullName, FileMode.Open);
                                    byte[] nameBytes = new byte[105];
                                    byte[] codeBytes = new byte[11];
                                    byte[] descBytes = new byte[200];
                                    fsRead.Seek(12, SeekOrigin.Begin);
                                    fsRead.Read(nameBytes, 0, nameBytes.Count());
                                    fsRead.Seek(117, SeekOrigin.Begin);
                                    fsRead.Read(codeBytes, 0, codeBytes.Count());
                                    fsRead.Seek(129, SeekOrigin.Begin);
                                    fsRead.Read(descBytes, 0, descBytes.Count());
                                    fsRead.Close();
                                    string name = System.Text.Encoding.ASCII.GetString(nameBytes);
                                    name = name.Split("\0".ToCharArray())[0];
                                    string code = System.Text.Encoding.ASCII.GetString(codeBytes);
                                    string desc = System.Text.Encoding.ASCII.GetString(descBytes);
                                    desc = desc.Split("\0".ToCharArray())[0];
                                    var patient = new Patient();
                                    patient.Code = code;
                                    patient.Name = name;
                                    patient.Desc = desc;
                                    patient.ScreenDate = fileTime.ToString("yyyy-MM-dd HH:mm:ss");

                                    patientList.Add(patient);
                                }

                            }
                        }
                        //对于子目录,进行递归调用 
                        else
                        {
                            ListFiles(files[i]);
                        }
                    }
                }
            }
            catch { }
        }
Пример #2
0
 private void ListFiles(FileSystemInfo info, DateTime fromDate, DateTime toDate)
 {
     if (!info.Exists) return;
     DirectoryInfo dir = info as DirectoryInfo;
     //不是目录 
     if (dir == null) return;
     if (!dir.Name.Equals("NORM"))
     {
         FileSystemInfo[] files = dir.GetFileSystemInfos();
         for (int i = 0; i < files.Length; i++)
         {
             FileInfo file = files[i] as FileInfo;
             //是文件 
             if (file != null)
             {
                 if (".tdb".Equals(file.Extension, StringComparison.OrdinalIgnoreCase))
                 {
                     if (file.LastWriteTime >= fromDate && file.LastWriteTime <= toDate)
                     {
                         FileStream fsRead = new FileStream(file.FullName, FileMode.Open);
                         byte[] nameBytes = new byte[105];
                         byte[] codeBytes = new byte[11];
                         byte[] descBytes = new byte[200];
                         fsRead.Seek(12, SeekOrigin.Begin);
                         fsRead.Read(nameBytes, 0, nameBytes.Count());
                         fsRead.Seek(117, SeekOrigin.Begin);
                         fsRead.Read(codeBytes, 0, codeBytes.Count());
                         fsRead.Seek(129, SeekOrigin.Begin);
                         fsRead.Read(descBytes, 0, descBytes.Count());
                         fsRead.Close();
                         string name = System.Text.Encoding.ASCII.GetString(nameBytes);
                         name = name.Split("\0".ToCharArray())[0];
                         string code = System.Text.Encoding.ASCII.GetString(codeBytes);
                         string desc = System.Text.Encoding.ASCII.GetString(descBytes);
                         desc = desc.Split("\0".ToCharArray())[0];
                         var patient = new Patient();
                         patient.Code = code;
                         patient.Name = name;
                         patient.Desc = desc;
                         patient.ScreenDate = file.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
                         patientList.Add(patient);
                         var key = code + ";" + name;
                         if (countDict.ContainsKey(key))
                         {
                             countDict[key] = countDict[key] + 1;
                         }
                         else
                         {
                             countDict.Add(key, 1);
                         }
                     }
                     //times++;
                 }
             }
             //对于子目录,进行递归调用 
             else
             {
                 ListFiles(files[i], fromDate, toDate);
             }
         }
     }
 }