int _fifo() { string sql_batch_no,batchno,resid; int i,j,k,v; num resinpnum,x,s; grid_seek("MG_Item","res_id","");//将光标定位到商品编码的最后一行; i=grid_cur_row("MG_Item");//获得最后一行的行号,用它减1就是真实的有数据的行数了。 for(j=1;j<i;j++) { sql_batch_no="select res_id,edt_id,produce_date,batch_no,num from edt_res where res_id='" + grid_get_v("MG_Item","res_id",j) ; sql_batch_no=sql_batch_no + "' and edt_id='" + gui_get_val('ComboBox_Ext_Edt_Id') + "'order by produce_date"; db_run(sql_batch_no); //fmt_date(db_res(2),'yyyy.mm.dd'); //格式化生产日期 grid_set_v('MG_Item','batch_no',j,db_res(3)); grid_set_v('MG_Item','produce_date',j,db_res(2)); grid_trigger_change('MG_Item','batch_no',-1); }; for(j=1;j<i;j++)//第一个循环用于获取最初的数据 { resid=grid_get_v("MG_Item","res_id",j); sql_batch_no="select res_id,edt_id,produce_date,batch_no,num from edt_res where res_id='" + resid + "' and edt_id='" + gui_get_val('ComboBox_Ext_Edt_Id') + "'order by batch_no"; db_run(sql_batch_no); k=db_row_count(); batchno=grid_get_v("MG_Item","batch_no",j); //获取循环行的批号 resinpnum=grid_get_v("MG_Item","inp_num",j); //获取循环行的数量 for(v=0;v<k-1;v++)//第二个循环用于新增行并填写正确的数据 { db_go_row(v); s=db_res(4); if(batchno==db_res(3) && resinpnum>s) { j=j+v; grid_seek_from('MG_Item',j,'res_id',resid); menu_trigger_click("Popu_Item_Copy_Curr"); grid_set_v('MG_Item','inp_num',j,db_res(4)); grid_set_v('MG_Item','produce_date',j,db_res(2)); grid_trigger_change('MG_Item','inp_num',-1); grid_insert_before('MG_Item',j+1); grid_seek_from('MG_Item',j+1,'res_id',''); // x=db_res(4); menu_trigger_click("Popu_Item_Paster"); db_go_row(v+1); grid_set_v('MG_Item','batch_no',j+1,db_res(3)); grid_set_v('MG_Item','produce_date',j+1,db_res(2)); grid_trigger_change('MG_Item','batch_no',-1); grid_set_v('MG_Item','inp_num',j+1,resinpnum-s); grid_trigger_change('MG_Item','inp_num',-1); batchno=grid_get_v("MG_Item","batch_no",j+1); resinpnum=grid_get_v("MG_Item","inp_num",j+1); s=db_res(4); i++; }; }; }; return 1; }; int func_before_save() { if(confirm('是否进行先进先出处理?')==1) { _fifo(); }; }; 脚本写得比较笨拙,还希望高手们多指点。 |