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

📄 waterfeepropertyfrm.pas

📁 供水营销打印程序源码
💻 PAS
字号:
unit WaterfeePropertyFrm;

interface

{$I InvPrinter.inc}

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, SJDBCustomPropertyFrm, cxLookAndFeelPainters, DB, PropStorageEh,
  StdCtrls, cxButtons, ExtCtrls, ComCtrls, cxControls, cxContainer, cxEdit,
  cxTextEdit, cxMaskEdit, cxDBEdit, cxDropDownEdit, cxCalendar, ADODB, Math,
  cxCurrencyEdit, cxCheckBox, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox;

type
  TfrmPropertyWaterfee = class(TSJDBCustomPropertyForm)
    PageControl: TPageControl;
    TabCopiesinfo: TTabSheet;
    TabPayment: TTabSheet;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    edtCustID: TcxDBMaskEdit;
    Label2: TLabel;
    edtName: TcxDBMaskEdit;
    Label3: TLabel;
    edtCopiesdate: TcxDBDateEdit;
    Label4: TLabel;
    edtPriorQty: TcxDBMaskEdit;
    edtCurrQty: TcxDBMaskEdit;
    Label5: TLabel;
    edtDerate: TcxDBMaskEdit;
    Label6: TLabel;
    edtDescription: TcxDBTextEdit;
    Label7: TLabel;
    Label8: TLabel;
    edtQuantity: TcxDBMaskEdit;
    Label9: TLabel;
    edtAmont: TcxDBCurrencyEdit;
    GroupBox2: TGroupBox;
    chkPayflag: TcxDBCheckBox;
    Label10: TLabel;
    edtInvoice: TcxDBMaskEdit;
    Label11: TLabel;
    edtPaydate: TcxDBDateEdit;
    Label12: TLabel;
    edtPayment: TcxDBCurrencyEdit;
    Label13: TLabel;
    edtCollector: TcxDBLookupComboBox;
    chkBlankoutflag: TcxDBCheckBox;
    Label14: TLabel;
    edtBlankoutdate: TcxDBDateEdit;
    Bevel2: TBevel;
    Label15: TLabel;
    edtWaterfee: TcxDBCurrencyEdit;
    procedure FormShow(Sender: TObject);
    procedure chkBlankoutflagPropertiesEditValueChanged(Sender: TObject);
    procedure chkPayflagPropertiesEditValueChanged(Sender: TObject);
    procedure edtCustIDExit(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure edtQuantityPropertiesEditValueChanged(Sender: TObject);
    procedure edtWaterfeePropertiesEditValueChanged(Sender: TObject);
    procedure edtPriorQtyPropertiesEditValueChanged(Sender: TObject);
  private
    FPriorQtybuf, FCurrQtybuf, FDeratebuf: Integer;
  public
    { Public declarations }
  end;

var
  frmPropertyWaterfee: TfrmPropertyWaterfee;

implementation

uses InvPrintDM, MainFrm, SJInvPrintGlobal, sjUtils;

{$R *.dfm}

procedure TfrmPropertyWaterfee.FormShow(Sender: TObject);
var
  APayflag: Boolean;
begin
  inherited;
  FPriorQtybuf := 0;
  FCurrQtybuf  := 0;
  FDeratebuf   := 0;

  TabPayment.Visible := not NewRecord;
  edtCustID.Properties.ReadOnly := not NewRecord;  // 编辑时不能修改客户编号
  with dasProperty.DataSet do
  begin
    if NewRecord then
    begin
      FieldByName('Copiesdate').AsDateTime := Date;
      edtCustID.SetFocus;
    end else
    begin
      APayflag := FieldByName('Payflag').AsBoolean;
      edtCustID.Properties.ReadOnly   := APayflag;
      edtPriorQty.Properties.ReadOnly := APayflag;
      edtCurrQty.Properties.ReadOnly  := APayflag;
      edtDerate.Properties.ReadOnly   := APayflag;
      edtQuantity.Properties.ReadOnly := APayflag;
      edtWaterfee.Properties.ReadOnly := APayflag;
      edtAmont.Properties.ReadOnly    := APayflag;
    end;
  end;

  {$IFDEF DJSR}
  PageControl.Pages[1].Visible := False;
  {$ENDIF DJSR}
end;

procedure TfrmPropertyWaterfee.chkBlankoutflagPropertiesEditValueChanged(
  Sender: TObject);
begin
  inherited;
  if chkBlankoutflag.Checked then
    edtBlankoutdate.DataBinding.StoredValue := Date
  else
    edtBlankoutdate.DataBinding.StoredValue := NULL;
end;

procedure TfrmPropertyWaterfee.chkPayflagPropertiesEditValueChanged(
  Sender: TObject);
begin
  inherited;
  if dasProperty.State in [dsEdit, dsInsert] then
  begin
    if chkPayflag.Checked then
    begin
      dasProperty.DataSet.FieldByName('Collector').Value := GUserID;
      dasProperty.DataSet.FieldByName('Paydate').Value   := Date;
      dasProperty.DataSet.FieldByName('Payment').Value   := dasProperty.DataSet.FieldByName('Amont').Value;
    end else
    begin
      edtInvoice.DataBinding.StoredValue      := NULL;
      edtPayment.DataBinding.StoredValue      := NULL;
      edtCollector.DataBinding.StoredValue    := NULL;
      edtPaydate.DataBinding.StoredValue      := NULL;
      edtBlankoutdate.DataBinding.StoredValue := NULL;
      chkBlankoutflag.DataBinding.StoredValue := False;
    end;
  end;

end;

procedure TfrmPropertyWaterfee.edtCustIDExit(Sender: TObject);
// 获取客户基本资料
var
  AQryCust: TADOQuery;
  Aid: string;

  function GetCustInfo(Aid: string): Boolean;
  begin
    Result := False;
    // 创建临时查询控件
    if not Assigned(AQryCust) then
    begin
      AQryCust := TADOQuery.Create(self);
      AQryCust.Connection := dmInvPrint.ADOConnection;
      AQryCust.CacheSize  := 1000;
    end;

    with AqryCust do
    begin
      Close;
      SQL.Clear;
      SQL.Add(Format('select C.*, U.sPrice, U.wPrice from Customer C, Usager U where CustID = ''%s'' and U.UsingID = C.UsingID', [Aid]));
      try
        Open;
      except
        Result := False;
      end;
      if not IsEmpty then
        Result := True;
    end;
  end;

begin
  inherited;
  if not NewRecord then
    Exit;

  if not edtCustID.EditModified then
    Exit;

  // 测试用户输入的客户编号是否合法
  try
    StrToInt(edtCustID.Text);
  except
    ShowMessage('您输入的客户编号不合法,请重新输入。'#13#10'正确的形式为:001, 2864023');
    Exit;
  end;

  Aid := PrefixStr('0', Trim(edtCustID.Text), 8);
  if not GetCustInfo(Aid) then
  begin
    ShowMessage(Format('没有编号为 %s 的客户资料,请确认后再试 。', [Aid]));
    edtCustID.SetFocus;
    Exit;
  end;

  with dasProperty.DataSet do
  try
    // 缓存客户上期用水量
    FPriorQtybuf := AqryCust.FieldByName('PriorQty').AsInteger;
    FCurrQtybuf  := AqryCust.FieldByName('CurrQty').AsInteger;
    FDeratebuf   := AqryCust.FieldByName('Derate').AsInteger;

    FieldByName('CustID').Value        := Aid;
    FieldByName('Name').Value          := AqryCust.FieldByName('Name').AsString;
    FieldByName('AreaID').Value        := AqryCust.FieldByName('AreaID').AsString;
    FieldByName('BookID').Value        := AqryCust.FieldByName('BookID').AsString;
    FieldByName('Address').Value       := AqryCust.FieldByName('Address').AsString;
    FieldByName('Copier').Value        := AqryCust.FieldByName('Copier').AsString;
    FieldByName('Copiesdate').Value    := Date;
    FieldByName('sPrice').Value        := AqryCust.FieldByName('sPrice').Value;
    FieldByName('wPrice').Value        := AqryCust.FieldByName('wPrice').Value;
    FieldByName('SewagePercent').Value := AqryCust.FieldByName('SewagePercent').Value; 
    FieldByName('UsingID').Value       := AqryCust.FieldByName('UsingID').Value;
    FieldByName('PriorQty').Value      := AqryCust.FieldByName('CurrQty').Value;
    {$IFDEF DJSR}
    edtQuantity.SetFocus;
    {$ELSE}
    edtCurrQty.SetFocus;
    {$ENDIF DJSR}
  finally
    if Assigned(AqryCust) then
      FreeAndNil(AqryCust);
  end;

end;

procedure TfrmPropertyWaterfee.btnOKClick(Sender: TObject);
var
  AUpdateflag: Boolean;
begin
  inherited;
  AUpdateflag := False;
  
  with dasProperty.DataSet do
  begin
    FieldByName('Modifier').Value   := GUserID;
    FieldbyName('Modifydate').Value := Date;
    if NewRecord then
      AUpdateflag := dmInvPrint.UpdateCustDegreebuf(edtCustID.DataBinding.DisplayValue,
        FCurrQtybuf - FPriorQtybuf + FDeratebuf);
    if edtPriorQty.EditModified or edtCurrQty.EditModified or edtDerate.EditModified then
      AUpdateflag := dmInvPrint.UpdateCustCopiesbuf(FieldByName('CustID').AsString,
        FieldByName('CurrQty').AsInteger, FieldByName('PriorQty').AsInteger,
        FieldByName('Derate').AsInteger);
  end;

  // 检查更新客户基础资料是否成功
  if NewRecord or edtPriorQty.EditModified or edtCurrQty.EditModified or edtDerate.EditModified then
    if not AUpdateflag then
    begin
      ShowMessage('更新客户基础资料失败,请检查后再试 。');
      Exit;
    end;

  ModalResult := mrOK;
end;

procedure TfrmPropertyWaterfee.edtQuantityPropertiesEditValueChanged(
  Sender: TObject);
begin
  inherited;
  {$IFDEF DJSR}
  if dasProperty.State in [dsEdit, dsInsert] then
  begin
    if self.Visible and (Trim(edtCustID.Text) = '') then
    begin
      ShowMessage('你没有选择正确的客户,不能进行记录的输入操作 。');
      Exit;
    end;

    if self.Visible then
    begin
      try
        StrToFloat(edtQuantity.Text);
      except
        ShowMessage('你输入的当前水量不正确或超过了系统设计的最大值,请确认后再试 。');
        edtQuantity.SetFocus;
        Exit;
      end;

      with dasProperty.DataSet do
      begin
        FieldByName('Waterfee').Value := RoundTo(FieldByName('sPrice').AsFloat * edtQuantity.DataBinding.DisplayValue, -2);
        FieldByName('PriorQty').Value := 0;
        FieldByName('CurrQty').Value  := edtQuantity.DataBinding.DisplayValue;
        FieldByName('Derate').Value   := 0;
      end;
    end;
  end;
  {$ENDIF DJSR}
end;

procedure TfrmPropertyWaterfee.edtWaterfeePropertiesEditValueChanged(
  Sender: TObject);
begin
  inherited;
  {$IFDEF DJSR}
  if dasProperty.State in [dsEdit, dsInsert] then
  begin
    if self.Visible and (Trim(edtCustID.Text) = '') then
    begin
      ShowMessage('你没有选择正确的客户,不能进行记录的输入操作 。');
      Exit;
    end;

    if self.Visible then
    begin
      try
        StrToFloat(edtWaterfee.Text);
      except
        ShowMessage('你输入的水费金额不正确或超过了系统设计的最大值,请确认后再试 。');
        edtWaterfee.SetFocus;
        Exit;
      end;

      // 倒推当期水量
      with dasProperty.DataSet do
      begin
        FieldByName('Quantity').Value := RoundTo(edtWaterfee.DataBinding.DisplayValue / FieldByName('sPrice').AsFloat, -2);
        FieldByName('PriorQty').Value := 0;
        FieldByName('CurrQty').Value  := edtQuantity.DataBinding.DisplayValue;
        FieldByName('Derate').Value   := 0;
      end;
    end;
  end;
  {$ENDIF DJSR}
end;

procedure TfrmPropertyWaterfee.edtPriorQtyPropertiesEditValueChanged(
  Sender: TObject);
begin
  inherited;
  {$IFNDEF DJSR}
  if dasProperty.State in [dsEdit, dsInsert] then
  begin
    if self.Visible and (Trim(edtCustID.Text) = '') then
    begin
      ShowMessage('你没有选择正确的客户,不能进行记录的输入操作 。');
      Exit;
    end;

    if self.Visible then
    begin
      try
        StrToFloat(edtWaterfee.Text);
      except
        ShowMessage('你输入的数据不正确或超过了系统设计的最大值,请确认后再试 。');
        TcxDBMaskEdit(Sender).SetFocus;
        Exit;
      end;

      with dasProperty.DataSet do
      begin
        FieldByName('Quantity').Value := FieldByName('CurrQty').Value - FieldByName('PriorQty').Value + FieldByName('Derate').Value;
        FieldByName('Waterfee').Value := FieldByName('Quantity').Value * FieldByName('sPrice').AsFloat;
      end;
    end;
  end;
  {$ENDIF DJSR}
end;

end.

⌨️ 快捷键说明

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