1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505:
| unit frmKonvSyncMain;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, DsCtrls, Menus, TBXDkPanels, SpTBXControls, DBXpress, Grids, DBGrids, DB, SqlExpr, ADODB, IniFiles, DCPcrypt2, DCPblockciphers, DCPtwofish, DCPsha256, RTdunRar3, JvComponentBase, JvPluginManager, MySQLDataset, MySQLServer, dcInternal, dcFileOperations, dcStdDialogs, dcDiskScanner, ComCtrls, HKStreamCol;
type TKonvSyncScript = class ScriptID: integer; ScriptAction: integer; SQLScript: TStringList; end;
type TfrmKonvSyncMainForm = class(TForm) mnuHauptMenu: TMainMenu; mnuDateiMenuItem: TMenuItem; mnuBeendenItem: TMenuItem; mnuAktionenItem: TMenuItem; mnuKonvSyncItem: TMenuItem; mnuExtrasItem: TMenuItem; mnuConfigItem: TMenuItem; mnuHelpItem: TMenuItem; mnuOpenHelpItem: TMenuItem; mnuTrenn1item: TMenuItem; mnuAboutitem: TMenuItem; dsgbAktion: TDsGroupBox; dslblFileNameInfo: TDsTitleLabel; txtFileName: TEdit; spbtnSelectFile: TSpeedButton; dsGbMySQlServerInfo: TDsGroupBox; lblServerHostNameIP: TLabel; txtHostNameIP: TEdit; lblServerUsername: TLabel; txtServerUserName: TEdit; lblServerPassword: TLabel; txtServerPassword: TEdit; rbtnDefaultServerPort: TRadioButton; rbtnPortSelect: TRadioButton; txtServerPort: TEdit; dsGbStatus: TDsGroupBox; sptbxPBarKonvertStatus: TSpTBXProgressBar; sptbxsbtnKonvertStart: TSpTBXSpeedButton; ADOConnection1: TADOConnection; ADOCommand1: TADOCommand; DataSource1: TDataSource; DBGrid1: TDBGrid; lblDBName: TLabel; txtServerDBName: TEdit; dsGbAccessInfo: TDsGroupBox; lblAccessFileInfo: TLabel; txtAccessFile: TEdit; sbtnAccessSelectFile: TSpeedButton; dsCbAuthentication: TDsCheckBox; lblAccessUser: TLabel; txtAccessUser: TEdit; lblAccessPassword: TLabel; txtAccessPassword: TEdit; DCP_twofish1: TDCP_twofish; ADOQuery1: TADOQuery; dRar31: TdRar3; mnuItemTrennExtra: TMenuItem; JvPluginManager1: TJvPluginManager; MySQLServer1: TMySQLServer; MySQLQuery1: TMySQLQuery; dcFileOperations1: TdcFileOperations; odSelectScriptFile: TdcOpenDialog; odSelectAccessFile: TdcOpenDialog; dcDiskScanner1: TdcDiskScanner; HKStreams1: THKStreams; procedure dRar31Error(Sender: TObject; Error: Integer); procedure JvPluginManager1NewCommand(Sender: TObject; ACaption, AHint, AData: string; AShortCut: TShortCut; ABitmap: TBitmap; AEvent: TNotifyEvent); procedure sptbxsbtnKonvertStartClick(Sender: TObject); procedure sbtnAccessSelectFileClick(Sender: TObject); procedure dsCbAuthenticationClick(Sender: TObject); procedure spbtnSelectFileClick(Sender: TObject); procedure mnuBeendenItemClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); private tablename: string; truncate_table: boolean; SQLScriptFileName: string; SQLScriptAktion: integer; procedure parseKonverterVBScriptFile(Dateiname: String); procedure parseScriptFile(DateiName: String); function ConnectADO_Access(AccessFileName: string; AccessUserName: string; AccessPassword: string): boolean; function Connect_MySQL(MySQLHost: string; MySQLPort: string; MySQLUserName: string; MySQLPassword: string; MySQLDatabase: string): boolean; procedure DisconnectDB(); function SQLScriptExecute(ExecuteType: integer; Script: TStringList): boolean; public end;
var frmKonvSyncMainForm: TfrmKonvSyncMainForm; ConfigIniFile: TIniFile; ScriptFile1: TIniFile; SQLScript1: TStringList; SQLScript2: TStringList; SQLScript3: TStringList; AppPath: string; PluginsList: TStringList; SQLScriptA: array of TKonvSyncScript; ScriptFileCounter: integer = 0; SQLFileName: string;
const ADOConnectionStringPart1: string = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='; ADOConnectionStringPart2: string = ';Persist Security Info=False'; ADOConnectionStringPart3: string = ';USER ID='; ADOConnectionStringPart4: string = ';PASSWORD='; ADOConnectionStringPart5: string = ';Jet OLEDB:Database Password='; ADOConnectionStringFinal: string = ';';
implementation
{$R *.dfm}
procedure TfrmKonvSyncMainForm.FormCreate(Sender: TObject); var tempint: integer; passwordstring: string;
begin AppPath := ExtractFilePath(Application.ExeName); PluginsList := TStringList.Create(); ConfigIniFile := TIniFile.Create(AppPath + 'config.ini');
DCP_twofish1.InitStr('**********',TDCP_sha256);
txtAccessFile.Text := ConfigIniFile.ReadString('access','host','serverdt.mdb'); dsCbAuthentication.Checked := ConfigIniFile.ReadBool('access','authEnabled',false); txtAccessUser.Text := ConfigIniFile.ReadString('access','authUser','root'); passwordstring := ConfigIniFile.ReadString('access','authPass',''); txtAccessPassword.Text := DCP_twofish1.DecryptString(passwordstring);
txtHostNameIP.Text := ConfigIniFile.ReadString('mysql','host','localhost'); txtServerUserName.Text := ConfigIniFile.ReadString('mysql','user','root'); passwordstring := ConfigIniFile.ReadString('mysql','pwd','r0403land82'); txtServerPassword.Text := DCP_twofish1.DecryptString(passwordstring); txtServerDBName.Text := ConfigIniFile.ReadString('mysql','database','lttddb'); tempint := ConfigIniFile.ReadInteger('mysql','port',3306); if tempint = 3306 then begin rbtnDefaultServerPort.Checked := true; txtServerPort.Text := ''; end else rbtnPortSelect.Checked := true; txtServerPort.Text := IntToStr(tempint);
ConfigIniFile.Free; DCP_twofish1.Burn();
end;
procedure TfrmKonvSyncMainForm.FormClose(Sender: TObject; var Action: TCloseAction); begin ConfigIniFile := TIniFile.Create(AppPath + 'config.ini');
DCP_twofish1.InitStr('**********',TDCP_sha256);
ConfigIniFile.WriteString('access','host',txtAccessFile.Text); ConfigIniFile.WriteBool('access','authEnabled',dsCbAuthentication.Checked); ConfiginiFile.WriteString('access','authUser',txtAccessUser.Text); ConfigIniFile.WriteString('access','authPass',DCP_twofish1.EncryptString(txtAccessPassword.Text));
ConfigIniFile.WriteString('mysql','host',txtHostNameIP.Text); ConfigIniFile.WriteString('mysql','user',txtServerUserName.Text); ConfigIniFile.WriteString('mysql','pwd',DCP_twofish1.EncryptString(txtServerPassword.Text)); ConfigIniFile.WriteString('mysql','database',txtServerDBName.Text); if rbtnDefaultServerPort.Checked then begin ConfigIniFile.WriteInteger('mysql','port',3306); end else ConfigIniFile.WriteInteger('mysql','port',StrToInt(txtServerPort.Text));
ConfigIniFile.Free; DCP_twofish1.Burn();
DisconnectDB(); end;
procedure TfrmKonvSyncMainForm.mnuBeendenItemClick(Sender: TObject); begin Close(); end;
procedure TfrmKonvSyncMainForm.spbtnSelectFileClick(Sender: TObject); begin odSelectScriptFile.InitialDir := AppPath; if odSelectScriptFile.Execute() then begin txtFileName.Text := odSelectScriptFile.FileName;
if StrComp(PCHar(ExtractFileExt(txtFileName.Text)), '.script') = 0 then begin parseKonverterVBScriptFile(txtFileName.Text); end else parseScriptFile(txtFileName.Text); end else txtFileName.Text := ''; end;
procedure TfrmKonvSyncMainForm.dsCbAuthenticationClick(Sender: TObject); begin if dsCbAuthentication.Checked = false then begin lblAccessUser.Enabled := false; lblAccessPassword.Enabled := false; txtAccessUser.Enabled := false; txtAccessPassword.Enabled := false; end;
if dsCbAuthentication.Checked = true then begin lblAccessUser.Enabled := true; lblAccessPassword.Enabled := true; txtAccessUser.Enabled := true; txtAccessPassword.Enabled := true; end; end;
procedure TfrmKonvSyncMainForm.sbtnAccessSelectFileClick(Sender: TObject); begin odSelectAccessFile.InitialDir := AppPath; if odSelectAccessFile.Execute() then begin txtAccessFile.Text := odSelectAccessFile.FileName; end else txtFileName.Text := '';
end;
procedure TfrmKonvSyncMainForm.parseKonverterVBScriptFile(Dateiname: string); var ScriptFile1: TIniFile; tempstr: string; begin ScriptFile1 := TIniFile.Create(Dateiname); tablename := ScriptFile1.ReadString('script','table',''); tempstr := ScriptFile1.ReadString('script','truncate_table','no'); if StrComp(PChar(tempstr), 'yes') = 0 then begin truncate_table := true; end else truncate_table := false; SQLScriptFileName := ScriptFile1.ReadString('script','script1','');
tempstr := ScriptFile1.ReadString('script','script1_run','copy'); if StrComp(PChar(tempstr), 'copy') = 0 then SQLScriptAktion := 1; if StrComp(PChar(tempstr), 'access') = 0 then SQLScriptAktion := 2; if StrComp(PChar(tempstr), 'mysql') = 0 then SQLScriptAktion := 3;
ScriptFile1.Free();
SQLScript1 := TStringList.Create(); SQLScript1.LoadFromFile(ExtractFilePath(txtFileName.Text)+ SQLScriptFileName);
MessageDlg('Script unterstützung für die Alten VB-Scripte deaktiviert!',mtInformation, [mbOK],0); end;
procedure TfrmKonvSyncMainForm.parseScriptFile(DateiName: String); var ScriptPath: string; ScriptConfig: TIniFile; int :integer; ScriptActionW: integer;
begin ScriptPath := ExtractFilePath(Application.ExeName); ScriptPath := ScriptPath + 'Script'; dRar31.TargetDirectory := ScriptPath; dRar31.Path2UnrarDll := AppPath; dRar31.NameofUnrarDll := 'unrar.dll'; dRar31.ArchiveFileName := DateiName; ScriptConfig := TIniFile.Create(ScriptPath + '\script_config.ini'); ScriptFileCounter := ScriptConfig.ReadInteger('ScriptFiles','Count',0);
if ScriptFileCounter <> 0 then begin SetLength(SQLScriptA, ScriptFileCounter);
for int := 0 to ScriptFileCounter - 1 do begin if int < 10 then begin SQLFileName := ScriptPath + '\' + ScriptConfig.ReadString('ScriptFiles','File0'+IntToStr(int+1),''); ScriptActionW := ScriptConfig.ReadInteger('ScriptFiles','File0'+IntToStr(int+1)+'_Aktion',0); end else SQLFileName := ScriptPath + '\' + ScriptConfig.ReadString('ScriptFiles','File'+IntToStr(int+1),''); ScriptActionW := ScriptConfig.ReadInteger('ScriptFiles','File'+IntToStr(int+1)+'_Aktion',0); SQLScriptA[int].ScriptID := (int + 1); SQLScriptA[int].ScriptAction := ScriptActionW; SQLScriptA[int].SQLScript.LoadFromFile(SQLFileName); end; end else ShowMessage('Die Script-Datei schein ungültig zu sein!');
sptbxsbtnKonvertStart.Enabled := true; end;
function TfrmKonvSyncMainForm.ConnectADO_Access(AccessFileName: string; AccessUserName: string; AccessPassword: string): boolean; begin ADOConnection1.Close();
if dsCbAuthentication.Checked then begin ADOConnection1.ConnectionString := ADOConnectionStringPart1 + AccessFileName + ADOConnectionStringPart2 + ADOConnectionStringPart3 + AccessUserName + ADOConnectionStringPart4 + AccessPassword; end else ADOConnection1.ConnectionString := ADOConnectionStringPart1 + AccessFileName + ADOConnectionStringPart2; ADOConnection1.Mode := cmShareDenyNone; ADOConnection1.LoginPrompt := false; try ADOConnection1.Open(); result := true; except result := false; end; end;
function TfrmKonvSyncMainForm.Connect_MySQL(MySQLHost: string; MySQLPort: string; MySQLUserName: string; MySQLPassword: string; MySQLDatabase: string): boolean; begin MySQLServer1.Disconnect();
MySQLServer1.Host := MySQLHost; MySQLServer1.Port := StrToInt(MySQLPort); MySQLServer1.UserName := MySQLUserName; MySQLServer1.Password := MySQLPassword; MySQLServer1.DatabaseName := mySQLDatabase;
MySQLServer1.Connect();
if MySQLServer1.Connected then begin result := true; end else result := false; end;
procedure TfrmKonvSyncMainForm.sptbxsbtnKonvertStartClick(Sender: TObject); var con1: boolean; con2: boolean; port: string; int, int2: integer;
begin con1 := ConnectADO_Access(txtAccessFile.Text, txtAccessUser.Text, txtAccessPassword.Text); if con1 = true then begin ShowMessage('Access - Datenbank - Verbindung Geöffnet!'); end else ShowMessage('Access - Datenbank - Verbindung Fehlgeschlagen!');
if rbtnPortSelect.Checked then begin port := txtServerPort.Text; end else port := IntToStr(3306); con2 := Connect_MySQL(txtHostNameIP.Text, port, txtServerUserName.Text, txtServerPassword.Text, txtServerDBName.Text); if con2 = true then begin ShowMessage('MySQL - Datenbank - Verbindung Geöffnet!'); end else ShowMessage('MySQL - Datenbank - Verbindung Fehlgeschlagen!');
for int := 0 to ScriptFileCounter - 1 do begin case SQLScriptA[int].ScriptAction of 0: SQLScriptExecute(1, SQLScriptA[int].SQLScript); 1: SQLScriptExecute(2, SQLScriptA[int].SQLScript); end; end; end;
procedure TfrmKonvSyncMainForm.DisconnectDB(); begin ADOCOnnection1.Close(); MySQLServer1.Disconnect(); MySQLServer1.Close(); end;
procedure TfrmKonvSyncMainForm.JvPluginManager1NewCommand(Sender: TObject; ACaption, AHint, AData: string; AShortCut: TShortCut; ABitmap: TBitmap; AEvent: TNotifyEvent); var Item : TMenuItem; begin Item := NewItem(ACaption, scNone, False, True, AEvent, 0, ''); mnuHauptMenu.Items[2].Add(Item); end;
function TfrmKonvSyncMainForm.SQLScriptExecute(ExecuteType: integer; Script: TStringList): boolean; var counter, counter2: integer; MySQLScript: TStringList; begin MySQLScript := TStringList.Create(); if ExecuteType = 1 then begin ADOQuery1.SQL := Script; for counter2 := 0 to SizeOf(Script) do begin ShowMessage(Script.Strings[counter2]); end; ADOQuery1.Active := true; end else ShowMessage(Script.Strings[0]); MySQLScript.Strings[0] := Script.Strings[0]; for counter := 0 to ADOQuery1.FieldCount - 1 do begin MySQLScript.Strings[0] := MySQLScript.Strings[0] + ADOQuery1.Fields[counter].Value; end; MySQLScript.Strings[0] := MySQLScript.Strings[0] + Script.Strings[1]; ShowMessage(MySQLScript.Strings[0]); MySQLQuery1.SQL := MySQLScript; MySQLQuery1.Active := true; end;
procedure TfrmKonvSyncMainForm.dRar31Error(Sender: TObject; Error: Integer); begin if error <> 10 then ShowMessage('Error ! : Code#'+inttostr(error)); end;
end. |