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

📄 uform_apart_edit.pas

📁 Delphi应用婚纱系统 Delphi应用婚纱系统
💻 PAS
字号:
unit Uform_apart_edit;
//部门管理窗口,用于设置各个部门的相关属性
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, StdCtrls, Buttons, ImgList, DB, ADODB;

type
  Tform_apart_edit = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    button_add: TBitBtn;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    ImageList1: TImageList;
    Label2: TLabel;
    Apart_list: TListView;
    recordset_temp: TADOQuery;
    Label4: TLabel;
    Label3: TLabel;
    Label1: TLabel;
    Bevel1: TBevel;
    Image2: TImage;
    Image1: TImage;
    procedure BitBtn3Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure button_addClick(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    intCount:integer;
  end;

var
  form_apart_edit: Tform_apart_edit;

implementation

uses UForm_apart_input, Uform_main;

{$R *.dfm}  

procedure Tform_apart_edit.BitBtn3Click(Sender: TObject);
//关闭本窗口
begin
  close;
end;

procedure Tform_apart_edit.FormShow(Sender: TObject);
//在本窗口开启时调用数据库内容初始化窗口内容
var
   i:integer;
   ListItem: TListItem;
   p:^integer;
begin
   //清除原先内容
   apart_list.Items.Clear ;
   recordset_temp.SQL.Clear ;
   recordset_temp.SQL.Add ('select * from [APART]');//选择APART表中的所有内容
   recordset_temp.Open ;
   intCount:=recordset_temp.RecordCount ;
   Label4.Caption :=inttostr(intCount) + '个';//初始化部门数目
   //读取APART表中所有的部门,显示在窗口中
   for i:=1 to recordset_temp.RecordCount do
   begin
      listitem:=apart_LIST.Items.Add ;
      listitem.Caption :=recordset_temp.Fields[1].AsString ;
      listitem.ImageIndex :=0;
      new(p);
      p^ := recordset_temp.Fields[0].AsInteger ;
      listitem.Data :=p;
      recordset_temp.Next;
   end;
end;

procedure Tform_apart_edit.BitBtn1Click(Sender: TObject);
//向数据库中添加新部门
var
   ListItem: TListItem;
   p:^integer;
begin
   //不断将用户输入的部门名称添加到数据库,直至用户希望停止为止
   repeat
      //初始化新建部门窗口的内容
      form_apart_input.Caption :='新建部门';
      form_apart_input.Edit1.Text :='';
      form_apart_input.Label1.Caption :='新建部门';
      form_apart_input.Label2.Caption :='新建部门';
      form_apart_input.Label3.caption:='    请在下面输入欲添加的部门名称:';
      form_apart_input.Image2.Picture :=form_apart_edit.Image2.Picture ;
      //显示新建部门窗口
      form_apart_input.ShowModal ;
      //判断用户是否正确输入部门名称
      if form_apart_input.bYesno =false then exit;
      //将输入内容添进数据库
      form_main.Dconnect.Execute ('insert into [APART]([APART_NAME]) values(''' + form_apart_input.stringApartname +''')');
      recordset_temp.SQL.Clear ;
      recordset_temp.SQL.Add ('select * from [APART]');
      recordset_temp.Open ;
      recordset_temp.Last ;
      new(p);
      p^:=recordset_temp.Fields[0].AsInteger ;
      //更新部门列表的内容
      listitem:=apart_LIST.Items.Add ;
      listitem.Caption :=form_apart_input.stringApartname ;
      listitem.ImageIndex :=0 ;
      listitem.Data:=p;
      //更新部门数量
      intCount := intCount+1;
      Label4.Caption :=inttostr(intCount) + '个';
   until messagebox(self.Handle ,'您是否还要添加新的部门?','标题',MB_YESNO or MB_ICONASTERISK)<> IDYES;
end;

procedure Tform_apart_edit.button_addClick(Sender: TObject);
//修改原有的部门名称
var
   p:^integer;
begin
   //是否在列表中选择某一部门
   if apart_list.Selected =nil then exit ;
   //查询数据库
   recordset_temp.SQL.Clear ;
   p:=Apart_list.Selected.Data;
   recordset_temp.SQL.Add ('select * from [APART] where [APART_ID]=' + inttostr(p^));
   recordset_temp.Open ;
   //确认数据库中存在该部门
   if recordset_temp.RecordCount <>0 then
   begin
      //初始化修改部门名称窗口
      form_apart_input.Edit1.Text :=recordset_temp.Fields[1].AsString ;
      form_apart_input.Caption :='修改部门名称';
      form_apart_input.Label1.Caption :='修改部门';
      form_apart_input.Label2.Caption :='修改部门';
      form_apart_input.Label3.caption:='    请在下面修改部门的名称:';
      form_apart_input.Image2.Picture :=form_apart_edit.Image2.Picture ;
      form_apart_input.ShowModal ;
      //判断用户是否正确输入部门名称
      if form_apart_input.bYesno =true then
      begin
         //修改对应内容
         form_main.Dconnect.Execute('update [APART] set [APART_NAME]=''' + form_apart_input.stringApartname + ''' where [APART_ID]=' + inttostr(P^));
         //修改部门列表对应内容
         apart_list.Selected.Caption :=form_apart_input.stringApartname ;
      end;
   end;
end;

procedure Tform_apart_edit.BitBtn2Click(Sender: TObject);
//删除某一部门
var
   temp:pchar;
   p:^integer;
   countt:integer;
begin
   //是否在部门列表中选择某部门
   if apart_list.Selected =nil then exit ;
   //搜寻数据库中关于该部门的评价
   p:=Apart_list.Selected.Data;
   recordset_temp.SQL.Clear ;
   recordset_temp.SQL.Add('select count([PJ_ID]) from [PJ] where [PJ_APART_ID]=' + inttostr(p^));
   recordset_temp.open;
   countt:=recordset_temp.Fields[0].AsInteger ;
   recordset_temp.Close ;
   //再次询问用户以确定删除
   temp:=pchar('您是否确定要删除['+apart_list.Selected.caption +  ']'
           + #13 + '如果您删除此部门,将有' + inttostr(countt) + '条评价将关连删除');
   if messagebox(self.Handle, temp,'警告',MB_yesno or MB_ICONQUESTION	)=IDyes then
   begin
      //删除数据库中对应内容
      form_main.Dconnect.Execute('delete * from [PJ] where [PJ_APART_ID]=' + inttostr(p^));
      form_main.Dconnect.Execute('delete * from [APART] where [APART_ID]=' + inttostr(p^));
      Dispose(p);
      //更新窗口显示
      apart_list.Selected.Delete ;
      intCount := intCount-1;
      Label4.Caption :=inttostr(intCount) + '个';
   end;
   apart_list.SetFocus ;
end;

end.

⌨️ 快捷键说明

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