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

📄 ufrmchild.pas

📁 数据库通用工具
💻 PAS
📖 第 1 页 / 共 2 页
字号:
          iNO := iNO + 1;
          mo.Lines.Add( ' 导入失败(未知原因) >< '+ss );
          qryA.Next;
          continue;
        end;
      end;
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~}
      //导入信息
      //==  基本信息  ==
      sID := FieldByName('id').AsString;//本地的ID主键
      sChildID := GetKeyID(FieldByName('childType').AsInteger , FieldByName('stationId').AsString);//生成儿童ID
      qryInsert.ParamByName('id'       ).AsString := sChildID;//儿童ID
      qryInsert.ParamByName('stationId').AsString := FieldByName('stationId').AsString;
      qryInsert.ParamByName('name'     ).AsString := sName;
      qryInsert.ParamByName('sex'      ).AsInteger := FieldByName('sex').AsInteger;
      qryInsert.ParamByName('birth'    ).AsDateTime := FieldByName('birth').AsDateTime;
      qryInsert.ParamByName('hkAddress').AsString := FieldByName('hkAddress').AsString;
      qryInsert.ParamByName('state'    ).AsInteger := FieldByName('state').AsInteger ;

      qryInsert.ParamByName('father'   ).AsString := sFather;
      qryInsert.ParamByName('mather'   ).AsString := sMather;
      qryInsert.ParamByName('childType').AsInteger := FieldByName('childType').AsInteger;
      qryInsert.ParamByName('buildDate').AsDateTime := FieldByName('buildDate').AsDateTime;
      qryInsert.ParamByName('telephone').AsString := FieldByName('telephone').AsString;
      qryInsert.ParamByName('handphone').AsString := FieldByName('handphone').AsString;
      qryInsert.ParamByName('address'  ).AsString := FieldByName('address').AsString;
      qryInsert.ParamByName('HomeIllS' ).AsString := FieldByName('HomeIllS').AsString;

      //==  补充信息  ==
      qryInsert.ParamByName('birthPaperId').AsString := FieldByName('birthPaperId').AsString;
      qryInsert.ParamByName('cfwork'   ).AsString := FieldByName('cfwork').AsString;
      qryInsert.ParamByName('cmwork'   ).AsString := FieldByName('cmwork').AsString;
      qryInsert.ParamByName('email'    ).AsString := FieldByName('email').AsString;
      qryInsert.ParamByName('change_address').AsString := FieldByName('change_address').AsString;
      qryInsert.ParamByName('changeDate').AsDateTime := FieldByName('changeDate').AsDateTime;
      qryInsert.ParamByName('changeType').AsInteger := FieldByName('changeType').AsInteger;
      qryInsert.ParamByName('GuoMinS'  ).AsString := FieldByName('GuoMinS').AsString;
      qryInsert.ParamByName('c_mark'   ).AsString := FieldByName('c_mark').AsString;

      //Childill 暂时无用
      qryInsert.ParamByName('Childill'  ).AsString := '0';
      qryInsert.ParamByName('cardid'    ).AsString := '';
      qryInsert.ParamByName('password'  ).AsString := '';
      qryInsert.ParamByName('cardstate' ).AsString := '0';
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~
      try
        //执行导入
        qryInsert.ExecSQL;
        iOK := iOK + 1;

      except
        //导入失败
        iNO := iNO + 1;
        mo.Lines.Add( ' 导入失败(插入出错) >< '+ss );
        qryInsert.Next;
        continue;
      end;
      //导入成功
      mo.Lines.Add( ' 导入成功 -> '+ss );
      
      //导入接种记录
      InsertInoculate(sID,sChildID);
      //==========================================================================
      //adoQry.Next;
      qryA.Next;
    end;//  while not adoQry.Eof do
  end;// with adoQry do
  
  ss := ' 儿童信息导入完毕!( 成功: '+IntToStr(iOK)+' 条, 失败: '+IntToStr(iNO)+' 条 )';
  mo.Lines.Add( ' -------------------------------------------------------------- ' );
  mo.Lines.Add( ' 结束时间: '+ DateTimeToStr( Now() ) );
  mo.Lines.Add( ss );

  //保存历史记录
  spath := ExtractFilePath(application.ExeName);
  sfile := FormatDateTime('yyyy-mm-dd hh-mm-ss',Now());
  sfile := sfile + '.txt';
  mo.Lines.SaveToFile(spath + sfile);
  
  //showMessage( ss );
  MessageBox( self.Handle,PChar(ss),' 提示 ',0 );

end;

//校验总库中的儿童信息是否已经存在,0=不存在,1=查询出错,2=存在
function TfrmChild.CheckChildInfo(sName,sBirth,sMather,sFather,iSex: String):integer;
begin
  with checkInfo do
  begin
    Close;
    ParamByName('name').AsString := sName;
    ParamByName('birth').AsString := sBirth;
    ParamByName('mather').AsString := sMather;
    ParamByName('father').AsString := sFather;
    ParamByName('sex').AsString := iSex;
    try
      Open;
    except
      CheckChildInfo := 1;
      exit;
    end;
    if IsEmpty = false then
    begin
      CheckChildInfo := 2;
      exit;
    end;
    CheckChildInfo := 0;
  end;
end;

function TfrmChild.GetKeyID( ichildType : integer ; sStationID : string):string;
var
  ss,sid : string;
begin
  //生成主键
  try
    GetKey.Close;
    GetKey.ParamByName('c_table').AsString := 'cd';
    GetKey.Open;
    //主键规则         1=常住,2=流动
    //站点号(6位)+类型(1位)+年(2位)+数字号(6位)
    //sStationID := StationID[ cbxStation.ItemIndex ];
    //ss := Copy(sStationID,1,6)+IntToStr(ichildType);//截取站点编号
    ss := Copy( sStationID,1,6 )+IntToStr(ichildType);//截取站点编号

    ss := ss + Copy( DateToStr( Date() ) , 3, 2); //加年

    sid := GetKey.FieldByName('l_id').AsString ;  //获得数字
    ss := ss + Copy('000000',1,6-length(sid))+sid;//组织编号

    GetKeyID := ss;
    KeyAdd.Close;
    KeyAdd.ParamByName('c_table').AsString := 'cd';
    KeyAdd.ExecSQL;

    //mo.Lines.Add( GetKey.FieldByName('c_table').AsString );
    //mo.Lines.Add( GetKey.FieldByName('l_id').AsString );
    //mo.Lines.Add( GetKey.FieldByName('tableName').AsString );
    
  except
    GetKeyID := '';
    exit;
  end;

end;

function TfrmChild.InsertInoculate(sID,sChildID: String):integer;
var
  sBacterinId,ss : string;
  sBacterinName,sInoculateDate : string;
  inum : integer;
  dInoculateDate:TDateTime;
begin

  sID := Trim(sID);
  sChildID := Trim(sChildID);

  with qryInoculateSel do
  begin
    close;
    ParamByName('ChildId').AsString := sID;
    try
      open;
    except
      exit;
    end;
    inum := 0;
    while not eof do
    begin

      dInoculateDate := qryInoculateSel.FieldByName('InoculateDate').AsDateTime;
      sBacterinId := qryInoculateSel.FieldByName('BacterinId').AsString;

      sBacterinName := qryInoculateSel.FieldByName('BacterinInfo').AsString;
      sInoculateDate:= qryInoculateSel.FieldByName('InoculateDate').AsString;

      ss := sBacterinName+' , 接种日期: '+sInoculateDate;

      //不必校验,因为儿童的编号每次都是新的,所以只校验儿童就行了

      //校验总库中的儿童接种记录是否已经存在,0=不存在,1=查询出错,2=存在
      //if CheckInoculateInfo(sChildID,sBacterinId) = 0 then
      //校验总库中的儿童应种信息是否已经存在,0=不存在,1=查询出错,2=存在
      //if CheckShouldInfo(sChildID,sBacterinId) = 0 then

      //导入接种记录
      {
      id, stationId, childId, bacterinId, bacterinInfo, inoculateHuman,
      inoculateDate, inoculateAddress, medicineCode, remark, typeId,
      batchCode, madeArea, isNation, price, other, iflag
      }
      adoInoculateAdd.Close;
      adoInoculateAdd.Parameters.ParamByName('id').Value := GetMainKey('il');
      adoInoculateAdd.Parameters.ParamByName('ChildId').Value := sChildID;
      adoInoculateAdd.Parameters.ParamByName('BacterinId').Value := sBacterinId;
      adoInoculateAdd.Parameters.ParamByName('InoculateHuman').Value := adoInoculateSel.FieldByName('InoculateHuman').AsString;
      adoInoculateAdd.Parameters.ParamByName('InoculateDate').Value := dInoculateDate;
      adoInoculateAdd.Parameters.ParamByName('Remark').Value := adoInoculateSel.FieldByName('Remark').AsString;
      adoInoculateAdd.Parameters.ParamByName('InoculateAddress').Value := frmMain.sStrtionID;
      
      adoInoculateAdd.Parameters.ParamByName('stationId').Value := sStationID;//frmMain.sStrtionID;
      //疫苗类别,1=计划内,2=计划外
      adoInoculateAdd.Parameters.ParamByName('typeId').Value := '1';

      try
        adoInoculateAdd.ExecSQL;
      except
        mo.Lines.Add( '         --  接种记录导入失败 >< ' + ss );
        next;
        continue;
      end;      
      mo.Lines.Add( '         --  接种记录导入成功 -> ' + ss ); 
      //========================================================================
      //导入应种记录
      {
      id, childId, BacterinId, shouldDate, isInoculate,
      stationId, inoculateDate, willDate, typeId
      }
      adoShouldJZAdd.Close;
      adoShouldJZAdd.Parameters.ParamByName('id'      ).Value := GetMainKey('sd');
      adoShouldJZAdd.Parameters.ParamByName('childId' ).Value := sChildID;
      adoShouldJZAdd.Parameters.ParamByName('BacterinId'    ).Value := sBacterinId;//adoInoculateSel.FieldByName('BacterinId').AsString;
      adoShouldJZAdd.Parameters.ParamByName('shouldDate'    ).Value := dInoculateDate;//adoInoculateSel.FieldByName('InoculateDate').AsDateTime;
      adoShouldJZAdd.Parameters.ParamByName('stationId'     ).Value := sStationID;//frmMain.sStrtionID;;
      adoShouldJZAdd.Parameters.ParamByName('inoculateDate' ).Value := dInoculateDate;//adoInoculateSel.FieldByName('InoculateDate').AsDateTime;

      adoShouldJZAdd.Parameters.ParamByName('willDate' ).Value := dInoculateDate;
      //疫苗类别,1=计划内,2=计划外
      adoShouldJZAdd.Parameters.ParamByName('typeId' ).Value := '1';

      try
        adoShouldJZAdd.ExecSQL;
      except
        mo.Lines.Add( '         --  应种记录导入失败 >< ' + ss );
        next;
        continue;
      end;
      //mo.Lines.Add( '         --  应种记录导入成功 -> ' + ss );
      //========================================================================
      inum := inum+1;
      next;

    end;    
    mo.Lines.Add( '         ==  成功导入接种记录数: ' + IntToStr(inum) );

  end;
  
end;

end.

⌨️ 快捷键说明

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