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

📄 untmaintainvs.~pas

📁 1、通过串口连接手机或短信终端发送短信; 2、内置Access数据库
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
unit UntMaintainVS;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBGrids, Grids, StdCtrls, Buttons, ToolWin, ComCtrls, DB, StrUtils;

type
  TFrmMaintainVS = class(TForm)
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    GroupBoxVS: TGroupBox;
    lbSelected: TLabel;
    lbForSelect: TLabel;
    Label2: TLabel;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    ComboBox1: TComboBox;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure ComboBox1Select(Sender: TObject);
    procedure StringGrid1DblClick(Sender: TObject);
    procedure StringGrid2DblClick(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ClearStringGrid1;
    procedure ClearStringGrid2;      
    procedure RefreshComboBox1;    
    procedure RefreshLabels;    
    procedure RefreshDBGrid1;
    procedure RefreshStringGrids;     
  end;

var
  FrmMaintainVS: TFrmMaintainVS;

implementation
uses UntMain, UntDM;
{$R *.dfm}

procedure TFrmMaintainVS.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  if frmMaintainVS<>nil then
  begin
    frmMaintainVS.Release;
    frmMaintainVS := nil;
  end;
end;

procedure TFrmMaintainVS.SpeedButton1Click(Sender: TObject);
begin
  Close;
end;

procedure TFrmMaintainVS.FormCreate(Sender: TObject);
begin
  if Length(MaintainTableName)>0 then GroupBoxVS.Caption := MaintainTableName;
  if GroupBoxVS.Caption='联系人分组表' then
  begin
    RadioButton1.Caption := '由联系人对应组别';
    RadioButton2.Caption := '由组别对应联系人';
    RadioButton1.Checked := True;
    Label1.Caption := '选定联系人';
    lbSelected.Caption := '已选对应组别';
    lbForSelect.Caption := '备选对应组别';
  end else if GroupBoxVS.Caption='公司人员表' then
  begin
    RadioButton1.Caption := '由员工对应公司';
    RadioButton2.Caption := '由公司对应员工';
    RadioButton1.Checked := True;
    Label1.Caption := '选定员工';
    lbSelected.Caption := '已选隶属公司';
    lbForSelect.Caption := '备选隶属公司';
  end;
  RefreshComboBox1;
  if ComboBox1.Items.Count>0 then ComboBox1.ItemIndex := 0;
  RefreshStringGrids;
  RefreshDBGrid1;
end;

procedure TFrmMaintainVS.RefreshDBGrid1;
begin
  if GroupBoxVS.Caption='联系人分组表' then
  begin
    DataSource1.DataSet := DM1.QryHumanVG;
    DM1.QryHumanVG.Close;
    DM1.QryHumanVG.Open;
    exit;
  end;
  if GroupBoxVS.Caption='公司人员表' then
  begin
    DataSource1.DataSet := DM1.QryCoVG;
    DM1.QryCoVG.Close;
    DM1.QryCoVG.Open;
    exit;
  end;
end;

procedure TFrmMaintainVS.RefreshLabels;
begin
  if GroupBoxVS.Caption='联系人分组表' then
  begin
    if RadioButton1.Checked=True then
    begin
      Label1.Caption := '选定联系人';
      lbSelected.Caption := '已选对应组别';
      lbForSelect.Caption := '备选对应组别';
    end else
    begin
      Label1.Caption := '选定组';
      lbSelected.Caption := '已选对应联系人';
      lbForSelect.Caption := '备选对应联系人';
    end;
  end else if GroupBoxVS.Caption='公司人员表' then
  begin
    if RadioButton1.Checked=True then
    begin
      Label1.Caption := '选定员工';
      lbSelected.Caption := '已选隶属公司';
      lbForSelect.Caption := '备选隶属公司';
    end else
    begin
      Label1.Caption := '选定公司';
      lbSelected.Caption := '已选所辖员工';
      lbForSelect.Caption := '备选所辖员工';
    end;
  end;
end;

procedure TFrmMaintainVS.RefreshComboBox1;
var
  sSQL,sTmp:string;
begin
  if GroupBoxVS.Caption='联系人分组表' then
  begin
    //刷新ComboBoxVS
    ComboBox1.Clear;
    if RadioButton1.Checked then sSQL := ' Select 姓名, 联系人ID from 联系人字典'
    else sSQL := ' Select 组名, 组ID from 联系人组别定义字典';
    DM1.QryMaintain.Close;
    DM1.QryMaintain.SQL.Text := sSQL;
    DM1.QryMaintain.Open;
    if DM1.QryMaintain.RecordCount>0 then DM1.QryMaintain.First;
    While not DM1.QryMaintain.Eof do
    begin
      if RadioButton1.Checked then
        sTmp := DM1.QryMaintain.FieldByname('姓名').AsString + '/'
               +DM1.QryMaintain.FieldByname('联系人ID').AsString
      else sTmp := DM1.QryMaintain.FieldByname('组名').AsString + '/'
               +DM1.QryMaintain.FieldByname('组ID').AsString;
      ComboBox1.Items.Add(sTmp);
      DM1.QryMaintain.Next;
    end;
    DM1.QryMaintain.Close;
    exit;
  end;

  if GroupBoxVS.Caption='公司人员表' then
  begin
    //刷新ComboBoxVS
    ComboBox1.Clear;
    if RadioButton1.Checked then sSQL := ' Select 姓名, 联系人ID from 联系人字典'
    else sSQL := ' Select 名称, 公司ID from 公司字典';
    DM1.QryMaintain.Close;
    DM1.QryMaintain.SQL.Text := sSQL;
    DM1.QryMaintain.Open;
    if DM1.QryMaintain.RecordCount>0 then DM1.QryMaintain.First;
    While not DM1.QryMaintain.Eof do
    begin
      if RadioButton1.Checked then
        sTmp := DM1.QryMaintain.FieldByname('姓名').AsString + '/'
               +DM1.QryMaintain.FieldByname('联系人ID').AsString
      else sTmp := DM1.QryMaintain.FieldByname('名称').AsString + '/'
               +DM1.QryMaintain.FieldByname('公司ID').AsString;
      ComboBox1.Items.Add(sTmp);
      DM1.QryMaintain.Next;
    end;
    DM1.QryMaintain.Close;
    exit;
  end;
end;

procedure TFrmMaintainVS.RefreshStringGrids;
var
  TmpStr,sTmp,sSQL,sSQLg,sSQLp:string;
  i:integer;
begin
  TmpStr := '';
  sTmp := '';
  TmpStr := ComboBox1.Text;
  if (Pos('/',TmpStr)=0)or(Length(TmpStr)<22) then exit;
  sTmp := RightStr(TmpStr,Length(TmpStr)-Pos('/',TmpStr));
  if Length(sTmp)=0 then exit;

  if GroupBoxVS.Caption='联系人分组表' then
  begin
    //刷新StringGrid1
    if RadioButton1.Checked then
      sSQL := ' Select g.组名, g.组ID from 联系人组别定义字典 g, 联系人分组表 pvg, 联系人字典 p'
             +'  Where (g.组ID=pvg.组ID)and(pvg.联系人ID=p.联系人ID)and(p.联系人ID='''+sTmp+''')'
             +' Order by g.组名 '
    else
      sSQL := ' Select p.姓名, p.联系人ID from 联系人组别定义字典 g, 联系人分组表 pvg, 联系人字典 p'
             +'  Where (p.联系人ID=pvg.联系人ID)and(pvg.组ID=g.组ID)and(g.组ID='''+sTmp+''')'
             +' Order by p.姓名 ';
    sSQLg := ' Select 组名, 组ID from 联系人组别定义字典 '
            +'  Where 组ID not in '
            +' (Select g.组ID from 联系人组别定义字典 g, 联系人分组表 pvg, 联系人字典 p'
            +'  Where (g.组ID=pvg.组ID)and(pvg.联系人ID=p.联系人ID)and(p.联系人ID='''+sTmp+'''))'
            +' Order by 组名 ';
    sSQLp := ' Select 姓名, 联系人ID from 联系人字典'
            +'  Where 联系人ID not in '
            +' (Select p.联系人ID from 联系人组别定义字典 g, 联系人分组表 pvg, 联系人字典 p'
            +'  Where (p.联系人ID=pvg.联系人ID)and(pvg.组ID=g.组ID)and(g.组ID='''+sTmp+'''))'
            +' Order by 姓名 ';
  end else if GroupBoxVS.Caption='公司人员表' then
  begin
    if RadioButton1.Checked then
      sSQL := ' Select g.名称, g.公司ID from 公司字典 g, 公司人员表 pvg, 联系人字典 p'
             +'  Where (g.公司ID=pvg.公司ID)and(pvg.联系人ID=p.联系人ID)and(p.联系人ID='''+sTmp+''')'
             +' Order by g.名称 '
    else
      sSQL := ' Select p.姓名, p.联系人ID from 公司字典 g, 公司人员表 pvg, 联系人字典 p'
             +'  Where (p.联系人ID=pvg.联系人ID)and(pvg.公司ID=g.公司ID)and(g.公司ID='''+sTmp+''')'
             +' Order by p.姓名 ';

    sSQLg := ' Select 名称, 公司ID from 公司字典'
            +'  Where 公司ID not in '
            +' (Select g.公司ID from 公司字典 g, 公司人员表 pvg, 联系人字典 p'
            +'  Where (g.公司ID=pvg.公司ID)and(pvg.联系人ID=p.联系人ID)and(p.联系人ID='''+sTmp+'''))'
            +' Order by 名称 ';
    sSQLp := ' Select 姓名, 联系人ID from 联系人字典'
            +'  Where 联系人ID not in '
            +' (Select p.联系人ID from 公司字典 g, 公司人员表 pvg, 联系人字典 p'
            +'  Where (p.联系人ID=pvg.联系人ID)and(pvg.公司ID=g.公司ID)and(g.公司ID='''+sTmp+'''))'
            +' Order by 姓名 ';
  end;

⌨️ 快捷键说明

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