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

📄 dlgtraymanage.cpp

📁 用VC编写的立体仓库的管理软件源程序和设计说明书。
💻 CPP
字号:
// DlgTrayManage.cpp : implementation file
//

#include "stdafx.h"
#include "Manage_WH.h"
#include "DlgTrayManage.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgTrayManage dialog


CDlgTrayManage::CDlgTrayManage(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgTrayManage::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgTrayManage)
	m_code = _T("");
	m_height = _T("");
	m_lenght = _T("");
	m_width = _T("");
	//}}AFX_DATA_INIT
	m_iAddOrChange = 0;
	m_hIcon = AfxGetApp()->LoadIcon(IDI_MYICON);
}


void CDlgTrayManage::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgTrayManage)
	DDX_Control(pDX, IDCANCEL, m_ButExit);
	DDX_Control(pDX, IDC_UNDO, m_ButUndo);
	DDX_Control(pDX, IDC_SAVE, m_ButSave);
	DDX_Control(pDX, IDC_DEL, m_ButDel);
	DDX_Control(pDX, IDC_CHANGE, m_ButEdit);
	DDX_Control(pDX, IDC_ADD, m_ButAdd);
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Text(pDX, IDC_CODE, m_code);
	DDV_MaxChars(pDX, m_code, 100);
	DDX_Text(pDX, IDC_HEIGHT, m_height);
	DDV_MaxChars(pDX, m_height, 10);
	DDX_Text(pDX, IDC_LENGHT, m_lenght);
	DDV_MaxChars(pDX, m_lenght, 10);
	DDX_Text(pDX, IDC_WIDTH, m_width);
	DDV_MaxChars(pDX, m_width, 10);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgTrayManage, CDialog)
	//{{AFX_MSG_MAP(CDlgTrayManage)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_CHANGE, OnChange)
	ON_BN_CLICKED(IDC_DEL, OnDel)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_UNDO, OnUndo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgTrayManage message handlers

BOOL CDlgTrayManage::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message==WM_KEYDOWN && (pMsg->wParam==13 || pMsg->wParam==27))
		return TRUE;
	return CDialog::PreTranslateMessage(pMsg);
}

BOOL CDlgTrayManage::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	SetIcon(m_hIcon,TRUE);

	m_list.InsertColumn(0,"托盘条形码",LVCFMT_LEFT,120,-1);
	m_list.InsertColumn(1,"托盘长度",LVCFMT_LEFT,90,-1);
	m_list.InsertColumn(2,"托盘宽度",LVCFMT_LEFT,90,-1);
	m_list.InsertColumn(3,"托盘高度",LVCFMT_LEFT,90,-1);
	m_list.InsertColumn(4,"托盘状态",LVCFMT_LEFT,90,-1);
	m_list.SetExtendedStyle( LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT );
	Refresh();
	return TRUE;
}

void CDlgTrayManage::Refresh()
{
	CString sVal;
	CAdoConnection cn;
	CAdoRecordSet  rs;
	cn.OpenUDLFile(gstrConSQLSer);
	rs.SetAdoConnection(&cn);
	rs.Open("select F_Index,F_Lenght,F_Width,F_Height,F_State from T_Salver_Manage",adCmdText);
	if (rs.GetRecordCount() > 0)
	{
		rs.MoveFirst();
		int row = 0;
		m_list.DeleteAllItems();
		m_list.SetRedraw(FALSE);
		while (!rs.IsEOF())
		{
			row = m_list.InsertItem(row,"");			
			for (int i = 0; i < 5; i++)
			{
				rs.GetCollect(i,sVal);
				m_list.SetItemText(row,i,sVal);
			}			
			rs.MoveNext();
			row++;
		}
		m_list.SetRedraw(TRUE);
	}
	rs.Close();
	cn.Close();
}

void CDlgTrayManage::Enabled(BOOL bEnabled)
{
	m_list.EnableWindow(!bEnabled);
	static_cast<CComboBox *>(GetDlgItem(IDC_STATUS))->EnableWindow(bEnabled);
	static_cast<CEdit *>(GetDlgItem(IDC_CODE))->EnableWindow(bEnabled);
	static_cast<CEdit *>(GetDlgItem(IDC_LENGHT))->EnableWindow(bEnabled);
	static_cast<CEdit *>(GetDlgItem(IDC_WIDTH))->EnableWindow(bEnabled);
	static_cast<CEdit *>(GetDlgItem(IDC_HEIGHT))->EnableWindow(bEnabled);
	m_ButUndo.EnableWindow(bEnabled);
	m_ButSave.EnableWindow(bEnabled);
	m_ButExit.EnableWindow(!bEnabled);
	m_ButDel.EnableWindow(!bEnabled);
	m_ButEdit.EnableWindow(!bEnabled);
	m_ButAdd.EnableWindow(!bEnabled);
}

void CDlgTrayManage::ClearFrom()
{
	static_cast<CEdit *>(GetDlgItem(IDC_CODE))->SetWindowText("");
	static_cast<CEdit *>(GetDlgItem(IDC_LENGHT))->SetWindowText("");
	static_cast<CEdit *>(GetDlgItem(IDC_WIDTH))->SetWindowText("");
	static_cast<CEdit *>(GetDlgItem(IDC_HEIGHT))->SetWindowText("");
	static_cast<CComboBox *>(GetDlgItem(IDC_STATUS))->SetCurSel(-1);
}

