⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dutydlg.cpp

📁 口通信 VC 完整串口通信程序Vc++源代码 串口通讯 vc++ 源代码 vc 串口通信 串口通信 mfc 通信 发送程序 vc++ 串口 VC 串口通信程序 完整串口通信程序Vc 源代码 VC串口通
💻 CPP
字号:
// DutyDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GSMTest.h"
#include "DutyDlg.h"

#include <winsock.h>
#include <mysql.h>
#include "database.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDutyDlg dialog


CDutyDlg::CDutyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDutyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDutyDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDutyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDutyDlg)
	DDX_Control(pDX, IDC_DUTY_LIST, m_ctrDutylist);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDutyDlg, CDialog)
	//{{AFX_MSG_MAP(CDutyDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDutyDlg message handlers

void CDutyDlg::OnOK() 
{
	int count=m_ctrDutylist.GetSelectedCount();

	POSITION pos=m_ctrDutylist.GetFirstSelectedItemPosition();
	if(pos==NULL)
	{
		AfxMessageBox("请选择负责人!");
		return;
	}	


	CDatabase1 database;	
	if(!database.ConnectDB())
	{	
		AfxMessageBox("连接服务器失败!");
		return;
	}
	
	CString sSQL;

	while (count--) 
	{
		int nItem = m_ctrDutylist.GetNextSelectedItem(pos);
		
		sSQL.Format("select id from trans_duty where duty_name='%s' and trans_id='%s'",
			m_ctrDutylist.GetItemText(nItem,1),m_sID);
		database.ExecuteSQL(sSQL,sSQL.GetLength());


		int cnt=(int)database.GetRowNum();
		if(cnt<=0)
		{
				CString charset="set names 'gb2312'";//使之正常显示中文,或用set character_set_results=gb2312;
		        database.ExecuteSQL(charset,charset.GetLength());//执行语句.
			sSQL.Format("insert into trans_duty (duty_NAME,trans_id) values('%s','%s')",
				m_ctrDutylist.GetItemText(nItem,1),m_sID);
			if(!database.ExecuteSQL(sSQL,sSQL.GetLength()))
			{
				AfxMessageBox("操作失败!");
				break;
			}
		}
	}
	CDialog::OnOK();
}

BOOL CDutyDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_ctrDutylist.InsertColumn(0,"ID",LVCFMT_CENTER,40,0);
	m_ctrDutylist.InsertColumn(1,"姓名",LVCFMT_CENTER,120,1);
	m_ctrDutylist.InsertColumn(2,"TEL",LVCFMT_CENTER,120,2);
	m_ctrDutylist.InsertColumn(3,"备注",LVCFMT_CENTER,100,3);
	
	m_ctrDutylist.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	bindduty();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDutyDlg::bindduty()
{
	m_ctrDutylist.DeleteAllItems();
	
	CDatabase1 database;	
	if(!database.ConnectDB())
	{
		return;
	}
	
	CString charset="set charset gb2312;";//使之正常显示中文,或用set character_set_results=gb2312;
	database.ExecuteSQL(charset,charset.GetLength());//执行语句.
	
	Data_Param result;		
	
	result.tab_name="duty_info";
	result.select_exp="duty_id,duty_name,duty_tel,remark";
	

	if(database.SelectAll(&result))
	{
		int count=(int)database.GetRowNum();			
		
		for(int i=0;i<count;i++)			
		{
			database.SeekData(i);				
			MYSQL_ROW row=database.GetRecord();
			
			m_ctrDutylist.InsertItem(i,row[0]);
			m_ctrDutylist.SetItemText(i,1,row[1]);
			m_ctrDutylist.SetItemText(i,2,row[2]);
			m_ctrDutylist.SetItemText(i,3,row[3]);
			
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -