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

📄 commucationview.cpp

📁 一个可以控制单片机根据通话时间和所拨地区进行计费的软件!
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// CommucationView.cpp : implementation of the CCommucationView class
//

#include "stdafx.h"
#include "Commucation.h"
#include "process.h"                           

#include "CommucationDoc.h"
#include "CommucationView.h"
#include "SelectDialog.h"
#include "PriceDialog.h"
#include "WarnDialog.h"
#include "ManagerDialog.h"
#include "ReportDialog.h"
#include "Search.h"
#include "Modifypasswd.h"
#include "Login.h"
#include "UserManage.h"
#include "Dayreport.h"
#include "MonthReport.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCommucationView

IMPLEMENT_DYNCREATE(CCommucationView, CFormView)

BEGIN_MESSAGE_MAP(CCommucationView, CFormView)
	//{{AFX_MSG_MAP(CCommucationView)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_COMMAND(ID_PRICE_SET, OnPriceSet)
	ON_BN_CLICKED(IDC_BUTTON16, OnButton16)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
	ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
	ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
	ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
	ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
	ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
	ON_BN_CLICKED(IDC_BUTTON15, OnButton15)
	ON_COMMAND(ID_REPORT_PRINT, OnReportPrint)
	ON_UPDATE_COMMAND_UI(ID_REPORT_PRINT, OnUpdateReportPrint)
	ON_COMMAND(ID_VIEW, OnView)
	ON_WM_PAINT()
	ON_WM_CTLCOLOR()
	ON_COMMAND(ID_VIEW_INFO, OnViewInfo)
	ON_WM_DESTROY()
	ON_COMMAND(ID_MODIFY_PASSWD, OnModifyPasswd)
	ON_COMMAND(ID_USER_MANAGER, OnUserManager)
	ON_COMMAND(ID_DAY_REPORT, OnDayReport)
	ON_COMMAND(ID_MONTH_REPORT, OnMonthReport)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_MESSAGE(WM_NEW_MESSAGE,OnNewMessage)
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCommucationView construction/destruction

CCommucationView::CCommucationView()
	: CFormView(CCommucationView::IDD)
{
	//{{AFX_DATA_INIT(CCommucationView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here
	//测试参数
	YearPos=1000;
	DayPos=1000;
	AndTotal=1000;
	RateNum=1000;

	CStdioFile file;
	CString filename;
	for(int i=0;i<16;i++)
	{
		total[i]=0;
		accumulator[i]=0;
		accumulate[i]=0;
		m_Force[i]=FALSE;
	}

	filename="code.txt";
	if(file.Open(filename,CFile::modeRead|CFile::typeText)==0)
	{
		AfxMessageBox("failure");
	}
	
	CString temp;
	temp="";
	CodeAmount=0;
	while(temp!="end")
	{
		CodeAmount+=1;
		file.ReadString(temp);
		code[CodeAmount]=temp;		
	}
	CodeAmount-=1;
	file.Close();

	filename="fee.txt";
	if(file.Open(filename,CFile::modeRead|CFile::typeText)==0)
	{
		AfxMessageBox("failure");
	}
	temp="";
	FeeAmount=0;
	while(temp!="end")
	{
		FeeAmount+=1;
		file.ReadString(temp);
		Fee[FeeAmount]=temp.Left(2);		
	}
	FeeAmount-=1;
	file.Close();

	SendLen=0;

	//给Button控件赋初值
	iButton[0]=1046;
	iButton[1]=1001;
	iButton[2]=1002;
	iButton[3]=1003;
	for(i=4;i<=14;i++)
	{
		iButton[i]=1026+i;
	}
	iButton[15]=1029;
	//给号码控件赋初值
	iTele[0]=1004;
	iTele[1]=1009;
	iTele[2]=1010;
	iTele[3]=1011;
	for(i=4;i<=8;i++)
	{
		iTele[i]=1020+i;
	}
	for(i=9;i<=13;i++)
	{
		iTele[i]=1032+i;
	}
	iTele[14]=1047;
	iTele[15]=1048;
	//起始时间付出值
	iStart[0]=1005;
	iStart[1]=1012;
	iStart[2]=1013;
	iStart[3]=1014;
	for(i=4;i<=15;i++)
	{
		iStart[i]=1045+i;
	}
	//通话时间
	iTime[0]=1006;
	iTime[1]=1015;
	iTime[2]=1016;
	iTime[3]=1017;
	for(i=4;i<=11;i++)
	{
		iTime[i]=1057+i;
	}
	for(i=12;i<=15;i++)
	{
		iTime[i]=1058+i;
	}
	//费用
	iSpend[0]=1007;
	iSpend[1]=1018;
	iSpend[2]=1019;
	iSpend[3]=1020;
	for(i=4;i<=15;i++)
	{
		iSpend[i]=1070+i;
	}
	//押金
	iRemain[0]=1008;
	iRemain[1]=1021;
	iRemain[2]=1022;
	iRemain[3]=1023;
	for(i=4;i<=15;i++)
	{
		iRemain[i]=1082+i;
	}

	LOGFONT lf;
	lf.lfHeight=47;
	lf.lfWidth=0;
	lf.lfEscapement=0;
	lf.lfOrientation=0;
	lf.lfWeight=FW_NORMAL;
	lf.lfItalic=FALSE;
	lf.lfUnderline=FALSE;
	lf.lfStrikeOut=FALSE;
	lf.lfCharSet=GB2312_CHARSET;
	lf.lfOutPrecision=OUT_STROKE_PRECIS;
	lf.lfClipPrecision=CLIP_STROKE_PRECIS;
	lf.lfQuality=DRAFT_QUALITY;
	lf.lfPitchAndFamily=VARIABLE_PITCH|FF_MODERN;
	strcpy(lf.lfFaceName,"黑体");

	myFont1.CreateFontIndirect(&lf);
	lf.lfHeight=25;
	myFont2.CreateFontIndirect(&lf);

	m_Initial=TRUE;
	test=2;
	NumFlag="";
	SerialNum=0;
	ComIsOpen=FALSE;

	CString str;
	filename="Phone.txt";
	if(file.Open(filename,CFile::modeRead|CFile::typeText)==0)
	{
		AfxMessageBox("failure");
	}    	

	for(i=0;i<16;i++)
	{
		m_Retry[i]=TRUE;
		m_Repeat[i]=TRUE;
		m_Rept[i]=TRUE;
		file.Seek(258+9*i,CFile::begin);
		file.ReadString(str);
		sscanf(str,"%f",&m_Money[i]);
		Clear[i]=FALSE;
	}
	file.Close();
	m_IsRece=0;
	info="";
	for(i=0;i<16;i++)
	{
		Code[i]="";
		backup[i]=0;
	}
	ComIsOpen=FALSE;
	m_IsView=0;
	try
	{	
    	m_pDB.Open("C:\\WINDOWS\\SYSTEM\\record.mdb");
	}
	catch(CDaoException*e)
	{
		DisplayDaoException(e);
		e->Delete();
	}

}

CCommucationView::~CCommucationView()
{
}

void CCommucationView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCommucationView)
	DDX_Control(pDX, IDC_BUTTON9, m_Bitmap9);
	DDX_Control(pDX, IDC_BUTTON8, m_Bitmap8);
	DDX_Control(pDX, IDC_BUTTON7, m_Bitmap7);
	DDX_Control(pDX, IDC_BUTTON6, m_Bitmap6);
	DDX_Control(pDX, IDC_BUTTON5, m_Bitmap5);
	DDX_Control(pDX, IDC_BUTTON4, m_Bitmap4);
	DDX_Control(pDX, IDC_BUTTON16, m_Bitmap16);
	DDX_Control(pDX, IDC_BUTTON15, m_Bitmap15);
	DDX_Control(pDX, IDC_BUTTON14, m_Bitmap14);
	DDX_Control(pDX, IDC_BUTTON13, m_Bitmap13);
	DDX_Control(pDX, IDC_BUTTON12, m_Bitmap12);
	DDX_Control(pDX, IDC_BUTTON11, m_Bitmap11);
	DDX_Control(pDX, IDC_BUTTON10, m_Bitmap10);
	DDX_Control(pDX, IDC_BUTTON3, m_Bitmap3);
	DDX_Control(pDX, IDC_BUTTON2, m_Bitmap2);
	DDX_Control(pDX, IDC_BUTTON1, m_Bitmap1);
	//}}AFX_DATA_MAP
}

BOOL CCommucationView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CCommucationView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	GetDocument()->SetPathName(_T("坤威电子"));

