📄 sydlg.cpp
字号:
// SyDlg.cpp : implementation file
//
#include "stdafx.h"
#include "yhgl.h"
#include "SyDlg.h"
#include "Choose.h"
#include "PreDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CYhglApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CSyDlg dialog
CSyDlg::CSyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSyDlg)
//}}AFX_DATA_INIT
m_nCurrentSel = -1;
m_bAutoSave = TRUE;
ct=0;
pt=0;
tag=0;
}
void CSyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSyDlg)
DDX_Control(pDX, IDC_BUTTONSET, m_qsxx);
DDX_Control(pDX, IDC_BUTTONAPPLY, m_apply);
DDX_Control(pDX, IDC_BUTTONDEL, m_Del);
DDX_Control(pDX, IDC_BUTTONADD, m_add);
DDX_Control(pDX, IDC_LIST1, m_pListCtrl);
DDX_Control(pDX, IDCANCEL, m_cancel);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSyDlg, CDialog)
//{{AFX_MSG_MAP(CSyDlg)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)
ON_BN_CLICKED(IDC_BUTTONADD, OnButtonadd)
ON_BN_CLICKED(IDC_BUTTONAPPLY, OnButtonapply)
ON_BN_CLICKED(IDC_BUTTONDEL, OnButtondel)
ON_BN_CLICKED(IDC_BUTTONSET, OnButtonset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSyDlg message handlers
BOOL CSyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_cancel.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_cancel.SetBkColor(RGB(234,216,187));
m_cancel.SetTooltipText(_T("退出"));
m_cancel.SetRounded(TRUE);
m_apply.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_apply.SetBkColor(RGB(234,216,187));
m_apply.SetTooltipText(_T("更新修改内容"));
m_apply.SetRounded(TRUE);
m_add.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_add.SetBkColor(RGB(234,216,187));
m_add.SetTooltipText(_T("创建新的用户权限组:权限组名称和密码不能为空!"));
m_add.SetRounded(TRUE);
m_Del.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_Del.SetBkColor(RGB(234,216,187));
m_Del.SetTooltipText(_T("删除指定用户权限组"));
m_Del.SetRounded(TRUE);
m_qsxx.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_qsxx.SetBkColor(RGB(234,216,187));
m_qsxx.SetTooltipText(_T("查看指定用户权限组对数据集的操作信息"));
m_qsxx.SetRounded(TRUE);
m_Del.EnableWindow(FALSE);
ListView_SetExtendedListViewStyle(::GetDlgItem(m_hWnd,IDC_LIST1),LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
::SendMessage(m_pListCtrl.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
//////////为列表控件添加列//////////
m_pListCtrl.flag=2;
m_pListCtrl.InsertColumn(0,"权限组ID",LVCFMT_LEFT,100);
m_pListCtrl.InsertColumn(1,"名称",LVCFMT_LEFT,100);
m_pListCtrl.InsertColumn(2,"密码",LVCFMT_LEFT,100);
m_pListCtrl.InsertColumn(3,"说明",LVCFMT_LEFT,150);
//////////读取数据库中的信息添加到列表控件///////////
int nItem;
_variant_t vQid,vQname,vQdes,vQcode;
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
CString sql;
CString sSDEUser(_T("SDE")); //sde的owner
sSDEUser.MakeUpper();
sql.Format("SELECT r.RoleGroupID,r.RoleGroupName,r.RolePassword,r.Description FROM SDE.TB_RoleGroupInfo r ORDER BY r.RoleGroupID");
_variant_t valsql((LPCTSTR)sql);
m_pRecordset->Open(valsql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
m_pRecordset2.CreateInstance("ADODB.Recordset");
while(!m_pRecordset->adoEOF)
{
vQid = m_pRecordset->GetCollect("RoleGroupID");
vQname = m_pRecordset->GetCollect("RoleGroupName");///取得username字段的值
vQcode=m_pRecordset->GetCollect("RolePassword");
vQdes=m_pRecordset->GetCollect("Description");
Info[ct].qid=vQid.lVal;
Info[ct].qname=(LPCTSTR)(_bstr_t)vQname;
Info[ct].qcode=(LPCTSTR)(_bstr_t)vQcode;
nItem=m_pListCtrl.InsertItem(0xffff,"");
m_pListCtrl.SetItemText(nItem,0,(_bstr_t)vQid);
m_pListCtrl.SetItemText(nItem,1,(_bstr_t)vQname);
m_pListCtrl.SetItemText(nItem,2,(_bstr_t)_T("******"));
if(vQdes.vt != VT_NULL)
{
m_pListCtrl.SetItemText(nItem,3,(_bstr_t)vQdes);
Info[ct].qdes =(LPCTSTR)(_bstr_t)vQdes;
}
else
{
m_pListCtrl.SetItemText(nItem,3,_T(""));
Info[ct].qdes=_T("");
}
ct++;
m_pRecordset->MoveNext();
}
}
catch(_com_error e)///捕捉异常
{
AfxMessageBox("读取数据库失败!");///显示错误信息
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSyDlg::PostNcDestroy()
{
//CSizingDialog::OnDestroy();
CDialog::PostNcDestroy();
delete this;
}
BOOL CSyDlg::Create()
{
return CDialog::Create(CSyDlg::IDD);
}
void CSyDlg::OnCancel()
{
//CDialog::OnCancel();
m_pRecordset->Close();
m_pListCtrl.flag=0;
DestroyWindow();
}
void CSyDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(pNMListView->uNewState&LVIS_SELECTED)
{
UpdateData();
m_nCurrentSel = pNMListView->iItem;
m_Del.EnableWindow();
}
*pResult = 0;
}
//检查与已有用户的冲突
//返回TRUE 冲突
BOOL CSyDlg::ConflictWithOldUserInDBAUser(LPCTSTR userName)
{
if (userName == NULL) return TRUE;
_RecordsetPtr tmpRecordset;
tmpRecordset.CreateInstance("ADODB.Recordset");
CString sql;
CString sSDEUser(_T("SDE")); //sde的owner
sSDEUser.MakeUpper();
sql.Format("SELECT USERNAME FROM DBA_USERS Where USERNAME=\'%s\' and DEFAULT_TABLESPACE=\'%s\'",userName,sSDEUser);
_variant_t valsql((LPCTSTR)sql);
tmpRecordset->Open(valsql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if (tmpRecordset->GetRecordCount() > 0) return TRUE;
return FALSE;
}
//以RoleGroupID + RoleGroupName作为唯一性约束检查TB_RoleGroupInfo中的重复项
BOOL CSyDlg::ConflictWithOldGroupUser(long groupID,LPCTSTR groupName)
{
if (groupID <=0 || groupName == NULL) return TRUE;
_RecordsetPtr tmpRecordset;
tmpRecordset.CreateInstance("ADODB.Recordset");
CString sql;
CString sSDEUser(_T("SDE")); //sde的owner
sSDEUser.MakeUpper();
sql.Format("SELECT * FROM SDE.TB_RoleGroupInfo Where RoleGroupID=%ld OR RoleGroupName=\'%s\'",groupID,groupName);
_variant_t valsql((LPCTSTR)sql);
tmpRecordset->Open(valsql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if (tmpRecordset->GetRecordCount() > 0) return TRUE;
return FALSE;
}
void CSyDlg::OnButtonadd()
{
m_nCurrentSel=m_pListCtrl.InsertItem(0xffff,"");
//自动维护递增的ID
if(ct==0)vQID=long(1);
else vQID = (long)(Info[ct-1].qid+1);
m_pListCtrl.SetItemText(m_nCurrentSel,0,(_bstr_t)vQID);
m_pListCtrl.SetItemText(m_nCurrentSel,1,(_bstr_t)_T(""));
m_pListCtrl.SetItemText(m_nCurrentSel,2,(_bstr_t)_T(""));
m_pListCtrl.SetItemText(m_nCurrentSel,3,(_bstr_t)_T(""));
m_pListCtrl.SetItemState(m_nCurrentSel,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED); //m_pListCtrl.SetHotItem(m_nCurrentSel);
m_pListCtrl.SetHotItem(m_nCurrentSel);
m_pListCtrl.SetFocus();
//在数组中自动维护递增的ID
if(ct==0)
Info[ct].qid=1;
else
Info[ct].qid= (Info[ct-1].qid+1);
Info[ct].qname=_T("");
Info[ct].qcode=_T("");
Info[ct].qdes=_T("");
Info[ct].bNewflag = TRUE; //设置新增标记
ct++;
GetDlgItem(IDC_BUTTONADD)->EnableWindow(FALSE);
}
void CSyDlg::OnButtonapply()
{
_variant_t RecordsAffected;
int m_nRecordsAffected = 0;
CString sql,sUserName,str;
int i=0;
long groupID;
//为权限组表SDE.TB_RoleGroupInfo的数据更新(包括新增)创建Recordset
_RecordsetPtr tmpRecordset;
tmpRecordset.CreateInstance("ADODB.Recordset");
sql.Format("SELECT RoleGroupID,RoleGroupName,RolePassword,Description FROM SDE.TB_RoleGroupInfo");
_variant_t valsql((LPCTSTR)sql);
tmpRecordset->Open(valsql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
while(i<ct)
{
if(m_pListCtrl.GroupInfo[i].flag1==1||m_pListCtrl.GroupInfo[i].flag2==1||m_pListCtrl.GroupInfo[i].flag3==1)
{
if(m_pListCtrl.GroupInfo[i].flag1==1)
Info[i].qname=m_pListCtrl.GroupInfo[i].qname;
if(m_pListCtrl.GroupInfo[i].flag2==1)
Info[i].qcode=m_pListCtrl.GroupInfo[i].qcode;
if(m_pListCtrl.GroupInfo[i].flag3==1)
Info[i].qdes=m_pListCtrl.GroupInfo[i].qdes;
if(Info[i].qname.IsEmpty()||Info[i].qcode.IsEmpty())
{
str.Format("列表项%d有无效信息(用户名或密码为空)",i);
MessageBox(str,"提示:");
i++; continue;
}
else
{
//取内存中的值
groupID = Info[i].qid;
vQID =(long)groupID;
sUserName = Info[i].qname;
sUserName.MakeUpper(); //用户名与oracle保持一致
vQNAME = sUserName;
vQCODE = Info[i].qcode;
vQDES = Info[i].qdes;
if (sUserName.IsEmpty())
{
MessageBox ("权限组的名称不能为空","");
continue;
}
//以RoleGroupID + RoleGroupName作为唯一性约束检查TB_RoleGroupInfo中的重复项
if (ConflictWithOldGroupUser(groupID,sUserName))
{
str.Format("新增用户(ID=%ld 组名=%s)与已数据库中已有权限组冲突!",groupID,sUserName);
MessageBox(str,"提示:");
i++; continue;
}
//新增行
if (Info[i].bNewflag)
{
// //检查与已有用户的冲突
// if (!ConflictWithOldUserInDBAUser(sUserName))
tmpRecordset->AddNew();
// else
// {
// str.Format("新增用户%s与已数据库中已有用户的冲突!",sUserName);
// MessageBox(str,"提示:");
// i++; continue;
// }
}
else
{
tmpRecordset->MoveFirst();
tmpRecordset->Move(i);
}
//写字段
tmpRecordset->PutCollect("RoleGroupID",vQID);
if (Info[i].bNewflag) //只有新增用户的用户名可以修改,密码无此限制
tmpRecordset->PutCollect("RoleGroupName",vQNAME);
tmpRecordset->PutCollect("RolePassword",vQCODE); //暂时定义为同SDE用户名称
tmpRecordset->PutCollect("Description",vQDES);
//
// //新增SDE用户
// if (Info[i].bNewflag && !sUserName.IsEmpty())
// {
// try
// {
// sql.Format(_T("CREATE USER %s PROFILE \"DEFAULT\" IDENTIFIED BY %s DEFAULT TABLESPACE \"SDE\" TEMPORARY TABLESPACE \"TEMP\" ACCOUNT UNLOCK"),Info[ct-1].qname,Info[ct-1].qcode);
// theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adExecuteNoRecords);
// sql.Format(_T("GRANT CONNECT,RESOURCE TO %s"),Info[ct-1].qname);
// theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adExecuteNoRecords);
// m_nRecordsAffected = RecordsAffected.iVal;
// }
// catch (_com_error e)///捕捉异常
// {
// str.Format("增加数据库用户%s失败!",sUserName);
// _bstr_t des(e.Description());
// MessageBox(str,"错误提示:",MB_OK|MB_ICONSTOP);
// GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
// return;
// }
// }
tmpRecordset->Update();
}
}
i++;
}
tmpRecordset->Close();
GetDlgItem(IDC_BUTTONADD)->EnableWindow(TRUE);
}
void CSyDlg::OnButtondel()
{
_variant_t RecordsAffected;
int m_nRecordsAffected = 0;
CString sql,str,sUserName;
long lGroupID;
int i=0;
m_bAutoSave = FALSE;
if(m_nCurrentSel >= 0)
{
//取权限组名 = oracle用户名
sUserName = m_pListCtrl.GetItemText( m_nCurrentSel, 1);
sUserName.MakeUpper();
//取用户组ID
str = m_pListCtrl.GetItemText( m_nCurrentSel, 0);
lGroupID = atol(str);
//删除控件中的记录
m_pListCtrl.DeleteItem(m_nCurrentSel);
//清内存
int count = m_pListCtrl.GetItemCount();
if(count <= m_nCurrentSel)
m_nCurrentSel = count-1;
else
{
for(int i=0;i<=(ct-m_nCurrentSel-2);i++)
{
Info[m_nCurrentSel+i].qname=Info[m_nCurrentSel+i+1].qname;
Info[m_nCurrentSel+i].qid=Info[m_nCurrentSel+i+1].qid;
Info[m_nCurrentSel+i].qcode=Info[m_nCurrentSel+i+1].qcode;
Info[m_nCurrentSel+i].qdes=Info[m_nCurrentSel+i+1].qdes;
}
}
ct--;
//TB_RoleGroupPrivilege中用户组ID=lGroupID的所有控制权限设置
sql.Format(_T("Delete From SDE.TB_RoleGroupPrivilege where RoleGroupID = %ld"),lGroupID);
if (theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adExecuteNoRecords) == NULL)
{
str.Format("删除了用户组%s权限表所有的控制权限设置!",sUserName);
MessageBox(str,"提示:");
}
//删除表SDE.TB_DSUSER中的记录
sql.Format(_T("Delete From SDE.TB_DSUSER where RoleGroupID = %ld"),lGroupID);
if (theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adExecuteNoRecords) == NULL)
{
str.Format("删除了属于用户组%s的所有用户!",sUserName);
MessageBox(str,"提示:");
}
//删除表SDE.TB_RoleGroupInfo中的记录
sql.Format(_T("Delete From SDE.TB_RoleGroupInfo where RoleGroupID = %ld"),lGroupID);
if (theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adExecuteNoRecords)!=NULL)
{
str.Format("删除用户组表TB_RoleGroupInfo数据项%s出错!",sUserName);
MessageBox(str,"提示:");
}
// //检查数据库中是否已有此用户
// if (!ConflictWithOldUserInDBAUser(sUserName))
// {
// str.Format("数据库中无用户%s",sUserName);
// MessageBox (str,"提示!");
// return;
// }
// //删除数据库中的用户
// sql.Format(_T("DROP USER %s CASCADE"), sUserName);
// if (theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adExecuteNoRecords)!= NULL)
// //m_nRecordsAffected = RecordsAffected.iVal;
// {
// str.Format("删除oracle数据库用户%s出错!",sUserName);
// MessageBox(str,"提示:");
// return;
// }
m_pListCtrl.SetItemState(m_nCurrentSel,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
m_pListCtrl.SetFocus();
}
m_bAutoSave = TRUE;
}
void CSyDlg::OnButtonset()
{
if (m_nCurrentSel==-1)
{
AfxMessageBox("没有选中权限组,查看失败!");
}
else
{
//调用对话框,设置权限组权限
CPreDlg *pDlg = new CPreDlg;
pDlg->rid=Info[m_nCurrentSel].qid;
pDlg->rname=Info[m_nCurrentSel].qname;
pDlg->Create();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -