📄 lendinfodlg.cpp
字号:
// LendInfoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FileMaSys.h"
#include "LendInfoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CFileMaSysApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CLendInfoDlg dialog
extern float FileWidth[];
extern CString strFile[];
float FileLend[7]={80,80,80,30,30,80,30}; //借阅文件列宽
CString strLend[7]={"档案名称","借阅人","借阅时间","预计天数","过期天数","归还日期","状态"};
//float FileWidth[6]={80,80,100,20,20,100}; //档案信息列宽
CLendInfoDlg::CLendInfoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLendInfoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLendInfoDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_IsSelUser=FALSE;
}
void CLendInfoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLendInfoDlg)
DDX_Control(pDX, IDCANCEL, m_BtnExitControl);
DDX_Control(pDX, IDC_BTN_RETURN, m_BtnReturnControl);
DDX_Control(pDX, IDC_BTN_LEND, m_BtnLendControl);
DDX_Control(pDX, IDC_COMBO_RUSERNAME, m_RUserNameControl);
DDX_Control(pDX, IDC_COMBO_RFILENAME, m_RFileNameControl);
DDX_Control(pDX, IDC_COMBO_LFILENAME, m_LFileNameControl);
DDX_Control(pDX, IDC_DATAGRID_FILEINFO, m_FileInfoControl);
DDX_Control(pDX, IDC_DATAGRID_LENDINFO, m_LendInfoControl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLendInfoDlg, CDialog)
//{{AFX_MSG_MAP(CLendInfoDlg)
ON_CBN_EDITCHANGE(IDC_COMBO_LFILENAME, OnEditchangeComboLfilename)
ON_CBN_EDITCHANGE(IDC_COMBO_RFILENAME, OnEditchangeComboRfilename)
ON_BN_CLICKED(IDC_BTN_LEND, OnBtnLend)
ON_BN_CLICKED(IDC_BTN_RETURN, OnBtnReturn)
ON_CBN_SELCHANGE(IDC_COMBO_RUSERNAME, OnSelchangeComboRusername)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLendInfoDlg message handlers
void CLendInfoDlg::OnEditchangeComboLfilename()
{
// TODO: Add your control notification handler code here
m_LFileNameControl.GetWindowText(m_LFileName);
CString sql;
sql="Select * From FileTable Where FileName Like '%"+m_LFileName+"%'";
m_RecordFileInfo.CreateInstance("ADODB.Recordset");
m_RecordFileInfo->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),
adOpenDynamic,adLockOptimistic,adCmdText);
m_FileInfoControl.SetRefDataSource(NULL);
m_FileInfoControl.SetRefDataSource((LPUNKNOWN)m_RecordFileInfo);
m_FileInfoControl.SetColumnHeaders(2);
SetColumnWidth(m_FileInfoControl,6,FileWidth,strFile);
m_FileInfoControl.Refresh();
//查询数据库中是否存在输入名称的记录
CString sql1;
sql1="Select * From FileTable Where FileName ='"+m_LFileName+"'";
m_RecordExist.CreateInstance("ADODB.Recordset");
m_RecordExist->Open((_variant_t)sql1,_variant_t((IDispatch *)theApp.m_pConnection,true),
adOpenDynamic,adLockOptimistic,adCmdText);
if (m_RecordExist->GetRecordCount()==0)
{
if (m_IsStatic.m_hWnd!=NULL)
{
m_IsStatic.DestroyWindow();
}
static CRect rect,rectStatic;
if (rect.IsRectNull())
{
m_LFileNameControl.GetWindowRect(&rect);
rectStatic.left=rect.right+15;
rectStatic.top=rect.top;
rectStatic.right=rectStatic.left+150;
rectStatic.bottom=rect.bottom;
ScreenToClient(&rectStatic);
}
m_IsStatic.Create("名字不完整或不存在",WS_CHILD | WS_VISIBLE | SS_CENTER,rectStatic,this);
if (m_font.m_hObject==NULL)
{
m_font.CreatePointFont(100,"宋体");
}
m_IsStatic.SetFont(&m_font,TRUE);
}
else
{
if (m_IsStatic.m_hWnd!=NULL)
{
m_IsStatic.DestroyWindow();
}
static CRect rect1,rectStatic1;
if (rect1.IsRectNull())
{
m_LFileNameControl.GetWindowRect(&rect1);
rectStatic1.left=rect1.right+15;
rectStatic1.top=rect1.top;
rectStatic1.right=rectStatic1.left+120;
rectStatic1.bottom=rect1.bottom;
ScreenToClient(&rectStatic1);
}
//获取可以借出的数量
long lendcount=m_RecordExist->GetCollect("LendCount").lVal;
CString str;
str.Format("有%d本档案可以借出",lendcount);
m_IsStatic.Create(str,WS_CHILD | WS_VISIBLE | SS_CENTER,rectStatic1,this);
if (m_font.m_hObject==NULL)
{
m_font.CreatePointFont(100,"宋体");
}
m_IsStatic.SetFont(&m_font,TRUE);
m_BtnLendControl.EnableWindow(TRUE);
}
}
void CLendInfoDlg::SetColumnWidth(CDataGrid &ProControl, short count, float *WidthArray,CString *strTitle)
{
_variant_t vIndex;
for (int i=0;i<count;i++)
{
vIndex=long(i);
((ProControl.GetColumns()).GetItem(vIndex)).SetWidth(WidthArray[i]);
((ProControl.GetColumns()).GetItem(vIndex)).SetCaption(strTitle[i]);
}
}
void CLendInfoDlg::OnEditchangeComboRfilename()
{
// TODO: Add your control notification handler code here
m_RFileNameControl.GetWindowText(m_RFileName);
CString sql;
sql="Select * From LendTable Where FileName Like '%"+m_RFileName+"%' And FileState = 0 ";
m_RecordLendInfo.CreateInstance("ADODB.Recordset");
m_RecordLendInfo->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),
adOpenDynamic,adLockOptimistic,adCmdText);
//把查询到的记录绑定到显示列表
m_LendInfoControl.SetRefDataSource(NULL);
m_LendInfoControl.SetRefDataSource((LPUNKNOWN)m_RecordLendInfo);
m_LendInfoControl.SetColumnHeaders(2);
SetColumnWidth(m_LendInfoControl,7,FileLend,strLend);
m_LendInfoControl.Refresh();
//打开名称完全正确的记录
m_RecordExist.CreateInstance("ADODB.Recordset");
CString sql1;
sql1="Select * From LendTable Where FileName = '"+m_RFileName+"' And FileState =0 ";
m_RecordExist->Open((_variant_t)sql1,_variant_t((IDispatch *)theApp.m_pConnection,true),
adOpenDynamic,adLockOptimistic,adCmdText);
if (m_RecordExist->GetRecordCount()!=0)
{
if (m_IsStatic.m_hWnd!=NULL)
{
m_IsStatic.DestroyWindow();
}
m_RecordExist->MoveFirst();
while (!m_RecordExist->adEOF)
{
CString strTemp=m_RecordExist->GetCollect("LendUser").bstrVal;
m_RUserNameControl.AddString(strTemp);
m_RecordExist->MoveNext();
}
m_RUserNameControl.SetCurSel(0);
m_RUserNameControl.GetLBText(0,m_cUser);
m_IsSelUser=TRUE;
m_BtnReturnControl.EnableWindow(TRUE);
}
else
{
if (m_IsStatic.m_hWnd!=NULL)
{
m_IsStatic.DestroyWindow();
}
static CRect rect,rectStatic;
if (rect.IsRectNull())
{
m_RFileNameControl.GetWindowRect(&rect);
rectStatic.left=rect.right+15;
rectStatic.top=rect.top;
rectStatic.right=rectStatic.left+150;
rectStatic.bottom=rect.bottom+rect.Height();
ScreenToClient(&rectStatic);
}
m_IsStatic.Create("名字不完整或不存在借阅记录",WS_CHILD | WS_VISIBLE | SS_CENTER,rectStatic,this);
if (m_font.m_hObject==NULL)
{
m_font.CreatePointFont(100,"宋体");
}
m_IsStatic.SetFont(&m_font,TRUE);
}
}
BOOL CLendInfoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_BtnLendControl.EnableWindow(FALSE);
m_BtnReturnControl.EnableWindow(FALSE);
HICON iconExit=(HICON)LoadImage(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON_ERROR),
IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
//设置退出按钮
m_BtnExitControl.SetIcon(iconExit);
m_BtnExitControl.DrawTransparent(TRUE);
m_BtnExitControl.SetColor(CButtonST::BTNST_COLOR_FG_IN,RGB(255,0,0));
m_BtnExitControl.SetAlign(CButtonST::ST_ALIGN_HORIZ);
//设置借阅文件按钮
m_BtnLendControl.SetIcon(IDI_ICON_BORROW);
m_BtnLendControl.DrawTransparent(TRUE);
m_BtnLendControl.SetColor(CButtonST::BTNST_COLOR_FG_IN,RGB(255,0,0));
m_BtnLendControl.SetAlign(CButtonST::ST_ALIGN_HORIZ);
//设置归还按钮
m_BtnReturnControl.SetIcon(IDI_ICON_RETURN);
m_BtnReturnControl.DrawTransparent(TRUE);
m_BtnReturnControl.SetColor(CButtonST::BTNST_COLOR_FG_IN,RGB(255,0,0));
m_BtnReturnControl.SetAlign(CButtonST::ST_ALIGN_HORIZ);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CLendInfoDlg::OnBtnLend()
{
// TODO: Add your control notification handler code here
CLendChartDlg dlg;
if (dlg.DoModal()==IDOK)
{
CString strName,sql1,sql2;
sql1="Select FileName, LendCount From FileTable Where FileName = '"+m_LFileName+"'";
sql2="Select * From LendTable";
m_RecordExist.CreateInstance("ADODB.Recordset");
m_RecordExist->Open((_variant_t)sql1,_variant_t((IDispatch *)theApp.m_pConnection,true),
adOpenDynamic,adLockPessimistic,adCmdText);
long count=m_RecordExist->GetCollect("LendCount").lVal;
if (count>0)
{
m_RecordExist->PutCollect("LendCount",_variant_t((long)(count-1)));
m_RecordExist->Update();
//修改借阅记录表
m_RecordLendChart.CreateInstance("ADODB.Recordset");
m_RecordLendChart->Open((_variant_t)sql2,_variant_t((IDispatch *)theApp.m_pConnection,true),
adOpenDynamic,adLockPessimistic,adCmdText);
m_RecordLendChart->AddNew();
m_RecordLendChart->PutCollect("FileName",_variant_t(m_LFileName));
m_RecordLendChart->PutCollect("LendUser",_variant_t(dlg.m_LUser));
// CTime now=CTime::GetCurrentTime();
// InTime=now.Format(_T("%Y%m%d"));
//获得系统当前时间 设为借阅时间
COleDateTime now=COleDateTime::GetCurrentTime();
m_RecordLendChart->PutCollect("LendTime",_variant_t((DATE)now));
m_RecordLendChart->PutCollect("LendLenth",_variant_t(dlg.m_DayCount));
m_RecordLendChart->PutCollect("OverdueDay",_variant_t(-(dlg.m_DayCount)));
m_RecordLendChart->PutCollect("FileState",_variant_t((long)0));
m_RecordLendChart->Update();
MessageBox("借阅成功");
}
else
{
MessageBox("借阅失败");
}
}
}
void CLendInfoDlg::OnBtnReturn()
{
// TODO: Add your control notification handler code here
if (m_IsSelUser)
{
CString strName,sql1,sql2;
sql1="Select FileName, LendCount From FileTable Where FileName = '"+m_RFileName+"'";
sql2="Select * From LendTable Where LendUser = '"+m_cUser+"'";
m_RecordExist.CreateInstance("ADODB.Recordset");
m_RecordExist->Open((_variant_t)sql1,_variant_t((IDispatch *)theApp.m_pConnection,true),
adOpenDynamic,adLockPessimistic,adCmdText);
//修改文件信息表
long count=m_RecordExist->GetCollect("LendCount").lVal;
m_RecordExist->PutCollect("LendCount",_variant_t((long)(count+1)));
m_RecordExist->Update();
//修改借阅记录表
m_RecordLendChart.CreateInstance("ADODB.Recordset");
m_RecordLendChart->Open((_variant_t)sql2,_variant_t((IDispatch *)theApp.m_pConnection,true),
adOpenDynamic,adLockPessimistic,adCmdText);
//获得系统当前时间,设为归还时间
COleDateTime now=COleDateTime ::GetCurrentTime();
m_RecordLendChart->PutCollect("ReturnTime",_variant_t((DATE)now));
m_RecordLendChart->PutCollect("FileState",_variant_t((long)1));
m_RecordLendChart->Update();
MessageBox("归还成功");
}
}
void CLendInfoDlg::OnSelchangeComboRusername()
{
// TODO: Add your control notification handler code here
int i=m_RUserNameControl.GetCurSel();
m_RUserNameControl.GetLBText(i,m_cUser);
m_IsSelUser=TRUE;
}
void CLendInfoDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
if (!m_LFileName.IsEmpty())
{
m_LFileNameControl.AddString(m_LFileName);
m_LFileNameControl.SetCurSel(0);
m_BtnLendControl.EnableWindow(TRUE);
SendMessage(CBN_EDITCHANGE,IDC_COMBO_LFILENAME,(LPARAM)GetDlgItem(IDC_COMBO_LFILENAME)->m_hWnd);
}
// Do not call CDialog::OnPaint() for painting messages
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -