📄 updatenodedlg.cpp
字号:
// UpdatenodeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Updatenode.h"
#include "UpdatenodeDlg.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CUpdatenodeDlg dialog
CUpdatenodeDlg::CUpdatenodeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUpdatenodeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUpdatenodeDlg)
m_danjia = 0;
m_shul = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CUpdatenodeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUpdatenodeDlg)
DDX_Control(pDX, IDOK, m_ok);
DDX_Control(pDX, IDCANCEL, m_cancel);
DDX_Control(pDX, IDC_LIST1, m_grid);
DDX_Control(pDX, IDC_EDIT6, m_date);
DDX_Control(pDX, IDC_EDIT5, m_bumen);
DDX_Control(pDX, IDC_EDIT4, m_name);
DDX_Control(pDX, IDC_EDIT1, m_wupin);
DDX_Text(pDX, IDC_EDIT2, m_danjia);
DDX_Text(pDX, IDC_EDIT3, m_shul);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUpdatenodeDlg, CDialog)
//{{AFX_MSG_MAP(CUpdatenodeDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUpdatenodeDlg message handlers
BOOL CUpdatenodeDlg::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
m_grid.SetExtendedStyle(LVS_EX_FLATSB
|LVS_EX_FULLROWSELECT
|LVS_EX_HEADERDRAGDROP
|LVS_EX_ONECLICKACTIVATE
|LVS_EX_GRIDLINES);
m_grid.InsertColumn(0,"编号",LVCFMT_LEFT,100,0);
m_grid.InsertColumn(1,"物品名",LVCFMT_LEFT,100,1);
m_grid.InsertColumn(2,"单价",LVCFMT_LEFT,100,2);
m_grid.InsertColumn(3,"销售数量",LVCFMT_LEFT,100,3);
m_grid.InsertColumn(4,"销售员",LVCFMT_LEFT,100,4);
m_grid.InsertColumn(5,"销售部门",LVCFMT_LEFT,100,5);
m_grid.InsertColumn(6,"销售时间",LVCFMT_LEFT,100,6);
AddtoGrid();
return TRUE; // return TRUE unless you set the focus to a control
}
void CUpdatenodeDlg::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 CUpdatenodeDlg::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 CUpdatenodeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CUpdatenodeDlg::EditisEmpty()
{
m_wupin.GetWindowText(wupin);
m_name.GetWindowText(name);
m_bumen.GetWindowText(bumen);
m_date.GetWindowText(date);
if(wupin.IsEmpty() || name.IsEmpty() || bumen.IsEmpty() || date.IsEmpty())
{
return true;
}
return false;
}
void CUpdatenodeDlg::AddtoGrid()
{
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
CString sql;
sql.Format("select* from xiaoshoubiao order by 编号 desc");
m_AdoConn.GetRecordSet((_bstr_t)sql);
while(m_AdoConn.m_pRecordset->adoEOF==0)
{
m_grid.InsertItem(0,"");
m_grid.SetItemText(0,0,(char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("编号"));
m_grid.SetItemText(0,1,(char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("物品名"));
m_grid.SetItemText(0,2,(char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("单价"));
m_grid.SetItemText(0,3,(char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("销售数量"));
m_grid.SetItemText(0,4,(char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("销售员"));
m_grid.SetItemText(0,5,(char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("销售部门"));
m_grid.SetItemText(0,6,(char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("销售时间"));
m_AdoConn.m_pRecordset->MoveNext();
}
m_AdoConn.ExitConnect();
}
BOOL CUpdatenodeDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message==WM_KEYDOWN)
{
if (pMsg->wParam == 13)
{
if (pMsg->hwnd != m_cancel.m_hWnd && pMsg->hwnd != m_ok.m_hWnd)
{
pMsg->wParam=9;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CUpdatenodeDlg::OnOK()
{
// TODO: Add extra validation here
if (EditisEmpty())
{
MessageBox("基础信息不能为空.","提示");
return;
}
UpdateData(true);
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
CString danjia,shul;
danjia.Format("%d",m_danjia);
shul.Format("%d",m_shul);
_bstr_t sql;
sql = "update xiaoshoubiao set 物品名='"+wupin+"',单价="+danjia+",销售数量="
+shul+",销售员='"+name+"',销售部门='"+bumen+"',销售时间='"+date+"' where 编号='"
+m_id+"'";
m_AdoConn.ExecuteSQL((_bstr_t)sql);
m_AdoConn.ExitConnect();
//删除列表控件中所有记录
m_grid.DeleteAllItems();
AddtoGrid();
//CDialog::OnOK();
}
void CUpdatenodeDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
UpdateData(true);
int pos;
pos=m_grid.GetSelectionMark();
m_id=m_grid.GetItemText(pos,0);
m_wupin.SetWindowText(m_grid.GetItemText(pos,1));
m_name.SetWindowText(m_grid.GetItemText(pos,4));
m_bumen.SetWindowText(m_grid.GetItemText(pos,5));
m_date.SetWindowText(m_grid.GetItemText(pos,6));
m_danjia = atoi(m_grid.GetItemText(pos,2));
m_shul = atoi(m_grid.GetItemText(pos,3));
UpdateData(false);
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -