分享

参数输入

 自信开朗 2015-05-04
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, 
  Forms, Dialogs,cxquery,cxSysUtils,db,adodb,cxPlatformTypes,cxRuntimeCore;
 var
 tmp,query:tcxquery; 
    //ado: tadoconnection;
    fieldsql,a,b: string;
    //query, tmp: tadoquery;
 str,cpbh,module,sqlstr:string;
  mys : Tmemorystream; 
  flist,flist1,flist2,cplist, cpzdlist, ss: tstringlist; 
  i,j,k:integer;
begin
  cpbh:='797C7D1F-B70A-4B89-BA61-55D8E6D40C96';     
{   str := 'Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=ICommodityYX;Data Source=.';
     // str:='Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=cx;Initial Catalog='+ tmp2.fieldbyname('name').asstring+';Data Source=192.168.0.9';
  ado := tadoconnection.Create(nil);
  ado.LoginPrompt := false;
  ado.ConnectionString := str;
  ado.Connected := true;
  query := tadoquery.Create(nil);
  query.Connection := ado;
  tmp := tadoquery.Create(nil);
  tmp.Connection := ado;} 
   flist1:=tstringlist.create; 
   flist2:=tstringlist.create;
   cplist:=tstringlist.create;  
   cpzdlist:=tstringlist.create;
   ss:=tstringlist.create;
   flist:=tstringlist.Create;
  query:=tcxquery.Create(nil);
  tmp:=tcxquery.Create(nil); 
  module := '客户产品'; 
  fieldsql:='';
  for j := 0 to IProject.ModuleByName(module).FieldGroups.count - 1 do
    for i := 0 to IProject.ModuleByName(module).FieldGroups.Items[j].Fields.count - 1 do
    begin
      if not IProject.ModuleByName(module).FieldGroups.Items[j].IsTable then
      begin
        flist1.Add(IProject.ModuleByName(module).FieldGroups.Items[j].Fields.Items[i].name);
        flist2.Add(IProject.ModuleByName(module).FieldGroups.Items[j].Fields.Items[i].DataProperties.FieldName);
        if fieldsql <> '' then fieldsql := fieldsql + ',' +IProject.ModuleByName(module).FieldGroups.Items[j].Fields.Items[i].DataProperties.FieldName
        else fieldsql := IProject.ModuleByName(module).FieldGroups.Items[j].Fields.Items[i].DataProperties.FieldName
      end;
    end;  
  // showmessage(fieldsql);   
       module := '产品资料';
  for j := 0 to IProject.ModuleByName(module).FieldGroups.count - 1 do
    for i := 0 to IProject.ModuleByName(module).FieldGroups.Items[j].Fields.count - 1 do
    begin
      if not IProject.ModuleByName(module).FieldGroups.Items[j].IsTable then
      begin
        cplist.Add(IProject.ModuleByName(module).FieldGroups.Items[j].Fields.Items[i].name);
        cpzdlist.Add(IProject.ModuleByName(module).FieldGroups.Items[j].Fields.Items[i].DataProperties.FieldName);
        //FField := IProject.FieldByName(module+'.'+IProject.ModuleByName(module).FieldGroups.Items[j].Fields.Items[i].name);
      end;
    end;
  a := '';
  sqlstr := '';
  for i := 0 to cplist.count - 1 do

    if (flist1.IndexOf(cplist.strings[i]) >= 0)and (cplist.Strings[i]<>'产品图片')  then
    begin
      k := flist1.IndexOf(cplist.strings[i]);
      a := a + ',' + cpzdlist.Strings[i];
      sqlstr := sqlstr + ':' + flist2.Strings[k]+',' ;
      ss.Add(flist2.Strings[k]);
    end;
  str := '';
  str := 'insert into cp(recordid' + a + ',yytp) values(:recordid ' + sqlstr + ':yytp)';
  
     //showmessage(str);
     //exit; 
  query.close;    
  query.sql.text:=  'select  ' + fieldsql + '  from khcp where recordid='+quotedstr(cpbh);
  query.open;
  tmp.close;
  tmp.sql.text:='delete from cp where cpbh='+quotedstr(query.fieldbyname('cpbh').asstring);
  tmp.ExecSQL;
  
  tmp.close;
  tmp.sql.text:=str;  
  showmessage(tmp.sql.text);
  tmp.ParamByName('recordid').value:=INewGUID; 
    //showmessage(query.fieldbyname('zwsm').asstring);
    flist.clear; 
   for i:=0 to ss.count-1 do 
   begin    
      str:='';
    if (query.fieldbyname(ss.strings[i]).DataType = ftstring) then
       flist.add('ftstring '+inttostr(i)+'/'+ss.strings[i]);
      if (query.fieldbyname(ss.strings[i]).DataType = ftwidestring) then
       flist.add('ftwidestring '+inttostr(i)+'/'+ss.strings[i]);
      if query.fieldbyname(ss.strings[i]).DataType = ftfloat then 
      
        flist.add('ftfloat '+inttostr(i)+'/'+ss.strings[i]);
      if query.fieldbyname(ss.strings[i]).DataType = ftinteger then
        flist.add('ftinteger '+inttostr(i)+'/'+ss.strings[i]);
      if query.fieldbyname(ss.strings[i]).DataType = ftbcd then
         flist.add('ftbcd '+inttostr(i)+'/'+ss.strings[i]);
      if query.fieldbyname(ss.strings[i]).DataType = ftFMTBcd then
         flist.add('ftFMTBcd '+inttostr(i)+'/'+ss.strings[i]);
      if query.fieldbyname(ss.strings[i]).DataType = ftdatetime then
         flist.add('ftdatetime '+inttostr(i)+'/'+ss.strings[i]);
      if query.fieldbyname(ss.strings[i]).DataType = ftwidememo then
         flist.add('ftwidememo '+inttostr(i)+'/'+ss.strings[i]);  
         
  if query.fieldbyname(ss.Strings[i]).DataType =ftwidestring  then  
    begin
    tmp.ParamByName(ss.Strings[i]).asstring:=query.fieldbyname(ss.strings[i]).asstring;
     showmessage('ftwidestring'+inttostr(i)+'/'+ss.strings[i]); 
    end 
     else
     begin
       if query.fieldbyname(ss.strings[i]).value<>null then 
       begin
        tmp.ParamByName(ss.Strings[i]).value:=query.fieldbyname(ss.strings[i]).value;
          showmessage('not ftstring is not null '+inttostr(i)+'/'+ss.strings[i]); 
        end 
      else
      begin
       if query.fieldbyname(ss.Strings[i]).DataType in [ftfloat,ftinteger] then 
       begin
           tmp.ParamByName(ss.Strings[i]).asfloat:=0 ;
             showmessage('ftfloat is null '+inttostr(i)+'/'+ss.strings[i]); 
         end 
       else if query.fieldbyname(ss.Strings[i]).DataType in [ftdatetime] then 
            begin
           tmp.ParamByName(ss.Strings[i]).value:=null;
             showmessage('ftdatetime is null '+inttostr(i)+'/'+ss.strings[i]); 
            end  
       else 
          begin
         tmp.ParamByName(ss.Strings[i]).value:=null;  
           showmessage('other is null '+inttostr(i)+'/'+ss.strings[i]); 
          end;  
      end;
           
     end; 
    // showmessage(inttostr(i)+'/'+ss.Strings[i]);} 
     // showmessage(inttostr(i)+'/'+ss.Strings[i]); 
    ///  query.fieldbyname(ss.Strings[i]).asstring:=query.fieldbyname(ss.Strings[i]).asstring;
  end;    // showmessage(inttostr(i)+'/'+ss.Strings[i]);  
   
    showmessage(flist.Text);
  
   mys := Tmemorystream.Create;
   TBlobField(query.fieldbyname('yytp')).SaveToStream(mys);
   
   mys.Position:=0;  
   
   tmp.ParamByName('yytp').LoadFromStream(mys,ftblob);
     showmessage('2');
   tmp.ExecSQL; 
      showmessage('3');
   mys.Free;
   showmessage('save success');                                                          
  
end.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多