📄 add.cpp
字号:
// Add.cpp : implementation file
//
#include "stdafx.h"
#include "横店集团保卫人员管理系统.h"
#include "Add.h"
#include "detailinfor.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern int Index;
extern CString SearchType;
extern CString SearchValue;
/////////////////////////////////////////////////////////////////////////////
// CAdd dialog
CAdd::CAdd(CWnd* pParent /*=NULL*/)
: CDialog(CAdd::IDD, pParent)
{
//{{AFX_DATA_INIT(CAdd)
m_address = _T("");
m_card_id = _T("");
m_change = _T("");
m_graduate = _T("");
m_id = _T("");
m_name = _T("");
m_phone = _T("");
m_prefere = _T("");
m_punish = _T("");
m_resume = _T("");
m_shop = _T("");
//}}AFX_DATA_INIT
}
void CAdd::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAdd)
DDX_Control(pDX, IDC_Sel, m_sel);
DDX_Control(pDX, IDC_PICTURE, m_picture);
DDX_Control(pDX, IDC_POLICY, m_policy);
DDX_Control(pDX, IDC_OK, m_ok);
DDX_Control(pDX, IDC_YEAR, m_year);
DDX_Control(pDX, IDC_MONTH, m_month);
DDX_Control(pDX, IDC_EDU, m_edu);
DDX_Control(pDX, IDC_DAY, m_day);
DDX_Control(pDX, IDC_BOY, m_boy);
DDX_Text(pDX, IDC_ADDRESS, m_address);
DDX_Text(pDX, IDC_CARD_ID, m_card_id);
DDX_Text(pDX, IDC_CHANGE, m_change);
DDX_Text(pDX, IDC_GRADUATE, m_graduate);
DDX_Text(pDX, IDC_ID, m_id);
DDX_Text(pDX, IDC_NAME, m_name);
DDX_Text(pDX, IDC_PHONE, m_phone);
DDX_Text(pDX, IDC_PREFERE, m_prefere);
DDX_Text(pDX, IDC_PUNISH, m_punish);
DDX_Text(pDX, IDC_RESUME, m_resume);
DDX_Text(pDX, IDC_SHOP, m_shop);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAdd, CDialog)
//{{AFX_MSG_MAP(CAdd)
ON_WM_CTLCOLOR()
ON_WM_PAINT()
ON_BN_CLICKED(IDC_OK, OnAdd)
ON_BN_CLICKED(IDC_QUIT, OnQuit)
ON_BN_CLICKED(IDC_Sel, OnSel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAdd message handlers
HBRUSH CAdd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor == CTLCOLOR_STATIC )
{
static HBRUSH hbrEdit = ::CreateSolidBrush( RGB(245,200,173) );
pDC->SetBkMode ( TRANSPARENT );
return hbrEdit;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CAdd::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(rect);
dc.FillSolidRect(rect,RGB(245,200,173));
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
void CAdd::OnAdd()
{
CString string;
this->GetWindowText(string);
UpdateData(true);
if(m_id.IsEmpty()||m_name.IsEmpty())
MessageBox("请填好ID号和姓名");
else
{
CString str;
int i;
CDetailInfor detail;
detail.Open();
if(Index==0)
{
detail.m_strFilter="编号='"+SearchValue+"'";
detail.Requery();
detail.Edit();
}
else
{
detail.AddNew();
detail.m_ID=this->m_id;
}
detail.m_Address=this->m_address;
detail.m_Card_ID=this->m_card_id;
detail.m_Change=this->m_change;
i=m_edu.GetCurSel();
if(i!=-1)
{
m_edu.GetLBText(i,str);
detail.m_Edu=str;
}
detail.m_Graduate=this->m_graduate;
detail.m_Name=this->m_name;
detail.m_Phone=this->m_phone;
if(!this->PhotoAddress.IsEmpty())
detail.m_Photo=this->PhotoAddress;
i=m_policy.GetCurSel();
if(i!=-1)
{
m_policy.GetLBText(i,str);
detail.m_Policy=str;
}
detail.m_Prefere=this->m_prefere;
detail.m_Punish=this->m_punish;
detail.m_Resume=this->m_resume;
if(m_boy.GetCheck())
detail.m_Sex="男";
else
detail.m_Sex="女";
detail.m_Shop=this->m_shop;
int year=m_year.GetCurSel(),month=m_month.GetCurSel(),day=m_day.GetCurSel();
if(year!=-1&&month!=-1&&day!=-1)
{
CString theTime,str;
m_year.GetLBText(year,theTime);
theTime+='-';
m_month.GetLBText(month,str);
theTime+=str;
theTime+='-';
m_day.GetLBText(day,str);
theTime+=str;
detail.m_Birthday=theTime;
}
detail.Update();
detail.Close();
if(Index!=0)
MessageBox("添加成功");
else
MessageBox("修改成功");
this->OnOK();
this->PhotoAddress="";
}
// TODO: Add your control notification handler code here
}
BOOL CAdd::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
if(pMsg->wParam==VK_RETURN)
OnAdd();
return CDialog::PreTranslateMessage(pMsg);
}
void CAdd::OnQuit()
{
this->OnOK();
}
BOOL CAdd::OnInitDialog()
{
CDialog::OnInitDialog();
CString str;
for(int i=0;i<100;i++)
{
str.Format("%d",i+1970);
m_year.AddString(str);
}
edit="修改";
if(Index==0)
{
this->SetWindowText(edit);
this->m_ok.SetWindowText(edit);
this->ShowInfo();
}
else if(Index==2)
{
this->SetWindowText("具体信息");
this->m_ok.EnableWindow(false);
m_sel.EnableWindow(false);
this->ShowInfo();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAdd::ShowInfo()
{
CDetailInfor detail;
detail.m_strFilter.Format("%s='%s'","编号",SearchValue);
detail.Open();
this->m_id=detail.m_ID;
this->m_address=detail.m_Address;
this->m_card_id=detail.m_Card_ID;
this->m_change=detail.m_Change;
int i=m_edu.FindString(-1,detail.m_Edu);
m_edu.SetCurSel(i);
this->m_graduate=detail.m_Graduate;
this->m_name=detail.m_Name;
this->m_phone=detail.m_Phone;
i=m_policy.FindString(-1,detail.m_Policy);
m_policy.SetCurSel(i);
this->m_prefere=detail.m_Prefere;
this->m_punish=detail.m_Punish;
this->m_resume=detail.m_Resume;
if(detail.m_Sex=="女")
{
CButton *bu=(CButton*)GetDlgItem(IDC_GIRL);
bu->SetCheck(true);
}
else
m_boy.SetCheck(true);
this->m_shop=detail.m_Shop;
CString str[4];
str[0]=detail.m_Birthday;
str[1]=str[0].Left(4);
str[0]=str[0].Right(str[0].GetLength()-str[0].Find('-')-1);
i=str[0].Find('-');
str[2]=str[0].Left(i);
str[3]=str[0].Right(str[0].GetLength()-str[0].Find('-')-1);
str[3].TrimLeft(' ');
str[3].TrimRight(' ');
i=m_year.FindString(-1,str[1]);
m_year.SetCurSel(i);
i=m_month.FindString(-1,str[2]);
m_month.SetCurSel(i);
i=m_day.FindString(-1,str[3]);
m_day.SetCurSel(i);
UpdateData(false);
HBITMAP hbitmap;
hbitmap=(HBITMAP)::LoadImage(NULL,detail.m_Photo,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
m_picture.SetBitmap(hbitmap);
}
void CAdd::OnSel()
{
CFileDialog dlg(true);
dlg.DoModal();
PhotoAddress=dlg.GetPathName();
CString StrTo;
GetModuleFileName(NULL,StrTo.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
StrTo.ReleaseBuffer ();
int nPos;
nPos=StrTo.ReverseFind('\\');
StrTo=StrTo.Left (nPos);
StrTo+="\\picture\\";
StrTo+=dlg.GetFileName();
////////////////////////////////////////////////////
CopyFile(PhotoAddress,StrTo,false); //false--原来存在则覆盖
PhotoAddress=StrTo;
PhotoAddress.Replace("\\","\\\\");
HBITMAP hbitmap;
hbitmap=(HBITMAP)::LoadImage(NULL,PhotoAddress,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
m_picture.SetBitmap(hbitmap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -