unit Unit1;
interface
uses
Windows, Messages, SysUtils,StrUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, ComCtrls, ToolWin, Menus, ExtCtrls, DBGridEhGrouping,
StdCtrls, DBCtrls, GridsEh, DBGridEh, DB, ADODB, ToolCtrlsEh, Grids, DBGrids,
Mask, DBCtrlsEh;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ToolButton9: TToolButton;
ToolBar2: TToolBar;
ToolButton10: TToolButton;
ToolButton11: TToolButton;
ToolButton12: TToolButton;
ToolButton13: TToolButton;
ToolButton14: TToolButton;
ToolButton15: TToolButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TreeView1: TTreeView;
Panel1: TPanel;
Panel2: TPanel;
Splitter1: TSplitter;
Panel3: TPanel;
ImageList1: TImageList;
PageControl2: TPageControl;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
PageControl3: TPageControl;
TabSheet5: TTabSheet;
TabSheet6: TTabSheet;
PageControl4: TPageControl;
TabSheet7: TTabSheet;
DBGridEh1: TDBGridEh;
Panel4: TPanel;
Button1: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
DBNavigator1: TDBNavigator;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
ComboBox3: TComboBox;
Edit5: TEdit;
Label12: TLabel;
Label13: TLabel;
Edit6: TEdit;
TreeView2: TTreeView;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DataSource2: TDataSource;
ADOQuery2: TADOQuery;
ADOQuery3: TADOQuery;
DBGrid1: TDBGrid;
DBDateTimeEditEh1: TDBDateTimeEditEh;
DBDateTimeEditEh2: TDBDateTimeEditEh;
DBDateTimeEditEh3: TDBDateTimeEditEh;
Label14: TLabel;
Label15: TLabel;
ListBox1: TListBox;
Button2: TButton;
Button3: TButton;
ADOQuery4: TADOQuery;
ADOCommand1: TADOCommand;
procedure FormShow(Sender: TObject);
procedure TreeView1Expanded(Sender: TObject; Node: TTreeNode);
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
procedure ADOQuery2AfterScroll(DataSet: TDataSet);
procedure ToolButton10Click(Sender: TObject);
procedure ToolButton11Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure DBGridEh1EditButtonClick(Sender: TObject);
private
{ Private declarations }
public
Ts:string;
fdbf:integer;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.ADOQuery2AfterScroll(DataSet: TDataSet);
begin
adoquery3.Close;
adoquery3.SQL.Text:='select * from Products a join OrderItems b on a.ProductID=b.ProductID where orderid=:p1';
adoquery3.Parameters.ParamByName('p1').Value:=adoquery2.FieldByName('orderid').AsString;
adoquery3.Open;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
form2.ShowModal;
end;
procedure TForm1.DBGridEh1EditButtonClick(Sender: TObject);
begin
//
end;
procedure TForm1.FormShow(Sender: TObject);
var
i:integer;
xcom:tcomponent;
s:string;
node1:ttreenode;
begin
fdbf:=2;
listbox1.Visible:=false;
pagecontrol2.ActivePageIndex:=1;
pagecontrol3.ActivePageIndex:=0;
dbnavigator1.DataSource:=datasource1;
for i := 1 to 9 do
begin
xcom:=findcomponent('toolbutton'+inttostr(i));
if xcom<>nil then
begin
ttoolbutton(xcom).Caption:='';
end;
end;
adoconnection1.Connected:=false;
adoconnection1.Connected:=true;
adoquery1.Connection:=adoconnection1;
adoquery2.Connection:=adoconnection1;
adoquery3.Connection:=adoconnection1;
adoquery4.Connection:=adoconnection1;
ts:='select orderid,orderdate,a.customerid,a.companyname as customercompany,b.shipperid,d.companyname as shipcompany,requireddate,shippeddate,freight,invoiceid,name,operator,invoicedate,OperationDate ';
ts:=ts+' from orders b join customers a on a.customerid=b.customerid join employees c on b.employeeid=c.employeeid ';
ts:=ts+' join shippers d on b.shipperid=d.shipperid';
ts:=ts+' where orderdate between ''2009-05-01'' and ''2009-05-31'' ';
adoquery2.Close;
adoquery2.sql.Text:=ts;
adoquery2.Open;
dbgrid1.DataSource:=datasource1;
datasource1.DataSet:=adoquery2;
with dbgrid1 do
begin
columns.clear;
columns[0].Title.caption:='訂單編號';
//Columns[0].ButtonStyle:=cbsellipsis; //QQQ ??!!
columns[1].Title.caption:='訂單日期';
columns[2].Title.caption:='客戶編號';
columns[3].Title.caption:='客戶名稱';
columns[4].Title.caption:='運輸公司';
columns[5].Title.caption:='公司名稱';
columns[6].Title.caption:='要貨日期';
columns[7].Title.caption:='發貨日期';
columns[8].Title.caption:='運輸費用';
columns[9].Title.caption:='發票';
columns[10].Title.caption:='業務員';
columns[11].Title.caption:='審核員';
columns[12].Title.caption:='發票日期';
columns[13].Title.caption:='審核日期';
for i := 0 to columns.Count- 1 do
begin
columns[i].title.Alignment:=tacenter;
end;
columns[8].Width:=50;
columns[11].Width:=50;
end;
datasource2.DataSet:=adoquery3;
dbgrideh1.DataSource:=datasource2;
adoquery3.Close;
adoquery3.sql.Text:='select * from Products a join OrderItems b on a.ProductID=b.ProductID';
adoquery3.Open;
with dbgrideh1 do
begin
columns.clear;
for i := 1 to 7 do columns.Add;
columns[0].FieldName:='productid';
columns[1].FieldName:='productname';
columns[2].FieldName:='quantityperunit';
columns[3].FieldName:='quantity';
columns[4].FieldName:='unitprice';
columns[5].FieldName:='discount';
columns[6].FieldName:='amount';
columns[0].Title.caption:='產品編號';
columns[1].Title.caption:='產品名稱';
columns[2].Title.caption:='規格型號';
columns[3].Title.caption:='數量';
columns[4].Title.caption:='單價';
columns[5].Title.caption:='折扣';
columns[6].Title.caption:='金額';
end;
with dbgrideh1 do
begin
for i := 0 to columns.Count - 1 do
columns[i].title.Alignment:=tacenter;
end;
adoquery1.Close;
adoquery1.SQL.Text:='select distinct orderdate from orders where orderdate between ''2009-05-01'' and ''2009-05-31''';
adoquery1.Open;
with adoquery1 do
begin
while not eof do
begin
s:='';
s:=copy(FieldByName('orderdate').AsString,8);
node1:=treeview1.items.add(nil,'5月'+s+'日');
treeview1.Items.AddChild(node1,'');
next;
end;
end;
for i := 0 to 6 do
begin
xcom:=findcomponent('edit'+inttostr(i));
if xcom<>nil then
begin
tedit(xcom).Text:='';
end;
end;
edit2.Enabled:=false;
label12.Caption:='';
label13.Caption:='';
label14.Width:=80;
label15.Width:=80;
adocommand1.Connection:=adoconnection1;
// dbgrideh1.Columns[0].ButtonStyle:=cbsEllipsis; // ???
end;
uj5u.com熱心網友回復:
procedure TForm1.ToolButton10Click(Sender: TObject);var
i:integer;
xcom:tcomponent;
s:string;
begin
fdbf:=1;
pagecontrol2.ActivePageIndex:=0;
edit2.Enabled:=true;
for i := 0 to 6 do
begin
xcom:=findcomponent('edit'+inttostr(i));
if xcom<>nil then
tedit(xcom).Text:='';
end;
s:='if object_id(''tmp'')is not null ';
s:=s+' drop table tmp ';
s:=s+' create table tmp( ';
s:=s+' productid varchar(14),';
s:=s+' productname varchar(40),';
s:=s+' quantityperunit varchar(20),';
s:=s+' quantity int,';
s:=s+' unitprice money,';
s:=s+' discount decimal(6,2),';
s:=s+' amount as CAST(quantity*unitprice*discount/100 AS DECIMAL(16,2)) )';
adocommand1.CommandText:=s;
adocommand1.Execute;
adocommand1.CommandText:='insert into tmp default values';
for i := 1 to 8 do adocommand1.Execute;
adoquery3.Close;
adoquery3.SQL.Text:='select * from tmp';
adoquery3.Open;
//dbgrideh1.Columns[0].ButtonStyle:=cbsauto;
//form1.dbgrideh1.Columns[0].ButtonStyle:=cbsellipsis; 問題是:這兩個怎么寫都錯,我就奇怪了
end;
procedure TForm1.ToolButton11Click(Sender: TObject);
begin
fdbf:=2;
pagecontrol2.ActivePageIndex:=1;
formshow(sender);
end;
procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
var
i:integer;
x1,x2,n:integer;
s,ss:string;
begin
adoquery4.Close;
adoquery4.SQL.Text:='select distinct name from orders a join Employees b on a.EmployeeID=b.EmployeeID where OrderDate between ''2009-05-01'' and ''2009-05-31''';
adoquery4.Open;
while not adoquery4.eof do
begin
if not adoquery4.Eof then
begin
combobox3.Items.Add(adoquery4.FieldByName('name').asstring);
adoquery4.Next
end;
end;
if fdbf=2 then //重繪按鈕
begin
if trystrtoint(node.Text,i) then
begin
edit2.Text:=node.Text;
adoquery1.Close;
adoquery1.SQL.Text:=ts+' and orderid=:p1 ';
adoquery1.Parameters.ParamByName('p1').value:=edit2.Text;
adoquery1.Open;
edit3.Text:=adoquery1.FieldByName('customerid').AsString;
edit4.Text:=adoquery1.FieldByName('shipperid').AsString;
edit5.Text:=adoquery1.FieldByName('freight').AsString;
label12.Caption:=adoquery1.FieldByName('customercompany').AsString;
label13.Caption:=adoquery1.FieldByName('shipcompany').AsString;
edit6.Text:=adoquery1.FieldByName('invoiceid').AsString;
x1:=label12.Width; //下劃線的動態變化
x2:=label13.Width;
label14.Width:=x1;
label15.Width:=x2;
dbdatetimeediteh1.Clear;
dbdatetimeediteh1.value:=adoquery1.FieldByName('requireddate').AsDateTime;
dbdatetimeediteh2.Clear;
dbdatetimeediteh2.value:=adoquery1.FieldByName('orderdate').AsDateTime;
dbdatetimeediteh3.Clear;
dbdatetimeediteh3.value:=adoquery1.FieldByName('SHIPpeddate').AsDateTime;
combobox3.Text:=adoquery1.FieldByName('name').AsString;
adoquery2.Locate('orderid',node.Text,[]);
end;
end;
if edit2.Enabled=true then //新增時候的清空
begin
dbdatetimeediteh3.Clear;
dbdatetimeediteh1.Clear;
combobox3.Text:='';
label12.Caption:='';
label13.Caption:='';
if fdbf=1 then //新增按鈕
begin
if not trystrtoint(node.Text,i) then
begin
x1:=posex('月',node.Text);
x2:=posex('日',node.Text);
ss:='2009-05-'+copy(node.Text,x1+1,x2-x1-1);
adoquery1.Close;
adoquery1.sql.Text:='select max(orderid) as n from orders where orderdate=:p1';
adoquery1.Parameters.ParamByName('p1').Value:=ss;
adoquery1.Open;
n:=adoquery1.FieldByName('n').AsInteger;
edit2.Text:=inttostr(n+1);
edit2.ReadOnly:=true;
dbdatetimeediteh2.Clear;
dbdatetimeediteh2.Value:=ss;
end;
end;
{ if trystrtoint(node.Text,i) then
begin
showmessage(node.Text);
s:='select MAX(orderid) as n from Orders where OrderDate=(select OrderDate from orders where orderid=:p1)';
adoquery1.Close;
adoquery1.SQL.text:=s;
adoquery1.Parameters.ParamByName('p1').Value:=strtoint(node.Text);
adoquery1.Open;
n:=adoquery1.FieldByName('n').AsInteger; //Q1:i:=adoquery1.FieldByName('n').AsInteger+1; 這樣做為什么不行?
//i:=i+1;
showmessage(inttostr(n));
edit2.Text:=inttostr(n);
edit2.ReadOnly:=true;
end; }
end;
end;
procedure TForm1.TreeView1Expanded(Sender: TObject; Node: TTreeNode);
var
s1:string;
x1,x2:integer;
begin
{取日期}
x1:=posex('月',node.Text);
x2:=posex('日',node.Text);
s1:=copy(node.Text,x1+1,x2-x1-1);
s1:='2009-05-'+s1;
//showmessage(s1);
adoquery1.Close;
adoquery1.SQL.Text:='select * from orders where orderdate=:p1';
adoquery1.Parameters.ParamByName('p1').Value:=s1;
adoquery1.Open;
if node.Item[0].Text='' then
begin
node.Item[0].Delete;
with adoquery1 do
begin
while not eof do
begin
treeview1.Items.AddChild(node,fieldbyname('orderID').asstring);
next;
end;
end;
end;
end;
end.
uj5u.com熱心網友回復:
錯誤提示是: incompatible types:' TcolumnButtonstyleeh 'and' tcolumnbuttonstyle 'could not compile used unit 'h:\..' 要怎么改呢?謝謝大家!
uj5u.com熱心網友回復:
6.在編輯訂單明細DBGridEh中,要求點擊小橢圓彈出表單,選擇產品編碼;產品編碼也可以輸入,要求使用onsettext對其進行驗證,輸入錯誤時加以提示,并聚焦在第一列,直到輸入正確為止或為空時;金額列根據數量、單價和折扣率自動計算得到;撰寫按回車鍵跳列的功能;在onsettext事件中用trystrtofloat等對數量、單價、折扣率資料進行驗證,發現錯誤時,將其值設定為0。這個是題目要求
uj5u.com熱心網友回復:
//dbgrideh1.Columns[0].ButtonStyle:=cbsauto;//form1.dbgrideh1.Columns[0].ButtonStyle:=cbsellipsis;
如果確定前臺設定靜態屬性名稱有cbsauto和cbsellipsis,那么肯定是缺少uses某一個單元,我在cxGrid遇到類似問題,半猜半試才找到(可能有簡便方法)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/120050.html
標籤:語言基礎/算法/系統設計
上一篇:TQRCompositeReport控制元件怎么增加頁碼??
下一篇:急求運行的時候登陸框出問題了
