unit uData;
interface
uses
ImgList,SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms,
Dialogs, DBTables, DB, ADODB,DBGrids;
type
TdmoMain = class(TDataModule)
imlMain: TImageList;
imlSmall: TImageList;
ADOconn: TADOConnection;
qCProduct: TADOQuery;
dsProduct: TDataSource;
dsCcustom: TDataSource;
qcCustomEdit: TADOQuery;
qcMarketStyle: TADOQuery;
dsCMarketStyle: TDataSource;
QHgetpro: TADOQuery;
qcMarket: TADOQuery;
qBMoney: TADOQuery;
qBInfo: TADOQuery;
qA: TADOQuery;
dsA: TDataSource;
qAssure: TADOQuery;
QWRPT: TADOQuery;
QHkind: TADOQuery;
QHDj: TADOQuery;
QHst: TADOQuery;
QHstore: TADOQuery;
DSStore: TDataSource;
qPower: TADOQuery;
qcUserPower: TADOQuery;
qcMaKind: TADOQuery;
qcMa: TADOQuery;
qcMaSelect: TADOQuery;
QHMater: TADOQuery;
qcLog: TADOQuery;
procedure LinkToDataBase;
procedure DataModuleCreate(Sender: TObject);
procedure QueryAllDataBase(ADOQ: TADOquery;
SSQL: String;ExcuteFlag:integer=0);
procedure GetCustomDataSet(GridName:TDBGrid);
function CheckID(queryID: TADOQuery;CheckSQL:string;FormhWnd:HWND): boolean;
procedure GetMarketDataSet(GridName:TDBGrid);
procedure MarketStyleData(MIDValue,MNameValue:string;MIDCheck:string;IUFlag:integer=0);
//get product dataset
procedure GetProductDataSet(GridName:TDBGrid);
procedure LoginRecord(InOut:integer=1);//1:login in 0:login out
function GetMaRecoNO:string;
private
{ Private declarations }
public
{ Public declarations }
ProductEditOrInsert:boolean;//Edit:true;Insert:false
CustomEditOrInsert:boolean;
//Edit:true ;Insert:false
MarketStyleInsertOrUpdate:boolean;
editID:string;
end;
var
dmoMain: TdmoMain;
implementation
uses uLevel, uCustom,uGlobal;
{$R *.dfm}
procedure TdmoMain.LinkToDataBase;
begin
try
ADOconn.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=yhzy';
// ADOConn.Connected:=True;
qCProduct.Connection:=ADOconn;
// qCProductShow.Connection:=adoconn;
qcCustomEdit.Connection:=ADOconn;
qcMarketstyle.Connection:=ADOconn;
qhgetpro.Connection:=ADOconn;
qcMarket.Connection:=ADOconn;
qcUserPower.Connection:=ADOconn;
qPower.Connection:=ADOconn;
qcLog.Connection:=ADOconn;
qcMaKind.Connection:=ADOConn;
qcMa.Connection:=ADOConn;
qcMaSelect.Connection:=adoconn;
qA.Connection:=adoconn;
//Han Code---------------------------------
QHMater.Connection:=ADOconn;
except
ShowMessage('ϵͳ'+#13+'ϵͳÁ¬½Ó´íÎó£¬ÇëÍ˳ö£¬¼ì²éÍøÂçÁ¬½ÓÊÇ·ñÕýÈ·£¡');
application.Terminate;
end;
end;
procedure TdmoMain.DataModuleCreate(Sender: TObject);
begin
LinkToDataBase;
ProductEditOrInsert:=true;
end;
procedure TdmoMain.QueryAllDataBase(ADOQ: TADOquery;
SSQL: String;ExcuteFlag:integer=0);
begin
with adoqdo
begin
close;
sql.Clear;
sql.Add(SSQL) ;
try
case ExcuteFlag of
0
pen ;
1:ExecSQL ;
end;
except
ShowMessage('ϵͳÌáʾ£ºÖ´ÐиòÙ×÷ʱ³öÏÖδ֪´íÎó£¡');
application.Terminate;
end;
//try end
end;
end;
procedure TdmoMain.GetCustomDataSet(GridName:TDBGrid);
var
SQLStr:string;
begin
sqlstr:='select LID ±àºÅ,Lname Ãû³Æ,Laddr µØÖ·,Llinkman ÁªÏµÈË,LTel µç»°,LEmail E_mail,Lnetsite ÍøÕ¾,';
sqlstr:=sqlstr+'Lmobile ÊÖ»ú,Lcall ´«ºô,LFax ´«Õæ,Lbank ¿ª»§ÐÐ,LTax Ë°ºÅ,Lmemo ¸½¼ÓÐÅÏ¢,Lflag ÀàÐÍ';
sqlstr:=sqlstr+' from LinkInfo';
dmomain.QueryAllDataBase(dmomain.qcCustomEdit,sqlstr,0 );
dmomain.dsCcustom.DataSet:=dmomain.qcCustomEdit;
gridname.DataSource :=dmomain.dsCcustom;
end;
function TdmoMain.CheckID(queryID: TADOQuery;CheckSQL:string;FormhWnd:HWND): boolean;
begin
with queryiddo
begin
close;
sql.Clear;
sql.Add(CheckSQL);
open;
if recordcount<>0 then
begin
Messagebox(formhWnd,'±àºÅÒѾ­´æÔÚ£¬ÇëÈ·ÈϺóÔÙÌí¼Ó»òÐ޸ģ¡','´íÎó',mb_ok+mb_iconerror);
result:=false;
// frmcustom.GetDataSet;
end//if end
else
begin
result:=true;
end;
//else
end
end;
// with end
end;
procedure TdmoMain.GetMarketDataSet(GridName:TDBGrid);
var
MarketStyleSQL:string;
begin
MarketStyleSQL:='select MID ±àºÅ,MName ÏÖ½ð»òÕßÒøÐÐÕË»§ from MarketStyle';
QueryAllDataBase(qcMarketStyle,MarketStyleSQL);
dsCMarketStyle.DataSet:=qcMarketStyle;
GridName.DataSource:=dsCMarketStyle;
end;
procedure TdmoMain.MarketStyleData(MIDValue,MNameValue:string;MIDCheck:string;IUFlag:integer=0);
var
MarketInsertSQL:string;
MarketUpdateSQL:string;
procedure MarketStyleInsert;
begin
MarketInsertSQL:='Insert Into MarketStyle(MID,MName)';
MarketInsertSQL:=MarketInsertSQL+'values(';
MarketInsertSQL:=MarketInsertSQL+''''+MIDValue+''''+',';
MarketInsertSQL:=MarketInsertSQL+''''+MNameValue+'''';
MarketInsertSQL:=MarketInsertSQL+')';
dmomain.QueryAllDataBase(qcMarketStyle,MarketInsertSQL,1);
end;
procedure MarketStyleUpdate;
begin
MarketUpdateSQL:='Update MarketStyle set ';
MarketUpdateSQL:=MarketUpdateSQL+'MID='+''''+MIDValue+''''+',';
MarketUpdateSQL:=MarketUpdateSQL+'MName='+''''+MNameValue+'''';
MarketUpdateSQL:=MarketUpdateSQL+' where MID='+''''+MIDCheck+'''';
dmomain.QueryAllDataBase(qcMarketStyle,MarketUpdateSQL,1);
end;
function MarketStyleCheckID():boolean;
var
CheckID:string;
begin
CheckID:='select MID from MarketStyle where MID='+''''+MIDCheck+'''';
dmomain.QueryAllDataBase(qcMarketStyle,CheckID);
if qcmarketStyle.RecordCount <>0 then
begin
showMessage('¸Ã±àºÅÒѾ­´æÔÚ£¡');
result:=false;
end
else
begin
result:=true;
end;
end;
// function end
begin
begin
case IUFlag of
0: if MarketstylecheckID=true then
MarketStyleInsert;
1: if EditID=MIDCheck then
MarketStyleUpdate
else
if MarketstylecheckID=true then
MarketStyleUpdate;
else
showmessage('ϵͳ²ÎÊýµ÷ÓôíÎó£¡');
end;
end;
end;
procedure TdmoMain.GetProductDataSet(GridName:TDBGrid);
var
GetProductSQL:string;
begin
GetProductSQL:='select p.PID ±àºÅ,k.KName Æ·ÖÖ,p.PName ²úÆ·Ãû³Æ,p.punit µ¥Î»,s.SName ¹æ¸ñ,d.DName µÈ¼¶,p.PPrice ³É±¾¼Û,p.PMemo ¸½¼ÓÐÅÏ¢,P.sid SID,P.did DID,P.kid KID';
GetProductSQL:=GetProductSQL+' from Product p,Kind k,Standard s,Dj d';
GetProductSQL:=GetProductSQL+' where (p.sid=s.sid) and (p.kid=k.kid) and (p.did=d.did) ';
dmomain.QueryAllDataBase(dmomain.qCProduct,GetProductSQL);
dmomain.dsProduct.DataSet:=dmomain.qCProduct;
GridName.DataSource:=dmomain.dsProduct;
end;
//Record user login out information
//Record user login in information
procedure TdmoMain.LoginRecord(InOut: integer);
var
LoginRecordSQL:string;
LogQuery:TADOQuery;
const
LoginINSTR='³É¹¦µÇ½±¾ÏµÍ³';
LoginOuterStr='³É¹¦Í˳ö±¾ÏµÍ³';
begin
LoginRecordSQL:='Insert into ylog(username,logContent) values(';
LoginRecordSQL:=LoginRecordSQL+''''+uGlobal.UserName+''''+',';
case InOut of
0:LoginRecordSQL:=LoginRecordSQL+''''+LoginOuterStr+''''+')';
1:LoginRecordSQL:=LoginRecordSQL+''''+LoginINstr+''''+')';
end;
LogQuery:=TADOQuery.Create(self);
LogQuery.Connection:=ADOconn;
dmomain.QueryAllDataBase(LogQuery,LoginRecordSQL,1);
LogQuery.Free;
end;
function TdmoMain.GetMaRecoNO:string;
var
GETMaRecNoSQL:string;
begin
GETMaRecNoSQL:='select max(MaIID) maxid from MaIOMain ';
self.QueryAllDataBase(self.qcMa,GETMaRecNoSQL);
if self.qcMa.RecordCount=0 then
result:='10000000'
else
result:=IntToStr(StrToInt(self.qcMa.fieldbyname('MaxID').AsString)+1);
end;
end.