怎样做客户-年月日定单数据的树型结构(100分)

  • 主题发起人 主题发起人 wdsu
  • 开始时间 开始时间
你的新问题不能那样做啊,那样一条一条来计算速度太慢,还是直接
用sql得到数据啊,如按年时,可以用
select * from orders
where substring(orderdate,1,4)='..'
反正原理就是那样,关键是怎么样得到数据!
 
to delphilai:
你好,我按你的思路编了代码如下:

program p_orders_design;

uses
Forms,
u_mainxt in 'u_mainxt.pas' {fm_mainxt},
dm_orders in 'dm_orders.pas' {DataModule2: TDataModule},
u_w_orders in 'u_w_orders.pas' {fm_w_ordersdetail},
ffunction in 'ffunction.pas',
u_login in 'u_login.pas' {fm_login},
U_w_customer in 'U_w_customer.pas' {fm_w_customer},
u_items in 'u_items.pas' {fm_w_items},
u_qrycust in 'u_qrycust.pas' {fm_searchcust},
u_alltype in 'u_alltype.pas',
u_customer in 'u_customer.pas' {fm_cust},
u_supply in 'u_supply.pas' {fm_supply},
u_flash in 'u_flash.pas' {fm_flash},
u_w_supply in 'u_w_supply.pas' {fm_w_supply};

{$R *.res}

begin
Application.Initialize;
try
fm_flash:=Tfm_flash.Create(Application);
fm_flash.Show;
fm_flash.Update;
// fm_login:=Tfm_login.create(Application);
// fm_login.show;
// fm_login.update;
// while fm_login.Active do
// Application.ProcessMessages;
// fm_login.Close;
// fm_login.Free;
Application.CreateForm(TDataModule2, DataModule2);
Application.CreateForm(Tfm_mainxt, fm_mainxt);





unit u_mainxt;

procedure Tfm_mainxt.initTreeView(TreeView1:TTreeview);
var
TreeNode1,TreeNode2,TreeNode3:TTreeNode;
begin
TreeView1.Items.Clear;
with datamodule2 do
begin
qrytemp.close;
qrytemp.sql.Clear;
qrytemp.sql.Add('select * from customer order by customerid');
qrytemp.open;
if qrytemp.IsEmpty then
begin
MessageDlg('你的客户表中还没有内容,请先输入客户!', mtWarning,
[mbOK], 0);
exit;
end;
qrytemp.first;
while not qrytemp.eof do
begin
qryorders.Close;
qryorders.sql.Clear;
AA---- qryorders.sql.Add('select distinct year(orderdate) as yy from orders where customerid='''+qrytemp.FieldByName('customerid').AsString);
qryorders.open;
if qryorders.IsEmpty then
begin
TreeNode1:=treeview1.Items.add(nil,qrytemp.fieldbyname('customerid').AsString+'@'+qrytemp.fieldbyname('customer_name').AsString);
qrytemp.Next;
continue;
end;
TreeNode1:=treeview1.Items.add(nil,qrytemp.fieldbyname('customerid').AsString+'@'+qrytemp.fieldbyname('customer_name').AsString);
qryorders.First;
while not qryorders.Eof do
begin
TreeNode2:=treeview1.Items.AddChild(TreeNode1,qryorders.fieldbyname('yy').AsString);
qrymonth.Close;
qrymonth.sql.Clear;
qrymonth.sql.Add('select distinct month(orderdate) as mm from orders where customerid='''+qrytemp.FieldByName('customerid').AsString+'''and year(orderdate)=:yy');
qrymonth.parambyname('yy').asstring:=qryorders.fieldbyname('yy').asstring;
qrymonth.open;
qrymonth.first;
while not qrymonth.Eof do
begin
TreeNode3:=treeview1.Items.AddChild(TreeNode2,qrymonth.fieldbyname('mm').asstring);
qrymonth.Close;
qryday.sql.Clear;
qryday.sql.Add('select distinct day(orderdate) as dd from orders where customerid='''+qrytemp.FieldByName('customerid').AsString+'''and year(orderdate)=:yy and month(orderdate)=:mm');
qryday.parambyname('yy').asstring:=qryorders.fieldbyname('yy').asstring;
qryday.parambyname('mm').asstring:=qrymonth.fieldbyname('mm').asstring;
qryday.open;
qryday.first;
while not qryday.Eof do
begin
Treeview1.Items.AddChildFirst(treenode3,qryday.fieldbyname('dd').AsString);
qryday.Next;
end;
qrymonth.Next;
end;
qryorders.Next;
end; // while not qryorders.eof...end
qrytemp.Next;
end; // while not qrytemp.eof do..end
end;// with datamodule2 do...end

end;
procedure Tfm_mainxt.FormCreate(Sender: TObject);
begin
initTreeView(TreeView1);
end;


又在AA处出现错误:(qryorders.sql.Add('select distinct year(orderdate) as yy from orders where customerid='''+qrytemp.FieldByName('customerid').AsString);)
---------------------------
Debugger Exception Notification
---------------------------
Project p_orders_design.exe raised exception class EDBEngineError with message 'Missing right quote.'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
??
还有哪位帮帮我,在那里缺引号或多引号呀,谢谢! to: wdsu@htc.net.cn
 
