ssbqr.pas

来自「一个仓库管理中的子系统--采购子系统」· PAS 代码 · 共 737 行 · 第 1/2 页

PAS
737
字号
unit ssbqr;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, Grids, DBGrids, StdCtrls, Buttons, DBCtrls, ExtCtrls,ComCtrls,QuickRpt;

var myRowCount,RwRecordCount:integer;

type
  TssbqrForm = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    qrBtn: TBitBtn;
    jhyidLabel: TLabel;
    BitBtn2: TBitBtn;
    TabControl1: TTabControl;
    StringGrid1: TStringGrid;
    tjqrCheck: TCheckBox;
    ycdhrqDate: TDateTimePicker;
    cgfsCombo: TComboBox;
    hgfczfCheck: TCheckBox;
    jhyzdcjCombo: TComboBox;
    DBGrid1: TDBGrid;
    printButton: TSpeedButton;
    startEdit: TEdit;
    endEdit: TEdit;
    Date1: TDateTimePicker;
    Date2: TDateTimePicker;
    startLabel: TLabel;
    endLabel: TLabel;
    cxBtn: TBitBtn;
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure jhyzdcjComboChange(Sender: TObject);
    procedure ycdhrqDateCloseUp(Sender: TObject);
    procedure cgfsComboChange(Sender: TObject);
    procedure hgfczf1CheckClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure qrBtnClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure tjqrCheckClick(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
    procedure jhyzdcjComboKeyPress(Sender: TObject; var Key: Char);
    procedure StringGrid1DblClick(Sender: TObject);
    procedure Date1CloseUp(Sender: TObject);
    procedure Date2CloseUp(Sender: TObject);
    procedure cxBtnClick(Sender: TObject);
    procedure printButtonClick(Sender: TObject);
    procedure DBGrid1CellClick(Column: TColumn);
  private
  FReport : TQuickRep;
  procedure InitstringGrid;
  procedure SetReport(Value : TQuickRep);
    { Private declarations }
  public
    function PostToDatabase:boolean;
    procedure SetSgridEMode;
    procedure initssbqrForm;
    procedure initsGridhead;
    property Report : TQuickRep read FReport write SetReport;
    { Public declarations }
  end;

var
  ssbqrForm: TssbqrForm;

implementation

uses sqbinput, Datamodule, sccgssb, bhgsqbqr, jhyxxcx, jhyrwReport,
  ssbreport;

{$R *.DFM}

procedure TssbqrForm.SetReport(Value : TQuickRep);
begin
  FReport:=Value;
end;

function  TssbqrForm.PostToDatabase:boolean;
var I:integer;
begin
   For I:=1 To rwRecordCount do
   begin
    if  stringGrid1.Cells[1,I]='确认' then
    begin
     if stringGrid1.Cells[15,I]='' then
     begin
      Showmessage('请您输入第'+inttostr(I)+'记录的预测到货时间');
      result:=false;
      exit;
     end;
     if stringGrid1.Cells[17,I]='0.0' then
     begin
      Showmessage('请您输入第'+inttostr(I)+'记录的采购数量核实');
      result:=false;
      exit;
     end;
     if stringGrid1.Cells[12,I]='' then
     begin
      Showmessage('请您输入第'+inttostr(I)+'记录的采购方式');
      result:=false;
      exit;
     end;
     if stringGrid1.Cells[11,I]='' then
     begin
      Showmessage('请您决定第'+inttostr(I)+'记录是否在合格分承制方表中采购');
      result:=false;
      exit;
     end;
     if stringGrid1.Cells[10,I]='' then
     begin
       Showmessage('请您确认第'+inttostr(I)+'记录的采购厂家');
       result:=false;
       exit;
     end;
   end;
   end;

   For I:=1 To rwRecordCount do
   begin
   if  stringGrid1.Cells[1,I]='确认' then
   begin
   with datamodule1.PublicQuery1 do
   begin
   requestLive:=True;
   sql.Clear;
   sql.Add('select * from dbo.a_cgssxb');
   sql.Add('where sqbid='+''''+stringGrid1.Cells[2,I]+''''+' and '+'cpbh='+''''+stringGrid1.cells[5,I]+'''');
   prepare;
   open;
   edit;
   fieldByName('ycdhsj').asstring:=sqinputForm.GetDate709(stringGrid1.cells[15,I]);
   fieldByname('cgslhs').asstring:=stringGrid1.cells[17,I];
   FieldBYName('tjqr').asstring:='1';
   post;

   close;
   sql.clear;
   sql.Add('select * From dbo.a_cghzglb');
   sql.add('where sqbid='+''''+stringGrid1.cells[2,I]+''''+' and '+'cpbh='+''''+stringGrid1.cells[5,I]+'''');
   prepare;
   open;
   edit;
   FieldByName('kcsl').AsFloat:=strToFloat(stringGrid1.Cells[13,I]);
   FieldByName('sxsl').AsFloat:=strtoFloat(stringGrid1.cells[14,I]);
   fieldByName('ycdhsj').asstring:=sqinputForm.GetDate709(stringGrid1.cells[15,I]);
   fieldByname('cgslhs').asstring:=stringGrid1.cells[17,I];
   FieldByName('sjcgsccj').asstring:=stringGrid1.cells[10,I];
   FieldByname('cgfs').asstring:=stringgrid1.cells[12,I];
   if stringGrid1.Cells[11,I]='是' then
   FieldByName('hg_Flag').asstring:='1'
   else
   FieldByname('hg_Flag').asstring:='0';
   post;
   showmessage('您确认的第'+inttostr(I)+'记录已经成功提交!');
   Requestlive:=False;
   close;
   end;
   end;
   {else
   if messageDlg('您是否确定不确认第'+inttostr(I)+'记录,确定请按OK!否则请按CANCEL!',mtInformation,[mbOK,mbCancel],0)=mrOK then
   continue
   else
   begin
   showmessage('请您确认未确认的记录!或者退出!');
   exit;
   end;}
   end;
   result:=true;
end;

procedure  TssbqrForm.SetSgridEMode;
begin
    with stringGrid1 do
    begin
    if (GoEditing in Options) then
    Options:=Options-[GoEditing];
    end;
end;

procedure TssbqrForm.InitstringGrid;
var I,J:Integer;
begin
     For I:=0 to stringGrid1.ColCount-1 do
     For J:=1 to stringGrid1.RowCount-1 do
     if (I=7) or (I=13) or (I=14) or (I=17) then
     stringGrid1.Cells[I,J]:='0.0'
     else
     if I=0 then
     stringGrid1.Cells[I,J]:=inttostr(J)
     else
     StringGrid1.Cells[I,J]:='';
end;

procedure TssbqrForm.initssbqrForm;
var I:Integer;
begin
    with datamodule1.PublicQuery1 do
    begin
    sql.clear;
    sql.Add('select * from dbo.a_cgssxb,dbo.a_cgsszb ');
    sql.Add('where dbo.a_cgssxb.sqbid=dbo.a_cgsszb.sqbid and ');
    sql.Add('dbo.a_cgssxb.jhy='+''''+jhyidlabel.Caption+''''+' and ');
    SQL.ADD(' dbo.a_cgssxb.tjqr='+''''+'0'+'''');
    sql.Text:=sql.Text+'order by dbo.a_cgssxb.sqbid desc';
    prepare;
    open;
    First;

    RwRecordCount:=RecordCount;
    stringgrid1.RowCount:=RecordCount+1;
    initstringGrid;
    
    with stringGrid1 do
    begin
    For I:=0 to RecordCount-1 do
    begin
    cells[1,I+1]:='未确认';
    cells[2,I+1]:=FieldByname('sqbid').asstring;
    Cells[3,I+1]:=FieldByName('cpmc').asstring;
    cells[4,I+1]:=FieldByName('xhgg').asstring;
    cells[5,I+1]:=FieldByName('cpbh').asstring;
    cells[6,I+1]:=FieldByName('jldw').asstring;
    cells[7,I+1]:=FieldByName('sbsl').asstring;
    cells[8,I+1]:=sqInputForm.ShowMeDate(FieldByname('sbrq').asstring);
    Cells[9,I+1]:=FieldByName('sccj').asstring;
    //Cells[10,I+1]:=FieldByName('sccj').asstring;
    Cells[13,I+1]:=FieldByName('kcsl').asstring;
    cells[14,I+1]:=FieldByName('xcgsl').asstring;
    
    Cells[16,I+1]:=FieldByName('xqdw').asstring;
    Cells[18,I+1]:=FieldByname('bz').asstring;
    Next;
    end;
    end;
    close;
    end;
end;

procedure TssbqrForm.initSGridhead;
begin
    with stringgrid1 do
    begin
       cells[1,0]:='确认提交';
       Cells[2,0]:='申请表ID';
       Cells[3,0]:='产品名称';
       cells[4,0]:='型号规格';
       cells[5,0]:='产品编号';
       cells[6,0]:='计量单位';
       cells[7,0]:='申请数量';
       cells[8,0]:='申请时间';
       cells[9,0]:='申请部门指定生产厂家';
       cells[10,0]:='计划员指定生产厂家';
       cells[11,0]:='是否为合格分承制方';
       cells[12,0]:='采购方式';
       cells[13,0]:='库存数量';
       cells[14,0]:='需采购数量';
       cells[15,0]:='预测到货时间';
       cells[16,0]:='需求单位';
       cells[17,0]:='采购数量核实';
       cells[18,0]:='备注';
    end;
end;
procedure TssbqrForm.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
     if aRow<=rwRecordCount then
     begin
     with Sender as TStringGrid do
     begin
      if gdFocused in State then
      begin
      if ACol=1 then
      begin
      tjqrcheck.SetBounds(
      Rect.Left+StringGrid1.left+1,
      Rect.Top+StringGrid1.Top+1,
      Rect.Right-Rect.Left+1,
      Rect.Bottom-Rect.Top);
      Canvas.DrawFocusRect(Rect);
      end
      else
      if ACol=10 then
      begin
      jhyzdcjCombo.SetBounds(
      Rect.Left+StringGrid1.left+1,
      Rect.Top+StringGrid1.Top+1,
      Rect.Right-Rect.Left+1,
      StringGrid1.DefaultRowHeight);
      Canvas.DrawFocusRect(Rect);
      end;
      if ACol=15 then
      begin
      ycdhrqDate.SetBounds(
      Rect.Left+StringGrid1.left+1,
      Rect.Top+StringGrid1.Top+1,
      Rect.Right-Rect.Left+1,
      StringGrid1.DefaultRowHeight);
      Canvas.DrawFocusRect(Rect);
      end
      else
      if ACol=12 then
      begin
      cgfsCombo.SetBounds(
      Rect.Left+StringGrid1.left+1,
      Rect.Top+StringGrid1.Top+1,
      Rect.Right-Rect.Left+1,
      StringGrid1.DefaultRowHeight);
      Canvas.DrawFocusRect(Rect);
      end
      else
       if ACol=11 then
      begin
      hgfczfcheck.SetBounds(
      Rect.Left+StringGrid1.left+1,
      Rect.Top+StringGrid1.Top+1,
      Rect.Right-Rect.Left+1,
      Rect.Bottom-Rect.Top);
      Canvas.DrawFocusRect(Rect);
      end;
    end;
    end;
    end;
end;

procedure TssbqrForm.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
   MyRowCount:=ARow;
   if Arow<=rwRecordCount then
   begin
   if ACol=1 then
     begin
      SetSgridEMode;
      tjqrCheck.Visible:=True;
      jhyzdcjCombo.Visible:=False;
      cgfsCombo.Visible:=False;
      ycdhrqDate.Visible:=False;
      hgfczfcheck.Visible:=False;
      tjqrcheck.Checked:=False;
     end
   else
   if ACol=10 then
    begin
    SetSgridEMode;
    tjqrCheck.Visible:=False;
    jhyzdcjCombo.Visible:=true;
    cgfsCombo.Visible:=False;
    ycdhrqDate.Visible:=False;
    hgfczfcheck.Visible:=False;
    end
   else
     if ACol=11 then
     begin
      SetSgridEMode;
      tjqrCheck.Visible:=False;
      jhyzdcjCombo.Visible:=False;
      cgfsCombo.Visible:=False;
      ycdhrqDate.Visible:=False;
      hgfczfcheck.Visible:=true;
      hgfczfcheck.Checked:=False;
     end
     else
     if ACol=12 then

⌨️ 快捷键说明

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