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

📄 ryxxedit.pas

📁 Delphi开发的人事管理系统
💻 PAS
字号:
unit RyxxEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ToolWin, ActnMan, ActnCtrls, ActnList, DB, DBCtrls, StdCtrls, ExtCtrls,
  RSGLCommon, Grids, DBGrids, ComCtrls, Menus, XPStyleActnCtrls, dmRsgl, ADODB,
  Jpeg;

type
  TRyxxEditForm = class(TForm)
    amZp: TActionManager;
    acZp: TAction;
    odlgZp: TOpenDialog;
    Panel5: TPanel;
    lblGrjl: TLabel;
    redtGrjl: TRichEdit;
    Panel6: TPanel;
    btOk: TButton;
    btCancel: TButton;
    Panel3: TPanel;
    lblGzrq: TLabel;
    lblSzbm: TLabel;
    lblSfbx: TLabel;
    lblJycd: TLabel;
    lblSfyh: TLabel;
    lblCsrq: TLabel;
    lblXb: TLabel;
    lblXm: TLabel;
    imgZp: TImage;
    lblBh: TLabel;
    cbSZBM: TComboBox;
    dtpGZRQ: TDateTimePicker;
    edtXm: TEdit;
    cbXB: TComboBox;
    dtpCSRQ: TDateTimePicker;
    cbSFYH: TComboBox;
    cbJYCD: TComboBox;
    cbSFBX: TComboBox;
    edtYgbh: TEdit;
    btLoadZp: TButton;
    btDelZp: TButton;
    procedure btOkClick(Sender: TObject);
    procedure acZpExecute(Sender: TObject);
    procedure acZpUpdate(Sender: TObject);
  private
    { Private declarations }
    FdmRsgl: TdmRsgl;
    FOperateType: TOperateType;
    FRecNo: Integer;
    procedure InitData;
    function CheckData: Boolean;
    function GetZPStream: TMemoryStream;
    procedure SetFieldStream(AStream: TadoblobStream);
    procedure SetControls(AState: Boolean);
  public
    { Public declarations }
    constructor Create(AOwner: TComponent; AdmRsgl: TdmRsgl;
      AOperateType: TOperateType); reintroduce;
  end;

implementation

{$R *.dfm}

constructor TRyxxEditForm.Create(AOwner: TComponent; AdmRsgl: TdmRsgl;
  AOperateType: TOperateType);
begin
  inherited Create(AOwner);
  FdmRsgl := AdmRsgl;
  FOperateType := AOperateType;

  if FOperateType in [optEdit, optBrowse] then
  begin
    FRecNo := FdmRsgl.adotRyxx.RecNo;
    InitData;
    if FOperateType = optBrowse then
      SetControls(False);
  end;

  if FOperateType <> optBrowse then 
  begin
    InitCombo(cbJYCD.Items, FdmRsgl.adotJycd, 'Jycd');
    InitCombo(cbSZBM.Items, FdmRsgl.adotBmxx, 'Bmmc');
    acZpUpdate(nil);
  end;
end;

procedure TRyxxEditForm.acZpExecute(Sender: TObject);
begin
  if imgZp.Picture.Graphic = nil then
  begin
    if odlgZp.Execute then
    begin
      imgZp.Picture.LoadFromFile(odlgZp.FileName);
    end
  end
  else
    imgZp.Picture.Graphic := nil;
end;

procedure TRyxxEditForm.btOkClick(Sender: TObject);
begin
  if CheckData then
  begin
    if FOperateType = optAdd then
      FdmRsgl.adotRyxx.Append
    else if FOperateType = optEdit then
      FdmRsgl.adotRyxx.Edit;

    with FdmRsgl.adotRyxx do
    begin
      FieldByName('Ygbh').AsString := edtYgbh.Text;
      FieldByName('Xm').AsString := edtXm.Text;
      FieldByName('Xb').AsString := cbXb.Text;
      FieldByName('Csrq').AsDateTime := dtpCsrq.Date;
      FieldByName('Gzrq').AsDateTime := dtpGzrq.Date;
      FieldByName('Jycd').AsString := cbJycd.Text;
      FieldByName('Bmmc').AsString := cbSzbm.Text;
      FieldByName('Sfyh').AsBoolean := (cbSfyh.ItemIndex = 1);
      FieldByName('Sfbx').AsBoolean := (cbSfbx.ItemIndex = 0);
      FieldByName('Grjl').AsString := redtGrjl.Lines.Text;
      if imgZp.Picture.Graphic <> nil then
        Tblobfield(FieldByName('Zp')).LoadFromStream(GetZPStream)
      else
        FieldByName('Zp').Value := Null;
      Post;
    end;
    ModalResult := mrOK;
  end;
end;

procedure TRyxxEditForm.InitData;
var
  l_Stream: TadoblobStream;
begin
  with FdmRsgl.adotRyxx do
  begin
    edtYgbh.Text := FieldByName('Ygbh').AsString;
    edtXM.Text := FieldByName('Xm').AsString;
    cbXB.Text := FieldByName('Xb').AsString;
    dtpCSRQ.Date := FieldByName('Csrq').AsDateTime;
    dtpGZRQ.Date := FieldByName('Gzrq').AsDateTime;
    cbJYCD.Text := FieldByName('Jycd').AsString;
    cbSZBM.Text := FieldByName('Bmmc').AsString;
    if FieldByName('Sfyh').AsBoolean then
      cbSfyh.ItemIndex := 1
    else
      cbSfyh.ItemIndex := 0;
    if FieldByName('Sfbx').AsBoolean then
      cbSFBX.ItemIndex := 0
    else
      cBSFBX.ItemIndex := 1;
    redtGRJL.Lines.Text := FieldByName('Grjl').AsString;
    if not Fieldbyname('Zp').IsNull then
    begin
      l_Stream := TAdoBlobStream.Create(Tblobfield(fieldbyname('Zp')),bmread);
      SetFieldStream(l_Stream);
    end;
  end;
end;

procedure TRyxxEditForm.acZpUpdate(Sender: TObject);
begin
  if imgZp.Picture.Graphic = nil then
  begin
    btLoadZp.Enabled := True;
    btDelZp.Enabled := False;
  end
  else begin
    btLoadZp.Enabled := False;
    btDelZp.Enabled := True;
  end;
end;

//检验数据的合法性
function TRyxxEditForm.CheckData: Boolean;
begin
  result := False;
  edtYgbh.Text := Trim(edtYgbh.Text);

  if edtYgbh.Text = '' then
  begin
    Application.MessageBox('编号不能为空!', '提示');
    edtYgbh.SetFocus;
    Exit;
  end
  else if FOperateType = optEdit then
    begin
      if FdmRsgl.adotRyxx.Locate('Ygbh', edtYgbh.Text, []) and (FdmRsgl.adotRyxx.RecNo <> FRecNo) then
      begin
        Application.MessageBox('编号已经存在!', '提示');
        edtYgbh.SetFocus;
        Exit;
      end;
    end
  else begin
    if FdmRsgl.adotRyxx.Locate('Ygbh', edtYgbh.Text, []) then
    begin
      Application.MessageBox('编号已经存在!', '提示');
      edtYgbh.SetFocus;
      Exit;
    end;
  end;
  result := True;
end;

function TRyxxEditForm.GetZPStream: TMemoryStream;
var
  ZpStream: TMemoryStream;
begin
  Result := nil;
  ZpStream := TMemoryStream.Create;
  if imgZp.Picture.Graphic <> nil then 
  begin
    imgZp.Picture.Graphic.SaveToStream(ZpStream);
    ZpStream.Position :=0;
    Result := ZpStream;
  end;
end;

procedure TRyxxEditForm.SetFieldStream(AStream: TadoblobStream);
var
  JpgImg: TJpegImage;
  FieldStream: TADOBlobStream;
begin
  FieldStream := AStream;
  try
    FieldStream.position := 0;
    JpgImg := Tjpegimage.Create;
    try 
      JpgImg.LoadFromStream(FieldStream);
      imgZp.Picture.Graphic := JpgImg;
    finally
      JpgImg.Free;
    end;
  finally
    FieldStream.Free;
    FieldStream := nil;
  end;
end;

procedure TRyxxEditForm.SetControls(AState: Boolean);
begin
  edtYgbh.Enabled := AState;
  edtXM.Enabled := AState;
  cbXB.Enabled := AState;
  dtpCSRQ.Enabled := AState;
  dtpGZRQ.Enabled := AState;
  cbJYCD.Enabled := AState;
  cbSZBM.Enabled := AState;
  cbSFYH.Enabled := AState;
  cbSFBX.Enabled := AState;

  redtGRJL.ReadOnly := not AState;
  redtGRJL.Font.Color := clGrayText;

  btLoadZP.Visible := AState;
  btDelZP.Visible := AState;
  btOk.Visible := AState;
  btCancel.Caption := '关闭';
end;

end.

⌨️ 快捷键说明

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