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

📄 unit2.pas

📁 商场客户管理系统: 该系统为数据库上机实验操作。 主要是针对数据库查询
💻 PAS
字号:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    DBGrid1: TDBGrid;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    ComboBox1: TComboBox;
    Button6: TButton;
    Button7: TButton;
    procedure Button5Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  var1,varstr:String;
implementation
 uses Unit1;
{$R *.dfm}

procedure TForm2.Button5Click(Sender: TObject);
begin
form2.Close;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
   var1:=Edit1.Text;
   if(var1='')then
      Showmessage('顾客编号不能够为空,请重新输入!')
   else
       begin
         adoquery1.Close;
         adoquery1.SQL.Clear;
         adoquery1.SQL.Add('select customer_id as "客户编号",customer_name as "客户姓名",customer_sex as "性别",');
         adoquery1.SQL.Add('customer_old as "年龄",customer_department as "单位",customer_adress as "地址",');
         adoquery1.SQL.Add('customer_phone as ''联系电话'',customer_beizhu as "备注"  from customer');
         adoquery1.SQL.Add('where customer_id='''+Edit1.text+'''');
         adoquery1.Open;
         if adoquery1.recordcount=0 then
             Showmessage('对不起,所要查找的客户信息不存在!')
         else
              begin
                 edit1.Text:=adoquery1.Fields[0].AsString;
                 edit2.Text:=adoquery1.Fields[1].AsString;
                 ComboBox1.Text:=adoquery1.Fields[2].AsString;
                 edit4.Text:=adoquery1.Fields[3].AsString;
                 edit5.Text:=adoquery1.Fields[4].AsString;
                 edit6.Text:=adoquery1.Fields[5].AsString;
                 edit7.Text:=adoquery1.Fields[6].AsString;
                 edit8.Text:=adoquery1.Fields[7].AsString;
                end;
      DBGRid1.Columns[0].Width:=45;        //修改dbgrid列宽度
      DBGRid1.Columns[1].Width:=45;
      DBGRid1.Columns[2].Width:=45;
      DBGRid1.Columns[3].Width:=45;
      DBGRid1.Columns[4].Width:=45;
      DBGRid1.Columns[5].Width:=45;
      DBGRid1.Columns[6].Width:=45;
      DBGRid1.Columns[7].Width:=45;
       end;
       end;

procedure TForm2.Button2Click(Sender: TObject);
begin
   var1:=Edit1.Text;
   if(var1='')then
      Showmessage('顾客编号不能够为空,请重新输入!')
    else
      begin
         adoquery1.Close;
         adoquery1.SQL.Clear;
         adoquery1.SQL.Add('select customer_id as "客户编号",customer_name as "客户姓名",customer_sex as "性别",');
         adoquery1.SQL.Add('customer_old as "年龄",customer_department as "单位",customer_adress as "地址",');
         adoquery1.SQL.Add('customer_phone as ''联系电话'',customer_beizhu as "备注"  from customer');
         adoquery1.SQL.Add('where customer_id='''+Edit1.text+'''');
         adoquery1.Open;
         if adoquery1.recordcount<>0 then
             Showmessage('对不起,客户信息已经存在!')
          else
             begin
               adoquery1.Close;
               adoquery1.SQL.Clear;
               adoquery1.SQL.Add('insert into customer(customer_id,customer_name,customer_sex ,');
               adoquery1.SQL.Add('customer_old,customer_department,customer_adress,');
               adoquery1.SQL.Add('customer_phone,customer_beizhu )values');
               adoquery1.Sql.Add('('''+Edit1.Text+''','''+Edit2.Text+''','''+ComboBox1.Text+''',');
               adoquery1.Sql.Add(''''+Edit4.Text+''','''+Edit5.Text+''','''+Edit6.Text+''',');
               adoquery1.Sql.Add(''''+Edit7.Text+''','''+Edit8.Text+''')');
             //  showMessage(adoquery1.Sql.getText());      //检测输入
               adoquery1.ExecSQL;
               showmessage('添加成功!');

             end;
      end;
end;

procedure TForm2.Button6Click(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
ComboBox1.Text:='';
Edit4.Text:='';
Edit5.Text:='';
Edit6.Text:='';
Edit7.Text:='';
Edit8.Text:='';

end;

procedure TForm2.Button3Click(Sender: TObject);
begin
   var1:=Edit1.Text;
   if(var1='')then
      Showmessage('顾客编号不能够为空,请重新输入!')
    else
      begin
         adoquery1.Close;
         adoquery1.SQL.Clear;
         adoquery1.SQL.Add('select customer_id as "客户编号",customer_name as "客户姓名",customer_sex as "性别",');
         adoquery1.SQL.Add('customer_old as "年龄",customer_department as "单位",customer_adress as "地址",');
         adoquery1.SQL.Add('customer_phone as ''联系电话'',customer_beizhu as "备注"  from customer');
         adoquery1.SQL.Add('where customer_id='''+Edit1.text+'''');
         adoquery1.Open;
         if adoquery1.recordcount=0 then
             Showmessage('对不起,客户信息不存在,请确认后重新输入!')
          else
             begin
               adoquery1.Close;
               adoquery1.SQL.Clear;
               adoquery1.SQL.Add('delete from customer where customer_id='''+Edit1.Text+'''');
              // showMessage(adoquery1.Sql.getText());      //检测输入
               adoquery1.ExecSQL;
               showmessage('删除成功!');
             end;
        end;       

end;

procedure TForm2.Button4Click(Sender: TObject);
begin
   var1:=Edit1.Text;
   varstr:='update customer set customer_id='''+Edit1.Text+''',customer_name='''+Edit2.Text+''','
             +'customer_sex='''+ComboBox1.Text+''',customer_old='''+Edit4.Text+''',customer_department='''+Edit5.Text+''','
             +'customer_adress='''+Edit6.Text+''',customer_phone='''+Edit7.Text+''',customer_beizhu='''+Edit8.Text+''''
             +'where customer_id='''+Edit1.text+'''';
   if(var1='')then
      Showmessage('顾客编号不能够为空,请重新输入!')
    else
      begin
         adoquery1.Close;
         adoquery1.SQL.Clear;
         adoquery1.SQL.Add('select customer_id as "客户编号",customer_name as "客户姓名",customer_sex as "性别",');
         adoquery1.SQL.Add('customer_old as "年龄",customer_department as "单位",customer_adress as "地址",');
         adoquery1.SQL.Add('customer_phone as ''联系电话'',customer_beizhu as "备注"  from customer');
         adoquery1.SQL.Add('where customer_id='''+Edit1.text+'''');
         adoquery1.Open;
         if adoquery1.recordcount=0 then
             Showmessage('对不起,客户信息已经存在!')
          else
             begin
               adoquery1.Close;
               adoquery1.SQL.Clear;
               adoquery1.SQL.Add(varstr);
               showMessage(adoquery1.Sql.getText());      //检测输入
               adoquery1.ExecSQL;
               showmessage('修改成功!');
             end;
      end;
end;

procedure TForm2.Button7Click(Sender: TObject);
begin
         adoquery1.Close;
         adoquery1.SQL.Clear;
         adoquery1.SQL.Add('select customer_id as "客户编号",customer_name as "客户姓名",customer_sex as "性别",');
         adoquery1.SQL.Add('customer_old as "年龄",customer_department as "单位",customer_adress as "地址",');
         adoquery1.SQL.Add('customer_phone as ''联系电话'',customer_beizhu as "备注"  from customer');
         adoquery1.Open;
         DBGRid1.Columns[0].Width:=45;        //修改dbgrid列宽度
         DBGRid1.Columns[1].Width:=45;
         DBGRid1.Columns[2].Width:=45;
         DBGRid1.Columns[3].Width:=45;
         DBGRid1.Columns[4].Width:=45;
         DBGRid1.Columns[5].Width:=45;
         DBGRid1.Columns[6].Width:=45;
         DBGRid1.Columns[7].Width:=45;
end;

end.

⌨️ 快捷键说明

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