用fastreport作主从表
主表:
fh name
1  张三
2  李四
3  王五
从表:
fh 费用类型 金额
1  电费     1.2 
1  水费     1.35
2  电费     2
2  水费     2
3  电费     3
3  水费     3
在主表有金额合计项:例如
fh :1   name: 张三  合计:2.5  (大写:) 贰元伍角
----------------------------------------------
电费:1 
水费:1回答正确再加分

解决方案 »

  1.   

    转人民币大写的函数
    var  
          money   :   Real;  
          zheng   :   Int64;  
          ling   :   Integer;  
          yi   :   Int64;  
          wan   :   Int64;  
          ge   :   Int64;  
          jiao   :   Int64;  
          fen   :   Int64;  
      begin  
      //   The   function   'StrToFloat'   might   rase   an   'EConverError'   exception.  
          try  
              money   :=   StrToFloat(Edit1.Text);  
          except  
              on   EConvertError   do  
              begin  
                  ShowMessage('请检查你是否输入了正确的数字.');  
                  Exit;  
              end;  
          end;  
      //预防四舍五入时出错  
          zheng   :=   Round   (money   *   1000);  
          ling   :=   (zheng   -   (zheng   div   1000)   *   1000)   div   10;  
          zheng   :=   zheng   div   1000;  
          if   zheng   >   999999999999   then  
          begin  
              ShowMessage   ('Overflow.');  
              Exit;  
          end;  
      //   The   amount   is   devided   into   several   parts.  
           
          yi   :=   zheng   div   100000000;  
          zheng   :=   zheng   -   yi   *   100000000;  
          wan   :=   zheng   div   10000;  
          zheng   :=   zheng   -   wan   *   10000;  
          ge   :=   zheng;  
          jiao   :=   ling   div   10;  
          fen   :=   ling   -   jiao   *   10;  
       
      ////输出亿  
          if   yi   >   0   then  
          begin  
              AddToResult   (yi);  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[13];  
          end;  
      ////输出万  
          if   wan   >   0   then  
          begin  
              AddToResult   (wan);  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[12];  
          end;  
      ////输出万以下  
          AddToResult   (ge);  
          if   (yi   =   0)   and   (wan   =   0)   and   (ge   =   0)   then  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[17];  
      //     if   ge   >   0   then  
          Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[16];  
       
       
      ////输出角  
          if   jiao   >   0   then  
          begin  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[jiao-1];  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[15];  
          end;  
      ////输出分  
          if   fen   >   0   then  
          begin  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[fen-1];  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[14];  
          end;  
          if   (jiao   =   0)   and   (fen   =   0)   then  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[18];  
       
      end;  
      //------------------------------------------------------  
      //逐位输出  
      procedure   TForm1.AddtoResult   (Value   :   Integer);  
       
      var  
          qian   :   Integer;  
          bai   :   Integer;  
          shi   :   Integer;  
      begin  
      //------  
          qian   :=   Value   div   1000;  
          Value   :=   Value   -   qian   *   1000;  
          bai   :=   Value   div   100;  
          Value   :=   Value   -   bai   *   100;  
          shi   :=   Value   div   10;  
          Value   :=   Value   -   shi   *   10;  
       
          if   qian   >   0   then  
          begin  
              IsNotHeader   :=   true;  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[qian-1];  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[11];  
              if   (bai   =   0)       and       ((shi   >   0)   or   (Value   >   0))           then  
                  Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[17];  
          end  
          else  
          if   IsNotHeader   and   ((bai   <>   0)   or   (shi   <>   0)   or   (Value   <>   0))   then  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[17];  
       
      //------  
          if   bai   >   0   then  
          begin  
              IsNotHeader   :=   true;  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[bai-1];  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[10];  
              if   (shi   =   0)   and   (Value   >   0)   then  
                  Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[17];  
          end;  
       
      //------  
       
          if   shi   >   0   then  
          begin  
              IsNotHeader   :=   true;  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[shi-1];  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[9];  
          end;  
       
      //-----  
          if   Value   >   0   then  
          begin  
              IsNotHeader   :=   true;  
              Edit2.Text   :=   Edit2.Text   +   ListBox1.Items.Strings[Value-1];  
          end;
      

  2.   

    select 主表.*,sum(金额) as 合计  from 主表 inner join 从表 on 主表.fh= 从表.fh
      

  3.   

    首先,谢谢楼上两位.我有转换大写的函数,也知道二楼上写的语句,我就是不知道,如何把合计小写值,和大写值写进去.是在delphi环境下写还是在fastrepot环境里写.谢谢
      

  4.   

    fastreport里好像不可以实现转换 需要在delphi里转换后再在fastreport上边显示,
      

  5.   

    fastreport 好久没有用了,findobject可以,在fastreport的beforeReport事件里控制也可以,不知道是不是叫这个事件 你再看看吧
      

  6.   

    如果在有一个从表,里面也有金额.你这种做法就不行了.
    select 主表.*,sum(从表1.金额) as 合计,sum(从表2.金额) as 合计 
    怎样把从表1和从表2的合计金额再次合计.啊
      

  7.   

    dataset是可以合计一列值的TAggregate 获得一个合计值 然后findobject再赋值,
    你也可以在数据库返回结果集的时候把合计也追加到你的结果集上
      

  8.   

    FastReports Demo 中有统计的例子,使用个函数吧;但是变成大写,很复杂呀。