⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit3.pas

📁 用于家庭养殖的财务进出
💻 PAS
📖 第 1 页 / 共 3 页
字号:
procedure ClearSGSheet;
var
  i:integer;
  sqlstr:string;
  index:integer;
begin
    i:=frm_main.PageControl1.ActivePageIndex;
    sqlstr:='select * from field_info where yn=''1'' and page='+inttostr(frm_main.PageControl1.ActivePageIndex+1);
    with dm.ADOQuery3 do  //内循环
    begin
      close;
      sql.Clear;
      sql.Add(sqlstr);
      open;
      first;
      while not eof do //创建label,之后编辑框
      begin
        index:=fieldbyname('ord').AsInteger-1;
        if (fieldbyname('type').AsString='E') OR (fieldbyname('type').AsString='UE') then
           editbox[i][index].Text:='';
        if fieldbyname('type').AsString='D' then
           maskedit[i][index].Text:='';
           //maskedit[i][index].DateTime:=now;//.Text:='';
        if fieldbyname('type').AsString='C' then
        begin
         {if combobox[i][index].Style=csDropDownList then
            combobox[i][index].ItemIndex:=0
          else}
            combobox[i][index].Text:='';
        end;
        if fieldbyname('type').AsString='M' then
          memo[i][index].Text:='';
        if fieldbyname('type').AsString='N' then
          editbox[i][index].Text:='';
      next;
      end;
    end;
end;

procedure Loadfield(activepage:integer;perscode:string);       //往激活页控件填值
var
  i:integer;
  sqlstr,sqltmp:string;
  index:integer;
  tmpstr:string;
  table_name:string;
  tmpvar:OleVariant;
  values:string;
begin
    i:=activepage;
    sqlstr:='select table_name from field_info where page='+inttostr(i+1);
    with dm.ADOQuery1 do
    begin
      close;
      sql.Clear;
      sql.Add(sqlstr);
      open;
      table_name:=fieldbyname('table_name').AsString;
    end;
    sqlstr:='select * from '+table_name+' where prescode='+quotedstr(perscode);
    with dm.ADOQuery1 do
    begin
      close;
      sql.Clear;
      sql.Add(sqlstr);
      open;
      sqltmp:='select * from field_info where yn=''1'' and page='+inttostr(i+1);
      with dm.ADOQuery2 do
      begin
        close;
        sql.Clear;
        sql.Add(sqltmp);
        open;
        first;
        while not eof do
        begin
          index:=dm.ADOQuery2.FieldValues['ord']-1;
          if (dm.ADOQuery2.fieldbyname('type').AsString<>'P'){ and (dm.ADOQuery2.FieldByName('lab_name').AsString<>'修改记录项')} then
          tmpvar:=dm.ADOQuery1.FieldValues[dm.ADOQuery2.FieldValues['field']];
          if tmpvar=null then
            values:=' '
          else
            values:=tmpvar;
          if (dm.ADOQuery2.FieldValues['type']='E')  then
            editbox[i][index].Text:=values;
          if (dm.ADOQuery2.FieldValues['type']='D') then
             maskedit[i][index].Text:=values;
            //maskedit[i][index].DateTime:=strtodate(values);
          if dm.ADOQuery2.FieldValues['type']='C' then
            combobox[i][index].Text:=values;
        if fieldbyname('type').AsString='M' then
          memo[i][index].Text:='';
          next;
        end;
      end;
    end;
end;

procedure Updatelistbox(stringlist,listbox:tobject);
var
 i:integer;
 sqlstr:string;
begin
  (stringlist as tstringlist).Clear;
  (listbox as tlistbox).Clear;
  with dm.ADOQuery1 do
  begin
    close;
    sql.Clear;
    sql.Add('select a0112 from a01 where prescode='+quotedstr(gencode));
    open;
    if not eof then
    begin
      {for i:=0 to frm_main.lb_company.Items.Count-1 do
      begin
        if frm_main.lb_company.Items[i]=fieldbyname('a0112').AsString then
        begin
          frm_main.lb_company.ItemIndex:=i;
          break;
        end;
      end;}
      //sqlstr:='select a0101,a0102,prescode from a01 where a0112='+quotedstr(company_code)+'union select distinct A01.A0101,A02.prescode,a01.prescode from A01,a02 where a01.prescode=a02.prescode and a0209='+quotedstr(company_code);
      //sqlstr:='select a0101,prescode from a01 where a0112='+quotedstr(company_code)+'union select distinct A01.A0101,A02.prescode from A01,a02 where A01.prescode=a02.prescode and a0209='+quotedstr(company_code);
      with dm.ADOQuery2 do
      begin
        close;
        sql.Clear;
        //sql.Add(sqlstr);
        //sql.Add('select a0101,prescode from a01 where a0112='+quotedstr(company_code)+ 'union select a0209,prescode from a02 where a0209='+quotedstr(company_code));
        sql.add('select a0101,a01.prescode,a02.prescode from a01,a02 where a02.a0209='+quotedstr(company_code)+' and a01.prescode=a02.prescode order by a0225');
        //sql.Add('select prescode,a0101 from a01 where a0112='+quotedstr(dm.ADOQuery1.fieldbyname('a0112').AsString));
        open;
        first;
        while not eof do
        begin
          (stringlist as tstringlist).Add(fieldbyname('a01.prescode').AsString);
          //showmessage(fieldbyname('a0101').AsString);
          (listbox as tlistbox).AddItem(fieldbyname('a0101').AsString,(listbox as tlistbox));
          next;
        end;
      end;
    end;
  end;
end;

procedure UpdateStringGrid;
var
  sqlstr:string;
  str,tmpstr:string;
  row,col:integer;
  code:string;
  fieldstr:string;  //生成grid所需的select子句中的字段表
  table_name:string;
  loopnum:integer;
  postion:integer;
  field:string;
  i:integer;
  colnum:integer;
  xhfield:string;
begin
    for i:=0 to frm_main.StringGrid1.RowCount-1 do
    begin
      frm_main.StringGrid1.Rows[i].Clear;
    end;
    col:=1;
    loopnum:=1;
    with dm.ADOQuery1 do
    begin
      close;
      sql.Clear;
      sql.Add('select is_browse,field,table_name,lab_name,type from field_info where page='+inttostr(frm_main.pagecontrol1.ActivePageindex+1)+' order by field');
      open;
      colnum:=recordcount;
      //=============20050403修改
      //if fieldbyname('table_name').AsString='A06' then  //将stringgrid的列宽根据stringgrid的宽度来平分
        frm_main.StringGrid1.DefaultColWidth:=frm_main.StringGrid1.Width div colnum;//.ColWidths[col]:=frm_main.StringGrid1.Width div colnum;
      //===================
      first;
      while not eof do
      begin
        if fieldbyname('is_browse').AsVariant then
        begin
          if (fieldbyname('type').AsString='N') and (fieldbyname('lab_name').AsString='序号') then
          begin
             XHpos:=col;
             xhfield:=fieldbyname('field').AsString;      //1023添加,得到序号的字段名
          end;
          frm_main.stringgrid1.Cells[col,0]:=dm.ADOQuery1.fieldbyname('lab_name').AsString;
          col:=col+1;
////////////////2006-03//////////////////////////////////////
          if loopnum=1 then
          begin
            fieldstr:=fieldbyname('field').AsString;
            loopnum:=loopnum+1;
          end else
            fieldstr:=fieldstr+','+fieldbyname('field').AsString;
        end;
        next;
      end;
      table_name:=fieldbyname('table_name').AsString;
    end;
    frm_main.stringgrid1.ColCount:=col;
    if gencode<>'' then
    begin
      row:=1;
      col:=1;
      if xhfield<>'' then  //200514修改
        sqlstr:='select xh,'+fieldstr+' from '+table_name+ ' where prescode='+quotedstr(gencode)+' order by '+xhfield
      else
        sqlstr:='select xh,'+fieldstr+' from '+table_name+ ' where prescode='+quotedstr(gencode);  //200514增加(xhfield字段为空出错)
      with dm.ADOQuery1 do
      begin
        close;
        sql.Clear;
        sql.Add(sqlstr);
        open;
        frm_main.StringGrid1.RowCount:=recordcount+1;
        first;
///////////////2006-03////////////////////////////////////////////
        fieldstr:=fieldstr+',';
        while not eof do
        begin
          postion:=pos(',',fieldstr);
          field:=copy(fieldstr,1,postion-1);
          tmpstr:=copy(fieldstr,postion+1,length(fieldstr));
          while field<>'' do
          begin
            frm_main.StringGrid1.Cells[0,row]:=fieldbyname('xh').AsString;
            xh_value:=strtoint(fieldbyname('xh').AsString);
            frm_main.stringgrid1.Cells[col,row]:=fieldbyname(field).AsString;
            postion:=pos(',',tmpstr);
            field:=copy(tmpstr,1,postion-1);
            tmpstr:=copy(tmpstr,postion+1,length(tmpstr));
            col:=col+1;
          end;
          row:=row+1;
          col:=1;
          next;
        end;
      end;
    end;
end;

function Checkfield:boolean;
var
  sqlstr:string;
  i,j:integer;
  index:integer;
  tmpyear,tmpmonth,tmpday:integer;
  Year,Month,Day:word;
  temp:string;
  fieldstr,valuestr:string;
  values:string;
  str:string;
  tmpstr:string;
  mulrecord:boolean;
begin
     result:=false;
     i:=frm_main.PageControl1.ActivePageIndex+1;
     sqlstr:='select * from field_info where yn=''1'' and page='+inttostr(i);
     with dm.ADOQuery1 do
     begin
       close;
       sql.Clear;
       sql.Add(sqlstr);
       open;
       first;
       while not eof do
       begin
        index:=fieldbyname('ord').AsInteger-1;
      //从界面上取值
          if (is_csadd=true) or is_mult=true then
          begin
          end;
          if (fieldbyname('type').AsString='E') or (fieldbyname('type').AsString='UE')   then
          begin
            values:=editbox[i-1][index].Text;
          end;
          if (fieldbyname('type').AsString='D')  then
          begin
            values:=maskedit[i-1][index].Text;
            tmpstr:=trim(values);
            if copy(tmpstr,1,1)<>'-' then
            begin
              tmpyear:=strtoint(copy(values,1,4));
              if trim(copy(values,6,2))='' then
              begin
                showmessage('请输入月份值!');
                result:=true;
                exit;
              end;
              if (Pos('-',copy(values,6,2))=1)  then
                tmpmonth:=strtoint(copy(copy(values,6,2),1,1))
              else
                tmpmonth:=strtoint(trim(copy(values,6,2)));
              if trim(copy(values,9,2))='' then
              begin
                showmessage('请输入日期!');
                result:=true;
                exit;
              end;
              if (Pos('-',copy(values,9,2))=1)  then
                tmpday:=strtoint(copy(copy(values,9,2),1,1))
              else
                tmpday:=strtoint(trim(copy(values,9,2)));
              decodedate(now,year,month,day);
              if tmpyear>strtoint(copy(inttostr(Year),1,4)) then
              begin
                showmessage('日期年份不对!');
                result:=true;
                exit;
              end;
              if (tmpmonth>12) or (tmpmonth<1 ) then
              //if (month>12) or (month<1) then
              begin
                showmessage('日期月份值只能在1~12之间!');
                result:=true;
                exit;
              end;
              if (tmpday>31) or (tmpday<1 ) then
              //if (month>12) or (month<1) then
              begin
                showmessage('日期值只能在1~31之间!');
                result:=true;
                exit;
              end;
            end
            else
            begin
              values:='';
            end;
          end;
          if ((fieldbyname('type').AsString='N') and fieldbyname('NotNull').AsVariant)  then
          begin
            //if editbox[i-1][index].Style=csDropDownList then
              if editbox[i-1][index].Text='' then
              begin
                application.MessageBox('序号不能为空!','注意',mb_ok);
                result:=true;
                exit;
              end;
              values:=editbox[i-1][index].Text;
          end;
          if fieldbyname('notnull').AsVariant then
            if values='' then
            begin
              str:= labelcaption[i-1][index].Caption+'的值不能为空';
              application.MessageBox(pchar(str),'注意',mb_ok);
              result:=true;
              exit;
            end;
        next;
      end;
   end;
     with dm.ADOQuery1 do
     begin
       close;
       sql.Clear;
       sql.Add('select mult_rec from page_def where page_no='+inttostr(i));
       open;
     end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -