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

📄 xscx.pas

📁 药品进销存管理系统(Delphi版),适合中小企业管理
💻 PAS
字号:
unit xscx;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, Mask, StdCtrls, ExtCtrls, ComCtrls, Buttons, ToolWin, Db,
  DBTables, Menus;

type
  TFrmxscx = class(TForm)
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    close_SpeedButton: TSpeedButton;
    Panel1: TPanel;
    Label3: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    ComboBox2: TComboBox;
    DBGrid1: TDBGrid;
    Database1: TDatabase;
    xs_DataSource: TDataSource;
    xs_Query: TQuery;
    ComboBox1: TComboBox;
    bm_Query: TQuery;
    ywy_Query: TQuery;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    Panel2: TPanel;
    Label1: TLabel;
    Label5: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    ComboBox3: TComboBox;
    ck_Query: TQuery;
    DateTimePicker1: TDateTimePicker;
    DateTimePicker2: TDateTimePicker;
    Label2: TLabel;
    Edit_kh: TEdit;
    SpeedButton2: TSpeedButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure close_SpeedButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
    procedure ComboBox1Exit(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure ComboBox3KeyPress(Sender: TObject; var Key: Char);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
    procedure SpeedButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Frmxscx: TFrmxscx;
  ck_id:array[0..25] of string;     //存仓库信息表ckxxb中仓库编号字段的值
  bm_id:array[0..30] of string;
  i:integer;
  butclick:shortint;

implementation

uses  main, kh;

{$R *.DFM}

procedure TFrmxscx.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=Cafree;
end;

procedure TFrmxscx.close_SpeedButtonClick(Sender: TObject);
begin
  Self.close;
end;

procedure TFrmxscx.FormCreate(Sender: TObject);
begin
  DateTimePicker1.DateTime:=date();
  DateTimePicker2.DateTime:=date();
  i:=0;
  ck_query.close;
  ck_query.Prepare;
  ck_query.open;
  combobox3.Clear;
  while not ck_query.Eof do
    begin
     combobox3.Items.Add(ck_query.fields[1].asstring);
     ck_id[i]:=ck_query.FieldByName('ck_bh').asString;
     inc(i);
     ck_query.Next;
    end;
  bm_query.close;
  bm_query.UnPrepare;
  bm_query.sql.Clear;
  bm_query.sql.Add('select * from bmb');
  bm_query.Prepare;
  bm_query.open;
  bm_query.First;
  i:=0;
  combobox1.Clear;
  while not bm_query.Eof do
    begin
      combobox1.Items.Add(bm_query.fieldbyname('bm_mc').asstring);
      bm_id[i]:=bm_query.fieldbyname('bm_bh').asstring;
      bm_query.Next;
      inc(i);
    end;
  combobox1.Text:='';
  combobox2.Text:='';
end;

procedure TFrmxscx.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
  key:=#0;
end;

procedure TFrmxscx.ComboBox1Exit(Sender: TObject);
begin
  combobox2.Clear;
  if combobox1.ItemIndex>-1 then
    begin
     ywy_query.close;
     ywy_query.UnPrepare;
     ywy_query.sql.Clear;
     ywy_query.sql.Add('select * from ywyb');
     ywy_query.Prepare;
     ywy_query.open;
     ywy_query.First;
     while not ywy_query.Eof do
       begin
         if ywy_query.FieldByName('bm_bh').asstring=bm_id[combobox1.ItemIndex] then
           begin
             combobox2.Items.Add(ywy_query.fieldbyname('ywy_xm').asstring);
             ywy_query.Next;
           end
         else
           ywy_query.Next;
       end;
    end;
end;

procedure TFrmxscx.ComboBox1Change(Sender: TObject);
begin
  combobox2.Clear;
end;

procedure TFrmxscx.SpeedButton3Click(Sender: TObject);
  var
     jetotal:real;
     cbtotal:real;
     lrtotal:real;
     sjtotal:real;
begin
   butclick:=1;  //1为预览销售商品汇总表,2为预览销售毛利汇总表
   label10.Caption:='利润合计';
   label5.Caption:='';
   label9.Caption:='';
   label11.Caption:='';
   label13.Caption:='';
   jetotal:=0.0;
   cbtotal:=0.0;
   lrtotal:=0.0;
   sjtotal:=0.0;
   xs_query.close;
   xs_query.sql.Clear;
   xs_query.sql.Add('SELECT pm,sum(sl) as sl,sum(je) as je,sum(cb) as cb,sum(sj) as sj,sum(lr) as lr');
   if combobox1.ItemIndex>-1 then
     xs_query.sql.Add(',bm_mc ');
   if combobox2.ItemIndex>-1 then
     xs_query.sql.Add(',ywy_xm ');
   if edit_kh.Text<>'' then
     xs_query.sql.Add(' ,kh_mc ');
   if combobox3.ItemIndex>-1 then
     xs_query.sql.Add(',xs_bh ');
     xs_query.sql.Add(',xsrq ');
   xs_query.sql.Add(' FROM xsxxb ');
   xs_query.sql.Add('where xsrq <='''+datetostr(DateTimePicker2.Date)+'''');
   xs_query.sql.Add('and xsrq >='''+datetostr(DateTimePicker1.Date)+'''');
   if combobox1.ItemIndex>-1 then
     xs_query.sql.Add(' and bm_mc='''+combobox1.Text+'''');
   if combobox2.Text<>'' then
     xs_query.sql.Add(' and ywy_xm='''+combobox2.Text+'''');
   if edit_kh.Text<>'' then
     xs_query.sql.Add(' and kh_mc='''+edit_kh.Text+'''');
   if combobox3.Text<>'' then
     xs_query.sql.Add(' and xs_bh like'+''''+ck_id[combobox3.itemindex]+'%'+'''');
   xs_query.sql.Add(' group by pm,xsrq');
   if combobox1.ItemIndex>-1 then
     xs_query.sql.Add(',bm_mc');
   if combobox2.ItemIndex>-1 then
     xs_query.sql.Add(',ywy_xm');
   if combobox3.ItemIndex>-1 then
     xs_query.sql.Add(',xs_bh');
   if edit_kh.Text<>'' then
     xs_query.sql.Add(' ,kh_mc');
   xs_query.Prepare;
   xs_query.open;
   xs_query.FieldByName('pm').DisplayLabel:='物品名称';
   xs_query.FieldByName('sl').DisplayLabel:='数量';
   xs_query.FieldByName('je').DisplayLabel:='金额';
   xs_query.FieldByName('je').DisplayWidth:=14;
   xs_query.FieldByName('cb').DisplayLabel:='成本';
   xs_query.FieldByName('cb').DisplayWidth:=14;
   xs_query.FieldByName('sj').DisplayLabel:='税金';
   xs_query.FieldByName('sj').DisplayWidth:=14;
   xs_query.FieldByName('lr').DisplayLabel:='利润';
   xs_query.FieldByName('lr').DisplayWidth:=14;
   if combobox1.ItemIndex>-1 then
     xs_query.FieldByName('bm_mc').DisplayLabel:='部门名称';
   if combobox2.ItemIndex>-1 then
     xs_query.FieldByName('ywy_xm').DisplayLabel:='业务员';
   xs_query.FieldByName('xsrq').DisplayLabel:='销售日期';
   if combobox3.ItemIndex>-1 then
     xs_query.FieldByName('xs_bh').DisplayLabel:='销售编号';
   if edit_kh.Text<>'' then
     xs_query.FieldByName('kh_mc').DisplayLabel:='客户名称';
   xs_query.First;
   while not xs_query.Eof do
     begin
       jetotal:=jetotal+xs_query.fieldbyname('je').AsFloat;
       cbtotal:=cbtotal+xs_query.fieldbyname('cb').AsFloat;
       lrtotal:=lrtotal+xs_query.fieldbyname('lr').AsFloat;
       sjtotal:=sjtotal+xs_query.fieldbyname('sj').AsFloat;
       xs_query.Next;
     end;
   label5.Caption:=floattostr(jetotal);
   label9.Caption:=floattostr(cbtotal);
   label11.Caption:=floattostr(lrtotal);
   label13.Caption:=floattostr(sjtotal);
end;

procedure TFrmxscx.SpeedButton4Click(Sender: TObject);
  var jetotal:real;
      cbtotal:real;
      mltotal:real;
      sjtotal:real;
begin
   butclick:=2;  //1为预览销售商品汇总表,2为预览销售毛利汇总表
   Label10.Caption:='毛利合计';
   label5.Caption:='';
   label9.Caption:='';
   label11.Caption:='';
   label13.Caption:='';
   jetotal:=0.0;
   cbtotal:=0.0;
   mltotal:=0.0;
   sjtotal:=0.0;
   xs_query.close;
   xs_query.sql.Clear;
   xs_query.sql.Add('SELECT bm_mc,');
   if combobox1.ItemIndex>-1 then
       xs_query.sql.Add('ywy_xm,');
   xs_query.sql.add('sum(je) as je,sum(cb) as cb,sum(sj) as sj,sum(ml) as ml,xsrq');
   xs_query.sql.Add(' FROM xsxxb ');
   xs_query.sql.Add('where xsrq <='''+datetostr(DateTimePicker2.Date)+'''');
   xs_query.sql.Add('and xsrq >='''+datetostr(DateTimePicker1.Date)+'''');
   if combobox1.ItemIndex>-1 then
     xs_query.sql.Add(' and bm_mc='''+combobox1.Text+'''');
   if combobox2.Text<>'' then
     xs_query.sql.Add(' and ywy_xm='''+combobox2.Text+'''');
   if edit_kh.Text<>'' then
     xs_query.sql.Add(' and kh_mc='''+edit_kh.Text+'''');
   xs_query.sql.Add(' group by bm_mc ');
  if (combobox1.ItemIndex>-1) then
      xs_query.sql.Add(',ywy_xm');
   xs_query.sql.Add(',xsrq');
   xs_query.sql.Add(' ORDER BY xsrq');
   xs_query.Prepare;
   xs_query.open;
   xs_query.FieldByName('bm_mc').DisplayLabel:='部门名称';
   if combobox1.ItemIndex>-1 then
     xs_query.FieldByName('ywy_xm').DisplayLabel:='业务员';
   xs_query.FieldByName('je').DisplayLabel:='销售金额';
   xs_query.FieldByName('je').DisplayWidth:=14;
   xs_query.FieldByName('cb').DisplayLabel:='成本';
   xs_query.FieldByName('cb').DisplayWidth:=14;
   xs_query.FieldByName('sj').DisplayLabel:='税金';
   xs_query.FieldByName('sj').DisplayWidth:=14;
   xs_query.FieldByName('ml').DisplayLabel:='毛利';
   xs_query.FieldByName('ml').DisplayWidth:=14;
   if combobox1.ItemIndex>-1 then
     xs_query.FieldByName('ywy_xm').DisplayLabel:='业务员'; 
   xs_query.FieldByName('xsrq').DisplayLabel:='销售日期';
   xs_query.First;
   while not xs_query.Eof do
     begin
       jetotal:=jetotal+xs_query.fieldbyname('je').AsFloat;
       cbtotal:=cbtotal+xs_query.fieldbyname('cb').AsFloat;
       mltotal:=mltotal+xs_query.fieldbyname('ml').AsFloat;
       sjtotal:=sjtotal+xs_query.fieldbyname('sj').AsFloat;
       xs_query.Next;
     end;
   label5.Caption:=floattostr(jetotal);
   label9.Caption:=floattostr(cbtotal);
   label11.Caption:=floattostr(mltotal);
   label13.Caption:=floattostr(sjtotal);
end;

procedure TFrmxscx.ComboBox3KeyPress(Sender: TObject; var Key: Char);
begin
  key:=#0;
end;

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

procedure TFrmxscx.SpeedButton2Click(Sender: TObject);
begin
  Frmkh:=TFrmkh.create(Self);
  Frmmain.pubedit:=edit_kh;
  Frmkh.show;
end;

end.

⌨️ 快捷键说明

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