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

📄 jgtz.pas

📁 这是用Delphi编写的中小企业管理系统
💻 PAS
字号:
unit jgtz;

interface

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

type
  Tf_jgtz = class(TForm)
    DataSource1: TDataSource;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    RadioButton3: TRadioButton;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    bfbxs: TLabel;
    Label3: TLabel;
    spdm: TEdit;
    bfb: TEdit;
    Spin: TSpinButton;
    splb: TComboBox;
    DBGrid1: TDBGrid;
    GroupBox3: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure FormShow(Sender: TObject);
    procedure bfbKeyPress(Sender: TObject; var Key: Char);
    procedure bfbChange(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure SpinUpClick(Sender: TObject);
    procedure SpinDownClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_jgtz: Tf_jgtz;

implementation
  uses DataModal;
{$R *.dfm}

procedure Tf_jgtz.FormShow(Sender: TObject);
begin
  Spin.Left := bfb.Left+bfb.Width-Spin.Width-1;
  Spin.Top := bfb.Top+2;
  splb.Clear;
  With Data.Query1  do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select lbmc from t_kclb');
    Open;
  end; 
  if Data.Query1.RecordCount>0 then
    while Not Data.Query1.Eof do
    begin
      splb.Items.Add(Trim(Data.Query1.Fields[0].AsString));
      Data.Query1.Next;
    end; 
end;

procedure Tf_jgtz.bfbKeyPress(Sender: TObject; var Key: Char);
var
  i: Boolean;
begin
  i := (Key<#8)or(Key>#8)and(Key<#45)or(Key>#45)and(Key<#46)or(Key>#46)and(Key<#48)or(Key>#57);
  if i then
    Key := #0;
end;


procedure Tf_jgtz.bfbChange(Sender: TObject);
begin
  if Trim(bfb.Text)<>'' then
  begin
    if Trim(bfb.Text)='-' then
    begin
      bfbxs.Caption := Trim(bfb.Text+'%');
      Exit;
    end; 
    Try
      StrToFloat(bfb.Text);
    Except
      Application.MessageBox('请输入合法数据.','提示',64);
      bfb.Clear;
      Exit;
    End;
    bfbxs.Caption := Trim(bfb.Text+'%');
  end  
  else
  begin
    bfbxs.Caption := '0%';
  end
end;

procedure Tf_jgtz.RadioButton1Click(Sender: TObject);
begin
  if Sender is TRadioButton then
    Case TRadioButton(Sender).Tag of 
      0 : begin
            spdm.Enabled := True;
            splb.Enabled := True;
          end;
      1: begin
           spdm.Enabled := False;
           splb.Enabled := True;
         end;
      2: begin
           spdm.Enabled := False;
           splb.Enabled := False;
         end;
    end;
  spdm.Clear;
  bfb.Text := '0';
end;

procedure Tf_jgtz.Button1Click(Sender: TObject);
begin
  if RadioButton1.Checked = True then
  begin
    if Trim(spdm.Text)<>'' then
    begin
      With Data.Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select a.spdm,a.spmc,a.spzl,b.bzsj from t_spjcxx a inner join t_spsj b on a.spdm = b.spdm and (a.spdm = :c or a.spmc = :c)');
        ParamByName('c').AsString := Trim(spdm.Text);
        Open;        
      end;  
      if Data.Query1.RecordCount>0 then 
      begin
        DataSource1.DataSet := Data.Query1;
        splb.ItemIndex := splb.Items.IndexOf(Trim(Data.Query1.FieldByName('spzl').AsString));
      end
      else
      begin
        DataSource1.DataSet := Nil;
        Application.MessageBox('该商品不存在或没有定价.','提示',64);
        spdm.Clear;
      end;
    end;
  end
  else if RadioButton2.Checked = True then
  begin
    if Trim(splb.Text)<>'' then
    begin
      with Data.Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select a.spdm,a.spmc,a.spzl,b.bzsj from t_spjcxx a inner join t_spsj b on a.spdm = b.spdm and a.spzl =:c ');
        ParamByName('c').AsString := Trim(splb.Text);
        Open;        
      end; 
      if Data.Query1.RecordCount>0 then
        DataSource1.DataSet := Data.Query1
      else
      begin
        DataSource1.DataSet := Nil;
        Application.MessageBox('该类商品没有定价或不存在.','提示',64);
        splb.ItemIndex := 0;
      end;     
    end;
  end
  else
  begin
    With Data.Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select a.spdm,a.spmc,a.spzl,b.bzsj from t_spjcxx a inner join t_spsj b on a.spdm = b.spdm');
      Open;
    end;
    if Data.Query1.RecordCount>0 then
      DataSource1.DataSet := Data.Query1
    else
    begin
      DataSource1.DataSet := Nil;
      Application.MessageBox('库存商品没有定价,不能进行调价.','提示',64);
    end;
  end;
end;

procedure Tf_jgtz.Button2Click(Sender: TObject);
begin      
  if Trim(bfb.Text)<>'' then
  begin
    if Application.MessageBox('确实要调整商品价格吗?','提示',mb_YesNo)=ID_Yes then
    begin
      if RadioButton1.Checked = True then
      begin
        if Trim(spdm.Text)<>'' then
        begin
          With Data.Query2 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('select * from t_spsj where spdm in(select spdm from t_spjcxx where spdm = :a or spmc =:a )');
            ParamByName('a').AsString := Trim(spdm.Text);
            Open;        
          end;  
          if Data.Query2.RecordCount>0 then 
          begin
            Try
              With Data.Query2 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('update t_spsj set bzsj = bzsj*(1+:a) where spdm in(select spdm from t_spjcxx where spdm = :b or spmc = :b)');                
                ParamByName('a').AsFloat := StrToFloat(bfb.Text)/100;
                ParamByName('b').AsString := Trim(spdm.Text);
                ExecSQL;
              end;
              Application.MessageBox('调价成功.','提示',64);
              spdm.Clear;
              bfb.Text := '0';
            Except
              Application.MessageBox('调价失败.','提示',64);
            end;      
          end
          else
            Application.MessageBox('该商品不存在或没有定价.','提示',64);
        end;
      end
      else if RadioButton2.Checked = True then
      begin
        if Trim(splb.Text)<>'' then
        begin
          With Data.Query2 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('select * from t_spsj where spdm in(select spdm from t_spjcxx where spzl = :a) ');
            ParamByName('a').AsString := Trim(splb.Text);
            Open;        
          end;  
          if Data.Query2.RecordCount>0 then 
          begin
            Try
              With Data.Query2 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('update t_spsj set bzsj = bzsj*(1+:a) where spdm in(select spdm from t_spjcxx where spzl = :b)');
                ParamByName('a').AsFloat := StrToFloat(bfb.Text)/100;
                ParamByName('b').AsString := Trim(splb.Text);
                ExecSQL;
              end;
              Application.MessageBox('调价成功.','提示',64);
              spdm.Clear;
              bfb.Text := '0';
            Except
              Application.MessageBox('调价失败.','提示',64);
            end;      
          end
          else
            Application.MessageBox('该商品不存在或没有定价.','提示',64);
        end;
      end
      else
      begin
        With Data.Query2 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from t_spsj');
          Open;        
        end;  
        if Data.Query2.RecordCount>0 then 
        begin
          Try
            With Data.Query2 do
            begin
              Close;
              SQL.Clear;
              SQL.Add('update t_spsj set bzsj = bzsj*(1+:a)');
              ParamByName('a').AsFloat := StrToFLoat(bfb.Text)/100;
              ExecSQL;
            end;
            Application.MessageBox('调价成功.','提示',64);
            spdm.Clear;
            bfb.Text := '0';
          Except
            Application.MessageBox('调价失败.','提示',64);
          end;      
        end
        else
          Application.MessageBox('该商品不存在或没有定价.','提示',64);
      end;
    end;
  end;
end;

procedure Tf_jgtz.SpinUpClick(Sender: TObject);
begin
  if (Trim(bfb.Text)<>'')and(Trim(bfb.Text)<>'-') then
    bfb.Text := FloatToStr(StrToFloat(bfb.Text)+1)
  else
    bfb.Text := '0';
end;

procedure Tf_jgtz.SpinDownClick(Sender: TObject);
begin
  if (Trim(bfb.Text)<>'')and(Trim(bfb.Text)<>'-') then
  begin
    //if StrToFloat(bfb.Text)-1>=0 then
      bfb.Text := FloatToStr(StrToFloat(bfb.Text)-1);
  end
  else
    bfb.Text := '0';
end;

end.

⌨️ 快捷键说明

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