?? datam.pas
字號:
unit datam;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,Controls, Forms,
Dialogs, db,ADODB,Registry;
function user_check(users,psw:string):boolean;
function source_check:boolean;
function cachenosave(mDataSet:TCustomADODataSet):Boolean;
procedure WriteRegAutoRun(FileName:string);
function premission(users,pms:string):boolean;
function read_pms(jies,pmsfu:string):boolean;
function write_pms(jiese,pmsfun:string;value:boolean):boolean;
function create_sell_no(xtable:string):string;
function create_withdraw_no(ttable:string):string;
function create_change_no(htable:string):string;
function create_movein_no(jtable:string):string;
function create_moveout_no(ctable:string):string;
function recommit_sys(username,sdate,stime:string;lq:real):boolean;
function en_crypt(const InString:string; StartKey:Integer): string;
function de_crypt(const InString:string; StartKey:Integer): string;
procedure dynamicchangedisplay(X, Y: integer);
implementation
uses data,maind;
const StartKey=888;
var
user_query,pms_query :TADOQuery;
//判斷用戶是否正確
function user_check(users,psw:string):boolean;
begin
result:=false;
try
user_query:=TADOQuery.Create(APPLICATION.Owner);
user_query.Connection:=Data.Dataman.ADOCon;
user_query.sql.clear;
user_query.sql.add('select jiese from syslogin');
user_query.sql.add('where yonghu =:yh and mima =:mm');
user_query.Parameters.ParamByName('yh').Value:=users;
user_query.Parameters.ParamByName('mm').Value:=de_crypt(psw,StartKey);
try
user_query.close;
user_query.open;
except
result:=false;
showmessage('用戶表無法打開, 無法登陸!'); exit;
end;
if not user_query.IsEmpty then
result:=true;
finally
user_query.Free;
end;
end;
//判斷數(shù)據(jù)源是否連接成功
function source_check:boolean;
begin
result:=true;
try
Dataman.ADOCon.Connected := false;
dataman.ADOCon.ConnectionString:='';
with Dataman.ADOCon do
begin
Provider := 'SQLOLEDB.1'; //數(shù)據(jù)庫:SQL Server
Properties['Persist Security Info'].Value:=False;
Properties['Data Source'].Value :=trim(ini_load_data('數(shù)據(jù)庫設(shè)置','jspboy')); //服務(wù)器地址
Properties['User ID'].Value :=trim(ini_load_user('數(shù)據(jù)庫設(shè)置','sa')); //數(shù)據(jù)庫用戶名
Properties['Password'].Value :=trim(ini_load_psw('數(shù)據(jù)庫設(shè)置','')); //密碼
Properties['Initial Catalog'].Value := trim(ini_load_dataname('數(shù)據(jù)庫設(shè)置','myr'));//數(shù)據(jù)庫名
end;
Dataman.ADOCon.LoginPrompt := False;
Dataman.ADOCon.Provider := 'SQLOLEDB.1' ;
Dataman.ADOCon.Connected:=true;
except
on e:exception do
begin
application.MessageBox(pchar('無法連接數(shù)據(jù)庫!請先配置好數(shù)據(jù)庫!'+#13+#13+e.Message),'錯誤信息',16);
application.Terminate;
exit;
end;
end;
end;
//判斷緩沖區(qū)是否提交成功
function cachenosave(mDataSet:TCustomADODataSet):Boolean;
var
vFiltered: Boolean;
vFilterGroup: TFilterGroup;
vBookmark: tbookmarkstr;
begin
Result := False;
if not mDataSet.Active then Exit;
if mDataSet.LockType <> ltBatchOptimistic then Exit;
vBookmark := mDataSet.Bookmark;
mDataSet.DisableControls;
try
vFiltered:=mDataSet.Filtered;
vFilterGroup:=mDataSet.FilterGroup;
try
mDataSet.Filtered := True;
mDataSet.FilterGroup := fgPendingRecords;
Result := mDataSet.RecordCount > 0;
finally
mDataSet.Filtered := vFiltered;
mDataSet.FilterGroup := vFilterGroup;
end;
finally
mDataSet.Bookmark := vBookmark;
mDataSet.EnableControls;
end;
end;
//讓程序在啟動時自動啟動
procedure WriteRegAutoRun(FileName:string);
var
Regf:TRegistry;
begin
Regf:=TRegistry.Create;
Regf.RootKey:=HKEY_LOCAL_MACHINE;
if Length(FileName)>0 then
try
RegF.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',false);
RegF.WriteString('牧羊人服飾',FileName);
except
end;
RegF.CloseKey;
RegF.Free;
end;
//判斷用戶的權(quán)限
function premission(users,pms:string):boolean;
begin
result:=false;
try
pms_query:=TADOQuery.Create(APPLICATION.Owner);
pms_query.Connection:=Dataman.ADOCon;
pms_query.sql.clear;
pms_query.sql.add('select purview.pmspms from syslogin,purview where syslogin.jiese=purview.jiese and syslogin.yonghu =:yh and purview.pmsfun =:psf');
pms_query.Parameters.ParamByName('yh').Value:=users;
pms_query.Parameters.ParamByName('psf').Value:=pms;
try
pms_query.close;
pms_query.open;
except
showmessage('用戶表無法打開'); exit;
end;
if pms_query.IsEmpty then
result:=true
else
result:=pms_query.Fields.Fields[0].Value;
finally
pms_query.Free;
end;
end;
//讀取權(quán)限表
function read_pms(jies,pmsfu:string):boolean;
begin
try
result:=false;
user_query:=TADOQuery.Create(APPLICATION.Owner);
user_query.Connection:=Dataman.ADOCon;
with user_query do
begin
close;
sql.clear;
sql.Add('select * from purview');
sql.Add('where jiese='''+jies+''' and pmsfun='''+pmsfu+'''');
open;
if eof=false then result:=fieldbyname('pmspms').AsBoolean;
if eof=true then result:=false;
end;
finally
user_query.Free;
end;
end;
//寫入權(quán)限表
function write_pms(jiese,pmsfun:string;value:boolean):boolean;
begin
try
user_query:=TADOQuery.Create(APPLICATION.Owner);
user_query.Connection:=Dataman.ADOCon;
with user_query do
begin
close;
sql.Clear;
sql.Add('select * from purview');
sql.Add('where jiese='''+jiese+''' and pmsfun='''+pmsfun+'''');
open;
try
if eof=false then
begin
sql.Clear;
sql.Add('update purview set');
sql.Add('pmspms=:pno');
sql.Add('where jiese='''+jiese+''' and pmsfun='''+pmsfun+'''');
parameters.ParamByName('pno').Value:=value;
execsql;
end
else
begin
sql.Clear;
sql.Add('insert into purview');
sql.Add('(jiese,pmsfun,pmspms)');
sql.Add('values('''+jiese+''','''+pmsfun+''',:pn)');
parameters.ParamByName('pn').Value:=value;
execsql;
end;
result:=true;
except
result:=false;
end;
end;
finally
user_query.free;
end;
end;
//生成銷售單號的函數(shù)
function create_sell_no(xtable:string):string;
var
str1,str2:string;
begin
try
str1:=formatdatetime('yymmdd',date);
user_query:=TADOQuery.Create(APPLICATION.Owner);
user_query.Connection:=Dataman.ADOCon;
user_query.close;
user_query.sql.clear;
user_query.SQL.add('select 銷售編號 from '+xtable+' where substring(銷售編號,4,6)=:xdate order by 銷售編號');
user_query.Parameters.ParamByName('xdate').Value:=str1;
user_query.Open;
if user_query.IsEmpty then
result:='MYR'+str1+'0001'
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -