unit cmain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, chbedit, PrnDbgeh, Db, ADODB, Mask, ToolEdit, Grids, DBGridEh,
ovcbase, o32igrid, dxGrClms, dxTL, dxDBGrid, dxCntner, AdvEdit;
type
Tmainform=class(TForm)
ADOQuery1:TADOQuery;
DataSource1:TDataSource;
AdvEdit1:TAdvEdit;
AdvEdit2:TAdvEdit;
dxDBGrid1:TdxDBGrid;
ComboBox1:TComboBox;
Label1:TLabel;
Button1:TButton;
ADOQuery2:TADOQuery;
chbedit1:Tchbedit;
Label2:TLabel;
dxDBGrid1Column2:TdxDBGridMaskColumn;
dxDBGrid1Column4:TdxDBGridMaskColumn;
dxDBGrid1price:TdxDBGridMaskColumn;
dxDBGrid1Column6:TdxDBGridMaskColumn;
dxDBGrid1Column8:TdxDBGridMaskColumn;
dxDBGrid1Column9:TdxDBGridDateColumn;
dxDBGrid1Column10:TdxDBGridMaskColumn;
dxDBGrid1Column11:TdxDBGridMaskColumn;
dxDBGrid1Column12:TdxDBGridMaskColumn;
dxDBGrid1Column14:TdxDBGridMaskColumn;
dxDBGrid1Column15:TdxDBGridMaskColumn;
AdvEdit3:TAdvEdit;
AdvEdit4:TAdvEdit;
Button2:TButton;
O32InspectorGrid1:TO32InspectorGrid;
PrintDBGridEh1:TPrintDBGridEh;
Button3:TButton;
DBGridEh1:TDBGridEh;
ADOQuery3:TADOQuery;
DataSource2:TDataSource;
DateEdit1:TDateEdit;
DateEdit2:TDateEdit;
procedure FormCreate(Sender:TObject);
procedure AdvEdit1ValueValidate(Sender:TObject;value:string;
var IsValid:Boolean);
procedure Button1Click(Sender:TObject);
procedure ComboBox1Change(Sender:TObject);
procedure dxDBGrid1DblClick(Sender:TObject);
procedure Button2Click(Sender:TObject);
procedure Button3Click(Sender:TObject);
procedure dxDBGrid1CustomDrawCell(Sender:TObject;ACanvas:TCanvas;
ARect:TRect;ANode:TdxTreeListNode;AColumn:TdxTreeListColumn;
ASelected,AFocused,ANewItemRow:Boolean;var AText:string;
var AColor:TColor;AFont:TFont;var AAlignment:TAlignment;
var ADone:Boolean);
procedure chbedit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
mainform:Tmainform;
implementation
uses cselectone,cdatamodule, cprintsj;
{$R *.DFM}
procedure Tmainform.FormCreate(Sender:TObject);
var
i:integer;
begin
DateEdit1.Date:=Now-30;
DateEdit2.Date:=now;
ComboBox1.Text:=ComboBox1.Items[0];
ComboBox1.ItemIndex:=0;
ComboBox1Change(nil);
ADOQuery1.open;
for i:=0 to 2 do with ADOQuery2 do
begin
close;
sql.text:='select * from price where bottletype='+inttostr(i+1);
open;
O32InspectorGrid1.Items.Value:=fieldbyname('price').asstring;
end;
end;
procedure Tmainform.AdvEdit1ValueValidate(Sender:TObject;value:string;
var IsValid:Boolean);
begin
try
StrToInt(value);
except
ShowMessage('只能输入数值');
AdvEdit1.SetFocus;
AdvEdit1.SelectAll;
isvalid:=false;
end;
end;
procedure Tmainform.Button1Click(Sender:TObject);
var
mm:string;
begin
with ADOQuery2 do
begin
close;
sql.text:='insert bottle (日期,客户名称,pym,bottype,旧瓶入,新瓶出,price,返还金额) values (getdate(),'''+chbedit1.text+''','''+chbedit1.Pym+''','+inttostr(combobox1.tag)+',0'+advedit1.Text+',0'+advedit4.text+',0'+advedit2.Text+',0'+advedit3.Text+')';
execsql;
close;
SQL.Text:='select max(id) id from bottle';
open;
mm:=fieldbyname('id').asstring;
ADOQuery1.Requery;
ADOQuery1.Locate('id',mm, [loCaseInsensitive]);
end;
printsj:=tprintsj.create(Self);
printsj.free;
AdvEdit1.Text:='';
AdvEdit2.Text:='';
AdvEdit3.Text:='';
AdvEdit4.Text:='';
end;
procedure Tmainform.ComboBox1Change(Sender:TObject);
begin
ComboBox1.Tag:=ComboBox1.ItemIndex+1;
with ADOQuery2 do
begin
close;
sql.text:='select * from price where bottletype='+inttostr(ComboBox1.ItemIndex+1);
open;
AdvEdit2.Text:=fieldbyname('price').asstring;
end;
end;
procedure Tmainform.dxDBGrid1DblClick(Sender:TObject);
var
mm:string;
begin
if (ADOQuery1.FieldByName('返还金额').AsFloat<>0)and(ADOQuery1.FieldByName('sign').AsInteger=0) then
if Application.MessageBox('执行这个过程意味着你已经收到了客户的现金'+
#13#10#13#10+'它是不可逆的'+#13#10#13#10+'你确认要执行吗?',
PChar(Caption),MB_YESNO+MB_ICONWARNING)=IDYES then with ADOQuery2 do
begin
mm:=adoquery1.fieldbyname('id').asstring;
close;
sql.text:='update bottle set sign=1 where id='+mm;
execsql;
ADOQuery1.Requery;
ADOQuery1.Locate('id',mm, [loCaseInsensitive]);
printsj:=tprintsj.create(Self);
printsj.free;
end;
end;
procedure Tmainform.Button2Click(Sender:TObject);
var
i:integer;
begin
for i:=0 to 2 do with ADOQuery2 do
begin
close;
sql.text:='update price set price='+O32InspectorGrid1.Items.Value+' where bottletype='+inttostr(i+1);
execsql;
end;
end;
procedure Tmainform.Button3Click(Sender:TObject);
begin
ADOQuery3.Close;
ADOQuery3.SQL.Text:='select 客户名称,case when bottype=1 then ''大瓶'' when bottype=2 then ''中瓶'' else ''小瓶'' end 瓶类型,sum(新瓶出)新瓶出,sum(旭然金额入库)旭然金额入库 from bottle where 日期 between :timer1 and :timer2 ';
ADOQuery3.SQL.Add('group by 客户名称,bottype having sum(旭然金额入库)<>0 order by 客户名称,bottype');
ADOQuery3.Parameters[0].Value:=DateEdit1.Date;
ADOQuery3.Parameters[1].Value:=DateEdit2.Date+1;
ADOQuery3.Open;
PrintDBGridEh1.PageHeader.CenterText.Clear;
PrintDBGridEh1.PageHeader.CenterText.Add('更新瓶旭然金额入库清单');
PrintDBGridEh1.PageHeader.CenterText.Add(DateEdit1.Text+'----'+dateedit2.Text);
PrintDBGridEh1.AfterGridText.Clear;
ADOQuery2.close;
ADOQuery2.sql.text:='select sum(旭然金额入库) dd from bottle where 日期 between :timer1 and :timer2 ';
ADOQuery2.Parameters[0].Value:=DateEdit1.Date;
ADOQuery2.Parameters[1].Value:=DateEdit2.Date+1;
ADOQuery2.Open;
PrintDBGridEh1.AfterGridText.Add('总金额:'+adoquery2.fieldbyname('dd').AsString);
PrintDBGridEh1.AfterGridText.Add('打印日期:'+datetimetostr(Now));
PrintDBGridEh1.Print;
ADOQuery3.Close;
ADOQuery3.sql.text:='select 客户名称,sum(客户支付) 客户支付,sum(旭然支付) 旭然支付 from bottle where sign=1 and 日期 between :timer1 and :timer2 group by 客户名称 having sum(旭然支付)>0';
ADOQuery3.Parameters[0].Value:=DateEdit1.Date;
ADOQuery3.Parameters[1].Value:=DateEdit2.Date+1;
ADOQuery3.Open;
PrintDBGridEh1.PageHeader.CenterText.Clear;
PrintDBGridEh1.PageHeader.CenterText.Add('更新瓶补助清单');
PrintDBGridEh1.PageHeader.CenterText.Add(DateEdit1.Text+'----'+dateedit2.Text);
PrintDBGridEh1.AfterGridText.Clear;
ADOQuery2.close;
ADOQuery2.sql.text:='select sum(旭然支付) dd from bottle where sign=1 and 日期 between :timer1 and :timer2 ';
ADOQuery2.Parameters[0].Value:=DateEdit1.Date;
ADOQuery2.Parameters[1].Value:=DateEdit2.Date+1;
ADOQuery2.Open;
PrintDBGridEh1.AfterGridText.Add('总金额:'+adoquery2.fieldbyname('dd').AsString);
PrintDBGridEh1.AfterGridText.Add('打印日期:'+datetimetostr(Now));
PrintDBGridEh1.Print;
end;
procedure Tmainform.dxDBGrid1CustomDrawCell(Sender:TObject;
ACanvas:TCanvas;ARect:TRect;ANode:TdxTreeListNode;
AColumn:TdxTreeListColumn;ASelected,AFocused,ANewItemRow:Boolean;
var AText:string;var AColor:TColor;AFont:TFont;
var AAlignment:TAlignment;var ADone:Boolean);
begin
try
if StrToInt(AText)<0 then AColor:=clred;
except
end;
end;
procedure Tmainform.chbedit1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button=mbright then
begin
selectedit:='';
selecteditstr:='';
select1:='客户名称';//结果2
selectstr:='客户名称';
select0:='pym';
selecttitle:='客户名称';
select00:='客户名称';
pymid:='';
selectfrom:='bottle';
selectwhere:='';
selectorder:='';
selectinsert:='';
inipym:='';
selectone:=tselectone.create(self);
try
if selecttrue then selectone.showmodal else if not selectonlyone then exit;
finally
selectone.free;
end;
if not selectcancel then chbedit1.Text:=selectreturn;
end;
end;
end.