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

📄 ustocplan.pas

📁 delphi 源代码 界面上模仿了在2ccc.com网站发布的某一个程序.数据库为SQL2000。
💻 PAS
字号:
unit uStocPlan;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uBasic, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ComCtrls, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, cxCalc, cxDBEdit, cxDropDownEdit,
  cxCalendar, cxMaskEdit, cxButtonEdit, cxContainer, cxTextEdit, ExtCtrls,
  ToolWin, jpeg, StdCtrls, DBClient, cxCurrencyEdit, DateUtils, fr_Class;

type
  TfrmStockPlan = class(TfrmBasic)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    cxDBTextEdit1: TcxDBTextEdit;
    cxDBButtonEdit1: TcxDBButtonEdit;
    cxDBButtonEdit2: TcxDBButtonEdit;
    cxDBDateEdit1: TcxDBDateEdit;
    cxDBDateEdit2: TcxDBDateEdit;
    cxDBCalcEdit1: TcxDBCalcEdit;
    colCode: TcxGridDBColumn;
    colName: TcxGridDBColumn;
    colHD: TcxGridDBColumn;
    colKD: TcxGridDBColumn;
    colColor: TcxGridDBColumn;
    colDw: TcxGridDBColumn;
    colSL: TcxGridDBColumn;
    colZl: TcxGridDBColumn;
    colDj: TcxGridDBColumn;
    colJe: TcxGridDBColumn;
    colNil: TcxGridDBColumn;
    Label7: TLabel;
    Label8: TLabel;
    procedure cxDBButtonEdit1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxDBButtonEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cxDBButtonEdit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cxDBButtonEdit2PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxDBDateEdit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cxDBCalcEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cxDBTextEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cxDBDateEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure colCodePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cdMasterNewRecord(DataSet: TDataSet);
  private
     procedure documentPrint;
    { Private declarations }
  protected
    procedure init();override;
    procedure GridEnterColNilToDo(col: TcxCustomGridTableItem);override;
    function GridItemChange(col1,col2: TcxCustomGridTableItem):boolean;Override;
    function GetCpData():boolean;Override;
    function SetGritItemFocused(B:Boolean):boolean;Override;
    procedure CpToItem;override;

    function ApplyData():boolean;Override;
  public
    { Public declarations }
  end;

var
  frmStockPlan: TfrmStockPlan;

implementation

uses
   uGlobal, uGetData, uPublic, uReport;


{$R *.dfm}

{ TfrmBasicStockPlan }

procedure TfrmStockPlan.GridEnterColNilToDo(
  col: TcxCustomGridTableItem);
begin
  inherited;
   IF col <> colJe THEN EXIT;
   cdItem.Append;
   colCode.Focused := true;
end;

procedure TfrmStockPlan.init;
begin
   inherited;
   Label7.Caption := '采购计划单';
   lbLittle.Caption := '操作步骤:';
   ActiveControl := cxDBButtonEdit1;
end;

procedure TfrmStockPlan.cxDBButtonEdit1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  inherited;
   If GetClientData('CCode',trim(cxDBButtonEdit1.Text)) <= 0 then exit;
   IF frmGetData.ShowModal = mrOk THEN BEGIN
      ClientToMaster;
      cxDBDateEdit2.SetFocus;
   END;
end;

procedure TfrmStockPlan.cxDBButtonEdit1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
   case key of
      vk_return : if cxDBButtonEdit1.Text = '' THEN
                     cxDBButtonEdit2.SetFocus
                  else
                     cxDBButtonEdit1PropertiesButtonClick(sender,0);
   end;
end;

procedure TfrmStockPlan.cxDBButtonEdit2KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
   case key of
      vk_return : if cxDBButtonEdit2.Text = '' THEN
                     cxDBButtonEdit1.SetFocus
                  else
                     cxDBButtonEdit2PropertiesButtonClick(sender,0);
   end;
end;

procedure TfrmStockPlan.cxDBButtonEdit2PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  inherited;
   If GetClientData('CName',trim(cxDBButtonEdit2.Text)) <= 0 then exit;
   IF frmGetData.ShowModal = mrOk THEN BEGIN
      ClientToMaster;
      cxDBDateEdit2.SetFocus;
   END;
end;

procedure TfrmStockPlan.cxDBDateEdit2KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
   case key of
      vk_return: cxDBCalcEdit1.SetFocus;
   end;
end;

procedure TfrmStockPlan.cxDBCalcEdit1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
   case key of
      vk_return: cxDBTextEdit1.SetFocus;
   end;
end;

procedure TfrmStockPlan.cxDBTextEdit1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
   case key of
      vk_return: cxDBDateEdit1.SetFocus;
   end;
end;

procedure TfrmStockPlan.cxDBDateEdit1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
   case key of
      vk_return: cxGrid4.SetFocus;
   end;
end;

function TfrmStockPlan.ApplyData: boolean;
begin
   Result := false;
   if cdMaster.FieldByName('iKeyClient').AsInteger <= 0 then begin
      infownd('提示:请输入客户信息,请检查!');
      Exit;
   end;
   if (yearof(cdMaster.FieldByName('DDatePz').AsDateTime) <> yearof(date)) or
      (monthOf(cdMaster.FieldByName('DDatePz').AsDateTime) < (monthOf(date)-1)) then
      if Not QueryWnd('提示:日期值与现在的日期值不大相符,继续保存吗?') then begin
         cxDBDateEdit1.SetFocus;
         exit;
      end;
   if cdMaster.FieldByName('ddateJh').AsDatetime <
      cdMaster.FieldByName('DDatePz').AsDateTime then begin
      infownd('提示:交货日期不能小于下单日期,请检查!');
      Exit;
   end;

   If frmMain.DCOMCn.AppServer.IApplyUpdateStockPlan(cdMaster.Data,cdItem.Data) = 1 then begin
      if queryWnd('保存成功,打印计划单吗?') then
         documentPrint;
      cxDBButtonEdit1.SetFocus;
      Result := True;
   end;
end;

function TfrmStockPlan.GetCpData(): boolean;
begin
   result := false;
   with frmMain.cdPub do begin
      close;
      commandText := 'select Ikey,ccode,cname,fhd,fkd,ccolor,cdw,fsl,fzl from T_Stock'+#13+
      'where Ccode like '''+trim(cdItem.fieldbyname('ccode').AsString)+'%''';
      open;

      fieldbyname('ikey').Visible := false;
      fieldbyname('ccode').DisplayLabel := '材料编号';
      fieldbyname('ccode').DisplayWidth := 18;
      fieldbyname('cname').DisplayLabel := '材料名称';
      fieldbyname('cName').DisplayWidth := 10;
      fieldbyname('FHD').DisplayLabel := '克重';
      fieldbyname('FHD').DisplayWidth := 8;
      fieldbyname('FKD').DisplayLabel := '宽度';
      fieldbyname('FKD').DisplayWidth := 8;
      fieldbyname('CCOLOR').DisplayLabel := '颜色';
      fieldbyname('CColor').DisplayWidth := 6;
      fieldbyname('CDW').DisplayLabel := '单位';
      fieldbyname('cdw').DisplayWidth := 4;
      fieldbyname('FSL').DisplayLabel := '库存量';
      fieldbyname('Fsl').DisplayWidth := 8;
      fieldbyname('FZL').DisplayLabel := '重量';
      fieldbyname('Fzl').DisplayWidth := 8;

      if recordcount <= 0 then exit;
      if recordcount = 1 then Begin
         cpToItem;
         Result := true;
      end;
      if (recordcount > 1) and (frmGetData.ShowModal = mrOk) then Begin
         cpToItem;
         Result := true;
      end;
   end;
end;

procedure TfrmStockPlan.CpToItem;
begin
   with frmMain.cdPub do Begin
      cdItem.Edit;
      cdItem.FieldByName('IkeyCp').Value := fieldbyname('IKey').Value;
      cdItem.FieldByName('CCode').Value := fieldbyname('CCODE').Value;
      cdItem.FieldByName('CName').Value := fieldbyname('CName').Value;
      cdItem.FieldByName('Fhd').Value := fieldbyname('FHD').Value;
      cdItem.FieldByName('FKD').Value := fieldbyname('FKD').Value;
      cdItem.FieldByName('Ccolor').Value := fieldbyname('Ccolor').Value;
      cdItem.FieldByName('Cdw').Value := fieldbyname('cdw').Value;
   end;
end;

function TfrmStockPlan.GridItemChange(col1,
  col2: TcxCustomGridTableItem): boolean;
begin
   result := ((col1 = colCode) and (col2 = colName));
end;

function TfrmStockPlan.SetGritItemFocused(B: Boolean): boolean;
begin
   result := true;
   if B then
      colSl.Focused := true
   else Begin
      colCode.Focused:=true;
      infoWnd('提示:没有该编码的材料,请检查!');
      abort;
   end;
end;

procedure TfrmStockPlan.colCodePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  inherited;
  SetGritItemFocused(GetCpData);
end;

procedure TfrmStockPlan.cdMasterNewRecord(DataSet: TDataSet);
begin
  inherited;
   cdMaster.FieldByName('ddatePZ').AsDateTime := date;
   cdMaster.FieldByName('ddateJh').AsDateTime := date + 1;
   cdMaster.FieldByName('idl').AsInteger := 11;
   cdMaster.FieldByName('cuser').AsString := user;
end;

procedure TfrmStockPlan.documentPrint;
var fje: real;
begin
   fje := cdMaster.fieldbyname('Fje').asfloat;
   UpperCasePrint(fje);
   frVariables['VcodeClient'] := cdMaster.fieldbyname('ccodeClient').asstring;
   frVariables['VnameClient'] := cdMaster.fieldbyname('cNameClient').asstring;
   frVariables['VdateJH'] := cdMaster.fieldbyname('DDateJh').asdateTime;
   frVariables['Vdh'] := cdMaster.fieldbyname('cdh').asstring;
   frVariables['VdatePZ'] := cdMaster.fieldbyname('DDatePz').asdatetime;
   frVariables['Vje'] := fje;
   frVariables['Vdress'] := cdMaster.fieldbyname('cPostDz').asstring;
   frVariables['Vtel'] := cdMaster.fieldbyname('cTel').asstring;
   frmReport.ReportS(10, 0, '', cdItem.Data);
end;

end.

⌨️ 快捷键说明

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