改成这样啊,少了一个''''号啊!
qryorders.sql.Add('select distinct year(orderdate) as yy from orders where customerid='''+
qrytemp.FieldByName('customerid').AsString+'''');
 
to dephilai:
你好,谢谢你给我回答,我已按你的加了两个引号
qryorders.sql.Add('select distinct year(orderdate) as yy from orders
where customerid='''+qrytemp.FieldByName('customerid').AsString+'''');
其他的没有改,
运行时 又出现错误:
---------------------------
Debugger Exception Notification
---------------------------
Project p_orders_design.exe raised exception class EDatabaseError with
message 'qryorders: Field '订单编号' not found'. Process stopped. Use
Step or Run to continue.
---------------------------
OK Help
---------------------------
???
其中orderid(定单编号)是主关键字,又不知道怎么回事了,百思不得其解,怎么会和
关键字冲突,帮帮我,谢谢!

[:(][:D]

谢谢!!



 
还有谁能帮帮我呀??
 
用dxDBGrid不就可以了?
 
to everybody,
用Dev Express DBTree可以相似地完成你所要的功能
 
我的语句行有什么错误呀?请高手赐教呀。谢谢!我实在没有办法了。
 
大家好:
我的问题已经解决,在主窗口的u_mainxt中的
qryorders.Close;
qryorders.sql.Clear;
qryorders.sql.Add('select distinct year
(orderdate) as yy from orders where customerid='''+qrytemp.FieldByName
('customerid').AsString+'''');
qryorders.open;
组件qryorders和数据模块中的datamodule2的 TDataModule2.dscustomerDtaChange
事件中的qryorders有冲突:
procedure TDataModule2.dscustomerDataChange(Sender: TObject;
Field: TField);
begin
qryorders.close;
qryorders.SQL.Clear;
qryorders.SQL.Add('select * from orders where
customerid='''+qrycustomersearch.fieldbyname('customerid').AsString+'''');
if qryorders.Prepared=false then qryorders.Prepare;
qryorders.Open;
qryorders.Last;

end;
把上面的qryorders换成一个新的query就行了
qryyear.Close;
qryyear.sql.Clear;
qryyear.sql.Add('select distinct year
(orderdate) as yy from orders where customerid='''+qrytemp.FieldByName
('customerid').AsString+'''');
qryyear.open;




 
多人接受答案了。
 
我现在又碰到了一个问题了,请大家帮帮忙了。
我要根据客户姓名和日期起止日期查询出包括定单详表的日期:
客户姓名 定货日期 定单的详细数据(即表orderdetail中的所有字段)
我写的sql 如下,但有错,请高手帮我看一下:
procedure Tfm_qrydatecust.btnqryClick(Sender: TObject);
var
wheresql,strcust:string;

begin
if (cbxcust.Items[cbxcust.ItemIndex]='全部') or (cbxcust.Items
[cbxcust.ItemIndex]='')
then wheresql:=''

else wheresql:='and (c.customer_name='''+cbxcust.Items
[cbxcust.itemindex]+')';
with datamodule2,qrydatecust do
begin
close;
SQL.clear;
sql.Add('select o.orderid,o.orderdate,c.customer_name');
sql.Add(',od.diam,od.length,od.num,od.pnum,od.plength');
sql.Add('from customer c ,orders o,orderdetail od where
(c.customerid=o.customerid)'''+wheresql+'''');
sql.Add('and (o.orderdate between'''+datetostr
(DateTimePicker1.datetime)+'''and'''+datetostr(DateTimePicker2.datetime)
+')''');
sql.Add('and (o.orderid=od.orderid)');
if prepared=false then prepare;
open;
end;

end;


谢谢!wdsu@htc.net.cn
 
后退
顶部