1. Export of DB files
Private voidInsertdb (DataTable DT,stringFileName) { Try { stringUserIDs =string. Empty; string[] str = CcbUserName.Text.Split (','); for(ints =0; s < Str. Length; s++) {UserIDs+ = GetUserId (Str[s]. Trim ()) +"',"; } userids= Userids.substring (0, Userids.length-1); if(string. IsNullOrEmpty (UserIDs)) {return; } Sqlitebaseclass SQLite=NewSqlitebaseclass (FileName); Try{sqlite.creatdatabase ();//Create a databaseSqlite. Sqliteconn =NewSystem.Data.SQLite.SQLiteConnection (SQLite). Strconntion); Sqlite. Sqliteconn.open (); //Create a tableSqlite.creatdatabasetable ("CREATE TABLE gpsinfo ([id] CHAR (+), [Gpstime] Datetime,[lon] Double,[lat] double,[speed] double,[direction] DOUBLE, [Sealevel] Double,[uploaded] int,[totallicheng] nvarchar ())"); Sqlite.creatdatabasetable ("CREATE TABLE sysparamters ([param] NVARCHAR (not Null,[pvalue] NVARCHAR ()"); Sqlite. strTableName="sysparamters"; //inserting GPS DataSqlite. strTableName ="Gpsinfo"; stringFields ="Id,gpstime,lon,lat,speed,direction,sealevel,totallicheng";//Field List stringValues =string. Empty;//Data ListUiprogressbar1.maximum =dt. Rows.Count; for(inti =0; i < dt. Rows.Count; i++) { //convert array data to, split string[] STRs = dt. Rows[i]. Itemarray.select (w = w.tostring ()). toarray<string>(); //time type in db to convert, or read the Times wrongDateTime date = convert.todatetime (dt. rows[i]["Time"]); Values="'"+ strs[0] +"', '"+ Date. ToString ("s") +"', '"+string. Join ("', '", STRs,3,6) +"'"; Sqlite.insertfielddata (fields, values);//Inserting DataUiprogressbar1.value =i; System.Windows.Forms.Application.DoEvents (); } } Catch(Exception ex) {Throw NewException (ex. Message); } finally { if(sqlite!=NULL&&sqlite. sqliteconn!=NULL) {SQLite. Sqliteconn.close (); }} msgboxshow.showinformation ("Export Success! "); } Catch(Exception ex) {msgboxshow.showwarning ("Export Error:"+Ex. Message); } }
2. Import of DB files
//Get DB data
private void Getdbdata (object sender, Waitwindoweventargs e) {try {i F (E.arguments.count > 0) {//Create SQLite operation Sqlitebaseclass SQLite = New Sqlitebaseclass (E.arguments[0]. ToString ()); Sqlite. Sqliteconn = new System.Data.SQLite.SQLiteConnection (SQLite. Strconntion); Sqlite. Sqliteconn.open (); Query format is correct string Strgps = "Select Id,gpstime,lon,lat,speed,direction,totallicheng,sealevel from Gpsinf o Limit 1 "; String Strsys = "Select Param,pvalue from Sysparamters"; DataSet Gpsset = Sqlite.getdatasetquerycontsql (STRGPS); DataSet Sysset = Sqlite.getdatasetquerycontsql (Strsys); if (Gpsset = = NULL | | Sysset = = NULL | | Gpsset.tables[0]. Rows.Count <= 0) {msgboxshow.showinformation ("DB file format error or no data present"); Return }//Get data string strgpsinfo = "Select ID as Inspector, gpstime as time, Lon as longitude, lat as latitude, sp Eed as speed, direction as direction, "+" Totallicheng as total mileage, sealevel as elevation from Gpsinfo ORDER by Gpstime "; DataTable Gpsinfodt = Sqlite.getdatasetquerycontsql (strgpsinfo). Tables[0]; Calculate total Mileage E.result = Calculatetotallicheng (Gpsinfodt); }} catch (Exception ex) {msgboxshow.showwarning ("Open db File Error:" + ex. Message); } }
C # implements import and export capabilities for DB files