36
36
BEGIN_EVENT_TABLE(frmExport, pgDialog)
37
EVT_TEXT(XRCID("txtFilename"), frmExport::OnChange)
38
EVT_RADIOBUTTON(XRCID("rbQuoteNone"), frmExport::OnChange)
39
EVT_RADIOBUTTON(XRCID("rbQuoteStrings"),frmExport::OnChange)
40
EVT_RADIOBUTTON(XRCID("rbQuoteAll"), frmExport::OnChange)
41
EVT_BUTTON(XRCID("btnFilename"), frmExport::OnBrowseFile)
42
EVT_BUTTON(wxID_HELP, frmExport::OnHelp)
43
EVT_BUTTON(wxID_OK, frmExport::OnOK)
44
EVT_BUTTON(wxID_CANCEL, frmExport::OnCancel)
37
EVT_TEXT(XRCID("txtFilename"), frmExport::OnChange)
38
EVT_RADIOBUTTON(XRCID("rbQuoteNone"), frmExport::OnChange)
39
EVT_RADIOBUTTON(XRCID("rbQuoteStrings"), frmExport::OnChange)
40
EVT_RADIOBUTTON(XRCID("rbQuoteAll"), frmExport::OnChange)
41
EVT_BUTTON(XRCID("btnFilename"), frmExport::OnBrowseFile)
42
EVT_BUTTON(wxID_HELP, frmExport::OnHelp)
43
EVT_BUTTON(wxID_OK, frmExport::OnOK)
44
EVT_BUTTON(wxID_CANCEL, frmExport::OnCancel)
49
49
frmExport::frmExport(wxWindow *p)
53
wxWindowBase::SetFont(settings->GetSystemFont());
54
LoadResource(p, wxT("frmExport"));
58
appearanceFactory->SetIcons(this);
59
cbQuoteChar->Disable();
63
bool uc=settings->GetExportUnicode();
64
rbUnicode->SetValue(uc);
65
rbLocal->SetValue(!uc);
67
bool isCrLf=settings->GetExportRowSeparator() == wxT("\r\n");
68
rbCRLF->SetValue(isCrLf);
69
rbLF->SetValue(!isCrLf);
71
int qt=settings->GetExportQuoting();
73
rbQuoteNone->SetValue(qt == 0);
74
rbQuoteStrings->SetValue(qt == 1);
75
rbQuoteAll->SetValue(qt == 2);
77
cbColSeparator->SetValue(settings->GetExportColSeparator());
80
cbQuoteChar->SetValue(settings->GetExportQuoteChar());
83
settings->Read(wxT("Export/LastFile"), &val, wxEmptyString);
84
txtFilename->SetValue(val);
53
wxWindowBase::SetFont(settings->GetSystemFont());
54
LoadResource(p, wxT("frmExport"));
58
appearanceFactory->SetIcons(this);
59
cbQuoteChar->Disable();
63
bool uc = settings->GetExportUnicode();
64
rbUnicode->SetValue(uc);
65
rbLocal->SetValue(!uc);
67
bool isCrLf = settings->GetExportRowSeparator() == wxT("\r\n");
68
rbCRLF->SetValue(isCrLf);
69
rbLF->SetValue(!isCrLf);
71
int qt = settings->GetExportQuoting();
73
rbQuoteNone->SetValue(qt == 0);
74
rbQuoteStrings->SetValue(qt == 1);
75
rbQuoteAll->SetValue(qt == 2);
77
cbColSeparator->SetValue(settings->GetExportColSeparator());
80
cbQuoteChar->SetValue(settings->GetExportQuoteChar());
83
settings->Read(wxT("Export/LastFile"), &val, wxEmptyString);
84
txtFilename->SetValue(val);
91
91
frmExport::~frmExport()
97
97
void frmExport::OnHelp(wxCommandEvent &ev)
99
DisplayHelp(wxT("export"), HELP_PGADMIN);
99
DisplayHelp(wxT("export"), HELP_PGADMIN);
103
103
void frmExport::OnChange(wxCommandEvent &ev)
105
cbQuoteChar->Enable(rbQuoteStrings->GetValue() || rbQuoteAll->GetValue());
106
btnOK->Enable(!txtFilename->GetValue().IsEmpty() && !cbColSeparator->GetValue().IsEmpty());
105
cbQuoteChar->Enable(rbQuoteStrings->GetValue() || rbQuoteAll->GetValue());
106
btnOK->Enable(!txtFilename->GetValue().IsEmpty() && !cbColSeparator->GetValue().IsEmpty());
110
110
void frmExport::OnOK(wxCommandEvent &ev)
112
settings->SetExportUnicode(rbUnicode->GetValue());
113
settings->SetExportRowSeparator(rbCRLF->GetValue() ? wxT("\r\n") : wxT("\n"));
114
settings->SetExportColSeparator(cbColSeparator->GetValue());
116
if (rbQuoteAll->GetValue())
117
settings->SetExportQuoting(2);
118
else if (rbQuoteStrings->GetValue())
119
settings->SetExportQuoting(1);
121
settings->SetExportQuoting(0);
123
settings->SetExportQuoteChar(cbQuoteChar->GetValue());
125
settings->Write(wxT("Export/LastFile"), txtFilename->GetValue());
112
settings->SetExportUnicode(rbUnicode->GetValue());
113
settings->SetExportRowSeparator(rbCRLF->GetValue() ? wxT("\r\n") : wxT("\n"));
114
settings->SetExportColSeparator(cbColSeparator->GetValue());
116
if (rbQuoteAll->GetValue())
117
settings->SetExportQuoting(2);
118
else if (rbQuoteStrings->GetValue())
119
settings->SetExportQuoting(1);
121
settings->SetExportQuoting(0);
123
settings->SetExportQuoteChar(cbQuoteChar->GetValue());
125
settings->Write(wxT("Export/LastFile"), txtFilename->GetValue());
136
136
bool frmExport::Export(pgSet *set)
138
ctlSQLResult *grid=0;
138
ctlSQLResult *grid = 0;
141
141
wxLogInfo(wxT("Exporting data from the grid"));
168
168
rowCount = grid->NumRows();
172
if (chkColnames->GetValue())
174
for (col=0 ; col < colCount ; col++)
179
line += cbColSeparator->GetValue();
181
if (rbQuoteStrings->GetValue() || rbQuoteAll->GetValue())
183
wxString qc = cbQuoteChar->GetValue();
172
if (chkColnames->GetValue())
174
for (col = 0 ; col < colCount ; col++)
177
line = wxEmptyString;
179
line += cbColSeparator->GetValue();
181
if (rbQuoteStrings->GetValue() || rbQuoteAll->GetValue())
183
wxString qc = cbQuoteChar->GetValue();
187
hdr = set->ColName(col);
187
hdr = set->ColName(col);
189
hdr = grid->OnGetItemText(-1, col+1).BeforeFirst('\n');
189
hdr = grid->OnGetItemText(-1, col + 1).BeforeFirst('\n');
191
hdr.Replace(qc, qc+qc);
192
line += qc + hdr + qc;
191
hdr.Replace(qc, qc + qc);
192
line += qc + hdr + qc;
197
line += set->ColName(col);
197
line += set->ColName(col);
199
line += grid->OnGetItemText(-1, col+1).BeforeFirst('\n');
199
line += grid->OnGetItemText(-1, col + 1).BeforeFirst('\n');
202
if (rbCRLF->GetValue())
207
if (rbUnicode->GetValue())
208
file.Write(line, wxConvUTF8);
211
buf = line.mb_str(wxConvLibc);
215
file.Write(line, wxConvLibc);
224
for (row=0 ; row < rowCount ; row++)
226
for (col=0 ; col < colCount ; col++)
231
line += cbColSeparator->GetValue();
233
bool needQuote=rbQuoteAll->GetValue();
202
if (rbCRLF->GetValue())
207
if (rbUnicode->GetValue())
208
file.Write(line, wxConvUTF8);
211
buf = line.mb_str(wxConvLibc);
215
file.Write(line, wxConvLibc);
224
for (row = 0 ; row < rowCount ; row++)
226
for (col = 0 ; col < colCount ; col++)
229
line = wxEmptyString;
231
line += cbColSeparator->GetValue();
233
bool needQuote = rbQuoteAll->GetValue();
237
text = set->GetVal(col);
238
typOid = set->ColTypClass(col);
237
text = set->GetVal(col);
238
typOid = set->ColTypClass(col);
242
text = grid->OnGetItemText(row, col+1);
242
text = grid->OnGetItemText(row, col + 1);
243
243
typOid = grid->colTypClasses[col];
246
if (!needQuote && rbQuoteStrings->GetValue())
248
// find out if string
251
case PGTYPCLASS_NUMERIC:
252
case PGTYPCLASS_BOOL:
261
wxString qc = cbQuoteChar->GetValue();
262
text.Replace(qc, qc+qc);
263
line += qc + text + qc;
268
if (rbCRLF->GetValue())
246
if (!needQuote && rbQuoteStrings->GetValue())
248
// find out if string
251
case PGTYPCLASS_NUMERIC:
252
case PGTYPCLASS_BOOL:
261
wxString qc = cbQuoteChar->GetValue();
262
text.Replace(qc, qc + qc);
263
line += qc + text + qc;
268
if (rbCRLF->GetValue())
273
if (rbUnicode->GetValue())
274
file.Write(line, wxConvUTF8);
277
buf = line.mb_str(wxConvLibc);
281
file.Write(line, wxConvLibc);
273
if (rbUnicode->GetValue())
274
file.Write(line, wxConvUTF8);
277
buf = line.mb_str(wxConvLibc);
281
file.Write(line, wxConvLibc);
291
"Data export incomplete.\n\n%d row contained characters that could not be converted to the local charset.\n\nPlease correct the data or try using UTF8 instead.",
292
"Data export incomplete.\n\n%d rows contained characters that could not be converted to the local charset.\n\nPlease correct the data or try using UTF8 instead.",
295
wxMessageBox(_("Data export completed successfully."), _("Export data"), wxICON_INFORMATION | wxOK);
291
"Data export incomplete.\n\n%d row contained characters that could not be converted to the local charset.\n\nPlease correct the data or try using UTF8 instead.",
292
"Data export incomplete.\n\n%d rows contained characters that could not be converted to the local charset.\n\nPlease correct the data or try using UTF8 instead.",
295
wxMessageBox(_("Data export completed successfully."), _("Export data"), wxICON_INFORMATION | wxOK);
301
301
void frmExport::OnCancel(wxCommandEvent &ev)
304
EndModal(wxID_CANCEL);
304
EndModal(wxID_CANCEL);
309
309
void frmExport::OnBrowseFile(wxCommandEvent &ev)
314
if (txtFilename->GetValue().IsEmpty())
315
directory = wxGetHomeDir();
318
directory = wxFileName(txtFilename->GetValue()).GetPath();
319
filename = wxFileName(txtFilename->GetValue()).GetFullName();
314
if (txtFilename->GetValue().IsEmpty())
315
directory = wxGetHomeDir();
318
directory = wxFileName(txtFilename->GetValue()).GetPath();
319
filename = wxFileName(txtFilename->GetValue()).GetFullName();
323
wxFileDialog file(this, _("Select export filename"), directory, filename,
324
_("CSV files (*.csv)|*.csv|Data files (*.dat)|*.dat|All files (*.*)|*.*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
323
wxFileDialog file(this, _("Select export filename"), directory, filename,
324
_("CSV files (*.csv)|*.csv|Data files (*.dat)|*.dat|All files (*.*)|*.*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
326
wxFileDialog file(this, _("Select export filename"), directory, filename,
327
_("CSV files (*.csv)|*.csv|Data files (*.dat)|*.dat|All files (*)|*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
326
wxFileDialog file(this, _("Select export filename"), directory, filename,
327
_("CSV files (*.csv)|*.csv|Data files (*.dat)|*.dat|All files (*)|*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
330
if (file.ShowModal() == wxID_OK)
332
txtFilename->SetValue(file.GetPath());
330
if (file.ShowModal() == wxID_OK)
332
txtFilename->SetValue(file.GetPath());