Right.cpp
上传用户:tangpei45
上传日期:2013-07-14
资源大小:9104k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Right.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfmRightManage *fmRightManage;
- //---------------------------------------------------------------------------
- __fastcall TfmRightManage::TfmRightManage(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmRightManage::FormClose(TObject *Sender,
- TCloseAction &Action)
- {
- // 删除窗体并回收空间
- Action = caFree;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmRightManage::Table1AfterScroll(TDataSet *DataSet)
- {
- // 先去除所有的权限标志
- for(int i=0; i<CheckListBox1->Items->Count; i++)
- CheckListBox1->Checked[i] = false;
- // 根据选择的用户设置权限标志
- Query1->Close();
- Query1->SQL->Clear();
- Query1->SQL->Add("select 权限名称 from 权限清单 where 用户编号='"
- + Table1->FieldByName("用户编号")->AsString + "'");
- Query1->Open();
- while(!Query1->Eof)
- {
- AnsiString szFunName = Query1->FieldByName("权限名称")->AsString;
- CheckListBox1->Checked[CheckListBox1->Items->IndexOf(szFunName)] = true;
- Query1->Next();
- }
- }
- //---------------------------------------------------------------------------
- // 选择或去除功能权限,修改数据库权限清单表
- void __fastcall TfmRightManage::CheckListBox1ClickCheck(TObject *Sender)
- {
- // 没有选择用户,退出函数
- if(!Table1->FieldByName("用户编号")) return;
- // 循环判断
- Query1->Close();
- Query1->SQL->Clear();
- AnsiString sql;
- // 不管没有选中,先全部删除,再根据选择的情况插入
- sql = "delete from 权限清单 where 用户编号='" ;
- sql += Table1->FieldByName("用户编号")->AsString + "'";
- Query1->SQL->Add(sql);
- for(int i=0; i<CheckListBox1->Items->Count; i++)
- {
- if(CheckListBox1->Checked[i]) // 选中权限,权限清单中插入一条
- {
- sql = "insert into 权限清单(用户编号,权限名称) values('" ;
- sql += Table1->FieldByName("用户编号")->AsString + "','";
- sql += CheckListBox1->Items->Strings[i] + "')";
- Query1->SQL->Add(sql);
- }
- }
- Query1->ExecSQL();
- Query1->Close();
- }
- //---------------------------------------------------------------------------