void CDlgTrayManage::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	for (int i=0;i<m_list.GetItemCount();i++)
	{
		if (m_list.GetItemState(i,LVIS_SELECTED) == LVIS_SELECTED)
		{
			static_cast<CEdit *>(GetDlgItem(IDC_CODE))->SetWindowText(m_list.GetItemText(i,0));
			static_cast<CEdit *>(GetDlgItem(IDC_LENGHT))->SetWindowText(m_list.GetItemText(i,1));
			static_cast<CEdit *>(GetDlgItem(IDC_WIDTH))->SetWindowText(m_list.GetItemText(i,2));
			static_cast<CEdit *>(GetDlgItem(IDC_HEIGHT))->SetWindowText(m_list.GetItemText(i,3));
			static_cast<CComboBox *>(GetDlgItem(IDC_STATUS))->SetCurSel(static_cast<CComboBox *>(GetDlgItem(IDC_STATUS))->FindString(-1,m_list.GetItemText(i,4)));
			break;
		}
	}
	*pResult = 0;
}

void CDlgTrayManage::OnAdd() 
{
	ClearFrom();
	Enabled(true);
	m_iAddOrChange=1;	
}

void CDlgTrayManage::OnChange() 
{
	UpdateData(TRUE);
	if (m_code.IsEmpty())
	{
		MessageBox("请在列表中选择要修改的托盘!","系统提示",MB_ICONSTOP|MB_OK);
		return;
	}
	Enabled(true);
	static_cast<CEdit *>(GetDlgItem(IDC_CODE))->EnableWindow(false);	
	m_iAddOrChange=2;		
}

void CDlgTrayManage::OnDel() 
{
	UpdateData(TRUE);
	if (m_code.IsEmpty())
	{
		MessageBox("请在列表中选择要删除的托盘!\n","系统提示",MB_ICONSTOP|MB_OK);
		return;
	}
	if (gstrPopedom == "普通用户")
	{
		MessageBox("对不起,您没有执行删除操作的权限!","系统提示",MB_ICONSTOP|MB_OK);
		return;
	}

	if (MessageBox("是否删除条码为["+m_code+"]的托盘信息?","系统提示",MB_ICONINFORMATION|MB_YESNO) == IDNO)
		return;
	
	CAdoConnection cn;
	cn.Execute("delete from T_Salver_Manage where F_Index = '"+m_code+"'",adCmdText);
	cn.Close();
	AddLog("删除条码为["+m_code+"]的托盘信息");
	Enabled(false);
	ClearFrom();
	Refresh();
}

void CDlgTrayManage::OnSave() 
{
	UpdateData(TRUE);
	if(MessageBox("确定要保存"+m_code+"的信息吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
		return;
	//取出文本框中的值
	CAdoConnection cn;
	CString sSQL,sStatus,sWarning;
	
	static_cast<CComboBox *>(GetDlgItem(IDC_STATUS))->GetWindowText(sStatus);

	if (m_code.IsEmpty())					sWarning = "托盘条码不能为空,请输入!";
	else if (sStatus.IsEmpty())				sWarning = "托盘状态不能为空,请选择!";
	else if (m_iAddOrChange==1 && IsHave(m_code))	sWarning = "编号["+m_code+"]的托盘信息已存在!";
	
	if (!sWarning.IsEmpty())
	{
		MessageBox(sWarning,"系统提示",MB_ICONSTOP|MB_OK);
		return;
	}

	switch(m_iAddOrChange)
	{
	case 1:
		sSQL="INSERT INTO T_Salver_Manage(F_Index,F_Lenght,F_Width,F_Height,F_State) VALUES('"+m_code+"','"+m_lenght+"','"+m_width+"','"+m_height+"','"+sStatus+"')";
		break;
	case 2:
		sSQL="UPDATE T_Salver_Manage SET F_Lenght='"+m_lenght+"',F_Width='"+m_width+"',F_Height='"+m_height+"',F_State='"+sStatus+"' WHERE F_Index='"+m_code+"'";
		break;
	}
	
	if (cn.OpenUDLFile(gstrConSQLSer))
	{
		cn.Execute(sSQL,adCmdText);
		cn.Close();
		switch(m_iAddOrChange)
		{
		case 1:
			AddLog("添加新托盘["+m_code+"]的信息");
			MessageBox("信息添加成功!","系统提示",MB_ICONINFORMATION|MB_OK);
			break;
		case 2:
			AddLog("修改托盘["+m_code+"]的信息!");
			MessageBox("信息修改成功!","系统提示",MB_ICONINFORMATION|MB_OK);
			break;
		}
		Enabled(false);
		ClearFrom();
		Refresh();
	}
	else
	{
		MessageBox("数据库连接失败!","系统提示",MB_ICONSTOP|MB_OK);
	}	
}

BOOL CDlgTrayManage::IsHave(const CString &m_trayCode)
{
	BOOL bHave = FALSE;
	CAdoConnection cn;
	CAdoRecordSet  rs;
	cn.OpenUDLFile(gstrConSQLSer);
	rs.SetAdoConnection(&cn);
	rs.Open("select * from T_Salver_Manage where F_Index='"+m_trayCode+"'",adCmdText);
	if (rs.GetRecordCount() != 0)
		bHave = TRUE;
	rs.Close();
	cn.Close();
	return bHave;
}

void CDlgTrayManage::OnUndo() 
{
	ClearFrom();
	Enabled(false);
	Refresh();	
}

⌨️ 快捷键说明

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