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

📄 rptdlgspsgdh.cpp

📁 面向软件工程的Visual C++网络程序开发
💻 CPP
字号:
// RptDlgSpsgdh.cpp : implementation file
//

#include "stdafx.h"
#include "falcon_jxc.h"
#include "RptDlgSpsgdh.h"
#include "FALCON_JXCView.h"
#include "message.h"
#include "DinghuoMx.h"

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

/////////////////////////////////////////////////////////////////////////////
// CRptDlgSpsgdh dialog


CRptDlgSpsgdh::CRptDlgSpsgdh(CWnd* pParent /*=NULL*/)
	: CDialog(CRptDlgSpsgdh::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRptDlgSpsgdh)
	m_strBaobiaomingcheng = _T("");
	m_strBumen = _T("");
	m_strZhibiaoren = _T("");
	m_strZhibiaoriqi = _T("");
	//}}AFX_DATA_INIT
//Andrew--------------------------------------------------
	m_pView = NULL;
	m_iRow = 1;
	m_iSelectRow = 0;
	m_bSave = FALSE;
}

CRptDlgSpsgdh::CRptDlgSpsgdh(CFALCON_JXCView * pView)
{
	m_pView = pView;
	m_iRow = 1;
	m_iSelectRow = 0;
	m_bSave = FALSE;
}

BOOL CRptDlgSpsgdh::Create()
{
	return CDialog::Create(CRptDlgSpsgdh::IDD);
}
//----------------------------------------------------------

void CRptDlgSpsgdh::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRptDlgSpsgdh)
	DDX_Control(pDX, IDC_COMBO_BUMEN, m_ctrBumen);
	DDX_Text(pDX, IDC_BAOBIAOMINGCHENG, m_strBaobiaomingcheng);
	DDX_CBString(pDX, IDC_COMBO_BUMEN, m_strBumen);
	DDX_Control(pDX, IDC_MSFLEXGRID1, m_CMSFlexGrid);
	DDX_Text(pDX, IDC_ZHIBIAOREN, m_strZhibiaoren);
	DDX_Text(pDX, IDC_ZHIBIAORIQI, m_strZhibiaoriqi);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRptDlgSpsgdh, CDialog)
	//{{AFX_MSG_MAP(CRptDlgSpsgdh)
	ON_BN_CLICKED(IDC_TIANJIA, OnTianjia)
	ON_BN_CLICKED(IDC_SHANCHU, OnShanchu)
	ON_BN_CLICKED(IDC_BAOCUN, OnBaocun)
	ON_BN_CLICKED(IDC_PRT_PRINT, OnPrtPrint)
	ON_BN_CLICKED(IDC_TUICHU, OnTuichu)
	ON_CBN_KILLFOCUS(IDC_COMBO_BUMEN, OnKillfocusComboBumen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRptDlgSpsgdh message handlers

BOOL CRptDlgSpsgdh::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_CMSFlexGrid.SetRows(m_iRow);
	m_CMSFlexGrid.SetCols(10);
	m_CMSFlexGrid.SetTextMatrix(0,0,"商品编码");
	m_CMSFlexGrid.SetTextMatrix(0,1,"名称");
	m_CMSFlexGrid.SetTextMatrix(0,2,"单位");
 	m_CMSFlexGrid.SetTextMatrix(0,3,"规格");	
	m_CMSFlexGrid.SetTextMatrix(0,4,"型号");	
	m_CMSFlexGrid.SetTextMatrix(0,5,"供货商");	
	m_CMSFlexGrid.SetTextMatrix(0,6,"生产厂商");		
	m_CMSFlexGrid.SetTextMatrix(0,7,"订货价");	
	m_CMSFlexGrid.SetTextMatrix(0,8,"订货数量");	
	m_CMSFlexGrid.SetTextMatrix(0,9,"订货金额");	

	m_ctrBumen.AddString("圣地亚");
	m_ctrBumen.AddString("欧典");
	m_ctrBumen.AddString("南洋");
	m_ctrBumen.AddString("库房");
	m_ctrBumen.AddString("所有部门");
	m_ctrBumen.SetCurSel(0);

	int yy,mm,dd;
	CTime time=CTime::GetCurrentTime();
	CString str;	
	yy=time.GetYear();
	mm=time.GetMonth();
	dd=time.GetDay();
	str.Format("%d-%d-%d",yy,mm,dd);
	m_strZhibiaoriqi = str;
	UpdateData();
	m_strZhibiaoriqi = str;
	GetWindowText(m_strBaobiaomingcheng);
	m_strBaobiaomingcheng = m_strBumen + "-" + m_strBaobiaomingcheng;
	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CRptDlgSpsgdh::OnTianjia() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if (m_bSave)
	{
		m_iRow = 1;
		OnInitDialog();
	}

	CDinghuoMx dlg;
	CString str;
	if(dlg.DoModal() == IDOK)
	{
		if (dlg.m_strBianma == "")
		{
			return;
		}

		if (m_iRow != 1)
		{
			for(int i = 1; i < m_iRow; i++)
			{
				if(dlg.m_strBianma == m_CMSFlexGrid.GetTextMatrix(i,0))
				{
					AfxMessageBox("该编码商品已存在!");
					return;
				}
			}
		}
		m_iRow++;
		m_CMSFlexGrid.SetRows(m_iRow);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,0,dlg.m_strBianma);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,1,dlg.m_strMingcheng);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,2,dlg.m_strDanwei);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,3,dlg.m_strGuige);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,4,dlg.m_strXinghao);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,5,dlg.m_strGonghuoshang);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,6,dlg.m_strShengchanchangshang);
		str.Format("%.2f",dlg.m_fDinghuojia);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,7,str);
		str.Format("%d",dlg.m_iDinghuoshuliang);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,8,str);
		str.Format("%.2f",dlg.m_fDinghuojine);
		m_CMSFlexGrid.SetTextMatrix(m_iRow-1,9,str);
		m_bSave = FALSE;
	}
}

