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

📄 ag_selchar.pas

📁 亚惠快餐管理信息系统 包括亚惠快餐管理的各项功能
💻 PAS
字号:
unit AG_SelChar;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB, CheckLst, DBCtrls;

type
  TFrmAG_SelChar = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    CheckListBox1: TCheckListBox;
    Button5: TButton;
    Button6: TButton;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    SelChar: string;
    FieldName: string;
    function CreateDictionary(DictionaryTableName: string): Boolean;
  end;

function SetWork(AFieldName: string; var ASelChar: string): Boolean;

implementation

uses main, PublicUnit;

{$R *.dfm}

function SetWork(AFieldName: string; var ASelChar: string): Boolean;
var
  FrmAG_SelChar: TFrmAG_SelChar;
  i: integer;
begin
  Result := False;
  Application.CreateForm(TFrmAG_SelChar, FrmAG_SelChar);
  with FrmAG_SelChar do
  begin
    FieldName := AFieldName;
    SelChar := ASelChar;
    if ShowModal = mrOK then
    begin
      ASelChar := '';
      for i := 0 to CheckListBox1.Items.Count - 1 do
        if CheckListBox1.Checked[i] then
          ASelchar := ASelchar + ',''' + CheckListBox1.Items[i] + '''';
      if ASelChar <> '' then
        ASelChar := Copy(ASelChar, 2, 10000000);
      Result := True;
    end;
    Free;
  end;
end;

{-------------------------------------------------------------------------------}

procedure TFrmAG_SelChar.FormShow(Sender: TObject);
var
  i: integer;
begin
  with ADOQuery1 do
  begin
    ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
      + FrmMain.DbUser + ';Password=' + FrmMain.DbPass + ';Initial Catalog=' +
      FrmMain.DbName + ';Data Source=' + FrmMain.ServerName;
    Sql.Add('Select RTrim(DICTIONARY)');
    Sql.Add('From Dic_' + FieldName);
    try
      Open;
    except
      if not CreateDictionary('Dic_' + FieldName) then
        Exit;
    end;
    Close;
    RefreshDBDictionery('Dic_' + FieldName);
    Close;
    Sql.Clear;
    Sql.Add('Select RTrim(DICTIONARY)');
    Sql.Add('From Dic_' + FieldName);
    try
      Open;
    except
      Exit;
    end;
    CheckListBox1.Items.Clear;
    while not Eof do
    begin
      CheckListBox1.Items.Add(Fields[0].Asstring);
      Next;
    end;
    for i := 0 to CheckListBox1.Items.Count - 1 do
      CheckListBox1.Checked[i] := True;
  end;
end;

procedure TFrmAG_SelChar.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ADOQuery1.Close;
end;

{-------------------------------------------------------------------------------}

procedure TFrmAG_SelChar.Button1Click(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to CheckListBox1.Items.Count - 1 do
    CheckListBox1.Checked[i] := True;
end;

procedure TFrmAG_SelChar.Button2Click(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to CheckListBox1.Items.Count - 1 do
    CheckListBox1.Checked[i] := False;
end;

procedure TFrmAG_SelChar.Button5Click(Sender: TObject);
var
  s: string;
begin
  s := '';
  if not InputQuery('增加节点', '请输入合法的节点值:', s) then
    Exit;
  s := Trim(s);
  if ((s = '') or (CheckListBox1.Items.IndexOf(s) <> -1)) then
    Exit;
  CheckListBox1.Items.Add(s);
  CheckListBox1.Checked[CheckListBox1.Items.IndexOf(s)] := True;
end;

procedure TFrmAG_SelChar.Button6Click(Sender: TObject);
begin
  if CheckListBox1.ItemIndex = -1 then
    Exit;
  CheckListBox1.Items.Delete(CheckListBox1.ItemIndex);
end;

function TFrmAG_SelChar.CreateDictionary(DictionaryTableName: string): Boolean;
var
  ADOQuery: TADOQuery;
begin
  Result := False;
  ADOQuery := TADOQuery.Create(Application);
  with ADOQuery do
  begin
    Close;
    ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
      + FrmMain.DbUser + ';Password=' + FrmMain.DbPass + ';Initial Catalog=' +
      FrmMain.DbName + ';Data Source=' + PublicUnit.ServerName;
    Sql.Clear;
    Sql.Add('Create Table ' + DictionaryTableName);
    Sql.Add('(ID varChar (10),DICTIONARY varChar(50) not null Primary Key)');
    try
      ExecSql;
    except
      ShowMessage('error');
      Exit;
    end;
    Free;
  end;
  Result := True;
end;

end.

⌨️ 快捷键说明

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