diff include/dndfile.h @ 3:1a64119ab257

Equipment Regist print-target by Drag & Drop.
author pyon@macmini
date Tue, 27 Aug 2013 18:50:00 +0900
parents
children fdba695b99f1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/dndfile.h	Tue Aug 27 18:50:00 2013 +0900
@@ -0,0 +1,53 @@
+// Filename   : dndfile.h
+// Last Change: 27-Aug-2013.
+//
+
+#include "db.h"
+
+class DnDFile : public wxFileDropTarget
+{
+    public:
+        DnDFile( wxGrid *grid )
+        {
+            m_grid = grid;
+        }
+        virtual bool OnDropFiles( wxCoord x, wxCoord y, const wxArrayString& filenames )
+        {
+            size_t nFiles = filenames.GetCount();
+            if ( nFiles != 1 ) return false;
+
+            m_grid->ClearGrid();
+            wxTextFile csv;
+            csv.Open( filenames[0] );
+
+            int d = csv.GetLineCount() - m_grid->GetNumberRows();
+            if ( d > 0 )
+                m_grid->AppendRows( d, true );
+
+            wxRegEx reHhs( wxT("^0[1238][0-9]{8}$") );
+            for ( int n = 0, j = 0; n < csv.GetLineCount(); n++ ) {
+                wxString hhsno = csv.GetLine( n ).BeforeFirst( ',', NULL );
+                if ( ! reHhs.Matches( hhsno ) ) {
+                    j++;
+                    continue;
+                }
+                int r = n - j;
+
+                wxArrayString info = wxSplit( GetHhsInfoByHhsNo( hhsno ), '_', '\\' );
+                wxArrayString path = GetPathByHhsNo( hhsno );
+
+                if ( info.IsEmpty() ) info.Add( wxEmptyString );
+                if ( path.IsEmpty() ) path.Add( wxEmptyString );
+
+                m_grid->SetCellValue( r, 0, hhsno );
+                m_grid->SetCellValue( r, 1, info[0] );
+                m_grid->SetCellValue( r, 2, path[0] );    
+            }
+            csv.Close();
+            return true;
+        }
+
+    private:
+        wxGrid* m_grid;
+};
+