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

📄 bas_standardprice_d.pas

📁 一个MRPII系统源代码版本
💻 PAS
字号:
unit Bas_StandardPrice_D;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Detail, StdCtrls, ExtEdit, Db, AdODB, ExtCtrls, Mask;

Type
  TFrm_Bas_StandardPrice_D = Class(TFrm_Base_Detail)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    ExtEdt_ItemCode: TExtEdit;
    Edt_SpPrice: TEdit;
    lbl_ItemName: TLabel;
    Label5: TLabel;
    Lbl_Uom: TLabel;
    medt_SPStArtMonth: TMaskEdit;
    procedure btn_okClick(Sender: TObject);
    procedure InOutItemCodeCheck(Sender: TObject);
    procedure medt_SPStArtMonthExit(Sender: TObject);
  private
    oldMonth,oldItemCode:string;
    { Private declarations }
  public
    procedure SaveData;Override;
    procedure InitControls;Override;
    procedure SetStatus(CurrentStatus:String;
              var EnableControls:String);Override;
    { Public declarations }
  end;

var
  Frm_Bas_StandardPrice_D: TFrm_Bas_StandardPrice_D;

implementation

uses Sys_Global, Bas_StandardPrice;
{$R *.DFM}

procedure TFrm_Bas_StandardPrice_D.InitControls;
begin
  with AdoQry_Maintain do
  begin
    ExtEdt_ItemCode.Text:=fieldbyname('ItemCode').AsString;
    edt_SpPrice.text:=floattostr(fieldbyname('spPrice').asfloat);
    lbl_ItemName.Caption:=fieldbyname('ItemName').AsString;
    lbl_Uom.Caption:=fieldbyname('UomName').AsString;
    oldMonth:=fieldbyname('spstArtMonth').asstring;
    oldItemCode:=fieldbyname('ItemCode').AsString;
    if fieldbyname('spstArtMonth').asstring='' then
      medt_SPStArtMonth.text:=Frm_Bas_StandardPrice.LoginMonth
      //Lbl_SPStArtMonth.Caption:=Frm_Bas_StandardPrice.LoginMonth
    else
     // Lbl_SPStArtMonth.Caption:=fieldbyname('spstArtMonth').asstring;
      medt_SPStArtMonth.text:=fieldbyname('spstArtMonth').asstring;

  end;
  inherited;
end;

procedure TFrm_Bas_StandardPrice_D.SaveData;
begin
  inherited;
  if (Add) then
  begin
    with AdoQry_Tmp do
    begin
      Close;
      SQL.clear;
      SQL.Add('Insert StandardPrice (spstArtMonth,ItemCode,spPrice)');
      SQL.Add('ValueS ('''+medt_SPStArtMonth.text+''','''+ExtEdt_ItemCode.Text+''','+Edt_SpPrice.Text+')');
      ExecSQL;
    end
  end
  else
  begin
    with AdoQry_Tmp do
    begin
      Close;
      SQL.clear;
      sql.text:=
        'Update StandardPrice '+
        '  set '+
        '  spstArtMonth='''+medt_SPStArtMonth.text+''','+
        '  ItemCode='''+ExtEdt_ItemCode.text+''','+
        '  spPrice='+Edt_SpPrice.Text+
        ' Where spstArtMonth='''+AdoQry_Maintain.fieldbyname('spstArtMonth').asstring+''''+
        '   and ItemCode='''+AdoQry_Maintain.fieldbyname('ItemCode').asstring+'''';
      ExecSQL;
    end
  end;
  //给AdoQry_Item各字段赋值
  with AdoQry_Maintain do
  begin
    fieldbyname('ItemCode').AsString:=ExtEdt_ItemCode.Text;
    fieldbyname('spstArtMonth').AsString:=medt_SpstArtMonth.text;
    fieldbyname('spPrice').Asfloat:=strtofloat(Edt_SpPrice.Text);
    fieldbyname('ItemName').asstring:=lbl_ItemName.Caption;
    fieldbyname('UomName').asstring:=lbl_Uom.Caption;
    Post;
  end;
end;

procedure TFrm_Bas_StandardPrice_D.btn_okClick(Sender: TObject);
begin
  inherited;
  ChangeInvStatus(AdoQry_tmp, '', medt_SPStArtMonth.text);
end;

procedure TFrm_Bas_StandardPrice_D.InOutItemCodeCheck(Sender: TObject);
begin
  inherited;
  if ActiveControl.Name='btn_Cancel' then
     exit;

  with AdoQry_Tmp do
  begin
    Close;
    SQL.clear;
    SQL.Add('Select Count(*) as RecCount '+
              ' From StandardPrice '+
              'Where ItemCode='''+ExtEdt_ItemCode.Text+''' '+
              '  and spstArtMonth='''+medt_SPStArtMonth.text+'''');
    Open;
    if fieldbyname('RecCount').AsInteger<>0 then
    begin
      DispInfo('  该月份该物料的计划价已经存在,不允许增加或修改!  ',1);
      TWinControl(Sender).SetFocus;
      Abort;
    end
    else
    begin
      Close;
      sql.clear;
      sql.Add('select UomName from Uom,Item where Uom.UomCode=Item.UomCode and ItemCode='''+ExtEdt_ItemCode.text+'''');
      open;
      lbl_Uom.Caption:=fieldbyname('UomName').asstring;
    end;
  end;
end;

procedure TFrm_Bas_StandardPrice_D.SetStatus(CurrentStatus:String;
  var EnableControls:String);
var
  tmp_Month:string;
begin
  inherited;
  if CurrentStatus='Edit' then
  begin
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.text:=
        ' select left(convert(varchAr,Invstatus),7) as InvStatus '+
        '  from Invstatus '+
        ' where InvStatusName=''clsperiod'' ';
      open;
     tmp_Month:=fieldbyname('Invstatus').asstring;
    end;
    if (tmp_Month>=medt_SPStArtMonth.text) then
    begin
      EnableControls:='none';
      SetFocus_Control:=btn_Cancel;
    end
    else
    begin
      EnableControls:='Edt_SpPrice,';
      SetFocus_Control:=Edt_SpPrice;
    end;
  end
  else if CurrentStatus='Add' then
  begin
    EnableControls:='medt_SPStArtMonth,ExtEdt_ItemCode,Edt_SpPrice,';
    SetFocus_Control:=medt_SPStArtMonth
  end;
end;

procedure TFrm_Bas_StandardPrice_D.medt_SPStArtMonthExit(Sender: TObject);
var
  tmp_Date:string;
begin
  inherited;
  if ActiveControl.Name='btn_Cancel' then
     exit;
  DateSeparator:='.';
  Shortdateformat:='yyyy.mm.dd';
  tmp_Date:=Trim(medt_SPStArtMonth.text)+'.01';
  try
    StrToDateTime(tmp_Date);
  except
    DispInfo('   日期非法!  ',1);
    TWinControl(Sender).SetFocus;
    Abort;
  end;
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.text:=
      ' select left(convert(varchAr,Invstatus),7) as InvStatus '+
      '  from Invstatus '+
      ' where InvStatusName=''clsperiod'' ';
    open;
   // tmp_Date:=datetostr(incMonth(strtodatetime(Trim(fieldbyname('Invstatus').asstring)+'.01'),2)-1);
    tmp_Date:=fieldbyname('Invstatus').asstring;
  end;
  if tmp_Date>medt_SPStArtMonth.text then
  begin
    DispInfo('   该月份己经结帐,不允许增加或修改!  ',1);
    TWinControl(Sender).SetFocus;
    Abort;
  end;
end;

end.

⌨️ 快捷键说明

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