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/p/3106422.html