// StaffInfo.cpp : 实现文件 // #include "stdafx.h" #include "YLGL.h" #include "StaffInfo.h" #include "DlgAnnex.h" // 生成表对应的Insert宏; #define INSERT_renyuan _T("INSERT INTO [renyuan](\ id,\ staff_department,\ staff_name,\ staff_gender,\ staff_phone,\ staff_family_address,\ staff_base_pay,\ staff_citizen_id_number,\ staff_married,\ staff_dimission,\ staff_fingerprinted1,\ staff_fingerprinted2,\ staff_self_phone,\ staff_father,\ staff_mother,\ staff_father_phone,\ staff_mother_phone,\ staff_emergency_name,\ staff_emergency_phone,\ staff_emergency_relationship,\ staff_hire_date,\ staff_leave_date,\ staff_self_qq,\ staff_self_weixin,\ staff_self_email,\ staff_educational,\ staff_native_place,\ staff_birthday,\ staff_graduate_institutions,\ staff_note,\ staff_qq,\ staff_trial_work_date,\ staff_position\ )VALUES(\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s',\ '%s'\ )") #define UPDATE_renyuan _T("UPDATE [renyuan]\ SET [staff_department] = '%s'\ ,[staff_name] = '%s'\ ,[staff_gender] = '%s'\ ,[staff_phone] = '%s'\ ,[staff_family_address] = '%s'\ ,[staff_base_pay] = '%s'\ ,[staff_citizen_id_number] = '%s'\ ,[staff_married] = '%s'\ ,[staff_dimission] = '%s'\ ,[staff_fingerprinted1] = '%s'\ ,[staff_fingerprinted2] = '%s'\ ,[staff_self_phone] = '%s'\ ,[staff_father] = '%s'\ ,[staff_mother] = '%s'\ ,[staff_father_phone] = '%s'\ ,[staff_mother_phone] = '%s'\ ,[staff_emergency_name] = '%s'\ ,[staff_emergency_phone] = '%s'\ ,[staff_emergency_relationship] = '%s'\ ,[staff_hire_date] = '%s'\ ,[staff_leave_date] = '%s'\ ,[staff_self_qq] = '%s'\ ,[staff_self_weixin] = '%s'\ ,[staff_self_email] = '%s'\ ,[staff_educational] = '%s'\ ,[staff_native_place] = '%s'\ ,[staff_birthday] = '%s'\ ,[staff_graduate_institutions] = '%s'\ ,[staff_note] = '%s' \ ,[staff_qq] ='%s'\ ,[staff_trial_work_date] ='%s' \ ,[staff_position] = '%s'\ WHERE id='%s'\ ") // CStaffInfo 对话框 IMPLEMENT_DYNAMIC(CStaffInfo, CDialog) CStaffInfo::CStaffInfo(CWnd* pParent /*=NULL*/) : CDialog(CStaffInfo::IDD, pParent) , m_staff_id(_T("")) , m_staff_name(_T("")) , m_staff_native_place(_T("")) , m_staff_self_phone(_T("")) , m_staff_phone(_T("")) , m_staff_self_qq(_T("")) , m_staff_self_wx(_T("")) , m_staff_self_email(_T("")) , m_staff_father(_T("")) , m_staff_mother(_T("")) , m_staff_mother_phone(_T("")) , m_staff_family_address(_T("")) , m_staff_emer_name(_T("")) , m_staff_emer_phone(_T("")) , m_staff_emer_relationship(_T("")) , m_staff_educational(_T("")) , m_staff_graduate_institutions(_T("")) , m_staff_citizen_id_number(_T("")) , m_staff_hire_date(_T("")) , m_staff_leave_date(_T("")) , m_staff_fingerprinted1(_T("")) , m_staff_fingerprinted2(_T("")) , m_staff_note(_T("")) , m_staff_birthday(_T("")) , m_staff_qq(_T("")) , m_staff_trial_work_date(_T("")) , m_staff_position(_T("")) { } CStaffInfo::~CStaffInfo() { } void CStaffInfo::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, LIST_STAFF, m_list); DDX_Control(pDX, CBOX_DEPT, m_cbox_dept); DDX_Control(pDX, CBOX_CREDENTIALS, m_cbox_credentials); DDX_Text(pDX, TX_STAFF_ID, m_staff_id); DDX_Text(pDX, TX_STAFF_NAME, m_staff_name); DDX_Text(pDX, TX_NATIVE_PLACE, m_staff_native_place); DDX_Text(pDX, TX_SELF_PHONE, m_staff_self_phone); DDX_Text(pDX, TX_STAFF_PHONE, m_staff_phone); DDX_Text(pDX, TX_SELF_QQ, m_staff_self_qq); DDX_Text(pDX, TX_SELF_WX, m_staff_self_wx); DDX_Text(pDX, TX_SELF_EMAIL, m_staff_self_email); DDX_Text(pDX, TX_FATHER_NAME, m_staff_father); DDX_Text(pDX, TX_FATHER_PHONE, m_staff_father_phone); DDX_Text(pDX, TX_MOTHER_NAME, m_staff_mother); DDX_Text(pDX, TX_MOTHER_PHONE, m_staff_mother_phone); DDX_Text(pDX, TX_FAMILY_ADDRESS, m_staff_family_address); DDX_Text(pDX, TX_EMER_NAME, m_staff_emer_name); DDX_Text(pDX, TX_EMER_PHONE, m_staff_emer_phone); DDX_Text(pDX, TX_EMER_RELATIONSHIP, m_staff_emer_relationship); DDX_Text(pDX, TX_EDUCATIONAL, m_staff_educational); DDX_Text(pDX, TX_GRADUATE_INSTITUTIONS, m_staff_graduate_institutions); DDX_Text(pDX, TX_CITIZEN_ID_NUMBER, m_staff_citizen_id_number); DDX_Text(pDX, TX_HIRE_DATE, m_staff_hire_date); DDX_Text(pDX, TX_LEAVE_DATE, m_staff_leave_date); DDX_Text(pDX, TX_FINGERPRINTED1, m_staff_fingerprinted1); DDX_Text(pDX, TX_FINGERPRINTED2, m_staff_fingerprinted2); DDX_Text(pDX, TX_NOTE, m_staff_note); DDX_Control(pDX, CBOX_GENDER, m_cbox_gender); DDX_Control(pDX, CBOX_MARRIED, m_cbox_married); DDX_Control(pDX, CBOX_DIMISSION, m_cbox_dimisson); DDX_Control(pDX, BTN_ADD_STAFF, m_btn_add_staff); DDX_Control(pDX, BTN_UPLOAD_IMAGE, m_btn_upload_image); //DDX_Control(pDX, BTN_DELETE_IMAGE, m_btn_delete_image); DDX_Text(pDX, TX_BIRTHDAY, m_staff_birthday); DDX_Text(pDX, TX_QQ, m_staff_qq); DDX_Text(pDX, TX_TRIAL_WORK, m_staff_trial_work_date); DDX_Text(pDX, TX_POSITION, m_staff_position); } BEGIN_MESSAGE_MAP(CStaffInfo, CDialog) ON_WM_CTLCOLOR() ON_NOTIFY(NM_CLICK, LIST_STAFF, &CStaffInfo::OnNMClickStaff) ON_BN_CLICKED(BTN_DELETE_STAFF, &CStaffInfo::OnBnClickedDeleteStaff) ON_BN_CLICKED(BTN_UPLOAD_IMAGE, &CStaffInfo::OnBnClickedUploadImage) //ON_BN_CLICKED(BTN_DELETE_IMAGE, &CStaffInfo::OnBnClickedDeleteImage) ON_BN_CLICKED(BTN_ADD_STAFF, &CStaffInfo::OnBnClickedAddStaff) ON_CBN_SELCHANGE(CBOX_CREDENTIALS, &CStaffInfo::OnCbnSelchangeCredentials) ON_WM_SYSCOMMAND() ON_BN_CLICKED(BTN_LOOK_IMAGE, &CStaffInfo::OnBnClickedLookImage) END_MESSAGE_MAP() // CStaffInfo 消息处理程序 BOOL CStaffInfo::OnInitDialog() { CDialog::OnInitDialog(); // 将对话框移动到指定显示位置; MoveWindow(&g_rc); CRect rcWnd; GetWindowRect(rcWnd); CRect rcList; m_list.GetWindowRect(rcList); rcList.right = rcWnd.right - 20; rcList.bottom = rcWnd.bottom - 15; ScreenToClient(rcList); m_list.MoveWindow(rcList); // 初始化其他控件列表; m_cbox_credentials.AddString(_T("身份证照")); m_cbox_credentials.AddString(_T("毕业证照")); m_cbox_credentials.AddString(_T("用工合同照")); m_cbox_credentials.AddString(_T("其他证件照")); m_list.SetHeadings( _T("编号, 60"), _T("姓名, 60"), _T("部门, 60"), _T("性别, 60"), _T("个人电话, 60"), _T("分配电话, 60"), _T("籍贯,60"), _T("学历,60"), _T("紧急联系人,60"), _T("紧急联系电话,60"), NULL); GetDepartment(); GetStaffInfo(); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void CStaffInfo::OnOK() { // 判断必填属性; if ( m_cbox_dept.GetCurSel() == -1 ) { MessageBox(_T("未选择部门")); return; } if ( m_cbox_gender.GetCurSel() == -1 ) { MessageBox(_T("未选择性别")); return; } if ( m_cbox_gender.GetCurSel() == -1 ) { MessageBox(_T("未选择婚否")); return; } if ( m_cbox_gender.GetCurSel() == -1 ) { MessageBox(_T("未选择是否在职")); return; } UpdateData(TRUE); if ( m_staff_id.IsEmpty() ) { MessageBox(_T("员工编号必填!")); return; } if ( m_staff_name.IsEmpty() ) { MessageBox(_T("员工姓名必填!")); return; } if ( m_staff_native_place.IsEmpty() ) { MessageBox(_T("员工籍贯必填!")); return; } if ( m_staff_self_phone.IsEmpty() ) { MessageBox(_T("员工个人电话必填!")); return; } if ( m_staff_self_qq.IsEmpty() ) { MessageBox(_T("员工个人QQ必填!")); return; } /*if ( m_staff_self_email.IsEmpty() ) { MessageBox(_T("员工个人邮箱必填!")); return; }*/ if ( m_staff_family_address.IsEmpty() ) { MessageBox(_T("员工家庭住址必填!")); return; } if ( m_staff_emer_name.IsEmpty() ) { MessageBox(_T("员工紧急联系人姓名必填!")); return; } if ( m_staff_emer_phone.IsEmpty() ) { MessageBox(_T("员工紧急联系人电话必填!")); return; } if ( m_staff_emer_relationship.IsEmpty() ) { MessageBox(_T("员工紧急联系人关系必填!")); return; } if ( m_staff_educational.IsEmpty() ) { MessageBox(_T("员工学历必填!")); return; } if ( m_staff_graduate_institutions.IsEmpty() ) { MessageBox(_T("员工毕业院校必填!")); return; } if ( m_staff_trial_work_date.IsEmpty() ) { MessageBox(_T("员工试工日期必填!")); return; } if ( m_staff_citizen_id_number.IsEmpty() ) { MessageBox(_T("员工身份证号必填!")); return; } if ( m_staff_hire_date.IsEmpty() ) { MessageBox(_T("员工入职时间必填!")); return; } if ( m_staff_birthday.IsEmpty() ) { MessageBox(_T("员工生日必填!")); return; } if ( m_staff_fingerprinted1.IsEmpty() && m_staff_fingerprinted2.IsEmpty()) { MessageBox(_T("员工指纹必填,请录入其中一个!")); return; } ////////////////////////////////////////////////////////////////////////// // 新增或修改; CString strSQL; CString staff_department; m_cbox_dept.GetLBText(m_cbox_dept.GetCurSel(), staff_department); CString staff_gender; m_cbox_gender.GetLBText(m_cbox_gender.GetCurSel(), staff_gender); CString staff_married; m_cbox_married.GetLBText(m_cbox_married.GetCurSel(), staff_married); CString staff_dimission; m_cbox_dimisson.GetLBText(m_cbox_dimisson.GetCurSel(), staff_dimission); if ( m_staff_old_id.IsEmpty() ) {// 未单击过列表, 新增员工信息; if ( IsExistStaff(strSQL) ) {// 存在唯一信息; MessageBox(strSQL); return; } // 消除空格; m_staff_phone.Trim(); m_staff_self_phone.Trim(); m_staff_citizen_id_number.Trim(); strSQL.Format(INSERT_renyuan, m_staff_id, staff_department, m_staff_name, staff_gender, m_staff_phone, m_staff_family_address, _T(""), m_staff_citizen_id_number, staff_married, staff_dimission, m_staff_fingerprinted1, m_staff_fingerprinted2, m_staff_self_phone, m_staff_father, m_staff_mother, m_staff_father_phone, m_staff_mother_phone, m_staff_emer_name, m_staff_emer_phone, m_staff_emer_relationship, m_staff_hire_date, m_staff_leave_date, m_staff_self_qq, m_staff_self_wx, m_staff_self_email, m_staff_educational, m_staff_native_place, m_staff_birthday, m_staff_graduate_institutions, m_staff_note , m_staff_qq, m_staff_trial_work_date, m_staff_position ); } else {// 修改员工信息 ; if (IsExistStaffInfo(m_staff_id, strSQL) ) { MessageBox(strSQL); return; } strSQL.Format(UPDATE_renyuan, staff_department, m_staff_name, staff_gender, m_staff_phone, m_staff_family_address, _T(""), m_staff_citizen_id_number, staff_married, staff_dimission, m_staff_fingerprinted1, m_staff_fingerprinted2, m_staff_self_phone, m_staff_father, m_staff_mother, m_staff_father_phone, m_staff_mother_phone, m_staff_emer_name, m_staff_emer_phone, m_staff_emer_relationship, m_staff_hire_date, m_staff_leave_date, m_staff_self_qq, m_staff_self_wx, m_staff_self_email, m_staff_educational, m_staff_native_place, m_staff_birthday, m_staff_graduate_institutions, m_staff_note , m_staff_qq, m_staff_trial_work_date, m_staff_position, m_staff_id ); } g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(strSQL); if (g_bSendOK == 0) return; // 刷新列表; GetStaffInfo(); } void CStaffInfo::OnCancel() { // TODO: 在此添加专用代码和/或调用基类 CDialog::OnCancel(); } void CStaffInfo::GetDepartment() { // 从服务器获取部门信息; g_sendhead.bsql = 0; g_sendhead.code[0] = 3; g_sendhead.tabcount = 1; g_pMainWnd->ProcessChatMessageRequest2(3); if (g_bSendOK == 0)return; CArray AryDepartment; DataToArray(&AryDepartment); // 初始化CBOX_DEPT控件; for (int i = 0; i < AryDepartment.GetSize(); i++ ) { m_cbox_dept.AddString(DAL::Case_3_GetDepartment(AryDepartment,i)); } } void CStaffInfo::GetStaffInfo() { g_sendhead.bsql = 0; g_sendhead.code[0] = 234; g_sendhead.tabcount = 1; g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0) return; DataToArray(&m_AryStaff); m_list.m_AryList.RemoveAll(); m_list.DeleteAllItems(); m_list.m_AryList.SetSize(m_AryStaff.GetSize()); for (int i = 0; i < m_AryStaff.GetSize(); i++) { m_list.m_AryList.ElementAt(i).RemoveAll(); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffId(m_AryStaff,i)); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffName(m_AryStaff,i)); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffDept(m_AryStaff,i)); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffGender(m_AryStaff,i)); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffSelfPhone(m_AryStaff,i)); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffPhone(m_AryStaff,i)); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffNativePlace(m_AryStaff,i)); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffEducational(m_AryStaff,i)); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffEmerName(m_AryStaff,i)); m_list.m_AryList.ElementAt(i).Add(DAL::Case_234_GetStaffEmerPone(m_AryStaff,i)); } m_list.SetItemCountEx(m_list.m_AryList.GetSize()); } void CStaffInfo::FillList() { } HBRUSH CStaffInfo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: 在此更改 DC 的任何属性 switch(nCtlColor) { case CTLCOLOR_DLG: { return CreateSolidBrush(g_clr_dlg); } break; case CTLCOLOR_BTN: break; case CTLCOLOR_STATIC: { pDC->SetBkMode(TRANSPARENT); return CreateSolidBrush(g_clr_dlg); } break; } // TODO: 如果默认的不是所需画笔,则返回另一个画笔 return hbr; } void CStaffInfo::ReSetCtrl() { m_staff_id = _T(""); m_staff_old_id = _T(""); m_staff_name = _T(""); m_staff_old_name = _T(""); m_staff_native_place = _T(""); m_staff_self_phone = _T(""); m_staff_phone = _T(""); m_staff_self_qq = _T(""); m_staff_self_wx = _T(""); m_staff_self_email = _T(""); m_staff_father = _T(""); m_staff_father_phone = _T(""); m_staff_mother = _T(""); m_staff_mother_phone = _T(""); m_staff_family_address = _T(""); m_staff_emer_name = _T(""); m_staff_emer_phone = _T(""); m_staff_emer_relationship = _T(""); m_staff_educational = _T(""); m_staff_graduate_institutions = _T(""); m_staff_citizen_id_number = _T(""); m_staff_hire_date = _T(""); m_staff_leave_date = _T(""); m_staff_fingerprinted1 = _T(""); m_staff_fingerprinted2 = _T(""); m_staff_note = _T(""); m_staff_position = _T(""); UpdateData(FALSE); // 清除相片; // 清除下拉框选择; m_cbox_dept.SetCurSel(-1); m_cbox_gender.SetCurSel(-1); m_cbox_married.SetCurSel(-1); m_cbox_dimisson.SetCurSel(-1); m_cbox_credentials.SetCurSel(-1); // 禁用上传,下载相片; GetDlgItem(BTN_UPLOAD_IMAGE)->EnableWindow(FALSE); //GetDlgItem(BTN_DELETE_IMAGE)->EnableWindow(FALSE); ((CEdit*)GetDlgItem(TX_STAFF_ID))->SetReadOnly(FALSE); } void CStaffInfo::OnNMClickStaff(NMHDR *pNMHDR, LRESULT *pResult) { LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast(pNMHDR); // TODO: 在此添加控件通知处理程序代码 if ( pNMItemActivate->iItem == -1 ) { ReSetCtrl(); return; } m_staff_old_id = m_list.GetItemText(pNMItemActivate->iItem, 0); m_staff_old_name = m_list.GetItemText(pNMItemActivate->iItem, 1); for (int i = 0; i < m_AryStaff.GetSize(); i++ ) { if ( DAL::Case_234_GetStaffId(m_AryStaff, i) == m_staff_old_id ) { // 启用上传,下载按钮; GetDlgItem(BTN_UPLOAD_IMAGE)->EnableWindow(TRUE); //GetDlgItem(BTN_DELETE_IMAGE)->EnableWindow(TRUE); m_staff_id = m_staff_old_id; m_staff_name = m_staff_old_name; m_cbox_gender.SelectString(0,DAL::Case_234_GetStaffGender(m_AryStaff,i)); m_cbox_dept.SelectString(0,DAL::Case_234_GetStaffDept(m_AryStaff,i)); m_staff_native_place = DAL::Case_234_GetStaffNativePlace(m_AryStaff,i); m_staff_self_phone = DAL::Case_234_GetStaffSelfPhone(m_AryStaff,i); m_staff_phone = DAL::Case_234_GetStaffPhone(m_AryStaff,i); m_staff_self_qq = DAL::Case_234_GetStaffSelfQQ(m_AryStaff,i); m_staff_self_wx = DAL::Case_234_GetStaffSelfWX(m_AryStaff,i); m_staff_self_email = DAL::Case_234_GetStaffSelfEmail(m_AryStaff,i); m_staff_father = DAL::Case_234_GetStaffFather(m_AryStaff,i); m_staff_father_phone= DAL::Case_234_GetStaffFatherPhone(m_AryStaff,i); m_staff_mother = DAL::Case_234_GetStaffMother(m_AryStaff,i); m_staff_mother_phone= DAL::Case_234_GetStaffMotherPhone(m_AryStaff,i); m_staff_family_address= DAL::Case_234_GetStaffFamilyAddress(m_AryStaff,i); m_staff_emer_name= DAL::Case_234_GetStaffEmerName(m_AryStaff,i); m_staff_emer_phone= DAL::Case_234_GetStaffEmerPone(m_AryStaff,i); m_staff_emer_relationship= DAL::Case_234_GetStaffEmerRelationShip(m_AryStaff,i); m_staff_educational = DAL::Case_234_GetStaffEducational(m_AryStaff,i); m_staff_graduate_institutions= DAL::Case_234_GetStaffGraduateInstitutions(m_AryStaff,i); m_staff_citizen_id_number = DAL::Case_234_GetStaffCitizenIdNumber(m_AryStaff,i); m_staff_hire_date= DAL::Case_234_GetStaffHireDate(m_AryStaff,i); m_staff_leave_date= DAL::Case_234_GetStaffLeaveDate(m_AryStaff,i); m_staff_birthday= DAL::Case_234_GetStaffBirthday(m_AryStaff,i); m_cbox_married.SelectString(0,DAL::Case_234_GetStaffMarried(m_AryStaff,i)); m_staff_fingerprinted1= DAL::Case_234_GetStaffFingerprinted1(m_AryStaff,i); m_staff_fingerprinted2= DAL::Case_234_GetStaffFingerprinted2(m_AryStaff,i); m_cbox_dimisson.SelectString(0, DAL::Case_234_GetStaffDimission(m_AryStaff,i)); m_staff_note = DAL::Case_234_GetStaffNote(m_AryStaff,i); m_staff_position = DAL::Case_234_GetStaffPosition(m_AryStaff,i); m_staff_trial_work_date = DAL::Case_234_GetStaffTrialWorkDate(m_AryStaff,i); ((CEdit*)GetDlgItem(TX_STAFF_ID))->SetReadOnly(TRUE); UpdateData(false); } } *pResult = 0; } void CStaffInfo::OnBnClickedDeleteStaff() // 删除员工; { POSITION pos = m_list.GetFirstSelectedItemPosition(); if ( pos == NULL ) { return; } if ( MessageBox(_T("确认删除该员工资料吗?"),_T("删除员工"), MB_YESNO | MB_ICONWARNING ) != IDYES ) return; if ( m_staff_id.IsEmpty() ) { MessageBox(_T("员工id空")); return; } CString strSQL; strSQL.Format(_T("delete from renyuan where id = '%s'"), m_staff_id); g_sendhead.bsql = true; g_pMainWnd->ProcessChatMessageRequest2(strSQL); if (g_bSendOK == 0) return; // 重新获取员工信息; GetStaffInfo(); } void CStaffInfo::OnBnClickedUploadImage() // 上传相片; { if ( m_cbox_credentials.GetCurSel() == CB_ERR) { MessageBox(_T("请选择要上传的相片类型")); return; } // 相片名称; CString strImageName; // 相片类型; CString strImageType ; m_cbox_credentials.GetLBText(m_cbox_credentials.GetCurSel(), strImageType); UpdateData(); CFileDialog fdlg(true, NULL, "", OFN_HIDEREADONLY, "jpg files(*jpg)|*.jpg||"); if (fdlg.DoModal() != IDOK) return; // 相片名称:带后缀; strImageName = fdlg.GetFileName(); CString path = fdlg.GetPathName(); CFile fp; if (!fp.Open(path, CFile::modeRead)) { AfxMessageBox(_T("文件打开失败!")); return; } DWORD length = fp.GetLength(); if (length > 1024 * 200) { AfxMessageBox(_T("文件太大,请上传小于200K的图片!")); fp.Close(); return; } DWORD dwSendLen = length + m_staff_id.GetLength() + m_staff_citizen_id_number.GetLength() + strImageType.GetLength() + strImageName.GetLength() +5*sizeof(DWORD); BYTE *pSendData = new BYTE[dwSendLen]; // 相片大小; memcpy(pSendData, &length, sizeof(DWORD)); // 相片内容; fp.Read(pSendData + sizeof(DWORD), length); fp.Close(); // 员工编号; DWORD dwLen = m_staff_id.GetLength(); memcpy(pSendData + length + sizeof(DWORD), &dwLen, sizeof(DWORD)); memcpy(pSendData + length + 2*sizeof(DWORD), m_staff_id.GetString(), dwLen); // 员工身份证号; DWORD dwLen1 = m_staff_citizen_id_number.GetLength(); memcpy(pSendData + length + 2*sizeof(DWORD) + dwLen, &dwLen1, sizeof(DWORD)); memcpy(pSendData + length + 3*sizeof(DWORD) + dwLen, m_staff_citizen_id_number.GetString(), dwLen1); // 相片类型; DWORD dwLen2 = strImageType.GetLength(); memcpy(pSendData + length + 3*sizeof(DWORD) + dwLen + dwLen1, &dwLen2, sizeof(DWORD)); memcpy(pSendData + length + 4*sizeof(DWORD) + dwLen + dwLen1, strImageType.GetString(), dwLen2); // 相片名称; DWORD dwLen3 = strImageName.GetLength(); memcpy(pSendData + length + 4*sizeof(DWORD) + dwLen + dwLen1 + dwLen2, &dwLen3, sizeof(DWORD)); memcpy(pSendData + length + 5*sizeof(DWORD) + dwLen + dwLen1 + dwLen2, strImageName.GetString(), dwLen3); g_nSendCode = 26; g_pMainWnd->ProcessChatMessageRequest2(pSendData, dwSendLen); g_nSendCode = 0; delete[]pSendData; if (g_bSendOK == 0) { return; } AfxMessageBox("上传成功!"); } void CStaffInfo::OnBnClickedDeleteImage() // 删除相片; { } void CStaffInfo::OnBnClickedAddStaff() // 添加员工; { ReSetCtrl(); // 自动生成id; int nIndex = 0; int nMaxId = 0; for (int i = 0; i < m_AryStaff.GetSize(); i++) { nIndex = _tstoi(DAL::Case_234_GetStaffId(m_AryStaff, i)); if ( nMaxId < nIndex) nMaxId = nIndex; } m_staff_id.Format(_T("%03d"), ++nMaxId); UpdateData(FALSE); } void CStaffInfo::OnCbnSelchangeCredentials() // 选择要显示或上传,下载的证件照; { // TODO: 在此添加控件通知处理程序代码 } BOOL CStaffInfo::IsExistStaff(CString &strMsg) { // 员工id, 员工身份证号, 员工个人电话, 员工个人QQ, 员工个人邮箱是否有相同的; // CString strStaffId, strStaffCitizenIdNumber, strStaffSelfPhone, strStaffSelfQQ, strStaffSelfEmail; UpdateData(TRUE); BOOL bExist = FALSE; for ( int i = 0; i < m_AryStaff.GetSize(); i++ ) { if ( DAL::Case_234_GetStaffId(m_AryStaff, i) == m_staff_id ) { bExist = TRUE; strMsg = _T("员工编号存在"); break; } if ( DAL::Case_234_GetStaffCitizenIdNumber(m_AryStaff, i) == m_staff_citizen_id_number ) { bExist = TRUE; strMsg = _T("员工身份证号存在"); break; } if ( DAL::Case_234_GetStaffSelfPhone(m_AryStaff, i) == m_staff_self_phone ) { bExist = TRUE; strMsg = _T("员工个人电话存在"); break; } if ( DAL::Case_234_GetStaffSelfQQ(m_AryStaff, i) == m_staff_self_qq ) { bExist = TRUE; strMsg = _T("员工个人QQ存在"); break; } /*if ( DAL::Case_234_GetStaffSelfEmail(m_AryStaff, i) == m_staff_self_email ) { bExist = TRUE; strMsg = _T("员工个人邮箱存在"); break; }*/ } return bExist; } BOOL CStaffInfo::IsExistStaffInfo(CString staff_id, CString &strMsg) { UpdateData(TRUE); BOOL bExist = FALSE; for ( int i = 0; i < m_AryStaff.GetSize(); i++ ) { if ( DAL::Case_234_GetStaffId(m_AryStaff, i) == staff_id ) { //bExist = TRUE; //strMsg = _T("员工编号存在"); continue;; } if ( DAL::Case_234_GetStaffCitizenIdNumber(m_AryStaff, i) == m_staff_citizen_id_number ) { bExist = TRUE; strMsg = _T("员工身份证号存在"); break; } if ( DAL::Case_234_GetStaffSelfPhone(m_AryStaff, i) == m_staff_self_phone ) { bExist = TRUE; strMsg = _T("员工个人电话存在"); break; } if ( DAL::Case_234_GetStaffSelfQQ(m_AryStaff, i) == m_staff_self_qq ) { bExist = TRUE; strMsg = _T("员工个人QQ存在"); break; } /*if ( DAL::Case_234_GetStaffSelfEmail(m_AryStaff, i) == m_staff_self_email ) { bExist = TRUE; strMsg = _T("员工个人邮箱存在"); break; }*/ } return bExist; } void CStaffInfo::OnSysCommand(UINT nID, LPARAM lParam) { // 禁止移动窗口; if (nID == SC_MOVE || nID == 0xF012) return; CDialog::OnSysCommand(nID, lParam); } void CStaffInfo::OnBnClickedLookImage() // 查看相片; { // 移除之前的相片资源; for (vector::iterator it = m_vtAnnex.begin(); it != m_vtAnnex.end(); it++) { if ( it->pImage ) delete it->pImage; } m_vtAnnex.clear(); // 获取相片类型; if ( m_cbox_credentials.GetCurSel() == CB_ERR) { MessageBox(_T("请选择要上传的相片类型")); return; } // 相片类型; CString strImageType ; m_cbox_credentials.GetLBText(m_cbox_credentials.GetCurSel(), strImageType); DWORD dwIndexCount = 0; DWORD dwSendLen = strImageType.GetLength() + m_staff_id.GetLength() + m_staff_citizen_id_number.GetLength() + 3*sizeof(DWORD); BYTE *pSendData = new BYTE[dwSendLen]; memset(pSendData, 0, dwSendLen); DWORD dwLen = strImageType.GetLength(); // 请求的相片类型; memcpy(pSendData, &dwLen, sizeof(DWORD)); dwIndexCount += sizeof(DWORD); memcpy(pSendData + dwIndexCount, strImageType.GetString(), strImageType.GetLength()); // 请求的员工id; dwLen = m_staff_id.GetLength(); dwIndexCount += strImageType.GetLength(); memcpy(pSendData + dwIndexCount, &dwLen, sizeof(DWORD)); dwIndexCount += sizeof(DWORD); memcpy(pSendData + dwIndexCount, m_staff_id.GetString(), m_staff_id.GetLength()); // 请求的员工身份证号; dwLen = m_staff_citizen_id_number.GetLength(); dwIndexCount += m_staff_id.GetLength(); memcpy(pSendData + dwIndexCount, &dwLen, sizeof(DWORD)); dwIndexCount += sizeof(DWORD); memcpy(pSendData + dwIndexCount, m_staff_citizen_id_number.GetString(), m_staff_citizen_id_number.GetLength()); // 向服务器请求; g_nSendCode = 27; g_pMainWnd->ProcessChatMessageRequest2(pSendData, dwSendLen); if ( pSendData )delete []pSendData; g_nSendCode = 0; if (g_bSendOK == 0) { return; } // 获取返回的相片数据; // 返回的数据结构: 相片数量->数据大小->相片名+名字长度->相片内容->数据大小->相片名+名字长度->相片内容->....; dwIndexCount = sizeof(DWORD); DWORD dwImageCount = 0; DWORD dwImageSize = 0; BYTE *pImageData = NULL; DWORD dwNameLen = 0; TCHAR szImageName[MAX_PATH] = {0}; memcpy(&dwImageCount, g_pData, sizeof(DWORD)); for ( DWORD i = 0; i < dwImageCount; i++ ) {// 轮询相片; // 相片名称 ; memset(szImageName, 0, MAX_PATH); memcpy(&dwNameLen, g_pData + dwIndexCount, sizeof(DWORD)); dwIndexCount += sizeof(DWORD); memcpy(szImageName, g_pData + dwIndexCount, dwNameLen); dwIndexCount += dwNameLen; // 相片大小; memcpy(&dwImageSize, g_pData + dwIndexCount, sizeof(DWORD)); dwIndexCount += sizeof(DWORD); // 相片内容; pImageData = g_pData + dwIndexCount; dwIndexCount += dwImageSize; // 保存图片到内存中, 不存储成文件; Image *pImage = NULL; LoadImageFromBuf(&pImage, pImageData, dwImageSize); Annex annex; annex.strMD5 = szImageName; annex.pImage = pImage; m_vtAnnex.push_back(annex); #ifdef _DEBUG // 正式使用时,不要保存文件; if ( pImage ) { CFile cf; CString strSave; strSave.Format(_T("%s\\staff\\%s\\%s\\"), g_szModulePath, m_staff_citizen_id_number, strImageType); SHCreateDirectoryEx(NULL, strSave, NULL); CMD5 md5; md5.SetBYTEText(pImageData, dwImageSize); strSave += md5.GetMD5Digest(); strSave += _T(".jpg"); if ( cf.Open(strSave, CFile::modeCreate|CFile::modeWrite) ) { cf.Write(pImageData, dwImageSize); cf.Close(); } } #endif } if ( m_vtAnnex.size() == 0 ) { MessageBox(_T("没有该类型的相片")); return; } CDlgAnnex dlg; dlg.m_pvtAnnex = &m_vtAnnex; dlg.m_staff_id = m_staff_id; dlg.m_strImageType = strImageType; dlg.m_staff_citizen_id_number = m_staff_citizen_id_number; dlg.DoModal(); }