toolother.cpp
来自「基于SQLSERVER2000的机械工艺数据库系统」· C++ 代码 · 共 511 行 · 第 1/2 页
CPP
511 行
// TOOLOTHER.cpp : implementation file
//
#include "stdafx.h"
#include "KNC_MIS.h"
#include "TOOLOTHER.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTOOLOTHER dialog
CTOOLOTHER::CTOOLOTHER(CWnd* pParent /*=NULL*/)
: CDialog(CTOOLOTHER::IDD, pParent)
{
//{{AFX_DATA_INIT(CTOOLOTHER)
m_sTooltype = _T("");
m_sToolID = _T("");
m_sOtherbrand = _T("");
m_sPath = _T("");
m_sOthername = _T("");
m_sOthermaterial = _T("");
m_sFormaterial = _T("");
m_sProducer = _T("");
//}}AFX_DATA_INIT
}
void CTOOLOTHER::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTOOLOTHER)
DDX_Control(pDX, IDC_LIST2, m_Otherlist);
DDX_CBString(pDX, IDC_COMBO1, m_sTooltype);
DDX_Text(pDX, IDC_EDIT1, m_sToolID);
DDX_Text(pDX, IDC_EDIT12, m_sOtherbrand);
DDX_Text(pDX, IDC_EDIT17, m_sPath);
DDX_Text(pDX, IDC_EDIT2, m_sOthername);
DDX_Text(pDX, IDC_EDIT3, m_sOthermaterial);
DDX_Text(pDX, IDC_EDIT5, m_sFormaterial);
DDX_Text(pDX, IDC_EDIT6, m_sProducer);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTOOLOTHER, CDialog)
//{{AFX_MSG_MAP(CTOOLOTHER)
ON_BN_CLICKED(IDC_OthertoolAdd, OnOthertoolAdd)
ON_BN_CLICKED(IDC_OthertoolBrowse, OnOthertoolBrowse)
ON_BN_CLICKED(IDC_OthertoolDelete, OnOthertoolDelete)
ON_BN_CLICKED(IDC_OthertoolModify, OnOthertoolModify)
ON_BN_CLICKED(IDC_OthertoolSave, OnOthertoolSave)
ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTOOLOTHER message handlers
void CTOOLOTHER::OnOthertoolAdd()
{
// TODO: Add your control notification handler code here
UpdateData(true);
m_sOtherbrand="";
m_sTooltype="";
m_sOthermaterial="";
m_sOthername="";
m_sFormaterial="";
m_sPath="";
m_sProducer="";
m_sToolID="";
tx_Otherbrand->EnableWindow(true);
tx_Tooltype->EnableWindow(true);
tx_Othermaterial->EnableWindow(true);
tx_Othername->EnableWindow(true);
tx_Formaterial->EnableWindow(true);
tx_Path->EnableWindow(true);
tx_Producer->EnableWindow(true);
tx_ToolID->EnableWindow(true);
flag=1;
bt_save->EnableWindow(true);
bt_add->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_delete->EnableWindow(false);
bt_browse->EnableWindow(true);
UpdateData(false);
}
void CTOOLOTHER::OnOthertoolBrowse()
{
// TODO: Add your control notification handler code here
UpdateData(true);
static char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
CFileDialog dlg(TRUE,"BMP",NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
if(dlg.DoModal() != IDOK)
return;
CString pathname = dlg.GetPathName();
m_sPath=dlg.GetPathName();
UpdateData(false);
char *m_pBuffer; //从BMP文件中读取的数据存放在此变量中
//@@@@@@@@@@ 读取BMP文件到m_pBuffer @@@@@@@@@@
CFile file; //定义文件对象
if( !file.Open(pathname, CFile::modeRead)) //以只读方式打开文件
{
MessageBox("无法打开BMP文件");
return;
}
DWORD m_filelen; //用于保存文件长度
m_filelen = file.GetLength(); //读取文件长度
m_pBuffer = new char[m_filelen + 1]; //根据文件长度分配数组空间
if(!m_pBuffer) //如果不空间不足则返回
{
MessageBox("无法分配足够的内存空间");
return;
}
if(file.ReadHuge(m_pBuffer, m_filelen) != m_filelen) //读取BMP文件到m_pBuffer中
{
MessageBox("读取BMP文件时出现错误");
return;
}
//@@@@@@@@@@ 将BMP文件数据从m_pBuffer中转换到m_hBitMap位图句柄中
LPSTR hDIB;
LPVOID lpDIBBits;
BITMAPFILEHEADER bmfHeader; //用于保存BMP文件头信息,包括类型、大小、位移量等
DWORD bmfHeaderLen; //保存文件头的长度
bmfHeaderLen = sizeof(bmfHeader); //读取文件头的长度
//将m_pBuffer中文件头复制到bmfHeader中
strncpy((LPSTR)&bmfHeader, (LPSTR)m_pBuffer, bmfHeaderLen);
if (bmfHeader.bfType != (*(WORD*)"BM")) //如果文件类型不对,则返回
{
MessageBox("BMP文件格式不准确");
return;
}
hDIB = m_pBuffer + bmfHeaderLen; //将指针移至文件头后面
//读取BMP文件的图像数据,包括坐标及颜色格式等信息到BITMAPINFOHEADER对象
BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB;
//读取BMP文件的图像数据,包括坐标及颜色格式等信息到BITMAPINFO对象
BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ;
//根据bfOffBits属性将指针移至文件头后
lpDIBBits = (m_pBuffer) + ((BITMAPFILEHEADER *)m_pBuffer)->bfOffBits;
CClientDC dc(this); //生成一个与当前窗口相关的CClientDC,用于管理输出设置
//生成DIBitmap数据
m_hBitmap = CreateDIBitmap(dc.m_hDC,&bmiHeader,CBM_INIT,lpDIBBits,&bmInfo,DIB_RGB_COLORS);
//激活OnPaint()函数,显示图像
Invalidate();
}
void CTOOLOTHER::OnOthertoolDelete()
{
// TODO: Add your control notification handler code here
// Del Records
_variant_t strQuery;
strQuery = "select * from toolother";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
POSITION pos = m_Otherlist.GetFirstSelectedItemPosition();
if ( pos == NULL )
{
AfxMessageBox(_T("没有选中的记录!"), MB_ICONEXCLAMATION);
return;
}
else
{
int iItem;
CString sToolid;
while (pos)
{
iItem = m_Otherlist.GetNextSelectedItem(pos);
sToolid = m_Otherlist.GetItemText(iItem, 0);
strQuery = "delete from toolother where toolid='"+sToolid+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
m_Otherlist.DeleteItem(iItem);
}
}
m_sOtherbrand="";
m_sTooltype="";
m_sOthermaterial="";
m_sOthername="";
m_sFormaterial="";
m_sPath="";
m_sProducer="";
m_sToolID="";
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
UpdateData(false);
}
void CTOOLOTHER::OnOthertoolModify()
{
// TODO: Add your control notification handler code here
}
void CTOOLOTHER::OnOthertoolSave()
{
// TODO: Add your control notification handler code here
UpdateData(true);
// Make sure all needed info is available
CString sWarning="";
if ( ""==m_sToolID ) sWarning=_T("刀具编号");
else if ( ""==m_sOthername) sWarning=_T("车刀名称");
else if ( ""==m_sTooltype) sWarning=_T("车刀类型");
else if ( ""==m_sOtherbrand) sWarning=_T("车刀型号");
else if ( ""==m_sOthermaterial) sWarning=_T("刀具材料");
else if ( ""==m_sFormaterial) sWarning=_T("适合加工材料");
else if ( ""==m_sProducer) sWarning=_T("生产商");
if ( ""!=sWarning )
{
sWarning += _T("不能为空");
AfxMessageBox(sWarning, MB_ICONEXCLAMATION);
return;
}
_variant_t strQuery;
if(flag==1) //添加记录
{
// Judge Other is unique
strQuery = "select * from toolother where toolid='"+m_sToolID+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
int iCount = theApp.m_pADOSet->GetRecordCount();
if ( 0!=iCount )
{
AfxMessageBox(_T("已经存在此刀具记录!"), MB_ICONEXCLAMATION);
return;
}
}
else if(flag==2)//修改
{ //删除旧记录
strQuery = "delete from toolother where toolid='"+m_sToolID+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
}
// Insert Record
strQuery = "insert toolother (toolid, toolname, tooltype,toolmodel,toolmaterial,formaterial,producer,toolpicdir) \
values ('"+m_sToolID+"', '"+m_sOthername+"', '"+m_sTooltype+"','"+m_sOtherbrand+"','"+m_sOthermaterial+"','"+m_sFormaterial+"','"+m_sProducer+"','"+m_sPath+"')";
int iItem;
POSITION pos = m_Otherlist.GetFirstSelectedItemPosition();
iItem = m_Otherlist.GetNextSelectedItem(pos);
m_Otherlist.DeleteItem(iItem);
//更新列表框数据
int j;
j=m_Otherlist.GetItemCount();
m_Otherlist.InsertItem(j, m_sToolID);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?