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

📄 unit3.pas

📁 服装制造业的库存管理系统,服装进销存进货,库存,出货等等.
💻 PAS
字号:
unit Unit3;

interface

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

type
  TForm3 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    DBGridEh1: TDBGridEh;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    ToolBar1: TToolBar;
    ToolButton2: TToolButton;
    SpeedButton15: TSpeedButton;
    SpeedButton20: TSpeedButton;
    ToolButton6: TToolButton;
    SpeedButton1: TSpeedButton;
    ToolButton8: TToolButton;
    SpeedButton5: TSpeedButton;
    ToolButton7: TToolButton;
    SpeedButton11: TSpeedButton;
    ComboBox1: TComboBox;
    DataSource1: TDataSource;
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBGridEh1DblClick(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton11Click(Sender: TObject);
    procedure SpeedButton20Click(Sender: TObject);
    procedure SpeedButton15Click(Sender: TObject);
  private
    function QueryTabel(aSql:string):Boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation
uses Data,Unit1;
{$R *.dfm}

{ TForm3 }

function TForm3.QueryTabel(aSql: string): Boolean;
begin
  with MyData do
  begin
    ADOSelect.SQL.Clear;
    ADOSelect.SQL.Add(aSql);
    ADOSelect.Open;
  end;
end;

procedure TForm3.SpeedButton1Click(Sender: TObject);
begin
  QueryTabel('Select * From 用户资料');
  if (Form1.Qx='操作者') or (Form1.Qx='浏览者')  then
  begin
    SpeedButton15.Enabled:=False;
    SpeedButton5.Enabled:=False;
    ComboBox1.Enabled:=False;
    QueryTabel('Select * From 用户资料 where 用户='''+form1.ComboBox1.Text+'''');
  end;  
end;

procedure TForm3.FormShow(Sender: TObject);
begin
  QueryTabel('Select * From 用户资料');
  if (Form1.Qx='操作者') or (Form1.Qx='浏览者')  then
  begin
    SpeedButton15.Enabled:=False;
    SpeedButton5.Enabled:=False;
    ComboBox1.Enabled:=False;    
    QueryTabel('Select * From 用户资料 where 用户='''+form1.ComboBox1.Text+'''');
  end;
end;

procedure TForm3.DBGridEh1DblClick(Sender: TObject);
begin
  if DataSource1.DataSet.RecordCount<=0 then
  begin
    MessageBox(Handle, '没有数据源!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
    Exit;
  end;
    Edit1.Text:=DataSource1.DataSet.FieldByName('用户').AsString;
    Edit2.Text:=DataSource1.DataSet.FieldByName('密码').AsString;
    Edit3.Text:=DataSource1.DataSet.FieldByName('密码').AsString;
    ComboBox1.Text:=DataSource1.DataSet.FieldByName('用户类别').AsString;        
end;

procedure TForm3.SpeedButton5Click(Sender: TObject);
begin
  if MessageBox(Handle, '你是否要删除?', '操作提示', MB_YESNO +
    MB_ICONWARNING + MB_DEFBUTTON3 + MB_TOPMOST)=IDYES then
  begin
    DataSource1.DataSet.Delete;
  end;
end;

procedure TForm3.SpeedButton11Click(Sender: TObject);
begin
   Close;
end;

procedure TForm3.SpeedButton20Click(Sender: TObject);
begin
  if Trim(Edit1.Text)='' then
  begin
    MessageBox(Handle, '请输入用户名!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
    Edit1.SetFocus;
    Exit;
  end;
  if Trim(Edit2.Text)='' then
  begin
    MessageBox(Handle, '请输入密码!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
    Edit2.SetFocus;
    Exit;
  end;
  if Trim(Edit2.Text)<>Trim(Edit3.Text) then
  begin
    MessageBox(Handle, '你输入的两次密码不正确!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
    Edit3.SetFocus;
    Exit;
  end;
  try
    DataSource1.DataSet.Edit;
    DataSource1.DataSet.FieldByName('用户').AsString:=Edit1.Text;
    DataSource1.DataSet.FieldByName('密码').AsString:=Edit2.Text;
    DataSource1.DataSet.FieldByName('用户类别').AsString:=ComboBox1.Text;
    DataSource1.DataSet.Post;
    Edit1.ReadOnly:=False;
    Edit1.Clear; Edit2.Clear; Edit3.Clear; 
    MessageBox(Handle, '修改成功!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
  except
    DataSource1.DataSet.Cancel;
    MessageBox(Handle, '修改用户失败!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
  end;
end;

procedure TForm3.SpeedButton15Click(Sender: TObject);
var
  i:Integer;
begin
  if Trim(Edit1.Text)='' then
  begin
    MessageBox(Handle, '请输入用户名!', '操作提示', MB_OK + MB_ICONWARNING + 
      MB_DEFBUTTON3 + MB_TOPMOST);
    Edit1.SetFocus;
    Exit;
  end;
  if Trim(Edit2.Text)='' then
  begin
    MessageBox(Handle, '请输入密码!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
    Edit2.SetFocus;
    Exit;
  end;
  if Trim(Edit2.Text)<>Trim(Edit3.Text) then
  begin
    MessageBox(Handle, '你输入的两次密码不正确!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
    Edit3.SetFocus;
    Exit;
  end;
  DataSource1.DataSet.First;
  for i:=1 to DataSource1.DataSet.RecordCount do
  begin
    if DataSource1.DataSet.FieldByName('用户').AsString=Edit1.Text then
    begin
      ShowMessage('此用户已经存在!');
      Exit;
    end;
    DataSource1.DataSet.Next;
  end;

  try
    DataSource1.DataSet.Insert;
    DataSource1.DataSet.FieldByName('用户').AsString:=Edit1.Text;
    DataSource1.DataSet.FieldByName('密码').AsString:=Edit2.Text;
    DataSource1.DataSet.FieldByName('用户类别').AsString:=ComboBox1.Text;
    DataSource1.DataSet.Post;
    Edit1.Clear; Edit2.Clear; Edit3.Clear;
    MessageBox(Handle, '增加用户成功!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
  except
    DataSource1.DataSet.Cancel;
    MessageBox(Handle, '增加用户失败!', '操作提示', MB_OK + MB_ICONWARNING +
      MB_DEFBUTTON3 + MB_TOPMOST);
  end;
end;

end.

⌨️ 快捷键说明

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