CLIST 数组的用法 CListCtrl m_list 用法

CList <CUser*,CUser*&>  m_Usermap;

CListCtrl  m_list;//m_list 是控件CList Control 变量名;

CUser 是一个类,里面的变量名对应m_list 的变量名;

m_list.SetExtendedStyle( m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
//3. 插入数据
m_list.InsertColumn( 0, "USER NAME", LVCFMT_CENTER, 80 );// 插入列
m_list.InsertColumn( 1, "LOGIN CLASS", LVCFMT_CENTER, 100 );

POSITION pos=m_list.GetFirstSelectedItemPosition();
if (pos)
{
int index=m_list.GetNextSelectedItem(pos);//得到选中的行号,

CUser *pUser=( CUser * )m_list.GetItemData(index);//通过这个行号而取得内容的对象(指针);
if (pUser)
{
POSITION postemp=m_Usermap.Find(pUser);
if (postemp)
{
if (theApp.m_adoConn.ExecuteNoSelectSQL(pUser->GetDeleteSQL()))
{
m_Usermap.RemoveAt(postemp);
FillAllUerList();
ShowUserinfo();
}
}
}
delete pUser;
pUser = NULL;
}

 

 

 

void CDlgSysManager::OnBnClickedButtonSave()
{
CUser *pUser;
CString strname,strlgclass,strpassword,strsecondpw;
this->GetDlgItemText(IDC_EDIT_USERNAME,strname);
this->GetDlgItemText(IDC_EDIT_PASSWORD,strpassword);
this->GetDlgItemText(IDC_EDIT_RETYPE,strsecondpw);
m_loginclass.GetWindowText(strlgclass);

if (IsAdd ==true)
{
POSITION pos =m_Usermap.GetHeadPosition();
if (pos)
{
while (pos)
{
CUser *ptempuser=m_Usermap.GetNext(pos);
if (ptempuser)
{
if ( ptempuser->GetName()==strname)
{
AfxMessageBox("Name had esix",MB_OK);
return;
}
}
}
if (strpassword != strsecondpw)
{
MessageBox("Two Password is defrent");
return;
}
pUser =new CUser;
pUser->SetName(strname);
pUser->SetPassword(strpassword);
int i;
if (strlgclass == "Administrator") i=0;
if (strlgclass == "Operator") i=1;
pUser->SetType(i);

if(theApp.m_adoConn.ExecuteNoSelectSQL( pUser->GetAddSQL() ) )
{
m_Usermap.AddTail(pUser);
FillAllUerList();
}
}
}

if (IsAdd !=true )//表明修改
{

if (strpassword != strsecondpw)
{
AfxMessageBox("two password are different",MB_OK);
return;
}

POSITION pos =m_list.GetFirstSelectedItemPosition();

int index=m_list.GetNextSelectedItem(pos);//得到选中的行号,
pUser=( CUser * )m_list.GetItemData(index);//通过这个行号而取得内容的对象(指针);
if (pUser)
{
CString stroldname;
stroldname = pUser->GetName();
if (stroldname != strname)
{
POSITION tempos =m_Usermap.GetHeadPosition();
while(tempos)
{
CUser *ptempuser = m_Usermap.GetNext(tempos);
if(ptempuser)
{
if (ptempuser->GetName() == strname)
{
AfxMessageBox("name had eist",MB_OK);
return;
}
}
}
}

if (strpassword != strsecondpw)
{
MessageBox("Two Password is defrent");
return;
}
pUser->SetName(strname);
pUser->SetPassword(strpassword);
int i;
if (strlgclass == "Administrator") i=0;
if (strlgclass == "Operator") i=1;
pUser->SetType(i);
CString strSQL;
if(theApp.m_adoConn.ExecuteNoSelectSQL( pUser->GetModifySQL(stroldname)) )
{
FillAllUerList();
}
}
}

m_adduser.EnableWindow(TRUE);
m_BtCancel.EnableWindow(FALSE);
m_delete.EnableWindow(TRUE);
m_modify.EnableWindow(TRUE);
m_save.EnableWindow(FALSE);

m_username.SetReadOnly(TRUE);
m_password.(TRUE);
m_retype.SetReadOnly(TRUE);
m_loginclass.EnableWindow(FALSE);
}

转载于:https://www.cnblogs.com/chenzuoyou/archive/2013/05/29/3106422.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值