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

📄 xmfm.pas

📁 不管我的程序编得怎么样
💻 PAS
字号:
unit xmfm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, ExtCtrls, jpeg, Grids, DBGrids, ComCtrls,
  Menus;

type
  Txmform = class(TForm)
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Panel1: TPanel;
    Image1: TImage;
    Image2: TImage;
    Panel2: TPanel;
    Image3: TImage;
    Panel3: TPanel;
    Image4: TImage;
    label1: TLabel;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    sp_name: TEdit;
    Label3: TLabel;
    sp_dw: TComboBox;
    Label4: TLabel;
    sp_money: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    sp_kc: TEdit;
    Label7: TLabel;
    sp_dz: TCheckBox;
    sp_kc_yes: TCheckBox;
    Label8: TLabel;
    Button1: TButton;
    BitBtn1: TBitBtn;
    GroupBox2: TGroupBox;
    StatusBar1: TStatusBar;
    DBGrid2: TDBGrid;
    sp_post: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    D1: TMenuItem;
    procedure BitBtn1Click(Sender: TObject);
    procedure sp_kcKeyPress(Sender: TObject; var Key: Char);
    procedure Image4MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure D1Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
  private
    { Private declarations }
    procedure clearedit;
    procedure savespsj(sp_id:string);
    procedure savesp;
  public
    { Public declarations }
  end;

var
  xmform: Txmform;
  sp_edit:boolean;
  sp_id:string;
implementation
uses mainfm,dmfm,loginfm;
{$R *.dfm}

procedure Txmform.BitBtn1Click(Sender: TObject);
begin
close;
end;

procedure Txmform.sp_kcKeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then Key := #0; 
end;

procedure Txmform.Image4MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
  SendMessage(Handle, WM_SYSCOMMAND, $F012, 0);
end;



procedure Txmform.clearedit;
begin
sp_name.Text:='';
sp_money.Text:='0';
sp_kc.Text:='0';
sp_post.text:='';
end;

procedure Txmform.FormShow(Sender: TObject);
begin
 clearedit;
 if G_flag=0 then
 begin
 Button1.Enabled:=true;
 end
else
 begin
  button1.Enabled:=false;
 end;
 with dm.aq_xm do
  begin
  close;
  sql.Clear;
  sql.Add('select * from 项目 order by id asc');
  try
   open;
  except
  end;
  DBGrid2.Columns[0].Width:=100;
  DBGrid2.Columns[1].Width:=60;
  DBGrid2.Columns[2].Width:=60;
  DBGrid2.Columns[3].Width:=60;
  DBGrid2.Columns[4].Width:=60;
  DBGrid2.Columns[5].Width:=60;
  DBGrid2.Columns[6].Width:=120; 
  DBGrid2.Columns[7].Width:=0;
  DBGrid2.Columns.Items[0].FieldName :='名称';
  DBGrid2.Columns.Items[1].FieldName :='单价';
  DBGrid2.Columns.Items[2].FieldName :='单位';
  DBGrid2.Columns.Items[3].FieldName :='库存';
  DBGrid2.Columns.Items[4].FieldName :='计算库存';
  DBGrid2.Columns.Items[5].FieldName :='打折';
  DBGrid2.Columns.Items[6].FieldName :='备注'; 
  DBGrid2.Columns.Items[7].FieldName :='id';
  StatusBar1.Panels.Items[0].Text:='共有 '+inttostr(RecordCount) + ' 条记录';
  end;
end;

procedure Txmform.Button1Click(Sender: TObject);
begin
if (sp_name.Text='') or (sp_money.Text='') then
 begin
  Application.MessageBox('请添写项目名称和单价!', '明宇提示', Mb_Ok or Mb_IconError);
  sp_name.SetFocus;
 end
else
 begin
  if sp_edit=true then
   begin
   savespsj(sp_id);
   end
  else
   begin
   savesp;
   end;
 end;
end;

