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

📄 gl_enter_moreaccountbook.pas

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

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Entry_Body, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,
  ExtCtrls, ComCtrls, ToolWin, Mask, StdCtrls, linkedit;

Type
  TFrm_Gl_Enter_MoreAccountBook = Class(TFrm_Base_Entry_Body)
    Label1: TLabel;
    Label5: TLabel;
    Edt_AccountBookName: TEdit;
    Edt_AccountBookCode: TEdit;
    Label2: TLabel;
    edt_kmCode: TLinkEdit;
    edt_kmName: TEdit;
    AdoQry_BodyAccountBookCode: TStringField;
    AdoQry_BodyBalancedirection: TIntegerField;
    AdoQry_BodykmCode: TStringField;
    AdoQry_BodykmName: TStringField;
    procedure FormCreate(Sender: TObject);
    procedure edt_kmCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure edt_kmCodeExit(Sender: TObject);
    procedure edt_kmCodeButtonClick(Sender: TObject);
  private
    CurrentFormStatus,BeModifyCreatureCode:String;
    { Private declarations }
  public
    procedure SetStatus(CurrentStatus:String;var AnswerStatus,
      EnableControls:String); Override;//设置各种状态下那些控件Enable
    procedure InitControls; Override;//初始化Form上所有控件
    procedure SaveData; Override;//把表头控件写入缓存,不要Post
    procedure CheckInfo;
    { Public declarations }
  end;

var
  Frm_Gl_Enter_MoreAccountBook: TFrm_Gl_Enter_MoreAccountBook;
  Month:String;

implementation

uses Gl_Enter_MoreAccountBook_D, Sys_Global;

{$R *.DFM}

{ TFrm_Gl_Enter_ForeignCurrencyRate }


procedure TFrm_Gl_Enter_MoreAccountBook.FormCreate(Sender: TObject);
begin
  inherited;

  Frm_Gl_Enter_MoreAccountBook_D:=TFrm_Gl_Enter_MoreAccountBook_D.Create(Self);
  Frm_Entry_Detail:=Frm_Gl_Enter_MoreAccountBook_D;
end;

procedure TFrm_Gl_Enter_MoreAccountBook.SetStatus(
  CurrentStatus: String; var AnswerStatus, EnableControls: String);
begin
  inherited;
  IF Status='Add' then
    EnableControls := 'Edt_AccountBookCode,Edt_AccountBookName,edt_kmCode,'
  else
    EnableControls := 'Edt_AccountBookName,';
end;

procedure TFrm_Gl_Enter_MoreAccountBook.InitControls;
var
  SqlText:String;
begin
  inherited;
    If Status='Add' then
  begin
    CurrentFormStatus:='Add';
    Edt_AccountBookCode.Text := '';
    Edt_AccountBookName.Text := '';
    Edt_kmCode.Text := '';
    edt_kmName.Text:='';
    SqlText:=' select top 0 AccountBookCode,  '
             +'        Balancedirection,  '
             +'        Gl_MoreAccountBookLine.kmCode,  '
             +'        Gl_AccountSubject.kmName        '
             +' from Gl_MoreAccountBookLine            '
             +' left join Gl_AccountSubject on Gl_MoreAccountBookLine.kmCode=Gl_AccountSubject.kmCode ';
    Executesql(AdoQry_Body,sqltext,0);
     DataSource.DataSet:=AdoQry_Body;
  end
  else
    begin
      With AdoQry_Head do
        begin
          Edt_AccountBookCode.Text := fieldbyname('AccountBookCode').AsString;
          Edt_AccountBookName.Text := fieldbyname('AccountBookName').AsString;
          BeModifyCreatureCode := fieldbyname('kmCode').AsString;
          Edt_kmCode.Text := fieldbyname('kmCode').AsString;
          Executesql(AdoQry_tmp,'select * from Gl_AccountSubject where kmCode='+quotedstr(Trim(edt_kmCode.text)),0);
          edt_kmName.Text:=AdoQry_tmp.fieldbyname('kmName').asstring;
          SqlText:=' select  AccountBookCode,  '
                   +'        Balancedirection,  '
                  + '        Gl_MoreAccountBookLine.kmCode,  '
                  + '        Gl_AccountSubject.kmName        '
                  + ' from Gl_MoreAccountBookLine            '
                   +' left join Gl_AccountSubject on Gl_MoreAccountBookLine.kmCode=Gl_AccountSubject.kmCode '
                   +' where AccountBookCode='+quotedstr(fieldbyname('AccountBookCode').asstring);
         Executesql(AdoQry_Body,sqltext,0);
        end;
    end;
  if Status='Add' then
  begin
    if Edt_AccountBookCode.CanFocus then
      Edt_AccountBookCode.SetFocus;
    TlBtn_InsertLine.Enabled := True;
    TlBtn_DeleteLine.Enabled := True;
  end
  else
  begin
    if Edt_AccountBookName.CanFocus then
      Edt_AccountBookName.SetFocus;
    TlBtn_InsertLine.Enabled := False;
    TlBtn_DeleteLine.Enabled := False;
  end;
end;

procedure TFrm_Gl_Enter_MoreAccountBook.CheckInfo;
begin
  if  (AdoQry_Body.RecordCount=0)then
  begin
    DispInfo('没有行数据,不能保存!',1);
    Abort;
  end;
  if (Status='Add') then
  begin
    if Trim(edt_AccountBookCode.text)='' then 
     begin
      DispInfo('多栏式帐簿代码不能为空!',3);
      edt_AccountBookCode.SetFocus;
      abort;
     end;
    if Trim(edt_kmCode.text)='' then 
     begin
      DispInfo('科目代码不能为空!',3);
      edt_AccountBookCode.SetFocus;
      abort;
     end;
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text := ' Select * From Gl_MoreAccountBook '
                          +'       Where AccountBookCode = '+quotedstr(Trim(edt_AccountBookCode.text));
    AdoQry_Tmp.Open;
    if not AdoQry_Tmp.Eof then
    begin
      DispInfo('多栏式帐簿代码不可重复!',1);
      Edt_AccountBookCode.SetFocus;
      Abort;
    end;

    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text := ' Select * From Gl_MoreAccountBook '
                          +'       Where kmCode = '+quotedstr(Trim(edt_kmCode.text));
    AdoQry_Tmp.Open;
    if not AdoQry_Tmp.Eof then
    begin
      DispInfo('科目代码不可重复!',1);
      Edt_kmCode.SetFocus;
      Abort;
    end;
  end;
  If (Status <> 'Add')  And  (BeModifyCreatureCode <> Trim(Edt_kmCode.Text)) Then
  begin
    if Trim(edt_kmCode.text)='' then 
     begin
      DispInfo('科目代码不能为空!',3);
      edt_kmCode.SetFocus;
      abort;
     end;
  
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text := ' Select * From Gl_MoreAccountBook '
                          +'       Where kmCode = '+quotedstr(Trim(edt_kmCode.text));
    AdoQry_Tmp.Open;
    if not AdoQry_Tmp.Eof then
    begin
      DispInfo('科目不可重复!',1);
      Edt_kmCode.SetFocus;
      Abort;
    end;
  end;

end;


procedure TFrm_Gl_Enter_MoreAccountBook.SaveData;
var
  SqlText:String;
