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

📄 sfc_bcpmonthqty_d.pas

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

Interface

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

Type
  TFrm_Sfc_BcPMonthqty_D = Class(TFrm_Base_Detail)
    Label1: TLabel;
    Label2: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Label3: TLabel;
    Edit4: TEdit;
    Label4: TLabel;
    lbl_DeptName: TLabel;
    Label6: TLabel;
    lbl_ItemName: TLabel;
    MaskEdit1: TMaskEdit;
    Label8: TLabel;
    lbl_UomName: TLabel;
    edt_SonItemCode: TEdit;
    Label5: TLabel;
    Label7: TLabel;
    lbl_SonItemName: TLabel;
    Label9: TLabel;
    edt_Sonqty: TEdit;
    Label10: TLabel;
    edt_SonScrAp: TEdit;
    procedure Edit2Exit(Sender: TObject);
    procedure Edit3Exit(Sender: TObject);
    procedure edt_SonItemCodeExit(Sender: TObject);
    procedure btn_okClick(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure InitControls; Override;
    procedure SaveData; Override;
  public
    { Public declarations }
  end;

var
  Frm_Sfc_BcPMonthqty_D: TFrm_Sfc_BcPMonthqty_D;

implementation
uses Sys_Global;
{$R *.DFM}
procedure TFrm_Sfc_BcPMonthqty_D.InitControls;
begin
  SetFocus_Control:=maskedit1;
  inherited;
  with AdoQry_Maintain do
  begin
    MaskEdit1.Text:=fieldbyname('wiPMonth').asstring;
    edit2.text:=fieldbyname('DeptCode').asstring;
    lbl_DeptName.Caption:=fieldbyname('DeptName').asstring;
    edit3.Text:=fieldbyname('ItemCode').AsString;
    Lbl_ItemName.Caption:=fieldbyname('ItemName').AsString;
    lbl_UomName.Caption:=fieldbyname('UomName').AsString;
    edit4.Text:=fieldbyname('wipqty').AsString;
    edt_SonItemCode.Text:=fieldbyname('sonItemCode').AsString;
    lbl_SonItemName.Caption:=fieldbyname('sonItemName').AsString;
    edt_Sonqty.Text:=fieldbyname('sonqty').AsString;
    edt_SonScrAp.Text:=fieldbyname('sonScrAp').AsString;
  end;
  if not (Add) then
  begin
     MaskEdit1.Enabled:=False;
     edit2.Enabled:=False;
     edit3.Enabled:=False;
  end;

end;
procedure TFrm_Sfc_BcPMonthqty_D.SaveData;
var
  wipid:string;
begin
  inherited;
  if(Add)then
  begin
    with AdoQry_tmp do
    begin
      Close;
      sql.text:='select Count(*) as aa from wipProduction '
            +' Where ItemCode='''+AdoQry_Maintain.fieldbyname('ItemCode').AsString+''''
            +' and wiPMonth='+QuotedStr(MaskEdit1.text)
            +' and DeptCode='+QuotedStr(edit2.text)
            +' and sonItemCode='+QuotedStr(edt_SonItemCode.text);
      open;
      if fieldbyname('aa').Value>0 then
      begin
         DispInfo('该物料已经存在',1);
         Abort;
      end;
    end;
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:='Insert wipProduction(wiPMonth,DeptCode,ItemCode,'
      +'wipqty,sonItemCode,sonqty,sonScrAp)'
      +' Values('
      +' '''+MaskEdit1.Text+''''
      +','''+edit2.Text+''''
      +', '''+edit3.Text+''''
      +','''+edit4.Text+''''
      +','''+edt_SonItemCode.Text+''''
      +','+edt_Sonqty.Text
      +','+edt_SonScrAp.Text
      +')'
      +' select @@IDENTITY as wipid ';
    AdoQry_Tmp.open;
    wipid:=AdoQry_tmp.fieldbyname('wipid').asstring;
  end
  else
  begin
    wipid:=AdoQry_Maintain.fieldbyname('wipid').AsString;
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:='Update wipProduction Set'
      +' wipqty='''+edit4.Text+''''
      +' ,sonItemCode='''+edt_SonItemCode.Text+''''
      +' ,sonqty='+edt_Sonqty.Text
      +' ,sonScrAp='+edt_SonScrAp.Text
      +' Where wipid='+AdoQry_Maintain.fieldbyname('wipid').AsString;
    AdoQry_Tmp.ExecSQL;
  end;
  with AdoQry_Maintain do
  begin
    fieldbyname('wipid').asstring:=wipid;
    fieldbyname('wiPMonth').asstring:=MaskEdit1.text;
    fieldbyname('wiPMonth').asstring:=MaskEdit1.text;
    fieldbyname('DeptCode').asstring:=edit2.Text;
    fieldbyname('DeptName').asstring:=lbl_DeptName.Caption;
    fieldbyname('ItemCode').AsString:= edit3.Text;
    fieldbyname('sonItemCode').AsString:=edt_SonItemCode.Text;
    fieldbyname('ItemName').asstring:=Lbl_ItemName.Caption;
    fieldbyname('wipqty').AsString:=edit4.Text;
    fieldbyname('UomName').AsString:=lbl_UomName.Caption;
    fieldbyname('sonItemName').asstring:=Lbl_SonItemName.Caption;
    fieldbyname('sonqty').asstring:=edt_Sonqty.Text;
    fieldbyname('sonScrAp').asstring:=edt_SonScrAp.Text;
    Post;
  end;

end;
procedure TFrm_Sfc_BcPMonthqty_D.Edit2Exit(Sender: TObject);
begin
  inherited;
  with AdoQry_Tmp do
  begin
    Close;
    sql.text:='select DeptName from Dept where DeptCode='+QuotedStr(edit2.text);
    open;
    if not eof then
       lbl_DeptName.Caption:=fieldbyname('DeptName').AsString
    else
        DispInfo('部门代码不存在!',1);
  end;
end;

procedure TFrm_Sfc_BcPMonthqty_D.Edit3Exit(Sender: TObject);
begin
  with AdoQry_Tmp do
  begin
    Close;
    sql.text:='select Item.ItemName,UomName,Bom.ItemCode as sonItemCode,'+
              'i.ItemName as sonItemName,Bom.Bomqty as sonqty,'+
              'Bom.BomScrAp_Percent as sonScrAp from Item '+
              'left join Uom on Item.UomCode=Uom.UomCode '+
              'left join Bom on Bom.ite_ItemCode=Item.ItemCode '+
              'left join Item i on i.ItemCode=Bom.ItemCode '+
              'where Item.ItemCode='+QuotedStr(edit3.text);
    open;
    if not eof then
    begin
       lbl_ItemName.Caption:=fieldbyname('ItemName').AsString;
       lbl_UomName.Caption:=fieldbyname('UomName').AsString;
       edt_SonItemCode.Text:=fieldbyname('sonItemCode').AsString;
        lbl_SonItemName.Caption:=fieldbyname('sonItemName').AsString;
        edt_Sonqty.Text:=fieldbyname('sonqty').AsString;
        edt_SonScrAp.Text:=fieldbyname('sonScrAp').AsString;
    end
    else
        DispInfo('物料代码不存在!',1);
  end;

end;

procedure TFrm_Sfc_BcPMonthqty_D.edt_SonItemCodeExit(Sender: TObject);
begin
//  inherited;
  with AdoQry_tmp do
  begin
    Close;
    sql.text:='select ItemName from Item where ItemCode='+QuotedStr(edt_SonItemCode.Text);
    open;
    if not eof then
    begin
      lbl_SonItemName.Caption:=fieldbyname('ItemName').AsString;
    end
    else
    begin
      DispInfo('子项代码输入有误!',1);
      edt_SonItemCode.SetFocus;
      abort;
    end;
  end;
end;

procedure TFrm_Sfc_BcPMonthqty_D.btn_okClick(Sender: TObject);
begin
  if(Status='Add')then
  begin
    AdoQry_Maintain.Append;
  end
  else
  begin
    AdoQry_Maintain.Edit;
  end;
  try
    SaveData;
  except
    DispInfo('数据保存出现错误!'+#13+#10+'可能是该记录已经被其他数据引用!',1);
    Abort;
  end;

  if Status='Add' then
  begin
    DispInfo('当前数据已经保存,可以继续增加!',3);
    InitControls;
    btn_ok.Enabled:=False;
  end
  else
    ModalResult:=mrOk;

end;

end.

⌨️ 快捷键说明

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