void CRptDlgSpsgdh::OnShanchu() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if (m_bSave)
	{
		AfxMessageBox("商品订货信息已保存,不能再删除!");
		m_iRow = 1;
		OnInitDialog();
		return;
	}

	CString str;

	if (m_iSelectRow >0)
	{	
		str = "是否删除商品"+m_CMSFlexGrid.GetTextMatrix(m_iSelectRow,0)+"?";
		if(AfxMessageBox(str,MB_YESNO) == IDYES)
		{
			if(m_iSelectRow == 1 && m_iRow == 2)
			{
				m_iRow--;
				m_CMSFlexGrid.SetRows(m_iRow);
			}
			else
			{
				m_CMSFlexGrid.RemoveItem(m_iSelectRow);
				m_iRow--;
				m_CMSFlexGrid.SetRows(m_iRow);
				m_CMSFlexGrid.Refresh();
			}
			UpdateData(FALSE);
			m_bSave = FALSE;
		}
	}
	else 
	{
		AfxMessageBox("请选择要删除的记录!");
		return;
	}
	m_iSelectRow=0;
}

void CRptDlgSpsgdh::OnBaocun() 
{
	// TODO: Add your control notification handler code here
	CFALCON_JXCDoc* pDoc = m_pView->GetDocument();

	UpdateData();

	if (m_bSave)
	{
		AfxMessageBox("所列商品订货信息已保存!");
//		m_iRow = 1;
//		OnInitDialog();
		return;
	}
	
	if(m_iRow == 1) 
	{
		AfxMessageBox("没有需保存的订货数据!");
		return;
	}

	
	if(m_CMSFlexGrid.GetTextMatrix(1,0) == "")
	{
		AfxMessageBox("无订货!");
		return;
	}

	if(pDoc->ConnectToServer())
	{

		pDoc->SendMsg("",1110);
	}
	else
		return;
a: 
	if(pDoc->m_b2110)
	{
	    m_sDingdanhao = pDoc->m_pMsg->ShortMessage;
		pDoc->m_b2110 = FALSE;
	}
	else
	{
		pDoc->ProcessReadMessage();
		goto a;
	}

	int iTemp = atoi(m_sDingdanhao);
	iTemp++;
	m_sDingdanhao.Format("%d",iTemp);

	CString strInsert="",strtemp="",str;
	int i,j;
	str.Format("%d",m_iRow-1);
	strInsert += str;
	strInsert += CHARFLAG;
	str.Format("%d",16);
	strInsert += str;
	strInsert += CHARFLAG;
	
	///////////////////////////////////转换日期格式
	int len = m_strZhibiaoriqi.GetLength();
	int Index = m_strZhibiaoriqi.Find("-");
	strtemp = m_strZhibiaoriqi.Mid(0,Index);
	str = m_strZhibiaoriqi.GetAt(Index+2);
	if(str == "-")
	{
		CString sMonth;
		sMonth = m_strZhibiaoriqi.GetAt(Index+1);
		int month = atoi(sMonth);
		sMonth.Format("0%d",month);
		strtemp += sMonth;
	}
	else
	{
		strtemp += m_strZhibiaoriqi.Mid(Index+1,2);
	}
	str = m_strZhibiaoriqi.GetAt(len-2);
	if(str == "-")
	{
		CString sDay;
		sDay = m_strZhibiaoriqi.GetAt(len-1);
		int day = atoi(sDay);
		sDay.Format("0%d",day);
		strtemp += sDay;
	}
	else
	{
		strtemp += m_strZhibiaoriqi.Mid(len-2,2);
	}
	m_strZhibiaoriqi = strtemp;
	/////////////////////////////////////////////
	
	for(i = 1 ; i < m_iRow; i++)
	{
		strInsert += m_sDingdanhao;
		strInsert += CHARFLAG;
		strInsert += m_strBumen;
		strInsert += CHARFLAG;
		for(j = 0; j < 10; j++)
		{
			strInsert += m_CMSFlexGrid.GetTextMatrix(i,j);
			strInsert += CHARFLAG;
		}
		strInsert += "";//当前库存
		strInsert += CHARFLAG;
		strInsert += "";//最小库存
		strInsert += CHARFLAG;
		strInsert+=m_strZhibiaoriqi;
		strInsert+=CHARFLAG;
		strInsert+=m_strZhibiaoren;
		strInsert+=CHARFLAG;
	}
	if(pDoc->ConnectToServer())
	{

		pDoc->SendMsg(strInsert,1111);//发送存储"订货单"请求
	}
	else
		return;

b:	if (pDoc->m_b2111)
	{
		pDoc->m_b2111 = FALSE;
		m_bSave = TRUE;
	}
	else
	{
		pDoc->ProcessReadMessage();
		goto b;
	}
	
}

void CRptDlgSpsgdh::OnPrtPrint() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CFALCON_JXCDoc* pDoc = m_pView->GetDocument();

	if(!m_bSave)
	{
		AfxMessageBox("请先保存订货信息!");
		return;
	}

	if (m_CMSFlexGrid.GetTextMatrix(1,0) == "")
	{
		AfxMessageBox("无可打印数据!");
		return ;
	}

	OnColSata();	//统计每列的最长字节串

	SendMessage(WM_COMMAND,ID_FILE_PRINT_PREVIEW);
	
//	m_strBumen = "";
//	m_strZhibiaoren = "";
//	for(int i=1;i<m_iRow;i++)
//	{
//		for(int j=0;j<10;j++)
//		{
//			m_CMSFlexGrid.SetTextMatrix(i,j,"");
//		}
//	}
//	UpdateData(FALSE);
}

void CRptDlgSpsgdh::OnTuichu() 
{
	// TODO: Add your control notification handler code here	
	if (m_bSave == FALSE && AfxMessageBox("尚未保存!是否退出?", MB_YESNO | MB_ICONQUESTION) == IDNO)
	{
		return;
	}
	else if(m_pView != NULL) 
		{
			m_pView->m_iPrtItem = -1;
			DestroyWindow();
		}	
		else
		{
			CDialog::OnOK();
 		}
	
}

BEGIN_EVENTSINK_MAP(CRptDlgSpsgdh, CDialog)
    //{{AFX_EVENTSINK_MAP(CRptDlgSpsgdh)
	ON_EVENT(CRptDlgSpsgdh, IDC_MSFLEXGRID1, -600 /* Click */, OnClickMsflexgrid1, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CRptDlgSpsgdh::OnClickMsflexgrid1() 
{
	// TODO: Add your control notification handler code here
	m_iSelectRow = m_CMSFlexGrid.GetRow();
}

void CRptDlgSpsgdh::OnColSata()	
{
	//Rows
	int iRows = m_CMSFlexGrid.GetRows()-1;
	if (iRows%20 != 0)
	{
		m_pView->m_iPageNum = int(iRows/20.0 + 1.0);	
	}
	else
	{
		m_pView->m_iPageNum = iRows/20;
	}
	
	//ColWidths
	m_pView->m_iAColWidth.RemoveAll();
	m_pView->m_iAColWidth.SetSize(m_CMSFlexGrid.GetCols());
	for (int i=0; i<m_CMSFlexGrid.GetCols(); i++)
	{
		int iMaxLen = 0;
		for (int j=0; j<m_CMSFlexGrid.GetRows(); j++)
		{
			int iLen = strlen(m_CMSFlexGrid.GetTextMatrix(j,i));
			iMaxLen = iMaxLen > iLen ? iMaxLen : iLen;
		}
			m_pView->m_iAColWidth.SetAt(i,iMaxLen);
	}	
//表格内容及字串	
//	CTime time;
//	int yy,mm,dd;
//	CString str;
	
//	m_ctrTimeQi.GetTime(time);	
//	yy =time.GetYear();
//	mm =time.GetMonth();
//	dd =time.GetDay();	
//	str.Format("%d-%d-%d",yy,mm,dd);
	m_pView->m_strTimeQi = "";
//
//	m_ctrTimeZhi.GetTime(time);
//	yy =time.GetYear();
//	mm =time.GetMonth();
//	dd =time.GetDay();	
//	str.Format("%d-%d-%d",yy,mm,dd);
	m_pView->m_strTimeZhi = "";

	m_pView->m_strBaobiaomingcheng = m_strBaobiaomingcheng;
	m_pView->m_strZhibiaoriqi = m_strZhibiaoriqi;
	m_pView->m_strZhibiaoren = m_strZhibiaoren;
	m_pView->m_CMSFlexGrid = &m_CMSFlexGrid;
}

void CRptDlgSpsgdh::OnOK() 
{
	//Dummy OnOk function!
}

void CRptDlgSpsgdh::OnCancel() 
{
	//Dummy OnCancel function!
}

void CRptDlgSpsgdh::OnKillfocusComboBumen() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	GetWindowText(m_strBaobiaomingcheng);
	m_strBaobiaomingcheng = m_strBumen + "-" + m_strBaobiaomingcheng;
	UpdateData(FALSE);	
}

⌨️ 快捷键说明

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