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

📄 frm_specialtyinfo.pas

📁 是一个用delphi设计的考勤系统
💻 PAS
字号:
{
***************************************************************
*  说明:专业基本信息维护                                     *
*  时间:2003/02/20                                           *
*  作者:杨泉清                                               *
***************************************************************
}
unit Frm_SpecialtyInfo;

interface

uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, ModalForm, DB, ADODB, ComCtrls, Grids, DBGrids, StdCtrls,
   YLabelButton, ChangeImage, Menus, ExtCtrls;

type
   TSpecialtyInfo = class(TMyModalForm)
      BtnNew: TChangeImg;
      LbtnNew: TLabelB;
      BtnEdit: TChangeImg;
      LBtnEdit: TLabelB;
      BtnDelete: TChangeImg;
      LBtnDelete: TLabelB;
      BtnRefresh: TChangeImg;
      LBtnRefresh: TLabelB;
      BtnHelp: TChangeImg;
      LBtnHelp: TLabelB;
      BtnFind: TChangeImg;
      LBtnFind: TLabelB;
      Label1: TLabel;
      Edtzybh: TEdit;
      Label2: TLabel;
      Edtzymc: TEdit;
      DBGrid1: TDBGrid;
      StatusBar1: TStatusBar;
      DataSource1: TDataSource;
      ADOQry: TADOQuery;
      GroupBox1: TGroupBox;
      ADOStp: TADOStoredProc;
      Label3: TLabel;
      CByxbh: TComboBox;
      Label4: TLabel;
      CBxqbh: TComboBox;
      procedure BtnNewClick(Sender: TObject);
      procedure BtnEditClick(Sender: TObject);
      procedure BtnDeleteClick(Sender: TObject);
      procedure BtnRefreshClick(Sender: TObject);
      procedure BtnFindClick(Sender: TObject);
      procedure BtnHelpClick(Sender: TObject);
      procedure DBGrid1CellClick(Column: TColumn);
      procedure FormClose(Sender: TObject; var Action: TCloseAction);
      procedure FormDestroy(Sender: TObject);
      procedure EdtzybhKeyDown(Sender: TObject; var Key: Word;
         Shift: TShiftState);
      procedure FormShow(Sender: TObject);
      procedure CByxbhKeyPress(Sender: TObject; var Key: Char);
      procedure CBxqbhExit(Sender: TObject);
      procedure CBxqbhKeyPress(Sender: TObject; var Key: Char);
      procedure CByxbhExit(Sender: TObject);
   private
    { Private declarations }
      procedure InitValue; //初始化窗体数据
      procedure SetEditValue; //设置各显示框的数据值
      function CheckValue: boolean; //检查各个输入框值的准确性
      procedure ExecStore(optmode: integer); //执行存储过程
      function ReturnSqlValue(Str: string; bz: string): string; //返回字段编号
   public
    { Public declarations }
   end;

var
   SpecialtyInfo: TSpecialtyInfo;

implementation
uses
   DM_DataModal, Uglobal, UgeneralFunc;
{$R *.dfm}

procedure TSpecialtyInfo.InitValue;
var
   xqbh: string;
begin
   Edtzybh.Text := '';
   Edtzymc.Text := '';
   cbyxbh.Text := '';
   Cbxqbh.ItemIndex := 0;
   cbxqbh.SetFocus;
   statusbar1.Panels[2].Text := 'Insert';
   xqbh := trim(ReturnSqlValue(cbxqbh.Text, 'xq'));
   with AdoQry do
   begin
      sql.Clear;
      sql.Add('select * from vZx_S_zyxx where xqbh=''' + xqbh + '''');
      open;
   end;
end;

procedure TSpecialtyInfo.SetEditValue;
begin
   if AdoQry.RecordCount > 0 then
   begin
      Cbxqbh.Text := AdoQry.fieldbyname('xqmc').Value;
      Cbyxbh.Text := AdoQry.fieldbyname('yxmc').Value;
      Edtzybh.Text := AdoQry.fieldbyname('zybh').Value;
      Edtzymc.Text := AdoQry.fieldbyname('zymc').Value;
   end;
end;

function TSpecialtyInfo.CheckValue: boolean;
begin
   result := false;
   if Cbxqbh.Text = '' then
   begin
      statusbar1.Panels[1].Text := '校区名称不可为空值,请选择!';
      Cbxqbh.SetFocus;
      Cbxqbh.SelectAll;
      exit;
   end;
   if Cbyxbh.Text = '' then
   begin
      statusbar1.Panels[1].Text := '院系名称不可为空值,请选择!';
      Cbyxbh.SetFocus;
      Cbyxbh.SelectAll;
      exit;
   end;
   if Edtzybh.Text = '' then
   begin
      statusbar1.Panels[1].Text := '专业编号不可为空值,请输入!';
      Edtzybh.SetFocus;
      Edtzybh.SelectAll;
      exit;
   end;
   if Edtzymc.Text = '' then
   begin
      statusbar1.Panels[1].Text := '专业名称不可为空值,请输入!';
      Edtzymc.SetFocus;
      Edtzymc.SelectAll;
      exit;
   end;
   Result := true;
end;

procedure TSpecialtyInfo.ExecStore(OptMode: integer);
begin
   with AdoStp do
   begin
      parameters.ParamByName('@czdx').Value := 3;
      parameters.ParamByName('@czfs').Value := OptMode;
      parameters.ParamByName('@yxbh').Value := ReturnSqlValue(Cbyxbh.Text, 'yx');
      parameters.ParamByName('@zybh').Value := Edtzybh.Text;
      Parameters.ParamByName('@mc').Value := Edtzymc.Text;
      try
         Execproc;
         Statusbar1.Panels[1].Text := parameters.paramByName('@retmsg').Value;
         InitValue;
      except
         Statusbar1.Panels[1].Text := '维护专业信息资料时出现意外!';
      end;
   end;
end;

procedure TSpecialtyInfo.BtnNewClick(Sender: TObject);
begin
   inherited;
   if CheckValue then ExecStore(1);
end;

procedure TSpecialtyInfo.BtnEditClick(Sender: TObject);
begin
   inherited;
   if CheckValue then ExecStore(3);
end;

procedure TSpecialtyInfo.BtnDeleteClick(Sender: TObject);
var
   msg: string;
begin
   inherited;
   msg := '请确认要删除该笔专业信息!';
   if showmsg(msg, 0, 2) then
   begin
      ExecStore(2);
   end
   else
      statusbar1.Panels[1].Text := '删除操作已取消!';
end;

procedure TSpecialtyInfo.BtnRefreshClick(Sender: TObject);
begin
   inherited;
   InitValue;
   statusbar1.Panels[1].Text := '';
end;

procedure TSpecialtyInfo.BtnFindClick(Sender: TObject);
var
   Sqlstr, Yxbh, xqbh: string;
   iRec: integer;
begin
   inherited;
   irec := 0;
   xqbh := ReturnSqlValue(Cbxqbh.Text, 'xq');
   yxbh := ReturnSqlValue(Cbyxbh.Text, 'yx');
   Sqlstr := 'select * from vZx_S_zyxx ';
   if (length(trim(xqbh)) > 0) then
   begin
      if irec < 1 then
      begin
         SqlStr := Sqlstr + ' where (xqbh like ''' + trim(xqbh) + ''')';
         inc(irec);
      end
      else begin
         SqlStr := Sqlstr + ' and (xqbh like ''' + trim(xqbh) + ''')';
         inc(irec);
      end;
   end;
   if (length(trim(yxbh)) > 0) then
   begin
      if irec < 1 then
      begin
         SqlStr := Sqlstr + ' where (yxbh like ''' + trim(yxbh) + ''')';
         inc(irec);
      end
      else begin
         SqlStr := Sqlstr + ' and (yxbh like ''' + trim(yxbh) + ''')';
         inc(irec);
      end;
   end;
   if (length(trim(Edtzybh.Text)) > 0) then
   begin
      if irec < 1 then
      begin
         SqlStr := Sqlstr + ' where (zybh like ''' + trim(edtzybh.text) + ''')';
         inc(irec);
      end
      else begin
         SqlStr := Sqlstr + ' and (zybh like ''' + trim(edtzybh.text) + ''')';
         inc(irec);
      end;
   end;
   if (length(trim(Edtzymc.Text)) > 0) then
   begin
      if irec < 1 then
      begin
         SqlStr := Sqlstr + ' where (zymc like ''' + trim(Edtzymc.text) + ''')';
         inc(irec);
      end
      else begin
         SqlStr := Sqlstr + ' and (zymc like ''' + trim(Edtzymc.text) + ''')';
         inc(irec);
      end;
   end;
   if irec = 0 then
   begin
      statusbar1.Panels[1].Text := '请输入查询条件';
      exit;
   end;
   with Adoqry do
   begin
      sql.Clear;
      sql.Add(sqlstr);
      open;
   end;
   if Adoqry.RecordCount > 0 then
   begin
      SetEditValue;
      cbxqbh.SetFocus;
      cbxqbh.SelectAll;
      statusbar1.Panels[1].Text := '查找到' + inttostr(Adoqry.RecordCount) + '笔符合条件的记录!';
      statusbar1.Panels[2].Text := 'Modify'
   end
   else begin
      InitValue;
      statusbar1.Panels[1].Text := '无符合条件的专业信息!';
   end;

end;

procedure TSpecialtyInfo.BtnHelpClick(Sender: TObject);
begin
   inherited;
  //帮助信息
   HtmlHelp(Handle, gtSyscs.sHelpFileName, $0001, DWORD(PChar('Introduction.htm')));
end;

procedure TSpecialtyInfo.DBGrid1CellClick(Column: TColumn);
begin
   inherited;
   SetEditValue;
   statusbar1.Panels[2].Text := 'Modify';
end;

procedure TSpecialtyInfo.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   inherited;
   Action := Cafree;
end;

procedure TSpecialtyInfo.FormDestroy(Sender: TObject);
begin
   inherited;
   SpecialtyInfo := nil;
end;

procedure TSpecialtyInfo.EdtzybhKeyDown(Sender: TObject; var Key: Word;
   Shift: TShiftState);
var
   Sqlstr: string;
begin
   inherited;
   if key = 13 then
   begin
      if Edtzybh.Text = '' then
      begin
         statusbar1.Panels[1].Text := '专业编号不可为空值,请输入!';
         exit;
      end;
      SqlStr := 'select * from vZx_S_zyxx   where zybh like ''' + trim(edtzybh.text) + '''';
      with Adoqry do
      begin
         sql.Clear;
         sql.Add(sqlstr);
         open;
      end;
      if Adoqry.RecordCount > 0 then
      begin
         SetEditValue;
         statusbar1.Panels[1].Text := '查找到' + inttostr(Adoqry.RecordCount) + '笔符合条件的记录!';
         statusbar1.Panels[2].Text := 'Modify'
      end;
      Edtzymc.SetFocus;
      edtzymc.SelectAll;
   end;

end;

procedure TSpecialtyInfo.FormShow(Sender: TObject);
var
   Sqlstr: string;
begin
   inherited;
   Sqlstr := 'select * from zx_s_xqxx ';
   SetComboxItems(WindData.AdoConn, CbXqbh, sqlstr, 'xqmc');
   InitValue;
end;

procedure TSpecialtyInfo.CByxbhKeyPress(Sender: TObject; var Key: Char);
begin
   inherited;
   key := #0;
end;

function TSpecialtyInfo.ReturnSqlValue(Str: string; bz: string): string; //返回字段名称
var
   Qry: TAdoQuery;
begin
   Qry := TAdoQuery.Create(nil);
   Qry.Connection := WindData.AdoConn;
   with Qry do
   begin
      sql.Clear;
      if bz = 'yx' then
         sql.Add('select yxbh from zx_s_yxxx where yxmc like ''' + trim(str) + '''')
      else if bz = 'xq' then
         sql.Add('select xqbh from zx_s_xqxx where xqmc like ''' + trim(str) + '''');
      open;
   end;
   if Qry.RecordCount > 0 then
   begin
      if bz = 'yx' then
         Result := Qry.fieldbyname('yxbh').AsString
      else if bz = 'xq' then
         Result := Qry.fieldbyname('xqbh').AsString;
   end
   else
      Result := '';
end;

procedure TSpecialtyInfo.CBxqbhExit(Sender: TObject);
var
   Sqlstr, xqbh: string;
begin
   inherited;
   xqbh := trim(ReturnSqlValue(cbxqbh.Text, 'xq'));
   Sqlstr := 'select * from zx_s_yxxx where xqbh=''' + xqbh + '''';
   SetComboxItems(WindData.AdoConn, Cbyxbh, sqlstr, 'yxmc');
   with adoqry do
   begin
      sql.Clear;
      sql.Add('select * from vzx_s_zyxx where xqbh=''' + xqbh + '''');
      open;
   end;
end;

procedure TSpecialtyInfo.CBxqbhKeyPress(Sender: TObject; var Key: Char);
begin
   inherited;
   key := #0;
end;

procedure TSpecialtyInfo.CByxbhExit(Sender: TObject);
var
   Sqlstr, xqbh, yxbh: string;
begin
   inherited;
   xqbh := trim(ReturnSqlValue(cbxqbh.Text, 'xq'));
   yxbh := trim(ReturnSqlValue(cbyxbh.Text, 'yx'));
   with adoqry do
   begin
      sql.Clear;
      sql.Add('select * from vzx_s_zyxx where xqbh=''' + xqbh + ''' and  yxbh=''' + yxbh + '''');
      open;
   end;
end;

end.

⌨️ 快捷键说明

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