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

📄 macinfo_unit.pas

📁 客户关系管理系统,可以进行一些简单的客户关系管理
💻 PAS
字号:
unit MacInfo_Unit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, ComCtrls, ToolWin, ExtCtrls, StdCtrls, Grids, DBGrids,
  DB, ADODB, Menus;

type
  TMacInfo_Form = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    CoolBar1: TCoolBar;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ImageList1: TImageList;
    DBGrid1: TDBGrid;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    procedure ToolButton3Click(Sender: TObject);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Edit3KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);

  private
    { Private declarations }
  public
    { Public declarations }
    Modify: boolean;
  end;

var
  MacInfo_Form: TMacInfo_Form;

implementation

uses Datamodule_Unit;

{$R *.dfm}

procedure TMacInfo_Form.ToolButton3Click(Sender: TObject);
begin
  Self.Close;
end;

procedure TMacInfo_Form.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = vk_Return then
  begin
    if Edit1.Text = '' then
    begin
      Application.MessageBox('请输入型号编码!', '提示', Mb_Ok or Mb_IconWarning);
    end
    else
    begin
      Edit2.SetFocus;
    end;
  end;
end;

procedure TMacInfo_Form.Edit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = vk_Return then
  begin
    if Edit2.Text = '' then
    begin
      Application.MessageBox('请输入型号名称!', '提示', Mb_Ok or Mb_IconWarning);
    end
    else
    begin
      ToolButton6.Click;
    end;
  end
end;

procedure TMacInfo_Form.FormCreate(Sender: TObject);
begin
  Modify := False;
  with datamodule_Unit.DM.aq_macinfo do
  begin
    Close;
    Sql.Clear;
    SQL.Add('select * from 机器型号表');
    try
      Open;
    except
    end;
    DBGrid1.Columns.Items[0].FieldName := 'Id';
    DBGrid1.Columns.Items[1].FieldName := 'Name';
    DBGrid1.Columns.Items[0].Title.Caption := '机器型号编号';
    DBGrid1.Columns.Items[1].Title.Caption := '型号名称';
  end;
end;

procedure TMacInfo_Form.FormActivate(Sender: TObject);
begin
  Edit1.SetFocus;
end;

procedure TMacInfo_Form.ToolButton2Click(Sender: TObject);
begin
  if Datamodule_Unit.DM.aq_macinfo.RecordCount > 0 then
  begin
    if application.MessageBox('是否真的删除?', '记录删除', 4) = 6 then
    begin
      try
        Datamodule_Unit.DM.aq_macinfo.Delete;
        Application.MessageBox('删除成功!', '提示', Mb_Ok or Mb_IconInformation);
      except
        Application.MessageBox('删除失败!', '提示', Mb_Ok or Mb_IconStop);
      end;
    end;
    with Datamodule_Unit.DM.aq_macinfo do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from 机器型号表');
      Active := true;
    end;
  end;
end;

procedure TMacInfo_Form.ToolButton1Click(Sender: TObject);
begin
  Edit1.Clear;
  Edit2.Clear;
  Edit1.SetFocus;
  if ToolButton2.Enabled = False then
  begin
    ToolButton2.Enabled := True;
  end;
  if ToolButton5.Enabled = False then
  begin
    ToolButton5.Enabled := True;
  end;
end;

procedure TMacInfo_Form.DBGrid1DblClick(Sender: TObject);
begin
  ToolButton5.Click;
end;

procedure TMacInfo_Form.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := CaFree;
  MacInfo_Form := nil;
end;


procedure TMacInfo_Form.ToolButton6Click(Sender: TObject);
begin
  ToolButton2.Enabled := True;
  ToolButton5.Enabled := True;
  if (Edit1.Text = '') or (Edit2.Text = '') then
  begin
    Application.MessageBox('请输入完整的信息!', '提示', Mb_Ok or Mb_IconWarning);
    Edit1.SetFocus;
  end
  else //输入信息完整可以保存
  begin
    with Datamodule_Unit.DM.aq_macinfo do
    begin
      SQL.Clear;
      SQL.Add('select * from 机器型号表 where id=:bm');
      Parameters.ParamByName('bm').Value := edit1.Text;
      Active := true;
      if Recordset.RecordCount > 0 then //有此条记录
      begin
        if Modify = False then //非修改模式
        begin
          Application.MessageBox('已有此信息,请重输!', '提示', Mb_Ok or Mb_IconWarning);
          Close;
          SQL.Clear;
          SQL.Add('select * from 机器型号表 order by id');
          Active := true;
          edit1.SetFocus;
        end
        else //单击了修改按钮
        begin
          Edit;
          FieldByName('id').AsString := Edit1.Text;
          FieldByName('name').AsString := Edit2.Text;
          try
            Post;
            Application.MessageBox('保存成功!', '提示', Mb_Ok or Mb_IconInformation);
            Modify := False;
          except
            Application.MessageBox('保存失败!', '提示', Mb_Ok or Mb_IconStop);
          end;
        end;
      end
      else //新用户
      begin
        SQL.Clear;
        SQL.Add('insert into 机器型号表(id,name) values(:bm,:mc)');
        parameters.ParamByName('bm').value := edit1.text;
        parameters.ParamByName('mc').value := edit2.text;
        try
          ExecSQL;
          Application.MessageBox('保存成功!', '提示', Mb_Ok or Mb_IconInformation);
        except
          Application.MessageBox('保存失败!', '提示', Mb_Ok or Mb_IconStop);
        end;
      end;
      SQL.Clear;
      SQL.Add('select * from 机器型号表');
      Active := true;
      Edit1.Clear;
      Edit2.Clear;
      Edit1.SetFocus;
    end;
  end;
end;

procedure TMacInfo_Form.ToolButton5Click(Sender: TObject);
begin
  if Datamodule_Unit.DM.aq_macinfo.RecordCount > 0 then
  begin
    Edit1.Text := Datamodule_Unit.DM.aq_macinfo.FieldValues['id'];
    Edit2.Text := Datamodule_Unit.DM.aq_macinfo.FieldValues['name'];
    Modify := True;
  end;
end;

procedure TMacInfo_Form.N1Click(Sender: TObject);
begin
  ToolButton1.Click;
end;

procedure TMacInfo_Form.N2Click(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TMacInfo_Form.N3Click(Sender: TObject);
begin
  ToolButton5.Click;
end;

procedure TMacInfo_Form.N4Click(Sender: TObject);
begin
  ToolButton6.Click;
end;

procedure TMacInfo_Form.FormShow(Sender: TObject);
begin
  Modify := False;
end;

procedure TMacInfo_Form.Edit3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = 13 then
  begin
    ToolButton6.Click;
  end;
end;

procedure TMacInfo_Form.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  if DBGrid1.DataSource.DataSet.RecNo mod 2 = 0 then //条件判断
  begin
    with DBGrid1 do
    begin
      Canvas.Font.Color := clBlack;
      Canvas.Brush.Color := clAqua;
    end;
  end
  else
  begin
    with DBGrid1 do
    begin
      Canvas.Font.Color := clBlack;
      Canvas.Brush.Color := clMoneyGreen;
    end;
  end;
  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

end.

⌨️ 快捷键说明

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