RTFormwork/项目代码/RTBasicsV1/D02针织坯布检验/spmain.pas

425 lines
11 KiB
ObjectPascal
Raw Permalink Normal View History

2024-07-07 09:35:27 +08:00
unit spmain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ComCtrls, ToolWin, ActnMan, ActnCtrls, ActnMenus, ActnList, DB,
ADODB, Grids, IniFiles, jpeg, ExtCtrls, Buttons, ImgList, StdCtrls, cxControls,
cxSplitter, MovePanel, SyncObjs, System.ImageList;
type
TMyThread = class(TThread)
protected
procedure Execute; override;
end;
const
keys = 'ljb^0122!@#*&^%$';
type
TFormMain = class(TForm)
StatusBar1: TStatusBar;
ADOConnection1: TADOConnection;
ImageList25: TImageList;
ImageList3: TImageList;
ImageList24: TImageList;
ADQ_Temp: TADOQuery;
Image_Tree: TImageList;
ADOQueryTmp: TADOQuery;
Timer2: TTimer;
MovePanel1: TMovePanel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Timer_link: TTimer;
procedure FormCreate(Sender: TObject);
procedure MNCloseClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ToolButton12Click(Sender: TObject);
procedure Panel1Click(Sender: TObject);
procedure Panel2Click(Sender: TObject);
procedure Panel3Click(Sender: TObject);
procedure Timer_linkTimer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
function intiData(): Boolean;
procedure GetServerDate();
public
ConDateBaseString: string;
V_User, V_UserID, User_Id, User_Name: string;
{ Public declarations }
// server, dtbase, user, pswd: String;
end;
var
FormMain: TFormMain;
gServerDate: TdateTime;
server, dtbase, user, pswd: string; {<7B><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD>}
gConString: string; <><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>}
gCurHandle: hwnd; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
newh: hwnd;
CriticalSection: TCriticalSection; {<7B><><EFBFBD><EFBFBD><EFBFBD>ٽ<EFBFBD>}
implementation
uses
logon, U_Link, U_iniParam;
{$R *.dfm}
procedure TMyThread.Execute;
begin
FreeOnTerminate := True;
CriticalSection.Enter;
try
with FormMain.ADOQueryTmp do
begin
close;
sql.Clear;
sql.Add('select getdate()');
open;
end;
except
try
with FormMain.ADOConnection1 do
begin
Connected := false;
ConnectionString := FormMain.ConDateBaseString;
LoginPrompt := false;
Connected := true;
end;
except
end;
end;
CriticalSection.Leave;
end;
function TFormMain.intiData(): Boolean;
var
mProdId: string; //<2F><>ǰ<EFBFBD><C7B0>Ʒ<EFBFBD><C6B7>
begin
SetLength(server, 255);
SetLength(dtbase, 255);
SetLength(user, 255);
SetLength(pswd, 255);
server := '';
dtbase := '';
user := 'sa';
pswd := 'rightsoft@123';
ADOConnection1.ConnectionString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
ConDateBaseString := ADOConnection1.ConnectionString;
try
frmLink := TfrmLink.create(self);
if frmLink.ShowModal = 1 then
begin
ADOConnection1.ConnectionString := frmLink.fADOConnString;
frmLink.hide;
end
else
begin
application.MessageBox('ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ', MB_ICONERROR);
PostMessage(Handle, WM_CLOSE, 0, 0);
frmLink.Release;
end;
except
application.MessageBox('ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ', MB_ICONERROR);
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
ConDateBaseString := ADOConnection1.ConnectionString;
Left := 0;
Top := 0;
Width := Screen.Width;
Height := Screen.Height;
try
ADOConnection1.Close;
ADOConnection1.Open;
Result := true;
except
result := false;
application.MessageBox('<27><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><><EFBFBD><EFBFBD>', mb_Ok + MB_ICONERROR);
PostMessage(self.handle, WM_CLOSE, 0, 0);
end;
end;
procedure TFormMain.FormCreate(Sender: TObject);
var
tmpstr: string;
begin
CriticalSection := TCriticalSection.Create;
if IsINIFile() then
ReadINIFile()
else
WriteINIFile;
if intiData() then
begin
GetServerDate();
// P_Tmp.Visible := True;
//P_Tmp.Align := AlClient;
FormLogon := TFormLogon.Create(self);
FormLogon.ShowModal;
end;
end;
procedure TFormMain.FormResize(Sender: TObject);
begin
//P_Tmp.Align := AlClient;
sendmessage(newh, 1034, 1, 0);
end;
procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction);
var
CanQuit: Boolean;
begin
sendmessage(newh, 1034, 4, 0);
if FormMain.MDICHildCount > 0 then
CanQuit := application.MessageBox('<27><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>Ҫ<EFBFBD>˳<EFBFBD><CBB3><EFBFBD>ǰϵͳ<CFB5><CDB3>?', '<27><>ʾ', mb_yesno + mb_IconQuestion) = idyes;
if CanQuit then
begin
Timer2.Enabled := false;
ADOConnection1.Close;
Action := CaFree;
end
else
Action := caNone;
end;
procedure TFormMain.MNCloseClick(Sender: TObject);
begin
close;
end;
procedure TFormMain.Timer1Timer(Sender: TObject);
begin
try
statusbar1.Panels[0].Text := '<27><>ǰʱ<C7B0>䣺' + datetimetostr(now);
except
end;
end;
procedure TFormMain.N2Click(Sender: TObject);
begin
end;
///////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
////////////////////////////////////////////////
procedure TFormMain.GetServerDate();
begin
with ADOQueryTmp do
begin
close;
sql.clear;
sql.Add('select getDate()as dt');
Open;
gServerDate := fieldByName('dt').AsDateTime;
close;
end;
end;
procedure TFormMain.Timer2Timer(Sender: TObject);
begin
FormMain.StatusBar1.Panels[0].Text := '<27><>ǰʱ<C7B0>䣺' + datetimetostr(now);
end;
procedure TFormMain.FormShow(Sender: TObject);
var
XSStr: string;
begin
try
IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'KnitInspFile.INI');
Panel1.Caption := IniFile.ReadString('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', <><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1', '<27>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>');
Panel3.Caption := IniFile.ReadString('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', <><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2', <><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
XSStr := IniFile.ReadString('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', <><C4A3><EFBFBD><EFBFBD>ʾ1', '1');
if XSStr = '1' then
begin
Panel1.Visible := True;
end
else
begin
Panel1.Visible := False;
end;
XSStr := IniFile.ReadString('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', <><C4A3><EFBFBD><EFBFBD>ʾ2', '1');
if XSStr = '1' then
begin
Panel3.Visible := True;
end
else
begin
Panel3.Visible := False;
end;
finally
IniFile.Free;
end;
Timer2.Enabled := True;
end;
procedure TFormMain.ToolButton12Click(Sender: TObject);
var
CanQuit: Boolean;
begin
sendmessage(newh, 1034, 4, 0);
if application.MessageBox('<27><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>Ҫ<EFBFBD>˳<EFBFBD><CBB3><EFBFBD>ǰϵͳ<CFB5><CDB3>?', '<27><>ʾ', mb_yesno + mb_IconQuestion) <> IDYES then
Exit;
ADOConnection1.Close;
Close;
end;
procedure TFormMain.Panel1Click(Sender: TObject);
type
TMyFunc = function(App: Tapplication; FormH: hwnd; FormID: integer; Language: integer; WinStyle: integer; GCode: Pchar; GName: Pchar; DataBase: Pchar; Title: PChar; Parameters1: PChar; Parameters2: PChar; Parameters3: PChar; Parameters4: PChar; Parameters5: PChar; Parameters6: PChar; Parameters7: PChar; Parameters8: PChar; Parameters9: PChar; Parameters10: PChar; DataBaseStr: PChar): hwnd; stdcall;
var
Tf: TMyFunc;
Tp: TFarProc;
Th: Thandle;
DllName, DllInt: string;
IniFile: TIniFile;
xx: string;
begin
//<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
//newh:=getForm(Application,1,ADOConnection1,PChar('sa'),PChar('dsa'));
//<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
// showMessage(intTostr(application.Handle));
ADOConnection1.Connected := False;
ADOConnection1.Connected := True;
{ with ADOQueryTmp do
begin
Close;
sql.Clear;
sql.Add('select * from SY_User where UserId='''+Trim(User_Id)+'''');
Open;
end;
if Trim(ADOQueryTmp.FieldByName('BanZu').AsString)='' then
begin
Application.MessageBox('<27><>ǰ<EFBFBD><C7B0>¼<EFBFBD>˰<EFBFBD><CBB0><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end; }
try
IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'KnitInspFile.INI');
DllName := IniFile.ReadString('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', 'DLL<4C>ļ<EFBFBD>1', 'TradeManagePB.dll');
DllInt := IniFile.ReadString('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', 'DLL<4C><4C><EFBFBD>ú<EFBFBD>1', '3');
finally
IniFile.Free;
end;
Th := LoadLibrary(PChar(DllName));
if Th > 0 then
begin
try
// Tp := GetProcAddress(Th, 'GetDllForm');
Tp := GetProcAddress(Th, PAnsichar(AnsiString('GetDllForm')));
if Tp <> nil then
begin
Tf := TMyFunc(Tp);
Tf(Application, 0, strtoint(DllInt), 0, 0, PChar(User_Id), PChar(User_Name), PChar(xx), PChar('55'), PChar(xx), PChar(xx), PChar(xx), PChar(xx), PChar(xx), PChar(xx), PChar(xx), PChar(xx), pchar(xx), PChar(xx), PChar(ConDateBaseString));
end
else
begin
ShowMessage('<27><>ӡִ<D3A1>д<EFBFBD><D0B4><EFBFBD>');
end;
finally
// FreeLibrary();
end;
end
else
begin
ShowMessage('<27>Ҳ<EFBFBD><D2B2><EFBFBD>' + Trim('dllname'));
end;
end;
procedure TFormMain.Panel2Click(Sender: TObject);
var
CanQuit: Boolean;
begin
sendmessage(newh, 1034, 4, 0);
if application.MessageBox('<27><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>Ҫ<EFBFBD>˳<EFBFBD><CBB3><EFBFBD>ǰϵͳ<CFB5><CDB3>?', '<27><>ʾ', mb_yesno + mb_IconQuestion) <> IDYES then
Exit;
ADOConnection1.Close;
Close;
end;
procedure TFormMain.Panel3Click(Sender: TObject);
type
TMyFunc = function(App: Tapplication; FormH: hwnd; FormID: integer; Language: integer; WinStyle: integer; GCode: Pchar; GName: Pchar; DataBase: Pchar; Title: PChar; Parameters1: PChar; Parameters2: PChar; Parameters3: PChar; Parameters4: PChar; Parameters5: PChar; Parameters6: PChar; Parameters7: PChar; Parameters8: PChar; Parameters9: PChar; Parameters10: PChar; DataBaseStr: PChar): hwnd; stdcall;
var
Tf: TMyFunc;
Tp: TFarProc;
Th: Thandle;
DllName, DllInt: string;
IniFile: TIniFile;
begin
//<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
//newh:=getForm(Application,1,ADOConnection1,PChar('sa'),PChar('dsa'));
//<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
// showMessage(intTostr(application.Handle));
ADOConnection1.Connected := False;
ADOConnection1.Connected := True;
{ with ADOQueryTmp do
begin
Close;
sql.Clear;
sql.Add('select * from SY_User where UserId='''+Trim(User_Id)+'''');
Open;
end;
if Trim(ADOQueryTmp.FieldByName('BanZu').AsString)='' then
begin
Application.MessageBox('<27><>ǰ<EFBFBD><C7B0>¼<EFBFBD>˰<EFBFBD><CBB0><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end; }
try
IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'KnitInspFile.INI');
DllName := IniFile.ReadString('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', 'DLL<4C>ļ<EFBFBD>2', 'TradeManagePB.dll');
DllInt := IniFile.ReadString('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', 'DLL<4C><4C><EFBFBD>ú<EFBFBD>2', '301');
finally
IniFile.Free;
end;
Th := LoadLibrary(PChar(DllName));
if Th > 0 then
begin
try
Tp := GetProcAddress(Th, 'GetDllForm');
if Tp <> nil then
begin
Tf := TMyFunc(Tp);
newh := Tf(Application, 0, strToint(DllInt), 0, 0, PChar(User_Id), PChar(User_Name), PChar(''), PChar(TToolButton(Sender).Caption), PChar(''), PChar(''), '', '', '', '', '', '', '', '', PChar(ConDateBaseString));
end
else
begin
ShowMessage('<27><>ӡִ<D3A1>д<EFBFBD><D0B4><EFBFBD>');
end;
finally
// FreeLibrary();
end;
end
else
begin
ShowMessage('<27>Ҳ<EFBFBD><D2B2><EFBFBD>' + Trim('dllname'));
end;
end;
procedure TFormMain.Timer_linkTimer(Sender: TObject);
begin
TMyThread.Create(False);
end;
procedure TFormMain.FormDestroy(Sender: TObject);
begin
CriticalSection.Free;
end;
end.