uredeploy.~pas

来自「DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.」· ~PAS 代码 · 共 605 行 · 第 1/2 页

~PAS
605
字号
unit Uredeploy;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, dxCntner, dxEditor, dxExEdtr, dxEdLib, Buttons, Grids,
  ComCtrls, StdCtrls, ExtCtrls, DB, ADODB, RpCon, RpConDS, RpDefine, RpRave;

type
  Tfrmredeploy = class(TForm)
    Panel2: TPanel;
    Label3: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Edit2: TEdit;
    ComboBox2: TComboBox;
    DTPicker3: TDateTimePicker;
    ComboBox3: TComboBox;
    Edit3: TEdit;
    StringGrid1: TStringGrid;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    SpeedButton1: TSpeedButton;
    Label10: TLabel;
    Edit1: TEdit;
    DTPicker1: TDateTimePicker;
    DTPicker2: TDateTimePicker;
    StringGrid2: TStringGrid;
    SpeedButton2: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton9: TSpeedButton;
    dxButtonEdit1: TdxButtonEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    ADOQuery3: TADOQuery;
    RvProject1: TRvProject;
    redeployConnection1: TRvDataSetConnection;
    redeployConnection2: TRvDataSetConnection;
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure StringGrid2KeyPress(Sender: TObject; var Key: Char);
    procedure StringGrid2SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure dxButtonEdit1Exit(Sender: TObject);
    procedure dxButtonEdit1ButtonClick(Sender: TObject;
      AbsoluteIndex: Integer);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure SpeedButton7Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmredeploy: Tfrmredeploy;
  sstockin,sstockout:string;
  sprovider:string;

implementation

uses Udatamodule, Ufilprod;

{$R *.dfm}

procedure Tfrmredeploy.FormCreate(Sender: TObject);
var
  arow,i:integer;
begin
  stringgrid1.Cells[1,0]:='调拨单号';
  stringgrid1.Cells[2,0]:='调出分店';
  stringgrid1.Cells[3,0]:='调入分店';
  stringgrid1.Cells[4,0]:='调拨时间';
  stringgrid2.Cells[1,0]:='商品编号';
  stringgrid2.Cells[2,0]:='商品名称';
  stringgrid2.Cells[3,0]:='商品数量';
  adoquery1.SQL.Text:='select filname from filiale';
  adoquery1.Open;
  while not adoquery1.Eof do
  begin
    combobox2.Items.Add(adoquery1.Fields[0].asstring);
    combobox3.Items.Add(adoquery1.Fields[0].asstring);
    adoquery1.Next;
  end;
  dtpicker1.Date:=date-7;
  dtpicker2.Date:=date;
  dtpicker3.Date:=date;
  adoquery1.SQL.Text:='select redepid,filidin,filidout,rededate,handleman from redeploy';
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    stringgrid1.Cells[0,1]:='*';
    stringgrid1.RowCount:=adoquery1.RecordCount+1;
    arow:=1;
    edit2.Text:=adoquery1.FieldValues['redepid'];
    edit3.Text:=adoquery1.FieldValues['handleman'];
    dtpicker3.Date:=adoquery1.FieldValues['rededate'];
    adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filidin']+'''';
    adoquery2.Open;
    for i:=0 to combobox3.Items.Count-1 do
      if combobox3.Items.Strings[i] = adoquery2.Fieldvalues['filname'] then
        combobox3.ItemIndex:=i;
    adoquery2.Close;
    adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filidout']+'''';
    adoquery2.Open;
    for i:=0 to combobox2.Items.Count-1 do
      if combobox2.Items.Strings[i] = adoquery2.Fieldvalues['filname'] then
        combobox2.ItemIndex:=i;
    adoquery2.Close;
    while not adoquery1.Eof do
    begin
      stringgrid1.Cells[1,arow]:=adoquery1.FieldValues['redepid'];
      stringgrid1.Cells[2,arow]:=adoquery1.FieldValues['filidout'];
      stringgrid1.Cells[3,arow]:=adoquery1.FieldValues['filidin'];
      stringgrid1.Cells[4,arow]:=adoquery1.FieldValues['rededate'];
      adoquery1.Next;
      inc(arow);
    end;
  end;
  adoquery1.Close;
  adoquery1.SQL.Text:='select redeploy1.prid,pluinfo.prname,redeploy1.salenum'
  +' from redeploy1 inner join pluinfo on redeploy1.prid = pluinfo.prid where'
  +' redepid = '''+edit2.Text+'''';
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    arow:=1;
    stringgrid2.RowCount:=adoquery1.RecordCount+1;
    while not adoquery1.Eof do
    begin
      stringgrid2.Cells[1,arow]:=adoquery1.FieldValues['prid'];
      stringgrid2.Cells[2,arow]:=adoquery1.FieldValues['prname'];
      stringgrid2.Cells[3,arow]:=adoquery1.FieldValues['salenum'];
      adoquery1.Next;
      inc(arow);
    end;
  end;
  adoquery1.Close;
end;

procedure Tfrmredeploy.SpeedButton1Click(Sender: TObject);
var
  i,arow:integer;
  sprovid:string;
begin
  for i:=1 to stringgrid1.RowCount-1 do
    stringgrid1.Rows[i].Clear;
  stringgrid1.RowCount:=2;
  for i:=1 to stringgrid2.RowCount-1 do
    stringgrid2.Rows[i].Clear;
  stringgrid2.RowCount:=2;
  adoquery1.SQL.Text:='select * from redeploy where rededate between '
  +'#'+datetostr(dtpicker1.Date)+'# and #'+datetostr(dtpicker2.Date)+'#';
  if edit1.Text <> '' then
  adoquery1.SQL.Add('and redepid = '''+edit1.Text+'''');
  adoquery1.Open;
   if adoquery1.RecordCount > 0 then
  begin
    stringgrid1.Cells[0,1]:='*';
    stringgrid1.RowCount:=adoquery1.RecordCount+1;
    arow:=1;
    edit2.Text:=adoquery1.FieldValues['redepid'];
    edit3.Text:=adoquery1.FieldValues['handleman'];
    dtpicker3.Date:=adoquery1.FieldValues['rededate'];
    adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filidin']+'''';
    adoquery2.Open;
    for i:=0 to combobox3.Items.Count-1 do
      if combobox3.Items.Strings[i] = adoquery2.Fieldvalues['filname'] then
        combobox3.ItemIndex:=i;
    adoquery2.Close;
    adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filidout']+'''';
    adoquery2.Open;
    for i:=0 to combobox2.Items.Count-1 do
      if combobox2.Items.Strings[i] = adoquery2.Fieldvalues['filname'] then
        combobox2.ItemIndex:=i;
    adoquery2.Close;
    while not adoquery1.Eof do
    begin
      stringgrid1.Cells[1,arow]:=adoquery1.FieldValues['redepid'];
      stringgrid1.Cells[2,arow]:=adoquery1.FieldValues['filidout'];
      stringgrid1.Cells[3,arow]:=adoquery1.FieldValues['filidin'];
      stringgrid1.Cells[4,arow]:=adoquery1.FieldValues['rededate'];
      adoquery1.Next;
      inc(arow);
    end;
  end;
  adoquery1.Close;
  adoquery1.SQL.Text:='select redeploy1.prid,pluinfo.prname,redeploy1.salenum'
  +' from redeploy1 inner join pluinfo on redeploy1.prid = pluinfo.prid where'
  +' redepid = '''+edit2.Text+'''';
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    arow:=1;
    stringgrid2.RowCount:=adoquery1.RecordCount+1;
    while not adoquery1.Eof do
    begin
      stringgrid2.Cells[1,arow]:=adoquery1.FieldValues['prid'];
      stringgrid2.Cells[2,arow]:=adoquery1.FieldValues['prname'];
      stringgrid2.Cells[3,arow]:=adoquery1.FieldValues['salenum'];
      adoquery1.Next;
      inc(arow);
    end;
  end;
  adoquery1.Close;
end;

procedure Tfrmredeploy.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  i:integer;
begin
  if speedbutton1.Enabled then
  begin
    if stringgrid1.Cells[1,arow] <> '' then
    begin
      stringgrid1.Cols[0].Clear;
      stringgrid1.Cells[0,1]:='*';
      edit2.Text:=stringgrid1.Cells[1,arow];
      adoquery1.SQL.Text:='select handleman from redeploy where redepid ='''+edit2.Text+'''';
      adoquery1.Open;
      edit3.Text:=adoquery1.fieldbyname('handleman').AsString;
      adoquery1.Close;
      adoquery2.SQL.Text:='select filname from filiale where filid = '''+stringgrid1.Cells[3,arow]+'''';
      adoquery2.Open;
      for i:=0 to combobox3.Items.Count-1 do
        if combobox3.Items.Strings[i] = adoquery2.Fields[0].AsString then
          combobox3.ItemIndex:=i;
      adoquery2.Close;
      adoquery2.SQL.Text:='select filname from filiale where filid = '''+stringgrid1.Cells[2,arow]+'''';
      adoquery2.Open;
      for i:=0 to combobox2.Items.Count-1 do
        if combobox2.Items.Strings[i] = adoquery2.Fields[0].AsString then
          combobox2.ItemIndex:=i;
      adoquery2.Close;
      adoquery1.Close;
      adoquery1.SQL.Text:='select redeploy1.prid,pluinfo.prname,redeploy1.salenum'
      +' from redeploy1 inner join pluinfo on redeploy1.prid = pluinfo.prid where'
      +' redepid = '''+edit2.Text+'''';
      adoquery1.Open;
      if adoquery1.RecordCount > 0 then
      begin
        arow:=1;
        stringgrid2.RowCount:=adoquery1.RecordCount+1;
        while not adoquery1.Eof do
        begin
          stringgrid2.Cells[1,arow]:=adoquery1.FieldValues['prid'];
          stringgrid2.Cells[2,arow]:=adoquery1.FieldValues['prname'];
          stringgrid2.Cells[3,arow]:=adoquery1.FieldValues['salenum'];
          adoquery1.Next;
          inc(arow);
        end;
      end;
      adoquery1.Close;
    end;
  end;   
end;

procedure Tfrmredeploy.SpeedButton2Click(Sender: TObject);
var
  ayear,amonth,adate:word;
  smonth,sdate,maxid:string;
  i:integer;
begin
  edit2.Text:='';
  edit3.Text:='';edit3.Enabled:=true;
  combobox2.ItemIndex:=-1; combobox2.Enabled:=true;
  combobox3.ItemIndex:=-1; combobox3.Enabled:=true;
  dtpicker3.Enabled:=true; dtpicker3.Date:=date;
  edit1.Enabled:=false; edit1.Text:='';
  dtpicker1.Enabled:=false;
  dtpicker2.Enabled:=false;
  speedbutton1.Enabled:=false;
  speedbutton2.Enabled:=false;
  speedbutton7.Enabled:=false;
  speedbutton9.Enabled:=false;
  speedbutton5.Enabled:=true;
  speedbutton6.Enabled:=true;
  decodedate(date,ayear,amonth,adate);
  smonth:=inttostr(amonth);sdate:=inttostr(adate);
  if length(smonth) < 2 then smonth:= '0'+smonth;
  if length(sdate) < 2 then sdate:='0'+sdate;
  maxid:=inttostr(ayear)+smonth+sdate;
  adoquery1.SQL.Text:='select max(redepid) as maxid from redeploy where redepid like '''+maxid+'%''';
  adoquery1.Open;
  if adoquery1.FieldValues['maxid'] = null then

⌨️ 快捷键说明

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