begin
  inherited;
  CheckInfo;
  DbConnect.beginTrans;
  Try
    AdoQry_Tmp.Close;
    If (Status='Add') Then
    begin
      SqlText:='Insert Gl_MoreAccountBook '
              +' (AccountBookCode,AccountBookName,kmCode)'
              +'  Values('
              +''''+Trim(Edt_AccountBookCode.Text)+''','
              +''''+Trim(Edt_AccountBookName.Text)+''','
              +''''+Trim(Edt_kmCode.Text)+''''
              +')';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;
      saveMoreAccountBookHistory(dbconnect,Trim(edt_AccountBookCode.text),userCode,0);
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.clear;

      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
        SqlText:='Insert Gl_MoreAccountBookLine '
                +' (AccountBookCode,Balancedirection,KmCode)'
                +'Values('
                +''''+Trim(Edt_AccountBookCode.Text)+''','
                +inttostr(AdoQry_Body.fieldbyname('Balancedirection').asinteger)+','
                +''''+AdoQry_Body.fieldbyname('KmCode').AsString+''')';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:=SqlText;
        AdoQry_Tmp.ExecSQL;
        saveMoreAccountBookLineHistory(dbconnect,Trim(edt_AccountBookCode.text),AdoQry_Body.fieldbyname('kmCode').asstring,userCode,0);

        AdoQry_Body.Next;
      end;
    end
    else
    begin
      saveMoreAccountBookHistory(dbconnect,Trim(edt_AccountBookCode.text),userCode,1);
      SqlText:='Update Gl_MoreAccountBook '
              +' Set AccountBookName='''+Trim(Edt_AccountBookName.Text)+''','
              +' kmCode= '''+Trim(Edt_kmCode.Text)+''''
              +' Where AccountBookCode='''+Trim(Edt_AccountBookCode.Text) +'''';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;
      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
        saveMoreAccountBookLineHistory(dbconnect,Trim(edt_AccountBookCode.text),AdoQry_Body.fieldbyname('kmCode').asstring,userCode,1);
        SqlText:=' UpDate Gl_MoreAccountBookLine '
                  +' Set  KmCode='+''''+AdoQry_Body.fieldbyname('KmCode').AsString+''''+','
                  +'      Balancedirection='+inttostr(AdoQry_Body.fieldbyname('Balancedirection').asinteger)
                  +' Where AccountBookCode='+''''+Trim(Edt_AccountBookCode.Text) +''''
                  +'        And kmCode ='''+AdoQry_Body.fieldbyname('kmCode').AsString+''' ';
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:=SqlText;
          AdoQry_Tmp.ExecSQL;
        AdoQry_Body.Next;
      end; //end while
    end;  //end if
    DbConnect.CommitTrans;
    Act_Save.Enabled:=False;
    DispInfo('数据保存成功!',3);
  Except
    on e:Exception do
    begin
      If DbConnect.InTransaction Then
        DbConnect.RollBackTrans;
        RecOrderror(Self,AdoQry_tmp,E.message);
        DispInfo('保存数据失败,请重试!',1);
        Abort;
    end ;
  end;
  with AdoQry_Head do
  begin
    fieldbyname('AccountBookCode').AsString := Trim(Edt_AccountBookCode.Text);
    fieldbyname('AccountBookName').AsString := Trim(Edt_AccountBookName.Text);
    fieldbyname('kmCode').AsString := Trim(Edt_kmCode.Text) ;
    fieldbyname('kmName').AsString := Trim(Edt_kmName.Text) ;
  end;

end;

procedure TFrm_Gl_Enter_MoreAccountBook.edt_kmCodeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
   If key=120 Then
  CommOnHint(Sender,AdoQry_Tmp,'KmName','科目名称','KmCode',
             '科目代码',' Gl_AccountSubject ');

end;

procedure TFrm_Gl_Enter_MoreAccountBook.edt_kmCodeExit(Sender: TObject);
var kmlevel:integer;
    i,j:integer;
begin
  inherited;
  if Activecontrol.Name =  'toolbutton4' then  exit;
  
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.text := 'Select KmName from Gl_AccountSubject Where KmCode='''+Trim(Edt_KmCode.Text) +'''';
    AdoQry_Tmp.Open;
    if AdoQry_Tmp.Eof then
    begin
      DispInfo('科目代码输入错误!',1);
      Edt_KmCode.SetFocus;
      Abort;
    end
    else
      Edt_KmName.Text := AdoQry_Tmp.fieldbyname('KmName').AsString;
if (status='Add')  then
 begin
   i:=1;
   AdoQry_Body.First;
   j:=AdoQry_Body.RecordCount;
   while i<=j do
    begin
      AdoQry_Body.Delete;
      i:=i+1;
    end;
   Executesql(AdoQry_tmp,'select * from Gl_AccountSubject where kmCode='+quotedstr(Trim(edt_kmCode.text)),0);
   kmlevel:=AdoQry_tmp.fieldbyname('kmlevel').asinteger;
   AdoQry_Body.Append;
   AdoQry_Body.fieldbyname('kmCode').asstring:=AdoQry_tmp.fieldbyname('kmCode').asstring;
   AdoQry_Body.fieldbyname('kmName').asstring:=AdoQry_tmp.fieldbyname('kmName').asstring;
   AdoQry_Body.fieldbyname('Balancedirection').asinteger:=iifinteger(AdoQry_tmp.fieldbyname('kmproperty').asinteger=1,2,1);
   AdoQry_Body.Post;
   Executesql(AdoQry_tmp,'select * from Gl_AccountSubject where kmlevel='+inttostr(kmlevel+1)+' and kmCode like '+quotedstr(Trim(edt_kmCode.text)+'%'),0);
    while not AdoQry_tmp.Eof do
     begin
       AdoQry_Body.Append;
       AdoQry_Body.fieldbyname('kmCode').asstring:=AdoQry_tmp.fieldbyname('kmCode').asstring;
       AdoQry_Body.fieldbyname('kmName').asstring:=AdoQry_tmp.fieldbyname('kmName').asstring;
       AdoQry_Body.fieldbyname('Balancedirection').asinteger:=AdoQry_tmp.fieldbyname('kmproperty').asinteger;
       AdoQry_Body.Post;
       AdoQry_tmp.Next;
     end;  
    AdoQry_Body.First;
 end;
end;

procedure TFrm_Gl_Enter_MoreAccountBook.edt_kmCodeButtonClick(
  Sender: TObject);
begin
  inherited;
  CommOnHint(Sender,AdoQry_Tmp,'KmName','科目名称','KmCode',
             '科目代码',' Gl_AccountSubject ');

end;

end.

⌨️ 快捷键说明

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