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

📄 cls_datapub.pas

📁 用Delhpi和mapx开发的警务管理系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
          Width:= miarrEditWidth[iLoop];
          Height:=miLabelHeight;
          if miState=0 then
            Enabled:=false;
          Caption:='编 辑';
          OnClick:=EditClick;
          Name:='btn_' + msArrColumnName[iloop];
        end;
      end
      else if UpperCase(msArrColumnType[iLoop]) = 'LONGTITUDE' then
      begin
        le_temp:= TBase_MaskEditLon.create(mContainer);
        with TBase_MaskEditLon(le_temp) do
        begin
          Parent:=mContainer;
          left:=iTotalWidth  - miarrEditWidth[iLoop];
          top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;
          Width:= miarrEditWidth[iLoop];
          Name:='medt_' + msArrColumnName[iloop];
        end;
      end
      else if UpperCase(msArrColumnType[iLoop]) = 'LATITUDE' then
      begin
        le_temp:= TBase_MaskEditLat.create(mContainer);
        with TBase_MaskEditLat(le_temp) do
        begin
          Parent:=mContainer;
          left:=iTotalWidth  - miarrEditWidth[iLoop];
          top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;
          Width:= miarrEditWidth[iLoop];
          Name:='medt_' + msArrColumnName[iloop];
        end;
      end
      else if (miArrColumnFor[iLoop]= 1)  then
      begin
        le_temp:= TBase_ComboBox.create(mContainer);
        with TBase_ComboBox(le_temp) do
        begin
          Parent:=mContainer;
          left:=iTotalWidth  - miarrEditWidth[iLoop];
          top:= (iRowNum+1) * miDistance + iRowNum * miLabelHeight + iLvHeight;
          Width:= miarrEditWidth[iLoop];
          if miState=11 then
            Enabled:=false;
          Style:=csDropDownList;
          Name:='cb_' + msArrColumnName[iloop];
          if (miState=1) and (miArrColumnPri[iLoop]=1) then
            Enabled:=false;
          //取得外键值
          if miState=3 then
          begin
            Items.Add('');
            itemsvalue.Add('');
          end;
          sqlString:='select * from ' + msArrFTableName[iloop];
          adoQue:=mdataOperate.adoGetAdoQuery(sqlString);
          for kLoop:=0 to adoQue.RecordCount - 1 do
          begin
            Items.Add(adoQue.fieldbyname(msArrFNameColumn[iLoop]).AsString);
            itemsvalue.Add(adoQue.fieldbyname(msArrFCodeColumn[iLoop]).AsString);
            adoQue.Next;
          end;
          adoQue.Free;
          ItemIndex:=0;
          //如果是嵌套表添加
          if miState=2 then
          begin
            Enabled:=false;
            //for kLoop:=0 to msFieldName.Count do
            //begin
              //if msFieldName.Strings[kLoop]<>'' then
            //end;
            for kLoop:=0 to Items.Count -1 do
            begin
              if itemsvalue[kLoop] = msFieldName.Strings[iLoop] then
                ItemIndex:=kLoop;
            end;
          end;
        end;
      end;
  end
  else
 begin
    with TBase_LabeledEdit.create(mContainer) 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];
      Text:='';
      Visible:=false;
      //iRowNum:=iRowNum + 1;
      if miState= 3 then
        iRowNum:=iRowNum -1;
    end;
 end;
 end;

  if (not(le_temp is TBase_BitBtn))  then
    le_temp.Width:=miWidth - le_temp.Left - miDistance*3;
  if miState =4 then
    lvDataShow;
end;
//*********************************************
//         取单个控件的数据                   *
//                                            *
//                                            *
//*********************************************
function TDataPub.sGetConValue(sControl: TControl): String;
begin
  if (sControl is TBase_LabeledEdit) then
    Result:=TBase_LabeledEdit(sControl).Text
  else if (sControl is TMaskEdit) then
    Result:=TMaskEdit(sControl).Text
  else if (sControl is TBase_ComboBox) then
    begin
      if TBase_ComboBox(sControl).Text='' then
        Result:=''
      else
        Result:=TBase_ComboBox(sControl).itemsvalue[TBase_ComboBox(sControl).itemindex];
    end
  else if(sControl is TBase_DateTimePicker) then
    Result:=Datetostr(TBase_DateTimePicker(sControl).date)
  else if (sControl is TBase_Time) then
    Result:=TimeToStr(TBase_Time(sControl).Time);
end;
//*********************************************
//         取单个控件的显示数据               *
//                                            *
//                                            *
//*********************************************
function TDataPub.sGetConShowValue(sControl: TControl): String;
begin
  if (sControl is TBase_LabeledEdit) then
    Result:=TBase_LabeledEdit(sControl).Text
  else if (sControl is TBase_ComboBox) then
    begin
      if TBase_ComboBox(sControl).Text='' then
        Result:=''
      else
        Result:=TBase_ComboBox(sControl).Items[TBase_ComboBox(sControl).itemindex];
    end
  else if(sControl is TBase_DateTimePicker) then
    Result:=Datetostr(TBase_DateTimePicker(sControl).date)
  else if (sControl is TBase_Time) then
    Result:=TimeToStr(TBase_Time(sControl).Time);
end;
//*********************************************
//         取窗体所有控件的数据               *
//   返回值  True:成功   False:失败           *
//                                            *
//*********************************************
procedure TDataPub.sGetDataValue;
var
  iLoop:integer;
  iComCount:integer;
  iNum:integer; 
  //iResult:integer;
begin
  iComCount:=mContainer.ControlCount;
  iNum:=0;
  //取得控件值
  for iLoop:=0 to iComCount - 1 do
  begin
    if (mContainer.Controls[iLoop] is TBase_LabeledEdit) or (mContainer.Controls[iLoop] is TBase_ComboBox) or(mContainer.Controls[iLoop] is TDateTimePicker) or(mContainer.Controls[iLoop] is TMaskEdit) then
    begin
      msArrDataValue[iNum]:=sGetConValue(mContainer.Controls[iLoop]);
      msArrShowValue[iNum]:=sGetConShowValue(mContainer.Controls[iLoop]);
      iNum:=iNum + 1;
    end;
  end;
end;
//*********************************************
//         添加记录                           *
//                                            *
//                                            *
//*********************************************
procedure Tdatapub.blnAddRecord;
var
  sqlString:string;
  sqlAutoSelect:string;
  adoQue:TADOQuery;
  iLoop,iResult:integer;
  hintCaption:array[0..50] of char;
  iAutoNum:integer;
  blnTemp:Boolean;   //是否需要进行唯一型检查,如果包含自动增长列则不需要检查
  //adoQue:TADOQuery;
begin
  //得到用户输入的数据
  sGetDataValue;
  //非空验证
  iResult:=iCheckNullAble();
  if iResult<>-1 then
    begin
      strpcopy(hintCaption,msArrColumnComments[iResult]+'不允许为空');
      Application.MessageBox(hintCaption,'提示',MB_OK + MB_ICONINFORMATION);
      exit;
    end;
  for iLoop:=0 to miColumnCount -1 do
  begin
    if miArrAuto[iLoop] = 1 then
    begin
      blnTemp:=true;
      break;
    end;
  end;
  //检查主键是否重复
  if blnTemp=false then
    begin
      if iCheckUnique = -1 then
      begin
        Application.MessageBox('记录重复!','提示',MB_OK + MB_ICONINFORMATION);
        exit;
      end;
    end;
  //形成Add sql 语句
  sqlString:='insert into ' + msTableName + '(';
  for iLoop:=0 to miColumnCount -1 do
  begin
    if (UpperCase(msArrColumnType[iLoop])<>'BLOB') and (UpperCase(msArrColumnType[iLoop])<>'TABLE') then
      sqlString:=sqlString + msArrColumnName[iLoop] + ',';
  end;
  sqlString:=copy(sqlString,1,length(sqlString)-1);
  sqlString:=sqlString + ')' + ' values(';
  //sqlString:='Select * from ' + msTableName + ' where ';
  for iLoop:=0 to miColumnCount -1 do
  begin
    if UpperCase(msArrColumnType[iLoop])='VARCHAR2' then
    begin
      if msArrDataValue[iLoop]<>'' then
        sqlString:=sqlString + '''' + msArrDataValue[iLoop] + ''','
      else
        sqlString:=sqlString + ''' '  + ''',';
    end
    else if UpperCase(msArrColumnType[iLoop])='LONGTITUDE' then
    begin
      if msArrDataValue[iLoop]<>'' then
       sqlString:=sqlString + '''' + msArrDataValue[iLoop] + ''','
      else
       sqlString:=sqlString + ''' ' + ''',';
    end
    else if UpperCase(msArrColumnType[iLoop])='LATITUDE' then
    begin
      if msArrDataValue[iLoop]<>'' then
        sqlString:=sqlString + '''' + msArrDataValue[iLoop] + ''','
      else
        sqlString:=sqlString + ''' ' + ''',';
    end
    else if (UpperCase(msArrColumnType[iLoop])='NUMBER') and (miArrAuto[iLoop]<>1) then
      begin
        if msArrDataValue[iLoop]<>'' then
          sqlString:=sqlString + msArrDataValue[iLoop] + ','
        else
          sqlString:=sqlString + '0,';
      end
    else if (UpperCase(msArrColumnType[iLoop])='NUMBER') and (miArrAuto[iLoop]=1) then
      begin
        sqlAutoSelect:='select ' + msArrColumnName[iLoop] + ' from ' + msTableName + ' order by '+ msArrColumnName[iLoop] + ' asc';
        adoQue:=mdataOperate.adoGetAdoQuery(sqlAutoSelect);
        adoQue.Last;
        iAutoNum:=adoQue.Fields[0].AsInteger;
        iAutoNum:=iAutoNum + 1;
        sqlString:=sqlString + inttostr(iAutoNum) + ',';
      end
    else if UpperCase(msArrColumnType[iLoop])='DATE' then
      sqlString:= sqlString + '''' + msArrDataValue[iLoop] + ''','
    else if UpperCase(msArrColumnType[iLoop])='TIME' then
      sqlString:= sqlString + '''' + msArrDataValue[iLoop] + ''',';
  end;
  sqlString:=copy(sqlString,1,length(sqlString)-1);
  sqlString:=sqlString + ')';
  try
    mdataOperate.blnExecuteSQL(sqlString);
  except on E:Exception do
    begin
      Application.MessageBox('保存失败!','提示',MB_OK + MB_ICONINFORMATION);
      exit;
    end;
  end;
  Application.MessageBox('保存成功!','提示',MB_OK + MB_ICONINFORMATION);
end;
//*********************************************
//         更新记录时更新ListView的显示       *
//                                            *
//                                            *
//*********************************************
procedure Tdatapub.lvChangeData;
var
  iLoop:integer;
  iIndex:integer;
  PtableTemp:pTable;
begin
  if miState=4 then
    lv_Temp:=TBase_ListView(mAttribute);
  for iLoop:=0 to lv_Temp.Items.Count -1 do
  begin
    if lv_Temp.Items[iLoop].Selected= true then
      iIndex:=iLoop;
  end;
  PtableTemp:=lv_Temp.Items[iIndex].Data;
  for iLoop:=0 to lv_Temp.Columns.Count -1 do
  begin
    if iLoop=0 then
      lv_Temp.Items[iIndex].Caption:=msArrShowValue[iLoop]
    else
      lv_Temp.Items[iIndex].SubItems[iLoop -1]:= msArrShowValue[iLoop];
    PtableTemp^.DataValue[iLoop]:=msArrdataValue[iLoop];
  end;

end;
//*********************************************
//         更新记录                           *
//                                            *
//                                            *
//*********************************************
procedure Tdatapub.blnUpdateRecord;
var
  sqlString:string;
  iLoop,iResult:integer;
  hintCaption:array[0..50] of char;
begin
  //得到用户输入的数据
  sGetDataValue;
  //非空验证
  iResult:=iCheckNullAble();
  if iResult<>-1 then
    begin
      strpcopy(hintCaption,msArrColumnComments[iResult]+'不允许为空');
      Application.MessageBox(hintCaption,'提示',MB_OK + MB_ICONINFORMATION);
      exit;
    end;
  //形成Update sql 语句
  sqlString:='update ' + msTableName + ' set ';
  for iLoop:=0 to miColumnCount -1 do
  begin
    if miArrColumnPri[iLoop]=0 then
    begin
      if UpperCase(msArrColumnType[iLoop])='VARCHAR2' then
      begin

⌨️ 快捷键说明

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