📄 eq_manager_sysdlg.cpp
字号:
// eq_manager_sysDlg.cpp : implementation file
//
#include "stdafx.h"
#include "eq_manager_sys.h"
#include "eq_manager_sysDlg.h"
#include "Eq_SEARCHDlg.h"
#include "Eq_STATEDlg.h"
#include "Eq_STATISTIC.h"
#include "UserLogin.h"
#include "UserManage.h"
#include "DBA.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEq_manager_sysDlg dialog
CEq_manager_sysDlg::CEq_manager_sysDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEq_manager_sysDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEq_manager_sysDlg)
m_id = _T("");
m_location = _T("");
m_manufa = _T("");
m_month = _T("");
m_name = _T("");
m_type = _T("");
m_val = _T("");
m_amount = _T("");
m_fix_year = _T("");
m_classid = _T("");
m_remark = _T("");
m_depid = _T("");
m_edit_1 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CEq_manager_sysDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEq_manager_sysDlg)
DDX_Control(pDX, IDC_BUTTON_DBA, m_bDBA);
DDX_Control(pDX, IDC_BUTTON8, m_button8);
DDX_Control(pDX, IDC_BUTTON7, m_button7);
DDX_Control(pDX, IDC_BUTTON6, m_button6);
DDX_Control(pDX, IDC_EDIT1, m_edit1);
DDX_Control(pDX, IDC_CHECK2, m_check2);
DDX_Control(pDX, IDC_BUTTON5, m_button5);
DDX_Control(pDX, IDC_COMBO_dep_id, m_dep_id);
DDX_Control(pDX, IDC_EDIT_amount, m_amount_c);
DDX_Control(pDX, IDC_DATETIMEPICKER_use_date, m_use_c);
DDX_Control(pDX, IDC_DATETIMEPICKER_purdate, m_pur_c);
DDX_Control(pDX, IDC_DATETIMEPICKER_install_date, m_install_c);
DDX_Control(pDX, IDC_EDIT_fix_year, m_fix_year_c);
DDX_Control(pDX, IDC_EDIT_location, m_location_c);
DDX_Control(pDX, IDC_EDIT_manufa, m_manufa_c);
DDX_Control(pDX, IDC_EDIT_month, m_month_c);
DDX_Control(pDX, IDC_EDIT_name, m_name_c);
DDX_Control(pDX, IDC_EDIT_type, m_type_c);
DDX_Control(pDX, IDC_EDIT_val, m_val_c);
DDX_Control(pDX, IDC_EDIT_id, m_id_c);
DDX_Control(pDX, IDC_EDIT_remark, m_re);
DDX_Control(pDX, IDC_COMBO_class_id, m_class_id);
DDX_Control(pDX, IDC_LIST_EQ_CLASS, m_list_eq_class);
DDX_Control(pDX, IDC_LIST_EQ, m_list_eq);
DDX_Control(pDX, IDC_LIST_DEP, m_list_dep);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_purdate, m_pur_date);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_install_date, m_install_date);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_use_date, m_use_date);
DDX_Text(pDX, IDC_EDIT_id, m_id);
DDX_Text(pDX, IDC_EDIT_location, m_location);
DDX_Text(pDX, IDC_EDIT_manufa, m_manufa);
DDX_Text(pDX, IDC_EDIT_month, m_month);
DDX_Text(pDX, IDC_EDIT_name, m_name);
DDX_Text(pDX, IDC_EDIT_type, m_type);
DDX_Text(pDX, IDC_EDIT_val, m_val);
DDX_Text(pDX, IDC_EDIT_amount, m_amount);
DDX_Text(pDX, IDC_EDIT_fix_year, m_fix_year);
DDX_CBString(pDX, IDC_COMBO_class_id, m_classid);
DDX_Text(pDX, IDC_EDIT_remark, m_remark);
DDX_CBString(pDX, IDC_COMBO_dep_id, m_depid);
DDX_Text(pDX, IDC_EDIT1, m_edit_1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEq_manager_sysDlg, CDialog)
//{{AFX_MSG_MAP(CEq_manager_sysDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON_close, OnBUTTONclose)
ON_BN_CLICKED(IDC_BUTTON3, OnButton_update)
ON_BN_CLICKED(IDC_BUTTON4, OnButton_storage)
ON_NOTIFY(NM_CLICK, IDC_LIST_EQ, OnClickListEq)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_EQ, OnColumnclickListEq)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON9, OnButton_born)
ON_BN_CLICKED(IDC_BUTTON_DBA, OnButtonDba)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEq_manager_sysDlg message handlers
BOOL CEq_manager_sysDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
if(CUserLogin::flag==1)
{
int nResult;
CUserLogin dlg;
nResult = dlg.DoModal();
if (nResult == IDOK)
{
}
else if(nResult == IDCANCEL)
{
CDialog::OnCancel();
}
}
InitControl();//初始化control列
ConnectDB();
//SetWindowText("设备管理系统-"+CUserLogin::UID);
return TRUE; // return TRUE unless you set the focus to a control
}
void CEq_manager_sysDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CEq_manager_sysDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CEq_manager_sysDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CEq_manager_sysDlg::InitControl()//添加控件显示列
{
DWORD dwExstyle=LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP|
LVS_EX_ONECLICKACTIVATE|LVS_EX_UNDERLINEHOT;
m_list_eq.SetExtendedStyle(dwExstyle);
m_list_eq_class.SetExtendedStyle(dwExstyle);
m_list_dep.SetExtendedStyle(dwExstyle);
//初试化设备信息表列表框控件
m_list_eq.InsertColumn(0,"设备编号",LVCFMT_CENTER,60);
m_list_eq.InsertColumn(1,"设备名称",LVCFMT_CENTER,80);
m_list_eq.InsertColumn(2,"类别编号",LVCFMT_CENTER,80);
m_list_eq.InsertColumn(3,"规格型号",LVCFMT_CENTER,200);
m_list_eq.InsertColumn(4,"设备数量",LVCFMT_CENTER,60);
m_list_eq.InsertColumn(5,"设备状态",LVCFMT_CENTER,60);
m_list_eq.InsertColumn(6,"购入日期",LVCFMT_CENTER,80);
m_list_eq.InsertColumn(7,"安装日期",LVCFMT_CENTER,80);
m_list_eq.InsertColumn(8,"部门编号",LVCFMT_CENTER,80);
m_list_eq.InsertColumn(9,"原值",LVCFMT_CENTER,70);
m_list_eq.InsertColumn(10,"安装地点",LVCFMT_CENTER,120);
m_list_eq.InsertColumn(11,"生产厂家",LVCFMT_CENTER,150);
m_list_eq.InsertColumn(12,"使用日期",LVCFMT_CENTER,80);
m_list_eq.InsertColumn(13,"使用年限",LVCFMT_CENTER,60);
m_list_eq.InsertColumn(14,"残值",LVCFMT_CENTER,80);
m_list_eq.InsertColumn(15,"月折旧金额",LVCFMT_CENTER,80);
m_list_eq.InsertColumn(16,"备注",LVCFMT_CENTER,200);
m_list_eq_class.InsertColumn(0,"类别编号",LVCFMT_CENTER,80);
m_list_eq_class.InsertColumn(1,"类别名称",LVCFMT_LEFT,100);
m_list_eq_class.InsertColumn(2,"设备数量",LVCFMT_CENTER,100);
m_list_eq_class.InsertColumn(3,"设备原值",LVCFMT_CENTER,118);
m_list_dep.InsertColumn(0,"部门编号",LVCFMT_CENTER,60);
m_list_dep.InsertColumn(1,"部门名称",LVCFMT_LEFT,80);
m_list_dep.InsertColumn(2,"部门主管",LVCFMT_LEFT,80);
m_list_dep.InsertColumn(3,"设备数量",LVCFMT_CENTER,80);
m_list_dep.InsertColumn(4,"设备原值",LVCFMT_CENTER,102);
//设置背景颜色
m_list_eq.SetBkColor(RGB(255,255,200));
m_list_dep.SetBkColor(RGB(255,255,200));
m_list_eq_class.SetBkColor(RGB(255,255,200));
m_list_eq.SetTextBkColor(RGB(255,221,221));
m_list_dep.SetTextBkColor(RGB(255,221,221));
m_list_eq_class.SetTextBkColor(RGB(255,221,221));
if(CUserLogin::DBAflag==0)
m_bDBA.ShowWindow(SW_HIDE);
//设置系统时间
SYSTEMTIME st;
::GetSystemTime(&st);
int year,month,day;
year=st.wYear;
month=st.wMonth;
day=st.wDay;
CString date=m_pur_date.Format("%Y-%m-%d");
date.Format("%d-%d-%d",year,month,day);
m_pur_date.ParseDateTime(date);
m_install_date.ParseDateTime(date);
m_use_date.ParseDateTime(date);
UpdateData(FALSE);
}
void CEq_manager_sysDlg::ConnectDB()//连接数据库函数
{
if(CUserLogin::flag==1)
{
TRY
{
// m_db.OpenEx(strConnect,CDatabase::noOdbcDialog);
m_db.OpenEx("DSN=ORADB;UID=eq_system;PWD=eq_system",CDatabase::noOdbcDialog);
CUserLogin::flag = 0;
}
CATCH(CDBException,ex)
{
AfxMessageBox("问题出在连接数据库");
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CMemoryException,pEx)
{
pEx->ReportError();
AfxMessageBox("memory exception");
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
END_CATCH
}
InitCtrlData();
}
void CEq_manager_sysDlg::InitCtrlData()
{
if(!m_db.IsOpen())
{
MessageBox("数据库没打开");
return;
}
m_list_eq_class.DeleteAllItems();
m_list_dep.DeleteAllItems();
m_list_eq.DeleteAllItems();
TRY
{
CRecordset rs(&m_db);
CRecordset rs1(&m_db);
CRecordset rs2(&m_db);
rs1.Open(CRecordset::dynaset,"select * from dep_info");
while(!rs1.IsEOF())
{
CString id,name,manager;
int n,val;
CDBVariant var;
//获得字段直
rs1.GetFieldValue((short)0,id);
rs1.GetFieldValue((short)1,name);
rs1.GetFieldValue((short)2,manager);
rs1.GetFieldValue((short)3,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
n=var.m_lVal;
var.Clear();
rs1.GetFieldValue((short)4,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
val=var.m_lVal;
var.Clear();
//向控件加入一条
InsertDep(id,name,manager,n,val);
rs1.MoveNext();
}
rs1.Close();
rs.Open(CRecordset::dynaset,"select * from eq_class");
while(!rs.IsEOF())
{
CString id,name;
int n,val;
CDBVariant var;
//获得字段直
rs.GetFieldValue((short)0,id);
rs.GetFieldValue((short)1,name);
rs.GetFieldValue((short)2,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
n=var.m_lVal;
var.Clear();
rs.GetFieldValue((short)3,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
val=var.m_lVal;
var.Clear();
//向控件加入一条
InsertEqclass(id,name,n,val);
rs.MoveNext();
}
rs.Close();
rs2.Open(CRecordset::dynaset,"select * from eq_info");
while(!rs2.IsEOF())
{
CString id,name,eq_class_id,eq_type,pur_date,install_date,dep_id,fix_place,manfac,use_date,remark;
int eq_amount,eq_state,fix_year,rem_val,mon_val,eq_val;
CDBVariant var;
//获得字段直
rs2.GetFieldValue((short)0,id);
rs2.GetFieldValue((short)1,name);
rs2.GetFieldValue((short)2,eq_class_id);
rs2.GetFieldValue((short)3,eq_type);
rs2.GetFieldValue((short)4,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
eq_amount=var.m_lVal;
else
eq_amount=0;
var.Clear();
rs2.GetFieldValue((short)5,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
eq_state=var.m_lVal;
else
eq_state=0;
var.Clear();
rs2.GetFieldValue((short)6,pur_date);
pur_date=pur_date.Mid(0,10);//节取字符串
rs2.GetFieldValue((short)7,install_date);
install_date=install_date.Mid(0,10);
rs2.GetFieldValue((short)8,dep_id);
rs2.GetFieldValue((short)9,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
eq_val=var.m_lVal;
else
eq_val=0;
var.Clear();
rs2.GetFieldValue((short)10,fix_place);
rs2.GetFieldValue((short)11,manfac);
rs2.GetFieldValue((short)12,use_date);
use_date=use_date.Mid(0,10);
rs2.GetFieldValue((short)13,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
fix_year=var.m_lVal;
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -