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

📄 unit4.pas

📁 材料管理系统
💻 PAS
字号:
unit Unit4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin, ComCtrls,ADODB;

type
  Tfrmxincailiao = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    DateTimePicker1: TDateTimePicker;
    Label5: TLabel;
    ComboBox1: TComboBox;
    Label6: TLabel;
    Edit4: TEdit;
    ComboBox2: TComboBox;
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1DropDown(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Edit4KeyPress(Sender: TObject; var Key: Char);

  private
    { Private declarations }
  public
    { Public declarations }
    function IsEmpty(const ScrString:string):boolean;
    function IsNotNumric(const ScrString:string):boolean;
    procedure clear();
  end;

var
  frmxincailiao: Tfrmxincailiao;

implementation

uses Unit2;

{$R *.dfm}
procedure TFrmxincailiao.clear();
begin
  //combobox1.Clear;
  edit1.Clear;
  edit2.clear;
//  Combobox2.Clear;
  edit4.Clear;
end;

function Tfrmxincailiao.IsNotNumric(const ScrString:string):boolean;
var
  c:string;
  i:integer;
  BoolResult:Boolean;
  cnt:integer;
begin
  cnt:=0;
  BoolResult := FALSE;
  if copy(ScrString,1,1)='.' then
    cnt:=1;
  for i := 2 to length(Scrstring) do
  begin
    //c:=PChar(copy(ScrString,i,1))^;
    c := Copy(ScrString,i,1);
    if c='-' then
    begin
      BoolResult:=true;
      break;
    end;
    if c = '.' then
    begin
      cnt:=cnt+1;
      if cnt>1 then
      begin
          boolResult:=true;
          break;
      end;
    end;

//    else
//      BoolResult:=false;
  end;
  Result := BoolResult;
end;

function Tfrmxincailiao.IsEmpty(const ScrString:string):boolean;
begin
  if trim(ScrString)='' then
    IsEmpty:=true
  else
    IsEmpty:=false;
end;

procedure Tfrmxincailiao.Button2Click(Sender: TObject);
begin
  self.Close;
end;

procedure Tfrmxincailiao.FormCreate(Sender: TObject);
begin
  datetimepicker1.DateTime := Date;
end;

procedure Tfrmxincailiao.ComboBox1DropDown(Sender: TObject);
//var
//  Query1:TADOQuery;
begin
//  combobox1.Clear;
//  combobox1.Items.Clear;
//  Query1:=TADOQuery.Create(nil);
//  Query1.Connection:=frmmain.ADOConnection1;
//  Query1.close;
//  Query1.SQL.Clear;         //cailiaoming,danwei,danjia,riqi
//  Query1.SQL.add('select distinct class from class');
//  Query1.open;
//  while not Query1.Eof do
//    begin
//      combobox1.Items.Add(trim(Query1.FieldByName('class').AsString));
//      Query1.Next;
//    end;
//    if combobox1.Items.Count>0 then
//      combobox1.ItemIndex:=0;
//  FreeAndNil(Query1);
end;

procedure Tfrmxincailiao.Button3Click(Sender: TObject);
var
  Query1:TADOQuery;
begin
  if IsEmpty(combobox1.Text)=true then
    begin
      application.MessageBox('请选择材料所属类别!','提示',MB_ICONINFORMATION);
      exit;
    end;
  if IsEmpty(edit1.text)=true then
    begin
      application.MessageBox('请填写材料名称!','提示',MB_ICONINFORMATION);
      exit;
    end;
  Query1:=TADOQuery.Create(nil);
  Query1.ConnectionString :=frmmain.ADOConnection1.ConnectionString;
  Query1.Close;
  Query1.SQL.Clear;
  Query1.SQL.Add('select * from cailiao where cailiaoming='''+trim(edit1.Text)+'''');
  Query1.Open;
  if not Query1.Eof then
  begin
    application.messagebox('此材料名称已存在!','提示',MB_ICONWARNING);
    edit1.Text:='';
    clear;
    exit;
  end
  else
    application.MessageBox('无此材料名称.','提示',MB_ICONINFORMATION);
  FreeAndNil(Query1);
end;

procedure Tfrmxincailiao.Button1Click(Sender: TObject);
var
//  cailiaoclass:string;
  Query1:TADOQuery;
//  Query2:TADOQuery;
begin
  if IsEmpty(combobox1.Text)=true then
    begin
      application.MessageBox('请选择材料所属类别!','提示',MB_ICONINFORMATION);
      exit;
    end;
  if IsEmpty(edit1.text)=true then
    begin
      application.MessageBox('请填写材料名称!','提示',MB_ICONINFORMATION);
      exit;
    end;
  if IsEmpty(Combobox2.Text)=true then
    begin
      application.MessageBox('单位不能为空!','提示',MB_ICONINFORMATION);
      exit;
    end;
  if IsEmpty(edit4.Text)=true then
    begin
      application.MessageBox('单价不能为空!','提示',MB_ICONINFORMATION);
      exit;
    end;
  if  IsNotNumric(edit4.Text)=true then
  begin
    application.MessageBox('请输入正确的数字.','错误',MB_ICONSTOP);
    edit4.Text:='';
    exit;
  end;
  Query1:=TADOQuery.Create(nil);
  Query1.ConnectionString := frmmain.ADOConnection1.ConnectionString;
  Query1.Close;
  Query1.SQL.Clear;
  Query1.SQL.Add('select * from cailiao where cailiaoming='''+trim(edit1.Text)+'''');
  Query1.Open;
  if not Query1.Eof then
  begin
    application.messagebox('此材料名称已存在!','提示',MB_ICONWARNING);
    edit1.Text := '';
    Edit2.Text := '';
//    Combobox2.Text := '';
    Edit4.Text := '';
    exit;
  end;

  try
    with Query1 do
    begin
      close;
      sql.clear;
      sql.add('insert cailiao values('''+trim(edit1.Text)+''','''+trim(combobox1.Text)+''','''+trim(edit2.Text)+''','''+
        trim(Combobox2.Text)+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+ ''',''' + DateToStr(datetimepicker1.date) +''')');
      execSQL;
    end;
FreeAndNil(Query1);
//cailiaoclass :=trim(Combobox1.Text);
//Query2 := TADOQuery.create(nil);
//Query2.ConnectionString := frmmain.ADOConnection1.ConnectionString;
with Frmmain.Queryycldj do
begin
  close;
  sql.Clear;
  if trim(Combobox1.Text)<>'' then
    sql.Add('select * from cailiao where class='''+ trim(Combobox1.Text) +'''')
  else
    sql.Add('select * from cailiao');
  prepared;
  open;
end;
//FreeAndNIl(Query2);
//showmessage('操作成功.');
clear;
  except
    begin
      showmessage('系统出错.');
    end;
  end;
end;

procedure Tfrmxincailiao.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
//  if (Key<#8) or (Key>#8)and(Key<#48) or (Key>#57) then
//      key:=#0;
  if not (key in ['0'..'9',#8,'.','-'] ) then
    key:=#0;
end;

end.

⌨️ 快捷键说明

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