/*	CDaoRecordset rs(&m_pDB);
	COleVariant varValue;
	CString str;
	CString month;
	long year;
	month.Format("%d",system.GetMonth());
	str="select * from years where name='"+month+"'";
	try
	{
		rs.Open(dbOpenDynaset,str);
	}
	catch(CDaoException* e)
	{
		DisplayDaoException(e);
		e->Delete();
	}
	try
	{
    	varValue=rs.GetFieldValue("year");
        year=varValue.iVal;
	}
    catch(CDaoException* e)
	{
	   	DisplayDaoException(e);
	   	e->Delete();
	}
	if(year!=system.GetYear())
	{
		rs.Edit();
		year=system.GetYear();
		varValue=COleVariant(year,VT_I4);
		rs.SetFieldValue("year",varValue);
		try
		{
			rs.Update();
		}
		catch(CDaoException* e)
		{
		 	DisplayDaoException(e);
		  	e->Delete();
		}
		if(rs.IsOpen())
			rs.Close();

		str="select * from "+month;
		try
		{
			rs.Open(dbOpenDynaset,str);
		}
		catch(CDaoException* e)
		{
			DisplayDaoException(e);
			e->Delete();
		}
		while(!rs.IsEOF())
		{
			rs.Delete();
			rs.MoveNext();
		}
		if(rs.IsOpen())
			rs.Close();
	}*/

	hClose=::LoadBitmap(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDB_CLOSE));
	hOpen=::LoadBitmap(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDB_OPEN));
	hChat=::LoadBitmap(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDB_CHAT));
	hDial=::LoadBitmap(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDB_DIAL));
	hCounter=::LoadBitmap(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDB_COUNTER));
	hAlarm=::LoadBitmap(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDB_ALARM));

	if(!ComIsOpen)
	{
		CFileException e;
		if(m_serial.OpenCOM(
		        1,			// COM number (1,2,etc.)
		    	&e,			// exception errors (defaults to NULL)
		        CBR_9600,	// baud rate, also CBR_1200, CBR_2400, etc.
			    NOPARITY,	// parity, also EVENPARITY, ODDPARITY, MARKPARITY, SPACEPARITY
				8,			// number of bits in a byte
	        	ONESTOPBIT // stopbits, also ONE5STOPBITS, TWOSTOPBITS
		        ))
		{
			m_serial.Listen(
				226,			// size of message header
         		this,		// pWnd of window to send "new message" message
			  	WM_NEW_MESSAGE  // message to send
        		);	
		    ComIsOpen=TRUE;			
			timerID=SetTimer(1,500,NULL);
		}
		else
    		ComIsOpen=FALSE;
	}
	else
	{
		AfxMessageBox("端口已经打开");
	}
}

/////////////////////////////////////////////////////////////////////////////
// CCommucationView printing

BOOL CCommucationView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	pInfo->m_bDirect=true;
	return DoPreparePrinting(pInfo);
}

void CCommucationView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CCommucationView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CCommucationView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
	// TODO: add customized printing code here
	int i,j;
	CTime systime=CTime::GetCurrentTime();
	CString str,temp;
	int number,adder;
	//
	if(m_Report==1)
	{
    	CStdioFile file;
    	CString filename;
    	filename="Phone.txt";
    	if(file.Open(filename,CFile::modeReadWrite|CFile::typeText)==0)
		{
    		AfxMessageBox("failure");
		}
		int count;
		float total;
		float addtion;
		//打印日期
		str=systime.Format("%B %d,%Y    %H:%M:%S");
		pDC->TextOut(0,80,str);
		//打印流水号
		CFont* pOldFont;
    	pOldFont=pDC->SelectObject(&myFont2);

		int Serial1,Serial2;
		file.Seek(245,CFile::begin);
		file.ReadString(str);
		sscanf(str.Left(6),"%d",&Serial1);
		sscanf(str.Mid(7,4),"%d",&Serial2);
		Serial1=Serial1-Serial2+1;
		temp.Format("%d",Serial1);
		number=6-temp.GetLength();
		for(i=0;i<number;i++)
		{
	    	temp="0"+temp;
		}
    	str="流水号:  "+temp+"——"+str.Left(6);
    	pDC->TextOut(500,80,str);
		file.Seek(252,CFile::begin);
		file.Write("0000",4);
		//打印列标题
		pDC->TextOut(250,120,"消号(次)     通话次数(次)     通话时间(分)     话单附加费(元)     合计(元)");    	
		//打印行标题
		pDC->TextOut(0,170,"********国际    :");
		pDC->TextOut(0,210,"********香港    :");
		pDC->TextOut(0,250,"********澳门    :");
		pDC->TextOut(0,290,"********台湾    :");
		pDC->TextOut(0,330,"********长途    :");
		pDC->TextOut(0,370,"********市内    :");
		pDC->TextOut(0,410,"********小区    :");
		pDC->TextOut(0,450,"********总计    :");
		//
		CString final;
		count=0;
		total=0;
		for(i=0;i<7;i++)
		{
			file.Seek(35*i,CFile::begin);
			file.ReadString(str);
			sscanf(str.Left(4),"%d",&adder);
			count+=adder;
			sscanf(str.Mid(5,8),"%d",&adder);
			adder=adder/60;
			temp.Format("%d",adder);
			number=6-temp.GetLength();
			for(j=0;j<number;j++)
			{
				temp="0"+temp;
			}
			final="             "+str.Left(4)+"             "+temp+"           ";
			final=final+str.Mid(14,9)+"         "+str.Mid(24,9);
			pDC->TextOut(250,180+40*i,final);
			sscanf(str.Mid(24,9),"%f",&addtion);
			total+=addtion;
		}
		temp.Format("%d",count);
		number=4-temp.GetLength();
		for(j=0;j<number;j++)
		{
			temp="0"+temp;
		}
		pDC->TextOut(418,450,temp);
		temp.Format("%9.2f",total);
		temp.TrimLeft();
		number=9-temp.GetLength();

⌨️ 快捷键说明

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