procedure Txmform.savespsj(sp_id:string);
begin
with dm.aq_xm do
 begin
 close;
 sql.Clear;
 sql.Add('select * from 项目 where id=:sp_id');
 Parameters.ParamByName('sp_id').Value:=sp_id;
 active:=true;
  begin
   edit;
   fieldbyname('名称').AsString:=sp_name.Text; 
   fieldbyname('单位').AsString:=sp_dw.Text;
   fieldbyname('单价').AsString:=sp_money.Text;
   fieldbyname('库存').AsString:=sp_kc.Text;
   fieldbyname('打折').AsBoolean:=sp_dz.Checked;
   fieldbyname('计算库存').AsBoolean:=sp_kc_yes.Checked;
   fieldbyname('备注').AsString:=sp_post.Text;
    try
     post;
     Application.MessageBox('项目修改成功!', '明宇提示', Mb_Ok or Mb_IconInformation);
     clearedit;
     sp_edit:=false;
    except
     Application.MessageBox('项目修改失败!', '明宇提示', Mb_Ok or Mb_IconStop);
    end;
  end;
 end;
end;

procedure Txmform.savesp;
var
asql:string;
begin
 with dm.aq_xm do
  begin
   close;
   sql.Clear;
   asql:='insert into 项目 (名称,单位,单价,库存,打折,计算库存,备注) values (:name,:dw,:money,:kc,:dz,:kc_yes,:sp_post)';
   sql.Add(asql);
      Parameters.ParamByName('name').Value:=sp_name.Text;
      parameters.ParamByName('dw').value:=sp_dw.text;
      parameters.ParamByName('money').Value:=sp_money.Text;
      parameters.ParamByName('kc').Value:=sp_kc.Text;
      parameters.ParamByName('dz').Value:=sp_dz.Checked; 
      parameters.ParamByName('kc_yes').Value:=sp_kc_yes.Checked;
      parameters.ParamByName('sp_post').Value:=sp_post.Text;

   try
    execsql;
    Application.MessageBox('项目添加成功!', '明宇提示', Mb_Ok or Mb_IconWarning);
    clearedit;
   except
    Application.MessageBox('项目添加失败!', '明宇提示', Mb_Ok or Mb_IconStop);
   end;
   close;
   sql.Clear;
   sql.Add('select * from 项目 order by id asc');
   active:=true;
   try
   open;
   except
   end;
  end;
end;

procedure Txmform.D1Click(Sender: TObject);
var
sp_id:string;
begin
with dm.aq_xm do
 begin
 if RecordCount>0 then
  begin
   if application.MessageBox('是否真的删除?', '明宇提示', 4) = 6 then
   try
     sp_id:=DBGrid2.DataSource.DataSet.FieldByName('id').asstring;
     close;
     sql.Clear;
     sql.Add('delete from 项目 where id='+sp_id);
     //Parameters.ParamByName('G_sjid').Value:=G_sjid
     execsql;
     active:=false;
     Application.MessageBox('项目删除成功!', '明宇提示', Mb_Ok or Mb_IconInformation);
     except
       Application.MessageBox('项目删除失败!', '提示', Mb_Ok or Mb_IconStop);
     end;
     
   close;
   sql.Clear;
   sql.Add('select * from 项目 order by id asc');
   active:=true;
   StatusBar1.Panels.Items[0].Text:='共有 '+IntToStr(RecordCount) + ' 条信息';
  end;
 end;
end;

procedure Txmform.N1Click(Sender: TObject);
begin
sp_edit:=true;
with dm.aq_xm do
 begin
   sp_name.Text:=FieldValues['名称'];
   sp_dw.Text:=FieldValues['单位'];
   sp_money.Text:=FieldValues['单价'];
   sp_kc.Text:=FieldValues['库存'];
   sp_dz.Checked:=FieldValues['打折'];
   sp_kc_yes.Checked:=FieldValues['计算库存'];
   sp_post.Text:=FieldValues['备注'];
   sp_id:=FieldValues['id'];
 end;
end;


end.

⌨️ 快捷键说明

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