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

📄 cls_datapub.pas

📁 用Delhpi和mapx开发的警务管理系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      end;
      iNum:=iNum + 1;
    end
    else if (mContainer.Controls[iLoop] is TBase_DateTimePicker) then
    begin
      //TBase_DateTimePicker(mContainer.Controls[iLoop]).Date:=strtodate(PtableTemp^.DataValue[iNum]);
      iNum:=iNum + 1;
    end
    else if (mContainer.Controls[iLoop] is TBase_Time) then
    begin
      //TBase_Time(mContainer.Controls[iLoop]).Time:=strtotime(PtableTemp^.DataValue[iNum]);
      iNum:=iNum + 1;
    end
    else if (mContainer.Controls[iLoop] is TBase_BitBtn) then
    begin
      mContainer.Controls[iLoop].Enabled:=true;
      iNum:=iNum + 1;
    end;
  end;
  sGetDataValue;
  sGetRelTable;
  sGetRelColumn;
  mcb_Relate.Clear;
  for iLoop:=0 to High(msArrRelTableNames) do
  begin
    mcb_Relate.itemsvalue.Add(msArrRelTableNames[iLoop]);
    mcb_Relate.items.Add(sGetRelTableMemo(msArrRelTableNames[iLoop]));
    mcb_Relate.ItemIndex:=0;
  end;
end;
//*********************************************
//         打开BLob字段编辑创体                       *
//                                            *
//                                            *
//*********************************************
procedure TDataPub.OpenClick(Sender: TObject);   //打开编辑窗体
var
  strSql:string;
  iLoop:integer;
begin
  strSql:='select * from ' + msTableName + ' where ';
  for iLoop:=0 to miColumnCount -1 do
  begin
    if miArrColumnPri[iLoop]=1 then
    begin
      if UpperCase(msArrColumnType[iLoop])='VARCHAR2' then
        strSql:=strSql + msArrColumnName[iLoop] + '=''' + msArrDataValue[iLoop] + ''' and   '
      else if UpperCase(msArrColumnType[iLoop])='LONGTITUDE' then
        strSql:=strSql + msArrColumnName[iLoop] + '=''' + msArrDataValue[iLoop] + ''' and   '
      else if UpperCase(msArrColumnType[iLoop])='LATITUDE' then
        strSql:=strSql + msArrColumnName[iLoop] + '=''' + msArrDataValue[iLoop] + ''' and   '
      else if UpperCase(msArrColumnType[iLoop])='NUMBER' then
        begin
          if msArrDataValue[iLoop]<>'' then
            strSql:=strSql + msArrColumnName[iLoop] + '=' + msArrDataValue[iLoop] + ' and   '
          else
            strSql:=strSql + msArrColumnName[iLoop] + '=0' + ' and   ';
        end
      else if UpperCase(msArrColumnType[iLoop])='DATE' then
        strSql:= strSql + msArrColumnName[iLoop] + '=''' + msArrDataValue[iLoop] + ''' and   ';
    end;
  end;
  strSql:=copy(strSql,1,length(strSql)-6);
  with TForm_Ole.Create(mdataOperate,msTableName,TBase_BitBtn(Sender).Name,strSql) do
  try
    ShowModal;
  finally
    free;
  end;
end;
//*********************************************
//         打开关联表的编辑窗体               *
//                                            *
//                                            *
//*********************************************
procedure TDataPub.EditClick(Sender:TObject);    //关联表编辑
var
  strSql,tempSql:string;
  iLoop:integer;
  adoQue:TADOQuery;
  sTableName:string;
  sFieldName:string;
  iPos:integer;
  iState:integer;
begin
  strSql:='select * from ' + msTableName + ' where ';
  tempSql:='';
  for iLoop:=0 to miColumnCount -1 do
  begin
    if miArrColumnPri[iLoop]=1 then
    begin
      if UpperCase(msArrColumnType[iLoop])='VARCHAR2' then
        tempSql:=tempSql + msArrColumnName[iLoop] + '=''' + msArrDataValue[iLoop] + ''' and   '
      else if UpperCase(msArrColumnType[iLoop])='LONGTITUDE' then
        tempSql:=tempSql + msArrColumnName[iLoop] + '=''' + msArrDataValue[iLoop] + ''' and   '
      else if UpperCase(msArrColumnType[iLoop])='LATITUDE' then
        tempSql:=tempSql + msArrColumnName[iLoop] + '=''' + msArrDataValue[iLoop] + ''' and   '
      else if UpperCase(msArrColumnType[iLoop])='NUMBER' then
        begin
          if msArrDataValue[iLoop]<>'' then
            tempSql:=tempSql + msArrColumnName[iLoop] + '=' + msArrDataValue[iLoop] + ' and   '
          else
            tempSql:=tempSql + msArrColumnName[iLoop] + '=0' + ' and   ';
        end
      else if UpperCase(msArrColumnType[iLoop])='DATE' then
        tempSql:= tempSql + msArrColumnName[iLoop] + '=''' + msArrDataValue[iLoop] + ''' and   ';
    end;
  end;
  strSql:=strSql + tempSql;
  strSql:=copy(strSql,1,length(strSql)-6);
  adoQue:=mdataOperate.adoGetAdoQuery(strSql);
  sFieldName:=TBase_BitBtn(Sender).Name;
  iPos:=pos('_',sFieldName);
  sFieldName:=copy(sFieldName,iPos + 1,length(sFieldName)-1);
  sTableName:=adoQue.fieldbyname(sFieldName).AsString;
  strSql:='select * from ' + sTableName + ' where ';
  strSql:=strSql + tempSql;
  strSql:=copy(strSql,1,length(strSql)-6);
  msFieldName:=TStringList.Create;
  for iLoop:=0 to high(msArrColumnName) do
  begin
    if miArrColumnPri[iLoop] = 1 then
      msFieldName.Add(msArrDataValue[iLoop])
    else
      msFieldName.Add('');
  end;
  if miState = 0 then
    iState:=2
  else
    iState:=miState;
 with TForm_Basic.create(mdataOperate,sTableName,strSql,iState,msFieldName) do
  try
    ShowModal;
  finally
    free;
  end;
end;
//*********************************************
//         生成窗体控件                       *
//   返回值  True:成功   False:失败           *
//                                            *
//*********************************************
function TDataPub.blnGenerateControl;
var
  iLoop,jLoop,kLoop:integer;
  iTotalWidth:integer;  //行控件总长度
  iRowNum:integer; //控件行数
  iRowStart:integer; //行开始控件个数
  blnTemp:boolean;//是否换行
  le_temp:TControl;
  iLvHeight:integer;
  adoQue,adoGridQue:TADOQuery;
  sqlString:string;
  cDataGrid:TGridListView;
begin
  if miState=11 then
  begin
    for iLoop:=mContainer.ComponentCount -1 downto 0 do
    begin
      try
        mContainer.Components[iLoop].Free;
      finally
        sqlString:='';
      end;
    end;
  end;
  iRowNum:=0;
  iRowStart:=0;
  if miState=1 then
  begin
    lv_Temp:=TBase_ListView.create(mContainer);
    cDataGrid:=TGridListView.Create(mdataOperate);
    with lv_Temp do
    begin
      Height:=230;
      iLvHeight:=Height;
      Align:=alTop;
      Top:=miDistance;
      Parent:=mContainer;
      OnSelectItem:=lvSelectItem;
    end;
    adoGridQue:=mdataOperate.adoGetAdoQuery(msSqlString);
    cDataGrid.AddDatatoListView(msTableName,adoGridQue,TlistView(lv_Temp),True);
    adoGridQue.Free;
    cDataGrid.Free;
    sChangeListCaption(lv_Temp);
    sChangeListData(lv_Temp);
    iLvHeight:=iLvHeight + miDistance * 2;
  end
  else
    iLvHeight:=0;

  for iloop:=0 to miColumnCount -1 do
  begin
    if miArrAuto[iLoop]<> 1 then
    begin
      //判断是否换行
      iTotalWidth:=miDistance;
      blnTemp:=false;
      if miState<> 3 then    // 如果不是查询条件窗体
      begin
        for jloop:=iRowStart to iloop do
          begin
            if miArrAuto[jLoop] <> 1 then
              iTotalWidth:=iTotalWidth + miArrLabelWidth[jloop] + miarrEditWidth[jLoop];
          end;
        if iTotalWidth > (miWidth - miDistance) then
        begin
          iRowNum:=iRowNum + 1;
          iTotalWidth:=miDistance + miArrLabelWidth[iloop] + miarrEditWidth[iLoop];
          iRowStart:= iLoop;
          blnTemp:=True;
        end;
      end
      else if (pos('2',msarrcolumnName[iLoop])=0) then
      begin
        iRowNum:=iRowNum +1;
        iTotalWidth:=miDistance+ miArrLabelWidth[iloop] + miarrEditWidth[iLoop];
      end
      else if  (pos('2',msarrcolumnName[iLoop])<>0) then
      begin
        iTotalWidth:=iTotalWidth+ miArrLabelWidth[iloop-1] + miarrEditWidth[iLoop-1] + miArrLabelWidth[iloop] + miarrEditWidth[iLoop];
        
      end;
      if (miState=3) and (iLoop=0) then
        iRowNum:=iRowNum-1;
      //创建Label标签
      with TBase_StaticText.create(mContainer) do
      begin
        Name:='lab_' + msArrColumnName[iloop];
        if miArrColumnFor[iLoop]<>1 then
          Caption:=msArrColumnComments[iloop]
        else
          Caption:=msArrFNameColumnMemo[iLoop];
          //copy(msArrColumnComments[iloop],1,length(msArrColumnComments[iloop])-4);
        Parent:=mContainer;
        Width:=miArrLabelWidth[iLoop];
        Height:=miLabelHeight;
        left:=iTotalWidth - miArrLabelWidth[iloop] - miarrEditWidth[iLoop];
        top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;
      end;
      //创建编辑框
      if ((blnTemp=true) and (not(le_temp is TBase_BitBtn)) or (miState=3) and (pos('2',msarrcolumnName[iLoop])=0)) and (not(le_temp=nil)) then
        le_temp.Width:=miWidth - le_temp.Left - miDistance*3;
      if (uppercase(msArrColumnType[iLoop])='VARCHAR2') and (miArrColumnFor[iLoop]= 0)  then
      begin
        le_temp:= TBase_LabeledEdit.create(mContainer);
        with TBase_LabeledEdit(le_temp) do
        begin
          Caption:='';
          Parent:=mContainer;
          left:=iTotalWidth  - miarrEditWidth[iLoop];
          top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;
          Width:= miarrEditWidth[iLoop];
          MaxLength:=miArrColumnLength[iloop];
          if (miState= 1) and (miArrColumnPri[iLoop]=1) then
            ReadOnly:=true;
          Name:='edt_' + msArrColumnName[iloop];
          if miState=11 then
            Enabled:=False;
          Text:='';
        end;
      end
      else if (uppercase(msArrColumnType[iLoop])='NUMBER') and (miArrColumnFor[iLoop]= 0) then
      begin
        le_temp:= TBase_LabeledEdit.create(mContainer);
        with TBase_LabeledEdit(le_temp) do
        begin
          Caption:='';
          Parent:=mContainer;
          left:=iTotalWidth  - miarrEditWidth[iLoop];
          top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;
          Width:= miarrEditWidth[iLoop];
          MaxLength:=miArrColumnLength[iLoop];
          Name:='edt_' + msArrColumnName[iloop];
          if miState=11 then
            Enabled:=False;
          Text:='';
          if miArrColumnScale[iloop]>0 then
            begin
              miCurrentIndex:=iLoop;
              OnKeyPress:=allFloatOnKeypress;
            end
          else
            begin
              OnKeyPress:=allIntOnKeypress;
            end;
        if (miState= 1) and (miArrColumnPri[iLoop]=1) then
          ReadOnly:=True;
        end;
      end
      else if uppercase(msArrColumnType[iLoop])='DATE' then
      begin
        le_temp:= TBase_DateTimePicker.create(mContainer);
        with TBase_DateTimePicker(le_temp) do
        begin
          Parent:=mContainer;
          left:=iTotalWidth  - miarrEditWidth[iLoop];
          top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;
          Width:= miarrEditWidth[iLoop];
          Name:='dtp_' + msArrColumnName[iloop];
          if miState=11 then
            Enabled:=False;
        end;
      end
      else if uppercase(msArrColumnType[iLoop])='TIME' then
      begin
        le_temp:= TBase_Time.create(mContainer);
        with TBase_Time(le_temp) do
        begin
          Parent:=mContainer;
          left:=iTotalWidth  - miarrEditWidth[iLoop];
          top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;
          Width:= miarrEditWidth[iLoop];
          Name:='tm_' + msArrColumnName[iloop];
          if miState=11 then
            Enabled:=False;
        end;
      end
      else if UpperCase(msArrColumnType[iLoop]) = 'BLOB' then
      begin
        le_temp:=TBase_BitBtn.Create(mContainer);
        with TBase_BitBtn(le_temp) do
        begin
          Parent:=mContainer;
          left:=iTotalWidth  - miarrEditWidth[iLoop];
          top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;
          Width:= miarrEditWidth[iLoop];
          Height:=miLabelHeight;
          if miState =0 then
            Enabled:=false;
          Caption:='打 开';
          OnClick:=OpenClick;
          Name:='bbtn_' + msArrColumnName[iloop];
        end;
      end
      else if UpperCase(msArrColumnType[iLoop]) = 'TABLE' then
      begin
        le_temp:=TBase_BitBtn.Create(mContainer);
        with TBase_BitBtn(le_temp) do
        begin
          Parent:=mContainer;
          left:=iTotalWidth  - miarrEditWidth[iLoop];
          top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;

⌨️ 快捷键说明

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