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

📄 ustocktype.pas

📁 适合行业为眼镜业
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit UStockType;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, fm_Base, DB, DBClient, StdCtrls, Grids, DBGrids, Buttons,
  ExtCtrls, Menus;

type
  TFmStockType = class(TfmBase)
    PopupMenu2: TPopupMenu;
    N3: TMenuItem;
    N4: TMenuItem;
    Panel3: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    btnpagedown: TBitBtn;
    BitBtn7: TBitBtn;
    Panel2: TPanel;
    DBGrid1: TDBGrid;
    Gridbase: TStringGrid;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    cmbtop: TComboBox;
    Panel4: TPanel;
    CBType: TComboBox;
    cbBrand: TComboBox;
    CbBreed: TComboBox;
    ckbtype: TCheckBox;
    ckbbreed: TCheckBox;
    ckbbrand: TCheckBox;
    Cbmstorage: TCheckBox;
    cmbmstorage: TComboBox;
    cdssort: TClientDataSet;
    cdspart: TClientDataSet;
    cbstorages: TCheckBox;
    cmbstorages: TComboBox;
    dsview: TDataSource;
    btnprint: TBitBtn;
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure btnpagedownClick(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure cmbmstorageChange(Sender: TObject);
    procedure ckbtypeClick(Sender: TObject);
    procedure ckbbrandClick(Sender: TObject);
    procedure ckbbreedClick(Sender: TObject);
    procedure CbmstorageClick(Sender: TObject);
    procedure cbstoragesClick(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure DBGrid1TitleClick(Column: TColumn);
    procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure CBTypeChange(Sender: TObject);
    procedure cbBrandChange(Sender: TObject);
    procedure GridbaseDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure btnprintClick(Sender: TObject);
  private
    { Private declarations }
     flag,LocalCount:integer;
     tj:string;
    tempsql,tables,groups:string;
    pS:boolean;
    procedure inistringgrid(visible:boolean);
    procedure redata;
    procedure cleardata;
  public
    { Public declarations }
  end;

var
  FmStockType: TFmStockType;

implementation

uses untdatadm, func,fm_SetColumn, Unitreportxf;

{$R *.dfm}
//////////////////////////自定义函数(完成加载数据,初始化,清除数据TSTRINGGRID)
procedure TFmStockType.redata;
var
  i,p,t,m,j,d,c:integer;
  f:boolean;
begin
  m:=Gridbase.RowCount-1;
  Gridbase.RowCount:=cdssort.RecordCount+1;
  t:=Gridbase.RowCount-1;
  i:=1;
  cdssort.First;
  while not cdssort.Eof do
  begin
    f:=true;
    if  trim(Gridbase.Cells[3,m-1])=trim(cdssort.fieldbyname('breed').AsString) then
    begin
      c:=0;
      j:= Gridbase.ColCount;
      for d:=1 to j do
      begin
        if trim(Gridbase.Cells[d,0])=trim(cdssort.fieldbyname('storage_no').AsString+'仓库') then
        begin
          c:=d;
        end;
      end;
      if c=0 then
      begin
        Gridbase.ColCount:=Gridbase.ColCount+1;
        Gridbase.ColWidths[Gridbase.ColCount-1]:=60;
        Gridbase.Cols[Gridbase.ColCount-1].Add(trim(cdssort.fieldbyname('storage_no').AsString+'仓库'));
        Gridbase.Cells[Gridbase.ColCount-1,m-1]:=trim(cdssort.fieldbyname('stock_amount').AsString );
      end else
      begin
        Gridbase.Cells[c,m-1]:=trim(cdssort.fieldbyname('stock_amount').AsString );
      end;
      f:=false;
    end;
    if f then
    begin
      for p:=1 to dbgrid1.FieldCount-1 do
      begin
        j:=gridbase.ColCount-1;
        c:=0;
        if (trim(Gridbase.Cells[1,m])<>'') and (trim(Gridbase.Cells[2,m])<>'') and (trim(Gridbase.Cells[3,m])<>'') then
        begin
          for d:=1 to j do
          begin
            if trim(Gridbase.Cells[d,0])=trim(cdssort.fieldbyname('storage_no').AsString+'仓库') then
            begin
              c:=d;
            end;
          end;
        end;
        if c=0 then
        begin
         c:=p;
        end ;
        Gridbase.Cells[c,m]:=trim(dbgrid1.Fields[p].AsString);
      end;
      inc(m);
    end;
   cdssort.Next;
  end;
  //////////////////////////////
  m:=0; //清除空白项
  for i:=1 to Gridbase.RowCount-1 do
  begin
    if trim(Gridbase.Cells[1,i])='' then inc(m);
  end;
  Gridbase.RowCount:=Gridbase.RowCount-m;
  label4.Caption:=inttostr(strtoint(label4.Caption)+Gridbase.RowCount-1);
  //showmessage(inttostr(Gridbase.RowCount-1));
  ////////////////////////////////
end;
//////////////////////////////////////
procedure TFmStockType.inistringgrid(visible:boolean);
var
  i:integer;
begin
  if visible then
  begin
    cleardata;
  end;
  Gridbase.Visible:=visible;
  if Gridbase.ColCount<= dbgrid1.Columns.Count then
  begin
    Gridbase.ColCount:=dbgrid1.Columns.Count;
  end;
  Gridbase.ColWidths[0]:=-1;
  cdssort.First;
  for i:=1 to dbgrid1.Columns.Count-1 do
  begin
    if  dbgrid1.Columns[i].Visible then
    begin
      Gridbase.ColWidths[i]:=dbgrid1.Columns[i].Width;
    end else
    begin
      Gridbase.ColWidths[i]:=-1;
    end;
    if (trim(dbgrid1.Columns.Items[i].Title.Caption)<>'库存数量') then
    begin
      Gridbase.cells[i,0]:=trim(dbgrid1.Columns[i].Title.Caption);
    end else
    begin
      Gridbase.cells[i,0]:=trim(cdssort.fieldbyname('storage_no').AsString)+'仓库';
    end;
  end;
  redata;
end;

procedure TFmStockType.cleardata;
var
  i:integer;
begin
  for i:=1 to Gridbase.RowCount-1 do
  begin
    Gridbase.Rows[i].Clear;
  end;
  Gridbase.RowCount:=2;
  for i:=0 to Gridbase.ColCount-1 do
  begin
    Gridbase.cols[i].Clear;
  end;
  Gridbase.ColCount:=2;
end;
/////////////////////////////////////////
procedure TFmStockType.BitBtn7Click(Sender: TObject);
begin
  inherited;
  close;
end;

procedure TFmStockType.BitBtn1Click(Sender: TObject);
var
  temp:widestring;
  datas:olevariant;
  str,str1:string;
  i,j:integer;
  zt:boolean;
begin
  inherited;
    cdssort.Close;
    cdssort.Data:=null;
    tj:=' where 1=1 ';
    str1:='';
    zt:=false;
    if not ps then
    begin
      str1:=' (';
      for j:=0 to cmbstorages.Items.Count-2 do
      begin
        i:=pos('仓库', trim(cmbstorages.Items.Strings[j]));
        if i>0 then
        begin
          str1:=str1+''''+copy(trim(cmbstorages.Items.Strings[j]),i+4,length(trim(cmbstorages.Items.Strings[j])))+''''+',';
        end else
        begin
          str1:=str1+''''+trim(cmbstorages.Items.Strings[j])+''''+',';
        end;
      end;
      str1:=str1+''''+trim(shopid)+''''+',';
    end;
    if ckbtype.Checked then tj:=tj+'and type='+''''+trim(cbtype.Text)+'''';
    if ckbbrand.Checked then tj:=tj+'and brand='+''''+trim(cbbrand.Text)+'''';
    if ckbbreed.Checked then tj:=tj+'and breed='+''''+trim(cbbreed.Text)+'''';
    if cbmstorage.Checked then
    begin
      str1:=' (';
      i:=pos('仓库', trim(cmbmstorage.Text));
      if i>0 then
      begin
        str1:=str1+''''+copy(trim(cmbmstorage.Text),i+4,length(trim(cmbmstorage.Text)))+''''+',';
      end else
      begin
        str1:=str1+''''+trim(cmbmstorage.Text)+''''+',';
      end;
      zt:=true;
    end ;
    if cbstorages.Checked then
    begin
      if trim(cmbstorages.Text)<>'全部仓库' then
      begin
        if not zt then str1:=' (';
        str1:=str1+''''+trim(cmbstorages.Text)+''''+',';
      end else
      begin
        if not cbmstorage.Checked then str1:=' (';
        for j:=0 to cmbstorages.Items.Count-2 do
        begin
          i:=pos('仓库', trim(cmbstorages.Items.Strings[j]));
          if i>0 then
          begin
            str1:=str1+''''+copy(trim(cmbstorages.Items.Strings[j]),i+4,length(trim(cmbstorages.Items.Strings[j])))+''''+',';
          end else
          begin
            str1:=str1+''''+trim(cmbstorages.Items.Strings[j])+''''+',';
          end;
        end;
      end;
    end;
    if trim(str1)<>'' then
    begin
      str1:=copy(str1,1,length(str1)-1);
      str1:=str1+')';
      tj:=tj+'and storage_no in '+trim(str1);
    end;
    screen.Cursor :=  crHourGlass;
    temp:=tempsql+tables+tj+groups;
    try
    datas:=adisp.GetRecord(temp);
    except
      application.MessageBox('服务器发生故障!',pchar(application.Title),mb_iconwarning);
      screen.Cursor :=  crdefault;
      exit;
    end;
       ////////////////////////////////
      if  not varisnull(datas) then
      begin
      cdssort.Data:=datas;
      cdssort.Open;
      datas:=null;
      cdssort.Last;
      LocalCount := GetKeyFieldValue('id',cdssort);   //传入具体字段
      btnpagedown.Enabled:=true;

⌨️ 快捷键说明

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