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

📄 totalquotemandlg.cpp

📁 这是一个功能相对完善的电脑报价管理系统 的一个例子
💻 CPP
字号:
// TotalQuoteManDlg.cpp : implementation file
//

#include "stdafx.h"
#include "QuoteManage.h"
#include "TotalQuoteManDlg.h"
#include "TotalQuote.h"
#include "QuoteManDlg.h"
#include "COMDEF.H"
#include "Columns.h"
#include "Column.h"
#include "_Recordset.h"

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

extern CUserInfo curUser;

/////////////////////////////////////////////////////////////////////////////
// CTotalQuoteManDlg dialog


CTotalQuoteManDlg::CTotalQuoteManDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTotalQuoteManDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTotalQuoteManDlg)
	//}}AFX_DATA_INIT
}


void CTotalQuoteManDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTotalQuoteManDlg)
	DDX_Control(pDX, IDC_ADODC1, m_Adodc);
	DDX_Control(pDX, IDC_DATAGRID1, m_Datagrid);
	DDX_Control(pDX, IDC_ADODC2, m_AdoCust);
	DDX_Control(pDX, IDC_DATACOMBO1, m_Cust);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTotalQuoteManDlg, CDialog)
	//{{AFX_MSG_MAP(CTotalQuoteManDlg)
	ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
	ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton)
	ON_BN_CLICKED(IDC_SUBMIT_BUTTON, OnSubmitButton)
	ON_BN_CLICKED(IDC_DETAIL_BUTTON, OnDetailButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTotalQuoteManDlg message handlers

BOOL CTotalQuoteManDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	RefreshData();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTotalQuoteManDlg::RefreshData()
{
	UpdateData(TRUE);	
	// 设置Select语句
	CString cSource;
	cSource = "SELECT t.TId AS 装机编号,c.Name AS 客户姓名,c.Mobile AS 手机电话,"
		" ISNULL(d.Num, 0) AS 配件数量,ISNULL(d.Total, 0.0) AS 总价, "
		" t.IsSubmit AS 是否成交, t.FitTime AS 装机时间"
		" FROM TotalQuote t INNER JOIN CustomerInfo c ON t.CustomerId = c.CustomerId"
		" LEFT OUTER JOIN (SELECT TId, SUM(Num) AS Num, SUM(SubTotal) AS Total "
		" FROM DetailQuote GROUP BY TId) d ON t.TId = d.TId";
	
	// 条件
	if(m_Cust.GetText() != "")
		cSource += " WHERE c.CustomerId = " + m_Cust.GetBoundText();

	//刷新ADO Data控件的记录源
	m_Adodc.SetRecordSource(cSource);
	m_Adodc.Refresh();
	
	//设置列宽度
	_variant_t vIndex;
	vIndex = long(0);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(50);
	vIndex = long(1);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(2);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(70);
	vIndex = long(3);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(50);
	vIndex = long(4);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(50);
	vIndex = long(5);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
	vIndex = long(6);
	m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
}

// 添加
void CTotalQuoteManDlg::OnAddButton() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	if(m_Cust.GetText() == "")
	{
		MessageBox("请选择一个客户!");
		return;
	}

	// 填写总单信息
	CTotalQuote cur;
	cur.CustomerId = atol(m_Cust.GetBoundText());
	CTime CurrentTime = CTime::GetCurrentTime();
	cur.FitTime = CurrentTime.Format("%Y-%m-%d");
	cur.SqlInsert();
	RefreshData();
}

// 详单按钮
void CTotalQuoteManDlg::OnDetailButton() 
{
	// TODO: Add your control notification handler code here
	if (m_Adodc.GetRecordset().GetEof()) 
	{
		MessageBox("请选择要查看详单的记录");
		return;
	}

	CQuoteManDlg dlg;
	dlg.cTId = m_Datagrid.GetItem(0);
	dlg.m_Id = m_Datagrid.GetItem(0);
	dlg.m_customer = m_Datagrid.GetItem(1);
	dlg.m_tel = m_Datagrid.GetItem(2);
	dlg.m_num = m_Datagrid.GetItem(3);
	dlg.m_price = m_Datagrid.GetItem(4);
	dlg.m_FitTime = m_Datagrid.GetItem(6);
	dlg.m_user = curUser.UserName;
	if(m_Datagrid.GetItem(5) == "是")
		dlg.IsSubmit = true;
	else
		dlg.IsSubmit = false;
	// 打开对话框
	dlg.DoModal();
	// 刷新
	RefreshData();
}

// 删除
void CTotalQuoteManDlg::OnDelButton() 
{
	// TODO: Add your control notification handler code here
	if (m_Adodc.GetRecordset().GetEof()) 
	{
		MessageBox("请选择要删除的记录");
		return;
	}

	if (MessageBox("是否删除当前记录?","请确认", MB_YESNO + MB_ICONQUESTION) == IDYES)
	{
		CTotalQuote cur;
		// 判断是否存在详单
		if(cur.HaveDetail(m_Datagrid.GetItem(0)))
		{
			MessageBox("此记录还有详单,不能删除");
			return;
		}

		// 删除
		cur.SqlDelete(m_Datagrid.GetItem(0));
		RefreshData();
	}
}

// 成交按钮
void CTotalQuoteManDlg::OnSubmitButton() 
{
	// TODO: Add your control notification handler code here
	if (m_Adodc.GetRecordset().GetEof()) 
	{
		MessageBox("请选择要成交的记录");
		return;
	}

	// 判断所选择的记录是否已经成交
	if(m_Datagrid.GetItem(5) == "是")
	{
		MessageBox("此笔记录已经成交");
		return;
	}

	// 更新信息
	UpdateData(TRUE);
	CTotalQuote cur;

	// 判断是否有详单
	if(!cur.HaveDetail(m_Datagrid.GetItem(0)))
	{
		MessageBox("还未填详单,不能成交此笔记录");
		return;
	}

	cur.IsSubmit = "是";

	if((MessageBox("是否成交?","请确认", MB_YESNO + MB_ICONQUESTION) == IDYES))
	{
		// 修改状态
		cur.SqlUpdateSubmit(m_Datagrid.GetItem(0));
		RefreshData();
		MessageBox("成交成功,请付款!");
	}
}

BEGIN_EVENTSINK_MAP(CTotalQuoteManDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CTotalQuoteManDlg)
	ON_EVENT(CTotalQuoteManDlg, IDC_DATACOMBO1, -600 /* Click */, OnClickDatacombo1, VTS_I2)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CTotalQuoteManDlg::OnClickDatacombo1(short Area) 
{
	// TODO: Add your control notification handler code here
	RefreshData();
}

⌨️ 快捷键说明

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