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

📄 queryspjxcunit.pas

📁 一个用delphi 开发的商场销售系统 涵盖很多功能
💻 PAS
字号:
unit QueryspjxcUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, QueryBassUnit, DB, DBTables, StdCtrls, ComCtrls, Buttons, Grids,
  DBGrids, ExtCtrls;

type
  TQueryspjxcForm = class(TQueryBassForm)
    CB_type: TComboBox;
    Label5: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure CB_GoodsChange(Sender: TObject);
    procedure CB_DepotChange(Sender: TObject);
    procedure SB_queryClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBG_dataDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure SB_printClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  QueryspjxcForm: TQueryspjxcForm;

implementation

uses FunctionUnit, MainUnit, PrograssUnit, PrintspjxcUnit, PrintBassUnit;

{$R *.dfm}

procedure TQueryspjxcForm.FormCreate(Sender: TObject);
var
  B_find: Boolean;
  I_temp: integer;
begin
  inherited;
  self.Caption := '商品进销存明细';
  with query_temp do
  begin
    close;
    sql.Clear;
    sql.Text := 'select name from depot';
    open;
    CB_depot.Items.Clear;
    CB_depot.Style := csDropDownList;
    CB_depot.Items.add('所有');
    while not eof do
    begin
      CB_depot.Items.add(fieldbyname('name').asstring);
      next;
    end;
    close;
    sql.Clear;
    sql.text := 'select * from goods order by name';
    open;
    CB_goods.Items.Clear;
    CB_goods.Style := csDropDownList;
    CB_goods.Items.add('所有');
    while not eof do
    begin
      B_find := false;
      for I_temp := 0 to CB_goods.items.Count - 1 do
      begin
        if CB_goods.Items[I_temp] = fieldbyname('name').asstring then
          B_find := true; //找到相同名称
      end;
      if not B_find then //没有找到时增加
        CB_goods.Items.add(fieldbyname('name').asstring);
      next;
    end;
    close;
  end;
end;

procedure TQueryspjxcForm.CB_GoodsChange(Sender: TObject);
begin
  inherited;
  with query_temp do
  begin
    close;
    sql.Clear;
    sql.text := 'select * from goods where name="' + cb_goods.Text + '" order by type ';
    open;
    cb_type.Items.Clear;
    cb_type.Style := csDropDownList;
    cb_type.Items.add('所有');
    while not eof do
    begin
      cb_type.Items.add(fieldbyname('type').asstring);
      next;
    end;
    close;
  end;
  CB_depotChange(sender);
end;

procedure TQueryspjxcForm.CB_DepotChange(Sender: TObject);
begin
  inherited;
  query_data.Close;
  sb_query.Enabled := True;
end;

procedure TQueryspjxcForm.SB_queryClick(Sender: TObject);
var
  S_depotname, S_goodsname, S_goodstype, S_begindate, S_enddate: string;
begin
  inherited;
  if not Checkrights(USERRIGHTS, '查看') then
  begin
    messagedlg(Errormsg0006 + '0007', mterror, [mbok], 0);
    exit;
  end;
  S_begindate := formatdatetime('yyyy-mm-dd', dtp_begin.Date);
  S_enddate := formatdatetime('yyyy-mm-dd', dtp_end.Date);
  if S_begindate > S_enddate then //开始日期大于结束日期
  begin
    messagedlg(Errormsg0012 + '0026', mtError, [mbok], 0);
    dtp_begin.SetFocus;
    exit;
  end;
  S_depotname := cb_depot.Text;
  S_goodsname := cb_goods.Text;
  S_goodstype := cb_type.text;
  if (S_depotname = '') or (S_depotname = '所有') then
    S_depotname := '%';
  if (S_goodsname = '') or (S_goodsname = '所有') then
    S_goodsname := '%';
  if (S_goodstype = '') or (S_goodstype = '所有') then
    S_goodstype := '%';
  application.CreateForm(TPrograssForm, PrograssForm);
  PrograssForm.P_message.Caption := '系统正在处理历史数据,请稍候……';
  PrograssForm.FormStyle := fsStayOnTop;
  PrograssForm.show;
  PrograssForm.Update;
  with query_data do
  begin
    close;
    sql.Clear;
    sql.Text := 'SELECT Depot.NAME depotname, Stockrecord.MYDATE, goods.NAME goodsname, goods.TYPE, "进货    " JXC,' //进货
      + ' Stockrecord.NUMBER number, Stockrecord.PRICE, "                    " peoplename, Stockrecord.MEMO'
      + ' FROM Stockrecord INNER JOIN Depot'
      + ' ON  (Stockrecord.DEPOTID = Depot.ID) INNER JOIN goods'
      + ' ON  (Stockrecord.GOODSID = goods.ID)'
      + ' WHERE DEPOT.NAME LIKE "' + S_depotname + '" AND goods.NAME LIKE "'
      + S_goodsname + '" AND goods.TYPE LIKE "' + S_goodstype + '" AND Stockrecord.MYDATE>="'
      + S_begindate + '" AND Stockrecord.MYDATE<="' + S_enddate + '"'
      + ' UNION ALL' //进货退货
      + ' SELECT Depot.NAME depotname, Threcord.MYDATE, goods.NAME goodsname, goods.TYPE, "进货退货" JXC,'
      + ' (0 - Threcord.NUMBER) number, Threcord.PRICE, "                    " peoplename, Threcord.MEMO'
      + ' FROM Threcord INNER JOIN Depot'
      + ' ON  (Threcord.DEPOTID = Depot.ID) INNER JOIN goods'
      + ' ON  (Threcord.GOODSID = goods.ID)'
      + ' WHERE DEPOT.NAME LIKE "' + S_depotname + '" AND goods.NAME LIKE "'
      + S_goodsname + '" AND goods.TYPE LIKE "' + S_goodstype + '" AND Threcord.MYDATE>="'
      + S_begindate + '" AND Threcord.MYDATE<="' + S_enddate + '"'
      + ' UNION ALL' //销售
      + ' SELECT Depot.NAME depotname, Sellrecord.MYDATE, goods.NAME goodsname, goods.TYPE, "销售    " JXC,'
      + ' Sellrecord.NUMBER number, Sellrecord.PRICE, YWYData.Name peoplename, Sellrecord.MEMO'
      + ' FROM Sellrecord INNER JOIN Depot'
      + ' ON  (Sellrecord.DEPOTID = Depot.ID) INNER JOIN goods'
      + ' ON  (Sellrecord.GOODSID = goods.ID)'
      + ' INNER JOIN YWYData ON  (Sellrecord.PEOPLEID = YWYData.Id)'
      + ' WHERE DEPOT.NAME LIKE "' + S_depotname + '" AND goods.NAME LIKE "'
      + S_goodsname + '" AND goods.TYPE LIKE "' + S_goodstype + '" AND Sellrecord.MYDATE>="'
      + S_begindate + '" AND Sellrecord.MYDATE<="' + S_enddate + '"'
      + ' UNION ALL' //销售退货
      + ' SELECT Depot.NAME depotname, XSTHrecord.MYDATE, goods.NAME goodsname, goods.TYPE, "销售退货" JXC,'
      + ' (0 - XSTHrecord.NUMBER) number, XSTHrecord.PRICE, YWYData.Name peoplename, XSTHrecord.MEMO'
      + ' FROM XSTHrecord INNER JOIN Depot'
      + ' ON  (XSTHrecord.DEPOTID = Depot.ID) INNER JOIN goods'
      + ' ON  (XSTHrecord.GOODSID = goods.ID)'
      + ' INNER JOIN YWYData ON  (XSTHrecord.PEOPLEID = YWYData.Id)'
      + ' WHERE DEPOT.NAME LIKE "' + S_depotname + '" AND goods.NAME LIKE "'
      + S_goodsname + '" AND goods.TYPE LIKE "' + S_goodstype + '" AND XSTHrecord.MYDATE>="'
      + S_begindate + '" AND XSTHrecord.MYDATE<="' + S_enddate + '"'
      + ' ORDER BY Depot.NAME,MYDATE';
    try
      open;
    except
      PrograssForm.Free;
      messagedlg(Errormsg0001 + '0017+0018+0020+0023+0025', mtError, [mbok], 0);
      close;
      exit;
    end;
  end;
  PrograssForm.Free;
end;

procedure TQueryspjxcForm.FormShow(Sender: TObject);
begin
  inherited;
  SB_query.Click;
end;

procedure TQueryspjxcForm.DBG_dataDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  inherited;
  if (trim(query_data.FieldByName('JXC').AsString) = '进货')
    or (trim(query_data.FieldByName('JXC').AsString) = '期初') then
    DBG_data.Canvas.Font.Color := clblue;
  DBG_data.DefaultDrawColumnCell(rect, datacol, column, state);
end;

procedure TQueryspjxcForm.SB_printClick(Sender: TObject);
begin
  inherited;
  try
    Application.CreateForm(TPrintspjxcForm, PrintspjxcForm);
    Application.CreateForm(TprintBassForm, printBassForm);
  except
    messagedlg(Errormsg0011, mtError, [mbok], 0);
    exit;
  end;
  PrintspjxcForm.QuickRep_SPJXCMX.preview;
  PrintspjxcForm.Free;
  printBassForm.Free;
end;

end.

⌨️ 快捷键说明

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