📄 lefttreeview.cpp
字号:
return;//无任何选项则返回
}
HTREEITEM NowRoot=m_TreeCtrl.GetParentItem(hSel); //取得父项句柄
int i=0;
while (NowRoot!=NULL)
{
i++;
NowRoot=m_TreeCtrl.GetParentItem(NowRoot);
}
CInputDlg dlg;
dlg.m_NewName=m_TreeCtrl.GetItemText(hSel);
if(m_TreeCtrl.GetItemText(hSel)=="未分类") return;
if((i!=3)&&(m_TreeCtrl.GetItemText(m_TreeCtrl.GetParentItem(hSel))!="未分类"))
{
if(i==0)
dlg.Set("重命名公司名称");//设置对话框的名称
else
if(i==1)
dlg.Set("重命名部门名称");
else
if(i==2)
dlg.Set("重命名部室名称");
if(dlg.DoModal()==IDOK)
{
if(MessageBox("确定要保存所有吗?","询问",MB_YESNO|MB_ICONINFORMATION)==IDYES)
{
try //将编辑后的部门存入数据库
{
SQLStr.Format("select * from Department where Cname = '%s'",m_TreeCtrl.GetItemText(hSel));
pDepartmentRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
pDepartmentRecordset->EditMode;
pDepartmentRecordset->PutCollect("Name",_variant_t(dlg.m_NewName)); //存入新部门名称
pDepartmentRecordset->PutCollect("Cname",_variant_t(dlg.m_NewName)); //存入新部门中文名称
pDepartmentRecordset->Update();
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
pDepartmentRecordset->Close();
AfxMessageBox( "数据库更新成功!" );
m_TreeCtrl.SetItemText(hSel,dlg.m_NewName);
}
}
else
return;
}
else
{
//MessageBox("here!");
CDeviceEditDlg EditDlg;
_variant_t var;
CString DeviceID; //记录当前设备ID
///////****设备编辑框初始化开始****/////////
///////****对话框初始化开始****/////////
///////****对话框初始化开始****/////////
//获取设备名
EditDlg.m_DeviceName=m_TreeCtrl.GetItemText(hSel);
try
{
SQLStr.Format("select * from Device where Devicename = '%s'",m_TreeCtrl.GetItemText(hSel));
pDeviceRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
DeviceID=(LPCSTR)_bstr_t(pDeviceRecordset->GetCollect("ID"));
// 获取设备型号
var=pDeviceRecordset->GetCollect("Devicetyle");
if(var.vt != VT_NULL)
EditDlg.m_Type=(LPCSTR)_bstr_t(var);
else
EditDlg.m_Type="无登记型号信息";
// 获取启用日期
var=pDeviceRecordset->GetCollect("datetime");
if(var.vt != VT_NULL)
EditDlg.m_StartDate=(LPCSTR)_bstr_t(var);
else
EditDlg.m_StartDate="无登记启用日期信息";
// 获取设备配置
var=pDeviceRecordset->GetCollect("Deviceconfig");
if(var.vt != VT_NULL)
EditDlg.m_Config=(LPCSTR)_bstr_t(var);
else
EditDlg.m_Config="无登记配置信息";
// 获取雇员ID
CString EmployeeID;
EmployeeID=(LPCSTR)_bstr_t(pDeviceRecordset->GetCollect("Employeeid"));
pDeviceRecordset->Close();
try
{
SQLStr.Format("select * from Employee where ID = %d",atoi(EmployeeID));
pEmployeeRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
CString DepartmentID;
if( pEmployeeRecordset->RecordCount!=0)
{
// 获取雇员姓名
EditDlg.m_EmployeeName=(LPCSTR)_bstr_t(pEmployeeRecordset->GetCollect("Cname"));
// 获取雇员所属部门ID
DepartmentID=(LPCSTR)_bstr_t(pEmployeeRecordset->GetCollect("Departmentid"));
EditDlg.m_SubDepartment=" ";
}
else
{
EditDlg.m_EmployeeName="该设备没有登记对应用户!";
EditDlg.m_SubDepartment="未登记所属部室!";
}
pEmployeeRecordset->Close();
if(EditDlg.m_SubDepartment==" ") //如果查找到了对应的雇员,再去查找该雇员所属部室
{
try
{
SQLStr.Format("select Cname from Department where ID = %d",atoi(DepartmentID));
pDepartmentRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
//获取设备所属部室名
if( pEmployeeRecordset->RecordCount!=0)
EditDlg.m_SubDepartment=(LPCSTR)_bstr_t(pDepartmentRecordset->GetCollect("Cname"));
else
EditDlg.m_SubDepartment="该雇员未登记部室。";
pDepartmentRecordset->Close();
}
/*//获取所有雇员姓名,添入EmployeeControl编辑框
try
{
SQLStr.Format("select * from Employee");
pEmployeeRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
while(!(pEmployeeRecordset->adoEOF))
{
var = pEmployeeRecordset->GetCollect("CName");
if(var.vt != VT_NULL)
{
//(LPCSTR)_bstr_t(var)
EditDlg.m_EmployeeControl.AddString((LPCSTR)_bstr_t(var));
MessageBox("here!");
}
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
pEmployeeRecordset->Close();*/
///////****设备编辑框初始化结束****/////////
///////****初始化结束****/////////
///////****初始化结束****/////////
//如果用户点击确定按钮,开始保存用户的修改
if(EditDlg.DoModal()==IDOK)
{
if(MessageBox("确定要保存所有吗?","询问",MB_YESNO|MB_ICONINFORMATION)==IDYES)
{
UpdateData(true); //更新数据
CString str;
str=EditDlg.m_StartDate;
//str.Format("数目是:%d",strlen(str));
//MessageBox();
if((str.Mid(0,4)<"1950")||(str.Mid(0,4)>"2100")||(str.Mid(5,2)>"12")||(str.Mid(5,2)<"01")||(str.GetAt(4)!='-')||(str.Mid(8,2)>"31")||(str.Mid(8,2)<"01"))//49代表ASCII1
{
MessageBox("请输入合法的启用日期!\n\n 例:2008-07-01","提示");
return;
}
//找到编辑后的部室对应ID
try
{
SQLStr.Format("select * from Department where Cname = '%s'",EditDlg.m_SubDepartment);
pDepartmentRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(pDepartmentRecordset->RecordCount!=0)
{
var=pDepartmentRecordset->GetCollect("ID");
if(var.vt != VT_NULL)
DepartmentID=(LPCSTR)_bstr_t(var);
}
else
{
MessageBox("更新失败,未找到对应部室");
return;
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
pDepartmentRecordset->Close();
//找到编辑后的雇员对应ID,并将该雇员所属的部室ID存入数据库
try
{
SQLStr.Format("select * from Employee where Cname = '%s'",EditDlg.m_EmployeeName);
pEmployeeRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(pEmployeeRecordset->RecordCount!=0)
{
var=pEmployeeRecordset->GetCollect("ID");
if(var.vt != VT_NULL)
{
EmployeeID=(LPCSTR)_bstr_t(var);
pEmployeeRecordset->EditMode;
//存入所属部室ID
pEmployeeRecordset->PutCollect("Departmentid",_variant_t(DepartmentID));
pEmployeeRecordset->Update();
}
}
else
{
MessageBox("更新失败,未找到对应雇员");
return;
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
pEmployeeRecordset->Close();
//将编辑后的设备相关信息存入数据库
try
{
SQLStr.Format("select * from Device where ID = %d",atoi(DeviceID));
pDeviceRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
pDeviceRecordset->EditMode;
//存入设备名
pDeviceRecordset->PutCollect("Devicename",_variant_t(EditDlg.m_DeviceName));
//存入设备型号
pDeviceRecordset->PutCollect("Devicetyle",_variant_t(EditDlg.m_Type));
//存入设备启用日期
pDeviceRecordset->PutCollect("datetime",_variant_t(EditDlg.m_StartDate));
//存入设备的配置信息
//MessageBox(EmployeeID);
pDeviceRecordset->PutCollect("Deviceconfig",_variant_t(EditDlg.m_Config));
//存入使用该设备的雇员ID
pDeviceRecordset->PutCollect("Employeeid",_variant_t(EmployeeID));
pDeviceRecordset->Update();
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
pDeviceRecordset->Close();
}
}
else
return;
}
AfxMessageBox( "更新成功!" );
UpdateTree();
}
void CLeftTreeView::OnPopUpProperties()
{
// TODO: Add your command handler code here
CTreeCtrl &m_TreeCtrl=GetTreeCtrl();
HTREEITEM hSel=m_TreeCtrl.GetSelectedItem();//取得选择项句柄
HTREEITEM NowRoot=m_TreeCtrl.GetParentItem(hSel); //取得父项句柄
int i=0;
while (NowRoot!=NULL)
{
i++;
NowRoot=m_TreeCtrl.GetParentItem(NowRoot);
}
if((i==3)||(m_TreeCtrl.GetItemText(m_TreeCtrl.GetParentItem(hSel))=="未分类"))
{
_variant_t var;
try
{
SQLStr.Format("select * from Device where Devicename = '%s'",m_TreeCtrl.GetItemText(hSel));
pDeviceRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
CPropertiesDlg dlg;
//获取机器名
dlg.m_DeviceNameEdit=m_TreeCtrl.GetItemText(hSel);
// 获取IP
dlg.m_IPAddressEdit=(LPCSTR)_bstr_t(pDeviceRecordset->GetCollect("Deviceip"));
// 获取MAC
dlg.m_MacAddressEdit=(LPCSTR)_bstr_t(pDeviceRecordset->GetCollect("Macaddr"));
// 获取设备型号
var=pDeviceRecordset->GetCollect("Devicetyle");
if(var.vt != VT_NULL)
dlg.m_Type=(LPCSTR)_bstr_t(var);
else
dlg.m_Type="该项信息为空";
// 获取启用日期
var=pDeviceRecordset->GetCollect("datetime");
if(var.vt != VT_NULL)
dlg.m_StartDate=(LPCSTR)_bstr_t(var);
else
dlg.m_StartDate="该项信息为空";
// 获取设备配置
var=pDeviceRecordset->GetCollect("Deviceconfig");
if(var.vt != VT_NULL)
dlg.m_Config=(LPCSTR)_bstr_t(var);
else
dlg.m_Config="该项信息为空";
// 获取雇员ID
int EmployeeID;
EmployeeID=atoi((LPCSTR)_bstr_t(pDeviceRecordset->GetCollect("Employeeid")));
pDeviceRecordset->Close();
try
{
SQLStr.Format("select * from Employee where ID = %d",EmployeeID);
pEmployeeRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
CString DepartmentID;
if( pEmployeeRecordset->RecordCount!=0)
{
// 获取雇员姓名
dlg.m_EmployeeName=(LPCSTR)_bstr_t(pEmployeeRecordset->GetCollect("Cname"));
// 获取雇员工单号
//dlg.m_EmployeeNo=(LPCSTR)_bstr_t(pEmployeeRecordset->GetCollect("No"));
// 获取雇员所属部室ID
DepartmentID=(LPCSTR)_bstr_t(pEmployeeRecordset->GetCollect("Departmentid"));
dlg.m_SubDepartmentName=" ";
}
else
{
dlg.m_EmployeeName="该设备没有登记对应用户!";
//dlg.m_EmployeeNo="无对应工单号!";
dlg.m_SubDepartmentName="无所属部室!";
}
pEmployeeRecordset->Close();
if(dlg.m_SubDepartmentName==" ") //如果查找到了对应的雇员,再去查找该雇员所属部室
{
try
{
SQLStr.Format("select Cname from Department where ID = %d",atoi(DepartmentID));
pDepartmentRecordset->Open(_bstr_t(SQLStr),
_variant_t(pConnection,true),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -