【delphi开源代码栏目提醒】:以下是网学会员为您推荐的delphi开源代码-frm_AUpdate.pas,希望本篇文章对您学习有所帮助。
unit frm_AUpdate;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, XPMan, Grids, DBGrids, ExtCtrls;
type
TfrmAUpdate = class(TForm)
GBxList: TGroupBox;
DBGList: TDBGrid;
ADOConnection1: TADOConnection;
AQUpdate: TADOQuery;
GBxOption: TGroupBox;
Label1: TLabel;
CBxOpNum: TComboBox;
EdCount: TEdit;
Label2: TLabel;
CBxUporDown: TComboBox;
EdPrice: TEdit;
CBXCenOrM: TComboBox;
BtnUpdate: TButton;
ATGoods: TADOTable;
DSList: TDataSource;
btnClose: TButton;
Bevel1: TBevel;
procedure BtnUpdateClick(Sender: TObject);
procedure EdCountKeyPress(Sender: TObject; var Key: Char);
procedure EdPriceKeyPress(Sender: TObject; var Key: Char);
procedure btnCloseClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
function CreateSQL(MES,UporDown,CenorM:integer;Count,price:string):string;
Function CreateSqlUporDown(Price,FieldName,UpOrDown,CenorM:string):string;
function CreateSqlWhere(field,MES,Count:string):string;
{ Private declarations }
public
{ Public declarations }
end;
var
frmAUpdate: TfrmAUpdate;
implementation
{$R *.dfm}
Function TfrmAupdate.CreateSqlUporDown(Price,FieldName,UpOrDown,CenorM:string):string;
begin
if Cenorm='' then
result:=FieldName+'='+FieldName+UporDown+Price
else
result:=FieldName+'='+FieldName+UporDown+'('+FieldName+Cenorm+Price+')';
end;
function TfrmAupDate.CreateSqlWhere(field,MES,Count:string):string;
begin
result:=' Where '+ field + MES + Count;
end;
Function TfrmAUpdate.CreateSQL(MES,UporDown,CenorM:integer;Count,price:string):String;
begin
case UporDown of
0: if Cenorm=0 then // up and monery add
result:=result+CreateSqlUpOrDown(price,'Price','+','')
else
result:=result+CreateSqlUpOrDown(Floattostr(strtoFloat(price) / 100),'Price','+','*');
1: if Cenorm=0 then //down and money add
result:=result+CreateSqlUpOrDown(price,'Price','-','')
else
result:=result+CreateSqlUpOrDown(Floattostr(strtoFloat(price) / 100),'Price','-','*');
end;
case Mes of
0: result:=result + CreateSqlWhere('SaveCount','>',Count);
1: result:=result + CreateSqlWhere('SaveCount','=',Count);
2: result:=result + CreateSqlWhere('SaveCount','<',Count);
end;
end;
procedure TfrmAUpdate.BtnUpdateClick(Sender: TObject);
var
sqlstring:string;
begin
if (trim(EDCount.Text) <> '') and(Trim(EDPrice.Text) <> '') then
begin
sqlstring:=CreateSQL(CBXOpNum.ItemIndex,CBXUporDown.ItemIndex,CBXCenorm.ItemIndex,EDCount.Text,Edprice.Text);
With AQUpDate do
begin
Close;
Sql.Clear;
Sql.Add('Update TB_Goods Set ');
Sql.Add(SQLString);
Execsql;
end;
ATGoods.Refresh;
end
else
showmessage('请正确填写更新选项!!');
end;
procedure TfrmAUpdate.EdCountKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',Char(vk_Back)]) then
key := #0;
end;
procedure TfrmAUpdate.EdPriceKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','.',Char(vk_Back)]) then
key := #0;
end;
procedure TfrmAUpdate.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmAUpdate.FormCreate(Sender: TObject);
begin
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Pass
word="";Persist Security Info=True;User ID=sa;Initial Catalog=
DelphiClassical200';
ADOConnection1.Open;
ATGoods.Open;
end;
end.