- // hospital_2Dlg.h : header file
- //
- #if !defined(AFX_HOSPITAL_2DLG_H__9A2D666C_B166_4FB5_AAE0_F270083318D1__INCLUDED_)
- #define AFX_HOSPITAL_2DLG_H__9A2D666C_B166_4FB5_AAE0_F270083318D1__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- /////////////////////////////////////////////////////////////////////////////
- // CHospital_2Dlg dialog
- struct patient //病人类
- {
- char order_number[10];
- char name[10];
- char sex[10];
- char birth[10];
- char tel_number[20];
- char department[20];
- };
- class CHospital_2Dlg : public CDialog
- {
- // Construction
- public:
- CHospital_2Dlg(CWnd* pParent = NULL); // standard constructor
- // Dialog Data
- //{{AFX_DATA(CHospital_2Dlg)
- enum { IDD = IDD_HOSPITAL_2_DIALOG };
- CString m_number;
- CString m_name;
- CString m_birth;
- CString m_department;
- CString m_phone;
- CString m_sex;
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CHospital_2Dlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- HICON m_hIcon;
- // Generated message map functions
- //{{AFX_MSG(CHospital_2Dlg)
- virtual BOOL OnInitDialog();
- afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
- afx_msg void OnPaint();
- afx_msg HCURSOR OnQueryDragIcon();
- afx_msg void OnCalculate();
- afx_msg void OnRefer();
- afx_msg void OnRegisterNew();
- afx_msg void OnButton1();
- afx_msg void OnModify();
- afx_msg void OnFresh();
- afx_msg void OnDelete();
- afx_msg void OnExit();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- //{{AFX_INSERT_LOCATION}}
- // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
- #endif // !defined(AFX_HOSPITAL_2DLG_H__9A2D666C_B166_4FB5_AAE0_F270083318D1__INCLUDED_)
- //////////////////////////////////////hospital_2.h
- // hospital_2Dlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "hospital_2.h"
- #include "hospital_2Dlg.h"
- #include "afxwin.h" //UpdateData
- #include "Windows.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- patient pat[4] = {{"01","丁丁","男","1994","1234","内科"},{"02","冬冬","女","1993","5678","外科"}};
- //定义病人结构体
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CHospital_2Dlg dialog
- CHospital_2Dlg::CHospital_2Dlg(CWnd* pParent /*=NULL*/)
- : CDialog(CHospital_2Dlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CHospital_2Dlg)
- m_number = _T("");
- m_name = _T("");
- m_birth = _T("");
- m_department = _T("");
- m_phone = _T("");
- m_sex = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- //m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
- }
- void CHospital_2Dlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CHospital_2Dlg)
- DDX_Text(pDX, IDC_EDIT1, m_number);
- DDX_Text(pDX, IDC_NAME, m_name);
- DDX_Text(pDX, IDC_BIRTH, m_birth);
- DDX_Text(pDX, IDC_DEPARTMENT, m_department);
- DDX_Text(pDX, IDC_PHONE, m_phone);
- DDX_Text(pDX, IDC_SEX, m_sex);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CHospital_2Dlg, CDialog)
- //{{AFX_MSG_MAP(CHospital_2Dlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_CALCULATE, OnCalculate)
- ON_BN_CLICKED(IDC_REFER, OnRefer)
- ON_BN_CLICKED(IDC_REGISTER_NEW, OnRegisterNew)
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_MODIFY, OnModify)
- ON_BN_CLICKED(IDC_FRESH, OnFresh)
- ON_BN_CLICKED(IDC_DELETE, OnDelete)
- ON_BN_CLICKED(IDC_EXIT, OnExit)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CHospital_2Dlg message handlers
- BOOL CHospital_2Dlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CHospital_2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CHospital_2Dlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CHospital_2Dlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CHospital_2Dlg::OnCalculate() //计费
- {
- CWnd* pWnd_name = GetDlgItem(IDC_NAME);
- pWnd_name->EnableWindow(FALSE);
- CWnd* pWnd_sex = GetDlgItem(IDC_SEX);
- pWnd_sex->EnableWindow(FALSE);
- CWnd* pWnd_birth = GetDlgItem(IDC_BIRTH);
- pWnd_birth->EnableWindow(FALSE);
- CWnd* pWnd_phone = GetDlgItem(IDC_PHONE);
- pWnd_phone->EnableWindow(FALSE);
- CWnd* pWnd_department = GetDlgItem(IDC_DEPARTMENT);
- pWnd_department->EnableWindow(FALSE); //控件不可用
- GetDlgItemText(IDC_EDIT1,m_number);
- for(int i = 0;i < 4;i++) //查询
- {
- if(strcmp(m_number,pat[i].order_number)==0)
- {
- if(strcmp(pat[i].department,"内科")==0)
- {
- MessageBox("挂号费用为10元","挂号费");
- }
- if(strcmp(pat[i].department,"外科")==0)
- {
- MessageBox("挂号费用为20元","挂号费");
- }
- }
- }
- }
- void CHospital_2Dlg::OnRefer() //查询
- {
- CWnd* pWnd_name = GetDlgItem(IDC_NAME);
- pWnd_name->EnableWindow(FALSE);
- CWnd* pWnd_sex = GetDlgItem(IDC_SEX);
- pWnd_sex->EnableWindow(FALSE);
- CWnd* pWnd_birth = GetDlgItem(IDC_BIRTH);
- pWnd_birth->EnableWindow(FALSE);
- CWnd* pWnd_phone = GetDlgItem(IDC_PHONE);
- pWnd_phone->EnableWindow(FALSE);
- CWnd* pWnd_department = GetDlgItem(IDC_DEPARTMENT);
- pWnd_department->EnableWindow(FALSE);
- CString s;
- char s1[10],s2[10],s3[10],s4[20],s5[20];;
- GetDlgItemText(IDC_EDIT1,m_number);
- for(int i = 0;i < 4;i++)
- {
- if(strcmp(m_number,pat[i].order_number)==0)
- {
- strcpy(s1,pat[i].name);
- strcpy(s2,pat[i].sex);
- strcpy(s3,pat[i].birth);
- strcpy(s4,pat[i].tel_number);
- strcpy(s5,pat[i].department);
- }
- }
- SetDlgItemText(IDC_EDIT2,s1); //个人信息的字符串叠加
- GetDlgItemText(IDC_EDIT2,s);
- s+=" ";
- s+=s2;
- SetDlgItemText(IDC_EDIT2,s);
- GetDlgItemText(IDC_EDIT2,s);
- s+=" ";
- s+=s3;
- SetDlgItemText(IDC_EDIT2,s);
- GetDlgItemText(IDC_EDIT2,s);
- s+=" ";
- s+=s4;
- SetDlgItemText(IDC_EDIT2,s);
- GetDlgItemText(IDC_EDIT2,s);
- s+=" ";
- s+=s5;
- SetDlgItemText(IDC_EDIT2,s);
- }
- void CHospital_2Dlg::OnRegisterNew() //写入病人信息到文件
- {
- UpdateData(true);
- CFile file;
- file.Open("D:\\\\患者.txt",CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate);//不删除原有数据
- file.Write("病人信息\\r\\n医保编号 ",strlen("病人信息\\r\\n医保编号 "));
- file.Write(m_number,strlen(m_number));
- file.Write("\\r\\n姓名 ",strlen("\\r\\n姓名 "));
- file.Write(m_name,strlen(m_name));
- file.Write("\\r\\n性别 ",strlen("\\r\\n性别 "));
- file.Write(m_sex,strlen(m_sex));
- file.Write("\\r\\n生日 ",strlen("\\r\\n生日 "));
- file.Write(m_birth,strlen(m_birth));
- file.Write("\\r\\n电话 ",strlen("\\r\\n电话 "));
- file.Write(m_phone,strlen(m_phone));
- file.Write("\\r\\n科室 ",strlen("\\r\\n科室 "));
- file.Write(m_department,strlen(m_department));
- file.Close();
- SetDlgItemText(IDC_NAME,"");
- SetDlgItemText(IDC_SEX,"");
- SetDlgItemText(IDC_BIRTH,"");
- SetDlgItemText(IDC_PHONE,"");
- SetDlgItemText(IDC_DEPARTMENT,"");
- }
- void CHospital_2Dlg::OnButton1() //编辑框可用,用于输入信息
- {
- UpdateData(true);
- CWnd* pWnd_name = GetDlgItem(IDC_NAME);
- pWnd_name->EnableWindow(TRUE);
- CWnd* pWnd_sex = GetDlgItem(IDC_SEX);
- pWnd_sex->EnableWindow(TRUE);
- CWnd* pWnd_birth = GetDlgItem(IDC_BIRTH);
- pWnd_birth->EnableWindow(TRUE);
- CWnd* pWnd_phone = GetDlgItem(IDC_PHONE);
- pWnd_phone->EnableWindow(TRUE);
- CWnd* pWnd_department = GetDlgItem(IDC_DEPARTMENT);
- pWnd_department->EnableWindow(TRUE);
- }
- void CHospital_2Dlg::OnModify() //编辑框可用,修改号码
- {
- CWnd* pWnd_phone = GetDlgItem(IDC_PHONE);
- pWnd_phone->EnableWindow(TRUE);
- }
- void CHospital_2Dlg::OnFresh() //病人号码更新
- {
- UpdateData(true);
- CWnd* pWnd_phone = GetDlgItem(IDC_PHONE);
- pWnd_phone->EnableWindow(FALSE);
- CString s;
- GetDlgItemText(IDC_PHONE,s);
- for(int i = 0;i < 2;i++)
- {
- if(strcmp(pat[i].order_number,m_number)==0)
- {
- strcpy(pat[i].tel_number,s);
- }
- }
- }
- void CHospital_2Dlg::OnDelete() //删除
- {
- system( "del d:\\\\患者.txt" );
- }
- void CHospital_2Dlg::OnExit() //退出
- {
- exit(0);
- }
- //////////////////////////////////hospital_2.cpp
- //该片段来自于http://www.codesnippet.cn/detail/090520149498.html
来源: http://www.codesnippet.cn/detail/090520149498.html