📄 staff.cpp
字号:
{
_variant_t TheValue;
m_pRs->MoveFirst();
while(m_pRs->adoEOF==VARIANT_FALSE)
{
//Retrieve column's value:
TheValue = m_pRs->Fields->GetItem(_variant_t("SN"))->Value;
_bstr_t s1=(_bstr_t)TheValue;
bHad = TRUE;
//Do something what you want to do: ......
m_pRs->MoveNext();
}
}
catch (_com_error &e)
{
////::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);
}
m_pRs->Close();
if( bHad )
{
AfxMessageBox(_T("此员工ID已经被他人抢注,请重新增加获取新的ID号!"));
return;
}
}
CString str_staff_name;
pWnd = GetDlgItem(IDC_EDIT_NAME);
pWnd->GetWindowText(str_staff_name);
if ( str_staff_name.GetLength() == 0 )
{
AfxMessageBox(_T("员工姓名不能为空!"));
return;
}
if ( str_staff_name.GetLength() > 20 )
{
AfxMessageBox(_T("员工姓名长度超出限制!"));
return;
}
CString str_staff_sex;
pWnd = GetDlgItem(IDC_COMBO_SEX);
pWnd->GetWindowText(str_staff_sex);
if ( str_staff_sex.GetLength() == 0 )
{
AfxMessageBox(_T("请选择员工性别!"));
return;
}
CString str_staff_post;
pWnd = GetDlgItem(IDC_EDIT_POST);
pWnd->GetWindowText(str_staff_post);
if ( str_staff_post.GetLength() == 0 )
{
AfxMessageBox(_T("员工职位不能为空!"));
return;
}
if ( str_staff_post.GetLength() > 20 )
{
AfxMessageBox(_T("员工职位长度超出限制!"));
return;
}
CString str_staff_depart;
pWnd = GetDlgItem(IDC_EDIT_DEPART);
pWnd->GetWindowText(str_staff_depart);
if ( str_staff_depart.GetLength() == 0 )
{
AfxMessageBox(_T("请选择员工部门!"));
return;
}
CString str_staff_id;
pWnd = GetDlgItem(IDC_EDIT_ID);
pWnd->GetWindowText(str_staff_id);
if ( str_staff_id.GetLength() == 0 )
{
AfxMessageBox(_T("员工身份证不能为空!"));
return;
}
if ( str_staff_id.GetLength() > 18 )
{
AfxMessageBox(_T("员工身份证长度超出限制!"));
return;
}
CString str_staff_tel;
pWnd = GetDlgItem(IDC_EDIT_TEL);
pWnd->GetWindowText(str_staff_tel);
if ( str_staff_tel.GetLength() == 0 )
{
AfxMessageBox(_T("员工电话不能为空!"));
return;
}
if ( str_staff_tel.GetLength() > 20 )
{
AfxMessageBox(_T("员工电话长度超出限制!"));
return;
}
CString str_staff_mobile;
pWnd = GetDlgItem(IDC_EDIT_MOBILE);
pWnd->GetWindowText(str_staff_mobile);
if ( str_staff_mobile.GetLength() == 0 )
{
AfxMessageBox(_T("员工手机不能为空!"));
return;
}
if ( str_staff_mobile.GetLength() > 20 )
{
AfxMessageBox(_T("员工手机长度超出限制!"));
return;
}
CString str_staff_edu;
pWnd = GetDlgItem(IDC_COMBO_EDU);
pWnd->GetWindowText(str_staff_edu);
if ( str_staff_edu.GetLength() == 0 )
{
AfxMessageBox(_T("请选择员工学历!"));
return;
}
CString str_staff_email;
pWnd = GetDlgItem(IDC_EDIT_EMAIL);
pWnd->GetWindowText(str_staff_email);
if ( str_staff_email.GetLength() == 0 )
{
AfxMessageBox(_T("员工电邮不能为空!"));
return;
}
if ( str_staff_email.GetLength() > 50 )
{
AfxMessageBox(_T("员工电邮长度超出限制!"));
return;
}
CString str_staff_jointime;
pWnd = GetDlgItem(IDC_DATETIMEPICKER_JOINTIME);
pWnd->GetWindowText(str_staff_jointime);
CString str_staff_addr;
pWnd = GetDlgItem(IDC_EDIT_ADDR);
pWnd->GetWindowText(str_staff_addr);
if ( str_staff_addr.GetLength() == 0 )
{
AfxMessageBox(_T("员工地址不能为空!"));
return;
}
if ( str_staff_addr.GetLength() > 50 )
{
AfxMessageBox(_T("员工地址长度超出限制!"));
return;
}
CString str_staff_note;
pWnd = GetDlgItem(IDC_EDIT_NOTE);
pWnd->GetWindowText(str_staff_note);
if ( str_staff_note.GetLength() > 50 )
{
AfxMessageBox(_T("员工地址长度超出限制!"));
return;
}
_variant_t RecordsAffected;
if ( bAdd )
{
m_strSql.Format(_T("INSERT INTO STAFF_TABLE(STAFF_ID,NAME,DEPART,SEX,POST,ID,TEL,MOBILE,EMAIL,JOIN_TIME,ADDR,NOTE,EDUCTION) VALUES ('")
+str_staff_staffid+ _T("','") +str_staff_name+ _T("','") +str_staff_depart+ _T("','") +str_staff_sex+ _T("','") +str_staff_post+
_T("','") +str_staff_id+ _T("','") +str_staff_tel+ _T("','") +str_staff_mobile+ _T("','") +str_staff_email+ _T("','") +str_staff_jointime+
_T("','") +str_staff_addr+ _T("','") +str_staff_note+ _T("','") +str_staff_edu+ _T("')"));
bool bSuccess = pMyConnect->Execute(_bstr_t(m_strSql),&RecordsAffected,adCmdText);
if( !bSuccess )
{
AfxMessageBox(_T("增加员工信息失败!"));
return;
}
AfxMessageBox(_T("增加员工信息成功!"));
}
else
{
m_strSql.Format(_T("update STAFF_TABLE set NAME='") +str_staff_name+ _T("',DEPART='") +str_staff_depart+ _T("',SEX='") +str_staff_sex+ _T("',POST='")
+str_staff_post+ _T("',ID='") +str_staff_id+ _T("',TEL='") +str_staff_tel+ _T("',MOBILE='") +str_staff_mobile+ _T("',EMAIL='")
+str_staff_email+ _T("',JOIN_TIME='") +str_staff_jointime+ _T("',ADDR='") +str_staff_addr+ _T("',NOTE='") +str_staff_note+ _T("',EDUCTION='") +str_staff_edu+ _T("' where (STAFF_ID='") +str_staff_staffid+ _T("')") );
bool bSuccess = pMyConnect->Execute(_bstr_t(m_strSql),&RecordsAffected,adCmdText);
if( !bSuccess )
{
AfxMessageBox(_T("修改员工信息失败!"));
return;
}
AfxMessageBox(_T("修改员工信息成功!"));
}
ClearInputEdit();
ListTree();
//OnOK();
}
void CStaff::OnTvnSelchangedTreeStaff(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
}
void CStaff::OnNMDblclkTreeStaff(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
HTREEITEM hItem = m_tree_staff.GetSelectedItem();
CWnd* pWnd;
CString str_temp = _T("");
_RecordsetPtr m_pRs;
CString m_strSql;
CString str_staff_staffid = _T("");
CString str_staff_name = _T("");
CString str_staff_depart = _T("");
CString str_staff_sex = _T("");
CString str_staff_post = _T("");
CString str_staff_id = _T("");
CString str_staff_tel = _T("");
CString str_staff_mobile = _T("");
CString str_staff_email = _T("");
CString str_staff_jointime = _T("");
CString str_staff_addr = _T("");
CString str_staff_note = _T("");
CString str_staff_edu = _T("");
if ( hItem != hRoot )
{
bool bStaffItem = TRUE;
for ( int i = 0; i < hSubItemNum; i++)
{
if ( hItem == sub_son[i])
{
bStaffItem = FALSE;
break;
}
}
if( bStaffItem )
{
bAdd = FALSE;
CString str_select = m_tree_staff.GetItemText( hItem );
str_staff_staffid = str_select.Left(STAFFID_LENGTH);
bool bHad = FALSE;
m_strSql.Format(_T("select NAME,DEPART,SEX,POST,ID,TEL,MOBILE,EMAIL,JOIN_TIME,ADDR,NOTE,EDUCTION from STAFF_TABLE where ( STAFF_ID ='") +str_staff_staffid+ _T("')") );
m_pRs.CreateInstance( __uuidof(Recordset) );
m_pRs->Open( _bstr_t(m_strSql), _variant_t((IDispatch *)pMyConnect,true), adOpenKeyset, adLockOptimistic, adCmdText);
try
{
_variant_t TheValue;
m_pRs->MoveFirst();
while(m_pRs->adoEOF==VARIANT_FALSE)
{
//Retrieve column's value:
bHad = TRUE;
TheValue = m_pRs->Fields->GetItem(_variant_t("NAME"))->Value;
_bstr_t s1=(_bstr_t)TheValue;
CString str_temp1 = s1;
str_staff_name = str_temp1;
TheValue = m_pRs->Fields->GetItem(_variant_t("DEPART"))->Value;
_bstr_t s2=(_bstr_t)TheValue;
CString str_temp2 = s2;
str_staff_depart = str_temp2;
TheValue = m_pRs->Fields->GetItem(_variant_t("SEX"))->Value;
_bstr_t s3=(_bstr_t)TheValue;
CString str_temp3 = s3;
str_staff_sex = str_temp3;
TheValue = m_pRs->Fields->GetItem(_variant_t("POST"))->Value;
_bstr_t s4=(_bstr_t)TheValue;
CString str_temp4 = s4;
str_staff_post = str_temp4;
TheValue = m_pRs->Fields->GetItem(_variant_t("ID"))->Value;
_bstr_t s5=(_bstr_t)TheValue;
CString str_temp5 = s5;
str_staff_id = str_temp5;
TheValue = m_pRs->Fields->GetItem(_variant_t("TEL"))->Value;
_bstr_t s6=(_bstr_t)TheValue;
CString str_temp6 = s6;
str_staff_tel = str_temp6;
TheValue = m_pRs->Fields->GetItem(_variant_t("MOBILE"))->Value;
_bstr_t s7=(_bstr_t)TheValue;
CString str_temp7 = s7;
str_staff_mobile = str_temp7;
TheValue = m_pRs->Fields->GetItem(_variant_t("EMAIL"))->Value;
_bstr_t s8=(_bstr_t)TheValue;
CString str_temp8 = s8;
str_staff_email = str_temp8;
TheValue = m_pRs->Fields->GetItem(_variant_t("JOIN_TIME"))->Value;
_bstr_t s9=(_bstr_t)TheValue;
CString str_temp9 = s9;
str_staff_jointime = str_temp9;
TheValue = m_pRs->Fields->GetItem(_variant_t("ADDR"))->Value;
_bstr_t s10=(_bstr_t)TheValue;
CString str_temp10 = s10;
str_staff_addr = str_temp10;
TheValue = m_pRs->Fields->GetItem(_variant_t("NOTE"))->Value;
_bstr_t s11=(_bstr_t)TheValue;
CString str_temp11 = s11;
str_staff_note = str_temp11;
TheValue = m_pRs->Fields->GetItem(_variant_t("EDUCTION"))->Value;
_bstr_t s12=(_bstr_t)TheValue;
CString str_temp12 = s12;
str_staff_edu = str_temp12;
//Do something what you want to do: ......
m_pRs->MoveNext();
}
}
catch (_com_error &e)
{
//::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);
}
m_pRs->Close();
if( !bHad )
{
AfxMessageBox(_T("查无此员工信息!"));
}
else
{
pWnd = GetDlgItem(IDC_EDIT_STAFFID);
pWnd->SetWindowText(str_staff_staffid);
pWnd = GetDlgItem(IDC_EDIT_NAME);
pWnd->SetWindowText(str_staff_name);
ResetCombo();
CString str1;
int n;
for (int i = 0; i < ((CComboBox*)GetDlgItem(IDC_COMBO_SEX))->GetCount(); i++)
{
n = ((CComboBox*)GetDlgItem(IDC_COMBO_SEX))->GetLBTextLen(i);
((CComboBox*)GetDlgItem(IDC_COMBO_SEX))->GetLBText(i, str1.GetBuffer(n));
str1.ReleaseBuffer();
if ( str1 == str_staff_sex )
{
((CComboBox*)GetDlgItem(IDC_COMBO_SEX))->SetCurSel(i);
}
}
pWnd = GetDlgItem(IDC_EDIT_POST);
pWnd->SetWindowText(str_staff_post);
pWnd = GetDlgItem(IDC_EDIT_DEPART);
pWnd->SetWindowText(str_staff_depart);
pWnd = GetDlgItem(IDC_EDIT_ID);
pWnd->SetWindowText(str_staff_id);
pWnd = GetDlgItem(IDC_EDIT_TEL);
pWnd->SetWindowText(str_staff_tel);
pWnd = GetDlgItem(IDC_EDIT_MOBILE);
pWnd->SetWindowText(str_staff_mobile);
for (int i = 0; i < ((CComboBox*)GetDlgItem(IDC_COMBO_EDU))->GetCount(); i++)
{
n = ((CComboBox*)GetDlgItem(IDC_COMBO_EDU))->GetLBTextLen(i);
((CComboBox*)GetDlgItem(IDC_COMBO_EDU))->GetLBText(i, str1.GetBuffer(n));
str1.ReleaseBuffer();
if ( str1 == str_staff_edu )
{
((CComboBox*)GetDlgItem(IDC_COMBO_EDU))->SetCurSel(i);
break;
}
}
pWnd = GetDlgItem(IDC_EDIT_EMAIL);
pWnd->SetWindowText(str_staff_email);
COleVariant vtime(str_staff_jointime);
vtime.ChangeType(VT_DATE);// 转换
COleDateTime oletimeTime = vtime;
VERIFY(((CDateTimeCtrl*)GetDlgItem(IDC_DATETIMEPICKER_JOINTIME))->SetTime(oletimeTime));
pWnd = GetDlgItem(IDC_EDIT_ADDR);
pWnd->SetWindowText(str_staff_addr);
pWnd = GetDlgItem(IDC_EDIT_NOTE);
pWnd->SetWindowText(str_staff_note);
}
}
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -