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

📄 u_modal.pas

📁 相关的销售服务管理行业的一个软件
💻 PAS
字号:
unit U_Modal;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Db, Grids, DBGrids, ADODB, Buttons;

type
  TF_Modal = class(TForm)
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    ADOQuery1: TADOQuery;
    Button1: TBitBtn;
    Button2: TBitBtn;
    procedure ComboBox1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ComboBox2Enter(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    function ModalSet(var TName,Field1,Field2: string; var Mode: Integer): Boolean;
    { Public declarations }
  end;

var
  F_Modal: TF_Modal;
  TN,F1,F2: string;
  Md: Integer;
implementation

uses U_DM;

{$R *.DFM}

function TF_Modal.ModalSet(var TName,Field1,Field2: string; var Mode: Integer): Boolean;
var
  i: Integer;

begin
  Result := False;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    case Mode of
      1:  try
            SQL.Add('select distinct '+ Field1 + ' from ' + TName + '  ');
            Open;
            First;
            ComboBox1.Items.Clear;
            while not Eof do
            begin
              ComboBox1.Items.Add(FieldByName(Field1).AsString);
              Next;
            end;
            Result := True;
          except
            Result := False;
          end;   //只 Field1 作为查询字段

      2:  try
            SQL.Add('select '+Field2+' from '+TName+' where '+Field1+'=:F1 ');
            Parameters.ParamByName('F1').value := ComboBox1.Text;
            OPen;
            First;
            ComboBox2.Items.Clear;
            while not Eof do
            begin
              ComboBox2.Items.Add(FieldByName(Field2).AsString);
              Next;
            end;
            Result := True;
          except
            Result := False;
          end;    //Field2 作为查询字段,Field1 作为查询条件

      3: try
           SQL.Add('select * from '+TName+' where '+Field1+'=:F1 and '+Field2+'=:F2 ');
           Parameters.ParamByName('F1').value := ComboBox1.Text;
           Parameters.ParamByName('F2').value := ComboBox2.Text;
           Open;

           if TName = 'xs_ZHXD' then
           begin
             for i := 2 to DM.ADOTableZHXD.FieldCount do
               DM.ADOTableZHXD.Fields.FieldByNumber(i).value := Fields.FieldByNumber(i).value;
           end;

           if TName = 'xs_MXD' then
           begin
             for i := 2 to DM.ADOTableMXD.FieldCount do
               DM.ADOTableMXD.Fields.FieldByNumber(i).value := Fields.FieldByNumber(i).value;
           end;

           if TName = 'xs_FHP' then
           begin
             for i := 2 to DM.ADOTableFHP.FieldCount do
               //DM.ADOTableFHP.Fields.FieldByNumber(i).value := Fields.FieldByNumber(i).value;
             begin
              // DM.ADOTableFHP.Edit;//9.21
               DM.ADOTableFHP.Fields.FieldByNumber(i).value := Fields.FieldByNumber(i).value;
             end;
           end;

           if TName = 'xs_BGD' then
           begin
             for i := 2 to DM.ADOTableBGD.FieldCount do
               DM.ADOTableBGD.Fields.FieldByNumber(i).value := Fields.FieldByNumber(i).value;
           end;

           if TName = 'xs_WTS' then
           begin
             for i := 2 to DM.ADOTableWTS.FieldCount do
               DM.ADOTableWTS.Fields.FieldByNumber(i).value := Fields.FieldByNumber(i).value;
           end;
           Result := True;
         except
           Result := False;
         end;       // Field1,Field2 均作为查询条件
    end;

  end;

end;

procedure TF_Modal.ComboBox1Click(Sender: TObject);
begin
  if ComboBox1.Text <> '' then
  begin
    Md := 2;
    if not ModalSet(TN, F1, F2, Md) then
      Application.MessageBox('','',0+64);
  end;
end;

procedure TF_Modal.Button1Click(Sender: TObject);
begin
  if ComboBox1.Text = '' then
  begin
    Application.MessageBox(PChar(Label1.Caption+'不能为空!'),'提示',0+64);
    ComboBox1.SetFocus;
    Exit;
  end;

  if ComboBox2.Text = '' then
  begin
    Application.MessageBox(PChar(Label2.Caption+'不能为空!'),'提示',0+64);
    ComboBox2.SetFocus;
    Exit;
  end;
  Md := 3;
  if ModalSet(TN, F1, F2, Md) then
    Close;
end;

procedure TF_Modal.ComboBox2Enter(Sender: TObject);
begin
  if ComboBox1.Text = '' then
  begin
    Application.MessageBox(PChar('请先选择'+ Label1.Caption+'!'),'提示',0+64);
    ComboBox1.SetFocus;
  end;
end;

procedure TF_Modal.Button2Click(Sender: TObject);
begin
 close;
end;

end.

⌨️ 快捷键说明

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