posts - 14,  comments - 3,  trackbacks - 0

      需求:希望dw_2的input_id字段能自动增加,并且按照一定的格式,即前面必须加sx两个字母,如sx100001,sx100002等。
      实现思路:
      1.如果数据表中无记录,分两种情况:一是数据窗口对象中也没有数据,则在数据窗口对象中插入一行(这是整个系统的第一条数据),则直接设定其为sx100001;二是数据窗口中有数据,则根据上一个值来设定新一行的数据。
 2.如果数据表中有数据,则要找出表中的input_id的最大值,分两种情况:一是如果数据窗口中无数据,则根据此最大值生成新一行的数据;二是如果数据窗口中有数据,则要根据数据窗口对象中最大流水号与数据表中的最大流水号判断哪个数据为最大,根据此最大值来生成新一行的数据。
string maxinputid1,maxinputid3,maxinputid0,maxinputid10
int input_idx
long maxinputid2
date currentdate
currentdate=today()

//dw_2的输血流水号自动生成。
 
 //如果数据表中没有记录,则分两种情况判断
 select count(input_id) into :input_idx from t_bloodinput;
 
 if input_idx<1 then
  dw_2.insertrow(0)
  dw_2.setfocus()
    dw_2.scrolltorow(dw_2.rowcount())
  
  //如果数据窗口中没有记录,则自动生成流水号为sx100001
  if dw_2.rowcount()<2 then
     dw_2.setitem(dw_2.rowcount(),1,'sx100001')

    //如果数据窗口中有记录,则要根据数据窗口中上一个记录的流水号进行自动生成
    else
   maxinputid10=dw_2.getitemstring(dw_2.rowcount()-1,1)
   maxinputid2=long(mid(maxinputid10,3,6))+1
     maxinputid3='sx'+string(maxinputid2)
   dw_2.setitem(dw_2.rowcount(),1,maxinputid3)
  end if
  
 else           //如果数据表中有记录,则找出最大流水号,并顺次生成流水号
  
  select max(input_id) into :maxinputid1 from t_bloodinput;
  
  if dw_2.rowcount()<1 then      //如果数据窗口中没记录,则流水号生成依据数据表中的最大流水号
   maxinputid10=maxinputid1
  else          //如果数据窗口中有记录,则流水号的生成要根据数据窗口中最大流水号与数据表中最大流水号的比较生成
     maxinputid0=dw_2.getitemstring(dw_2.rowcount(),1)
     if maxinputid1>=maxinputid0 then maxinputid10=maxinputid1
     if maxinputid1<maxinputid0 then maxinputid10=maxinputid0
  end if
  
  maxinputid2=long(mid(maxinputid10,3,6))+1
  maxinputid3='sx'+string(maxinputid2) 
  dw_2.insertrow(0)
  dw_2.setfocus()
    dw_2.scrolltorow(dw_2.rowcount())
    dw_2.setitem(dw_2.rowcount(),1,maxinputid3)

  
   end if
 dw_2.setitem(dw_2.rowcount(),3,bah)
 dw_2.setitem(dw_2.rowcount(),2,currentdate)
 dw_2.setcolumn(2)


 

posted on 2007-07-17 22:39 wlj768 阅读(1135) 评论(1)  编辑 收藏 引用 所属分类: 数据库编程之PB学习

FeedBack:
# re: 编号的自动格式化生成
2007-07-18 10:46 | www.8383.com
只要有博客就可以在8383.com免费申请.CN域名,输入域名就能直接进入博客,我刚申请了一个,快输入8383hosting.cn到我的博客看我是如何耍酷吧  回复  更多评论
  
只有注册用户登录后才能发表评论。
<2007年7月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(1)

随笔分类(11)

随笔档案(14)

文章分类(2)

1

搜索

  •  

最新评论

阅读排行榜

评论排行榜