2
|
1 // Filename : mainframe.cpp
|
6
|
2 // Last Change: 08-Oct-2011.
|
2
|
3 //
|
|
4 #include "symbol.h"
|
|
5 #include "common.h"
|
|
6 #include "myframe.h"
|
|
7 #include "delwhite.h"
|
4
|
8 #include "marksheet.h"
|
2
|
9 #include "main.h"
|
|
10
|
|
11 // resources
|
|
12 // the application icon (under Windows and OS/2 it is in resources and even
|
|
13 // though we could still include the XPM here it would be unused)
|
|
14 #if !defined(__WXMSW__) && !defined(__WXPM__)
|
|
15 #include "sample.xpm"
|
|
16 #endif
|
|
17
|
|
18 //////////////////////////////////////////////////////////////////////////
|
|
19 // control constructor
|
|
20
|
|
21 // 検索履歴をログに保存
|
|
22 /*
|
|
23 void MyCmdBox::WriteLog( wxString& cmd, wxString& path )
|
|
24 {
|
|
25 wxString logfn = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("log.txt");
|
|
26 wxTextFile logFile;
|
|
27 logFile.Open( logfn );
|
|
28 wxDateTime now = wxDateTime::Now();
|
|
29 wxString log = now.Format( wxT("%Y-%m-%d %H:%M:%S") ) + wxT(" ") + cmd + wxT(" ") + path;
|
|
30 logFile.AddLine( log );
|
|
31 logFile.Write();
|
|
32 logFile.Close();
|
|
33
|
|
34 return;
|
|
35 }
|
|
36 */
|
|
37
|
|
38 //////////////////////////////////////////////////////////////////////////
|
|
39 // frame constructor
|
|
40 MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title )
|
|
41 : wxFrame( parent, id, title )
|
|
42 {
|
3
|
43 this->SetBackgroundColour( wxColour(wxT("WHEAT")) );
|
2
|
44 // set the frame icon
|
|
45 SetIcon(wxICON(sample));
|
|
46
|
|
47 // メニューバー
|
|
48 m_menubar = new wxMenuBar();
|
|
49
|
|
50 m_menuFile = new wxMenu();
|
4
|
51 m_menuFile->Append( ID_OPWORK, wxT("作業フォルダを開く"), wxT("Open work folder") );
|
|
52 m_menuFile->AppendSeparator(); //----
|
2
|
53 m_menuFile->Append( wxID_ABOUT, wxT("&About...\tF1"), wxT("Show about dialog") );
|
4
|
54 m_menuFile->AppendSeparator(); //----
|
2
|
55 m_menuFile->Append( wxID_EXIT, wxT("終了(&X)\tAlt-X"), wxT("Quit this program") );
|
|
56
|
|
57 m_menubar->Append( m_menuFile, wxT("ファイル(&F)") );
|
|
58
|
|
59 this->SetMenuBar( m_menubar );
|
|
60
|
|
61 // ステータスバー
|
|
62 int widths[] = { -1, 150, 120 };
|
|
63 m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP );
|
|
64 m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths );
|
|
65 m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
66
|
|
67 // コントロール
|
|
68 wxBoxSizer* bSizerTop;
|
|
69 bSizerTop = new wxBoxSizer( wxVERTICAL );
|
|
70
|
|
71 wxBoxSizer* bSizerWork;
|
|
72 bSizerWork = new wxBoxSizer( wxHORIZONTAL );
|
|
73
|
|
74 m_staticTextWork = new wxStaticText( this, wxID_ANY, wxT("作業用フォルダ"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
75 bSizerWork->Add( m_staticTextWork, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
76
|
|
77 m_dirPickerWork = new wxDirPickerCtrl( this, ID_WORKDIR, wxGetApp().dir, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE );
|
|
78 bSizerWork->Add( m_dirPickerWork, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
79
|
|
80 m_buttonDetWhite = new wxButton( this, ID_DTWHITE, wxT("白紙検知"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
81 bSizerWork->Add( m_buttonDetWhite, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
82
|
|
83 bSizerTop->Add( bSizerWork, 0, wxEXPAND, 5 );
|
|
84
|
|
85 wxBoxSizer* bSizerMoveTo;
|
|
86 bSizerMoveTo = new wxBoxSizer( wxHORIZONTAL );
|
|
87
|
|
88 m_staticTextMoveTo = new wxStaticText( this, wxID_ANY, wxT("移動先フォルダ"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
89 bSizerMoveTo->Add( m_staticTextMoveTo, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
90
|
3
|
91 wxArrayString drives;
|
|
92 drives.Add(wxT("C:"));
|
|
93 drives.Add(wxT("Y:"));
|
|
94 drives.Add(wxT("Z:"));
|
|
95 m_comboBoxMoveDrive = new wxComboBox( this, ID_DRIVE, wxT("C:"), wxDefaultPosition, wxSize( 50,-1 ), drives, 0 );
|
|
96 bSizerMoveTo->Add( m_comboBoxMoveDrive, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
2
|
97
|
3
|
98 m_datePickerCcn = new wxDatePickerCtrl( this, ID_DATE, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN );
|
2
|
99 bSizerMoveTo->Add( m_datePickerCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
100
|
3
|
101 wxArrayString ccns;
|
|
102 ccns.Add(wxT("角館1")); ccns.Add(wxT("角館2")); ccns.Add(wxT("角館3")); ccns.Add(wxT("角館4"));
|
|
103 ccns.Add(wxT("西仙1")); ccns.Add(wxT("西仙2")); ccns.Add(wxT("西仙3"));
|
|
104 ccns.Add(wxT("千畑1")); ccns.Add(wxT("千畑2")); ccns.Add(wxT("千畑3"));
|
|
105 ccns.Add(wxT("大曲1")); ccns.Add(wxT("大曲2")); ccns.Add(wxT("大曲3")); ccns.Add(wxT("大曲4")); ccns.Add(wxT("大曲5")); ccns.Add(wxT("大曲6"));
|
|
106 ccns.Add(wxT("六郷1")); ccns.Add(wxT("六郷2")); ccns.Add(wxT("六郷3"));
|
|
107 m_comboBoxCcn = new wxComboBox( this, ID_CCN, wxEmptyString, wxDefaultPosition, wxSize( 100,-1 ), ccns, 0 );
|
|
108 bSizerMoveTo->Add( m_comboBoxCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
2
|
109
|
3
|
110 m_buttonSetDir = new wxButton( this, ID_STDIR, wxT("フォルダ指定"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
111 bSizerMoveTo->Add( m_buttonSetDir, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
112
|
|
113 m_buttonMkDir = new wxButton( this, ID_MKDIR, wxT("フォルダ作成"), wxDefaultPosition, wxDefaultSize, 0 );
|
2
|
114 bSizerMoveTo->Add( m_buttonMkDir, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
115
|
|
116 bSizerTop->Add( bSizerMoveTo, 0, 0, 5 );
|
|
117
|
|
118 wxBoxSizer* bSizerDoMove;
|
|
119 bSizerDoMove = new wxBoxSizer( wxHORIZONTAL );
|
|
120
|
|
121 m_staticTextDummy = new wxStaticText( this, wxID_ANY, wxT("移動先ふぉるだ"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
122 m_staticTextDummy->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ) );
|
|
123
|
|
124 bSizerDoMove->Add( m_staticTextDummy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
125
|
|
126 m_textCtrlMoveDir = new wxTextCtrl( this, ID_DIR, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
127 m_textCtrlMoveDir->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_INACTIVEBORDER ) );
|
|
128
|
|
129 bSizerDoMove->Add( m_textCtrlMoveDir, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
130
|
|
131 m_buttonDoMove = new wxButton( this, ID_DOMOVE, wxT("画像移動"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
132
|
|
133 bSizerDoMove->Add( m_buttonDoMove, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 );
|
|
134
|
|
135 bSizerTop->Add( bSizerDoMove, 0, wxEXPAND, 5 );
|
|
136
|
|
137 m_listCtrl = new wxListCtrl( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL );
|
4
|
138 wxListItem itemCol;
|
|
139 itemCol.SetText( wxT("通番") );
|
|
140 m_listCtrl->InsertColumn( 0, itemCol );
|
|
141 m_listCtrl->SetColumnWidth( 0, 100 );
|
|
142 itemCol.SetText( wxT("被保険者番号") );
|
|
143 m_listCtrl->InsertColumn( 1, itemCol );
|
|
144 m_listCtrl->SetColumnWidth( 1, 180 );
|
|
145 itemCol.SetText( wxT("ファイル数") );
|
|
146 m_listCtrl->InsertColumn( 2, itemCol );
|
|
147 m_listCtrl->SetColumnWidth( 1, 100 );
|
2
|
148 bSizerTop->Add( m_listCtrl, 1, wxALL|wxEXPAND, 5 );
|
|
149
|
|
150 this->SetSizer( bSizerTop );
|
|
151 this->Layout();
|
|
152
|
|
153 this->Centre( wxBOTH );
|
|
154 m_buttonDetWhite->SetFocus();
|
|
155 }
|
|
156
|
|
157 // destructor
|
|
158 MyFrame::~MyFrame()
|
|
159 {
|
|
160 }
|
|
161
|
|
162 // Event Table
|
|
163 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
|
|
164 EVT_SIZE( MyFrame::OnSize )
|
|
165 EVT_MOVE( MyFrame::OnMove )
|
|
166 EVT_MENU( wxID_EXIT, MyFrame::OnQuit )
|
|
167 EVT_MENU( wxID_ABOUT, MyFrame::OnAbout )
|
4
|
168 EVT_MENU( ID_OPWORK, MyFrame::OnOpenWorkDir )
|
2
|
169 EVT_BUTTON( ID_DTWHITE, MyFrame::OnDetectWhite )
|
4
|
170 EVT_BUTTON( ID_STDIR, MyFrame::SetDir )
|
|
171 EVT_BUTTON( ID_MKDIR, MyFrame::MakeDir )
|
|
172 EVT_BUTTON( ID_DOMOVE, MyFrame::MoveImages )
|
5
|
173 EVT_LIST_ITEM_ACTIVATED( ID_LIST, MyFrame::OnOpenHhsDir )
|
2
|
174 EVT_CLOSE( MyFrame::SaveConfig )
|
|
175 END_EVENT_TABLE()
|
|
176
|
|
177 // Event Handlers
|
|
178 /* サイズ変更 */
|
|
179 void MyFrame::OnSize(wxSizeEvent& event)
|
|
180 {
|
|
181 this->Refresh( true, NULL );
|
|
182 TellLocation();
|
|
183 event.Skip();
|
|
184 }
|
|
185 /* ウィンドウ移動 */
|
|
186 void MyFrame::OnMove(wxMoveEvent& WXUNUSED(event))
|
|
187 {
|
|
188 TellLocation();
|
|
189 return;
|
|
190 }
|
|
191 /* ウィンドウ位置とサイズを表示 */
|
|
192 void MyFrame::TellLocation( void )
|
|
193 {
|
|
194 wxRect r = this->GetRect();
|
|
195 int x = r.GetX();
|
|
196 int y = r.GetY();
|
|
197 int w = r.GetWidth();
|
|
198 int h = r.GetHeight();
|
|
199 SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 2 );
|
|
200 }
|
|
201 /* 終了 */
|
|
202 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
203 {
|
|
204 Close(true);
|
|
205 }
|
|
206
|
|
207 /* バージョン情報 */
|
|
208 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
209 {
|
|
210 wxMessageBox(
|
|
211 wxString::Format(
|
|
212 wxT("Version %d.%d ( build %d ) by %s\n")
|
|
213 wxT("running under %s."),
|
|
214 VER, REV, BLD, wxVERSION_STRING,
|
|
215 wxGetOsDescription().c_str()
|
|
216 ),
|
|
217 wxT("About this program"), wxOK | wxICON_INFORMATION, this );
|
|
218 }
|
|
219
|
|
220 /* 白紙検知 */
|
|
221 void MyFrame::OnDetectWhite(wxCommandEvent& WXUNUSED(event))
|
|
222 {
|
|
223 FrameDelWhite* dw = new FrameDelWhite( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxCAPTION|wxFRAME_NO_TASKBAR|wxMAXIMIZE_BOX|wxRESIZE_BORDER );
|
|
224 dw->SetMinSize( wxSize( 580, 680 ) );
|
|
225
|
|
226 dw->m_dir = m_dirPickerWork->GetPath();
|
|
227 dw->SetTitle( wxT("Delete White Sheet - ") + dw->m_dir );
|
|
228 dw->LoadImages();
|
|
229
|
|
230 dw->Show(true);
|
|
231 }
|
|
232
|
3
|
233 /* 移動先フォルダセット */
|
|
234 void MyFrame::SetDir(wxCommandEvent& WXUNUSED(event))
|
|
235 {
|
|
236 wxString dir;
|
|
237 dir.Append( m_comboBoxMoveDrive->GetValue() );
|
|
238 dir.Append( wxFILE_SEP_PATH );
|
|
239 wxDateTime dt = m_datePickerCcn->GetValue();
|
|
240 dir.Append( dt.Format(wxT("%Y%m%d")) );
|
|
241 dir.Append( wxFILE_SEP_PATH );
|
|
242 dir.Append( m_comboBoxCcn->GetValue() );
|
|
243 m_textCtrlMoveDir->SetValue( dir );
|
|
244 }
|
|
245
|
4
|
246 /* 移動先フォルダ作成 */
|
3
|
247 void MyFrame::MakeDir(wxCommandEvent& WXUNUSED(event))
|
|
248 {
|
4
|
249 wxString dirname = m_textCtrlMoveDir->GetValue();
|
|
250 wxString ccn = m_comboBoxCcn->GetValue();
|
|
251 if ( dirname.Len() < 15 || ccn.IsEmpty() ) {
|
|
252 wxMessageBox(wxT("フォルダを指定してください."));
|
|
253 return;
|
|
254 }
|
|
255
|
|
256 wxStringTokenizer tkz( dirname, wxFILE_SEP_PATH );
|
|
257 wxString d;
|
|
258 while ( tkz.HasMoreTokens() ) {
|
|
259 d.Append( tkz.GetNextToken() );
|
|
260 d.Append( wxFILE_SEP_PATH );
|
|
261 if ( !wxDirExists( d ) ) wxMkdir( d );
|
|
262 }
|
3
|
263 }
|
|
264
|
4
|
265 /* 画像移動 */
|
|
266 void MyFrame::MoveImages(wxCommandEvent& WXUNUSED(event))
|
2
|
267 {
|
4
|
268 wxString dirname = m_textCtrlMoveDir->GetValue();
|
|
269 wxString ccn = m_comboBoxCcn->GetValue();
|
|
270 if ( dirname.IsEmpty() || ccn.IsEmpty() ) {
|
|
271 wxMessageBox(wxT("フォルダを指定してください."));
|
|
272 return;
|
|
273 }
|
|
274
|
|
275 dirname.Append( wxFILE_SEP_PATH );
|
|
276 if ( !wxDirExists( dirname ) ) {
|
|
277 wxMessageBox(wxT("フォルダが存在しません."));
|
|
278 return;
|
|
279 }
|
|
280
|
|
281 wxString workdir = m_dirPickerWork->GetPath();
|
|
282 wxDir dir( workdir );
|
|
283 if ( !dir.IsOpened() ) return;
|
|
284
|
|
285 wxString filename;
|
|
286 bool cout = dir.GetFirst( &filename, wxT("*.jpg"), wxDIR_FILES );
|
|
287
|
|
288 int cnt=0, r=0;
|
|
289 wxString hhs;
|
|
290 m_listCtrl->DeleteAllItems();
|
|
291 while ( cout ) {
|
|
292 wxString from = workdir + wxFILE_SEP_PATH + filename;
|
|
293 if ( IsMarksheet( from ) ) {
|
|
294 hhs = GuessHhs( from );
|
|
295 wxString d = dirname + hhs;
|
|
296 wxMkdir( d );
|
|
297 m_listCtrl->InsertItem( r, wxString::Format(wxT("%d"),r+1) );
|
|
298 m_listCtrl->SetItem( r, 1, hhs, -1 ); // 被保険者番号
|
|
299 m_listCtrl->SetItem( r-1, 2, wxString::Format(wxT("%d"),cnt), -1 ); // ファイル数
|
|
300 if ( r % 2 ) m_listCtrl->SetItemBackgroundColour( r, wxColour(wxT("WHEAT")) );
|
|
301 r++;
|
|
302 cnt=0;
|
|
303 }
|
|
304 if ( hhs.IsEmpty() ) {
|
|
305 wxMessageBox(wxT("マークシートの画像ファイルを確認してください."));
|
|
306 return;
|
|
307 }
|
|
308 wxString to = dirname + wxFILE_SEP_PATH + hhs + wxFILE_SEP_PATH + filename;
|
|
309 wxRenameFile( from, to, false );
|
|
310 // write log
|
|
311 cout = dir.GetNext( &filename );
|
|
312 cnt++;
|
|
313 }
|
|
314 m_listCtrl->SetItem( r-1, 2, wxString::Format(wxT("%d"),cnt), -1 ); // ファイル数
|
|
315 if ( cnt < 5 ) m_listCtrl->SetItemTextColour( r, *wxRED );
|
5
|
316 if ( cnt > 5 ) m_listCtrl->SetItemTextColour( r, *wxBLUE );
|
4
|
317
|
|
318 wxString cmd = wxT("explorer ") + dirname;
|
|
319 wxExecute( cmd );
|
|
320 }
|
|
321
|
5
|
322 /* 被保険者のフォルダを開く */
|
6
|
323 void MyFrame::OnOpenHhsDir(wxListEvent& event)
|
5
|
324 {
|
|
325 wxString hhsdir = m_textCtrlMoveDir->GetValue();
|
|
326 hhsdir.Append( wxFILE_SEP_PATH );
|
6
|
327
|
|
328 wxListItem item = event.GetItem();
|
|
329 item.SetColumn(1);
|
|
330 item.SetMask(wxLIST_MASK_TEXT);
|
|
331 m_listCtrl->GetItem( item );
|
5
|
332 hhsdir.Append( item.GetText() );
|
|
333 wxMessageBox(hhsdir);
|
|
334 //wxString execmd = wxT("explorer ") + hhsdir;
|
|
335 }
|
|
336
|
4
|
337 /* 作業フォルダを開く */
|
|
338 void MyFrame::OnOpenWorkDir(wxCommandEvent& WXUNUSED(event))
|
|
339 {
|
|
340 wxString workdir = m_dirPickerWork->GetPath();
|
|
341 wxString execmd = wxT("explorer ") + workdir;
|
2
|
342 wxExecute( execmd );
|
|
343 }
|
|
344
|
|
345
|
|
346 /* 設定を保存 */
|
|
347 void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event))
|
|
348 {
|
|
349 if ( !IsIconized() && !IsMaximized() ) {
|
|
350 wxGetApp().rect = this->GetRect();
|
|
351 }
|
|
352 wxGetApp().dir = m_dirPickerWork->GetPath();
|
|
353
|
|
354 Destroy();
|
|
355 }
|
|
356
|