📄 informationissueform.cpp
字号:
// InformationIssueForm.cpp : implementation file
//
#include "stdafx.h"
#include "ClientRelationship.h"
#include "InformationIssueForm.h"
#include "InformationIssue.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInformationIssueForm dialog
CInformationIssueForm::CInformationIssueForm(CWnd* pParent /*=NULL*/)
: CDialog(CInformationIssueForm::IDD, pParent)
{
//{{AFX_DATA_INIT(CInformationIssueForm)
m_issueDate = COleDateTime::GetCurrentTime();
m_department = _T("");
m_staffName = _T("");
m_subject = _T("");
m_content = _T("");
m_informationIssueID = _T("");
is_search=0;
//}}AFX_DATA_INIT
}
void CInformationIssueForm::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInformationIssueForm)
DDX_Control(pDX, IDC_staffName, m_staffNameCombo);
DDX_Control(pDX, IDC_department, m_departmentCombo);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_DateTimeCtrl(pDX, IDC_issueDate, m_issueDate);
DDX_CBString(pDX, IDC_department, m_department);
DDX_CBString(pDX, IDC_staffName, m_staffName);
DDX_Text(pDX, IDC_subject, m_subject);
DDX_Text(pDX, IDC_content, m_content);
DDX_Text(pDX, IDC_informationIssueID, m_informationIssueID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInformationIssueForm, CDialog)
//{{AFX_MSG_MAP(CInformationIssueForm)
ON_BN_CLICKED(IDC_add, OnAdd)
ON_BN_CLICKED(IDC_delete, OnDelete)
ON_BN_CLICKED(IDC_modify, OnModify)
ON_BN_CLICKED(IDC_save, OnSave)
ON_BN_CLICKED(IDC_cancelation, OnCancelation)
ON_BN_CLICKED(IDC_exit, OnExit)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInformationIssueForm message handlers
BOOL CInformationIssueForm::OnInitDialog()
{
CDialog::OnInitDialog();
//设定列表框控件的样式
DWORD style;
style=m_list.GetExStyle();
style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
m_list.SetExtendedStyle(style);
//为列表框控件增加列并为列添加列标题
m_list.InsertColumn(0,"公告编号",LVCFMT_LEFT,100);
m_list.InsertColumn(1,"公告日期",LVCFMT_LEFT,100);
m_list.InsertColumn(2,"发布部门",LVCFMT_LEFT,100);
m_list.InsertColumn(3,"发布人员",LVCFMT_LEFT,100);
m_list.InsertColumn(4,"公告主题",LVCFMT_LEFT,100);
m_list.InsertColumn(5,"公告内容",LVCFMT_LEFT,100);
CString strSQL;
//为组合框控件添加可选项
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select distinct departmentName from department";//构造查询语句
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);//打开查询记录集
int i=0;
//将数据库中的各行加入到组合框中
while(!(m_pRecordset->adoEOF))
{
m_departmentCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("departmentName")));
m_pRecordset->MoveNext();//记录集指针向后移动
i++;
}
m_pRecordset->Close();//关闭记录集
//为员工组合框添加可选项
strSQL="select distinct staffName from staff";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_staffNameCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("staffName")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
//将目前所有的信息公告都加入到列表框控件中
strSQL="select * from informationIssue ";//构造查询语句
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText); //打开查询结果记录集
CString str;
i=0;
while(!(m_pRecordset->adoEOF))
{
m_list.InsertItem(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("informationIssueID")));//公告编号
COleDateTime issueDate= m_pRecordset->GetCollect("issueDate");//发布日期
str.Format("%d-%d-%d",issueDate.GetYear(),issueDate.GetMonth(),issueDate.GetDay());//将发布日期转换成字符串
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Department")));//部门
m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("StaffName")));//发布人员
m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Subject")));//公告主题
m_list.SetItemText(i,5, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("content")));//公告内容
m_pRecordset->MoveNext();//记录集指针向后移动
i++;
}
//为编辑控件可用性控制变量赋初值
tx_issueDate=GetDlgItem(IDC_issueDate);//发布日期
tx_department=GetDlgItem(IDC_department);//发布部门
tx_staffName=GetDlgItem(IDC_staffName);//发布人员
tx_subject=GetDlgItem(IDC_subject); //公告主题
tx_content=GetDlgItem(IDC_content); //公告内容
tx_informationIssueID=GetDlgItem(IDC_informationIssueID);//公告编码
//为按钮控件可用性控制变量赋初值
bt_add=GetDlgItem(IDC_add); //添加
bt_delete=GetDlgItem(IDC_delete); //删除
bt_modify=GetDlgItem(IDC_modify); //修改
bt_save=GetDlgItem(IDC_save); //保存
bt_cancelation=GetDlgItem(IDC_cancelation); //取消
//初始情况下,所有的编辑控件均不可用
tx_issueDate->EnableWindow(false);
tx_department->EnableWindow(false);
tx_staffName->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_informationIssueID->EnableWindow(false);
if(is_search==0)//被菜单调用
{
bt_add->EnableWindow(true);
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_save->EnableWindow(false);
bt_cancelation->EnableWindow(false);
}
else if(is_search==1)//被查询对话框调用
{
CInformationIssue informationIssue;
informationIssue.GetData(m_informationIssueID);//获取被双击的信息公告的详细信息
m_issueDate = informationIssue.GetIssueDate();//发布日期
m_department = informationIssue.GetDepartment();//发布部门
m_staffName = informationIssue.GetStaffName();//发布人员
m_subject = informationIssue.GetSubject();//公告主题
m_content = informationIssue.GetContent();//公告内容
//设定按钮的可用性
bt_add->EnableWindow(true);
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_save->EnableWindow(false);
bt_cancelation->EnableWindow(false);
}
UpdateData(false);//将数据更新到对话框
return TRUE;
}
void CInformationIssueForm::OnAdd()
{
CString m_formID;
int formID=((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->GetCollect("informationIssueID").intVal;
if(formID<10)
m_formID.Format("KHYG0000%d",formID);
else if(formID<100&&formID>9)
m_formID.Format("KHYG000%d",formID);
else if(formID<1000&&formID>99)
m_formID.Format("KHYG00%d",formID);
CString str;
str.Format("%d",formID+1);
((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->PutCollect("informationIssueID",_variant_t(str));
((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->Update();
m_issueDate = COleDateTime::GetCurrentTime();
m_department = _T("");
m_staffName = _T("");
m_subject = _T("");
m_content = _T("");
m_informationIssueID = m_formID;
tx_issueDate->EnableWindow(true);
tx_department->EnableWindow(true);
tx_staffName->EnableWindow(true);
tx_subject->EnableWindow(true);
tx_content->EnableWindow(true);
tx_informationIssueID->EnableWindow(false);
bt_add->EnableWindow(false);
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_save->EnableWindow(true);
bt_cancelation->EnableWindow(true);
flag=1;
UpdateData(false);
}
void CInformationIssueForm::OnDelete()
{
CInformationIssue informationIssue;
informationIssue.sqlDelete(m_informationIssueID);
m_issueDate = COleDateTime::GetCurrentTime();
m_department = _T("");
m_staffName = _T("");
m_subject = _T("");
m_content = _T("");
m_informationIssueID = _T("");
tx_issueDate->EnableWindow(false);
tx_department->EnableWindow(false);
tx_staffName->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_informationIssueID->EnableWindow(false);
bt_add->EnableWindow(true);
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_save->EnableWindow(false);
bt_cancelation->EnableWindow(false);
Refresh();
UpdateData(false);
}
void CInformationIssueForm::OnModify()
{
tx_issueDate->EnableWindow(true);
tx_department->EnableWindow(true);
tx_staffName->EnableWindow(true);
tx_subject->EnableWindow(true);
tx_content->EnableWindow(true);
tx_informationIssueID->EnableWindow(false);
bt_add->EnableWindow(false);
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_save->EnableWindow(true);
bt_cancelation->EnableWindow(false);
flag=2;
UpdateData(false);
}
void CInformationIssueForm::OnSave()
{
UpdateData(true);
CInformationIssue informationIssue;
informationIssue.SetIssueDate(m_issueDate);
informationIssue.SetDepartment(m_department);
informationIssue.SetStaffName(m_staffName);
informationIssue.SetSubject(m_subject);
informationIssue.SetContent(m_content);
informationIssue.SetInformationIssueID(m_informationIssueID);
if(flag==1)
{
informationIssue.sqlInsert();
int i=m_list.GetItemCount();
CString str;
m_list.InsertItem(i,m_informationIssueID);
str.Format("%d-%d-%d",m_issueDate.GetYear(),m_issueDate.GetMonth(),m_issueDate.GetDay());
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2,m_department);
m_list.SetItemText(i,3,m_staffName);
m_list.SetItemText(i,4,m_subject);
m_list.SetItemText(i,5,m_content);
}
else if(flag==2)
{
informationIssue.sqlUpdate(m_informationIssueID);
Refresh();
}
tx_issueDate->EnableWindow(false);
tx_department->EnableWindow(false);
tx_staffName->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_informationIssueID->EnableWindow(false);
bt_add->EnableWindow(true);
bt_delete->EnableWindow(true);
bt_modify->EnableWindow(true);
bt_save->EnableWindow(false);
bt_cancelation->EnableWindow(false);
UpdateData(false);
}
void CInformationIssueForm::OnCancelation()
{
m_issueDate = COleDateTime::GetCurrentTime();
m_department = _T("");
m_staffName = _T("");
m_subject = _T("");
m_content = _T("");
m_informationIssueID = _T("");
tx_issueDate->EnableWindow(false);
tx_department->EnableWindow(false);
tx_staffName->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_informationIssueID->EnableWindow(false);
bt_add->EnableWindow(true);
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_save->EnableWindow(false);
bt_cancelation->EnableWindow(false);
CString m_formID;
int formID=((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->GetCollect("informationIssueID").intVal;
if(formID<10)
m_formID.Format("KHYG0000%d",formID);
else if(formID<100&&formID>9)
m_formID.Format("KHYG000%d",formID);
else if(formID<1000&&formID>99)
m_formID.Format("KHYG00%d",formID);
CString str;
str.Format("%d",formID-1);
((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->PutCollect("informationIssueID",_variant_t(str));
((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->Update();
UpdateData(false);
}
void CInformationIssueForm::OnExit()
{
this->OnCancel();
}
void CInformationIssueForm::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateData(true);
POSITION pos = m_list.GetFirstSelectedItemPosition();//获取单击的位置
if(pos)
{
int nFirstSelItem = m_list.GetNextSelectedItem(pos);//获取单击的条目
m_informationIssueID=m_list.GetItemText(nFirstSelItem,0);//获取单击的条目的公告编码
}
CInformationIssue informationIssue;//构造信息公告对象
informationIssue.GetData(m_informationIssueID);//获取指定公告编码的公告的详细信息
m_issueDate = informationIssue.GetIssueDate();//发布日期
m_department = informationIssue.GetDepartment();//发布部门
m_staffName = informationIssue.GetStaffName();//发布人员
m_subject = informationIssue.GetSubject();//公告主题
m_content = informationIssue.GetContent();//公告内容
tx_issueDate->EnableWindow(false);
tx_department->EnableWindow(false);
tx_staffName->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_informationIssueID->EnableWindow(false);
bt_add->EnableWindow(true);
bt_delete->EnableWindow(true);
bt_modify->EnableWindow(true);
bt_save->EnableWindow(false);
bt_cancelation->EnableWindow(false);
UpdateData(false);//将数据更新到对话框
*pResult = 0;
}
void CInformationIssueForm::Refresh()
{
m_list.DeleteAllItems();
CString strSQL;
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select * from informationIssue ";//构造查询语句
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText); //打开查询结果记录集
CString str;
int i=0;
while(!(m_pRecordset->adoEOF))
{
m_list.InsertItem(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("informationIssueID")));//公告编号
COleDateTime issueDate= m_pRecordset->GetCollect("issueDate");//发布日期
str.Format("%d-%d-%d",issueDate.GetYear(),issueDate.GetMonth(),issueDate.GetDay());//将发布日期转换成字符串
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Department")));//部门
m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("StaffName")));//发布人员
m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Subject")));//公告主题
m_list.SetItemText(i,5, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("content")));//公告内容
m_pRecordset->MoveNext();//记录集指针向后移动
i++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -