00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef HK_IMPORTCSV
00012 #define HK_IMPORTCSV
00013 #include <iostream>
00014 #include <fstream>
00015 #include "hk_class.h"
00016 #include "hk_datasource.h"
00017 #include "hk_dsvisible.h"
00018 #include "hk_column.h"
00019 #include <vector>
00020
00021 using namespace std;
00022
00023 class hk_column;
00024
00025 typedef class colstruct
00026 {
00027 public:
00028 colstruct(void){col=NULL;}
00029 hk_string colname;
00030 hk_column* col;
00031 int currentvalue;
00032 } colstruct;
00041 class hk_importcsv:public hk_dsvisible
00042 {
00043 public:
00044 hk_importcsv(void);
00045 virtual ~hk_importcsv(void);
00046
00047
00052 bool execute(enum_interaction i=interactive);
00056 void set_filedefinition(const hk_string& textdelimiter="\"",const hk_string& betweenfields=",", const hk_string& rowdelimiter="\n",const hk_string& datetimeformat="",const hk_string& dateformat="",const hk_string& timeformat="", const hk_string& charset="",const hk_string& locale="");
00060 void set_filename(const hk_string& filename);
00065 void set_firstrow_contains_fieldnames(bool f=true);
00071 void set_append_rows(bool f=false);
00075 void set_create_new_table(bool n=true);
00080 void add_columnname(const hk_string& col);
00081 void clear_columnlist(void);
00082 void set_detect_autoinc(bool);
00083 bool detect_autoinc(void) const;
00084 hk_string textdelimiter(void){return p_textdelimiter;}
00085 hk_string betweenfield(void) {return p_betweenfields;}
00086 hk_string rowdelimiter(void) {return p_rowdelimiter;}
00087 hk_string datetimeformat(void) {return p_datetimeformat;}
00088 hk_string dateformat(void) {return p_dateformat;}
00089 hk_string timeformat(void) {return p_timeformat;}
00090 hk_string filelocale(void) {return p_locale;}
00091 hk_string filecharset(void){return p_charset;}
00092 void set_overwrite_table(bool);
00093 bool overwrite_table(void);
00094 vector<hk_string>* create_valuelist( hk_string& row);
00095 void get_line(ifstream&,hk_string&);
00096
00097 protected:
00098 void set_progressdialog(progress_dialogtype* progressdialog);
00099 progress_dialogtype* progressdialog(void)const;
00100 void set_columns(void);
00101 void create_automatic_columns(void);
00102 bool initialize_table(enum_interaction);
00103 virtual bool before_columns_deleted(void);
00108 virtual bool widget_specific_after_new_row(void);
00109
00110 private:
00111 void reset(void);
00112 bool p_create_new_table;
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 hk_column::enum_columntype interpret_columntype(hk_string&f);
00123 ifstream* p_filestream;
00124 hk_string p_filename;
00125 hk_string p_textdelimiter;
00126 hk_string p_rowdelimiter;
00127 hk_string p_betweenfields;
00128 hk_string p_charset;
00129 hk_string p_locale;
00130 bool p_firstrow_contains_fieldnames;
00131 vector<hk_string> p_valuelist;
00132 vector<colstruct> p_columnlist;
00133 bool p_datamode;
00134 bool p_cancelimport;
00135 bool p_overwrite;
00136 bool p_detect_autoinc;
00137 hk_datasource::enum_accessmode p_accessmode;
00138 hk_string p_datetimeformat,p_dateformat,p_timeformat;
00139 progress_dialogtype* p_progressdialog;
00140 };
00141 #endif