📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "MyImageDB.h"
#include "MainFrm.h"
#include "dbconnectdlg.h"
#include "include\ado.h"
#include "Splash.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_DBCONNECT, OnDbConnect)
ON_COMMAND(ID_COLORTOOLBAR, OnColorToolbar)
ON_UPDATE_COMMAND_UI(ID_COLORTOOLBAR, OnUpdateColorToolbar)
ON_COMMAND(ID_REGIONSEGSHOW, OnRegionsegShow)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
ptClassArrToSeg = NULL;//选择列表信息
numberInPtClassArrToSeg = -1;
selIDInPtClassArrToSeg = -1;
mySegmentPara = NULL;
isShowSegpara = isShowColorToolbar = TRUE;
recordCount = -1;
isSegInfoDbOK = isTrainPointDbOK = isDbOK = FALSE;
seginfoRs = trainpointRs = myRs = NULL;
selName = "";
selRow = -1;
strConnection = "";
tableName = "";
userName = "";
}
CMainFrame::~CMainFrame()
{
if (mySegmentPara!=NULL)
{
delete mySegmentPara;
mySegmentPara = NULL;
}
if ( ptClassArrToSeg!=NULL)
{
delete [] ptClassArrToSeg;
ptClassArrToSeg = NULL;
}
if ( mySegmentPara!=NULL)
{
delete [] mySegmentPara;
mySegmentPara = NULL;
}
if (myRs)
{
myRs->Close();
}
if (seginfoRs)
{
seginfoRs->Close();
}
if (trainpointRs)
{
trainpointRs->Close();
}
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
CRect rFrame;
GetWindowRect(rFrame);
INT x = rFrame.right - 90;
INT y = rFrame.top + 90;
//颜色信息面板;
myPaletteBar.Create(this, IDD_COLOR_PALETTE, CBRS_LEFT, ID_COLORTOOLBAR);
myPaletteBar.SetWindowText("颜色与位置");
myPaletteBar.EnableDocking(CBRS_ALIGN_RIGHT | CBRS_ALIGN_LEFT);
DockControlBar(&myPaletteBar);
//FloatControlBar(&myPaletteBar, CPoint(x, y), CBRS_ALIGN_TOP);
myPaletteBar.ShowWindow(SW_SHOW);
/*
//分割信息面板;
mySegmentPara = new CSegmentPara;
mySegmentPara->Create(this, IDD_SEARCHPARA, CBRS_LEFT, ID_REGIONSEGSHOW);
mySegmentPara->SetWindowText("分割信息");
//mySegmentPanel.EnableDocking(CBRS_ALIGN_RIGHT | CBRS_ALIGN_LEFT);
mySegmentPara->EnableDocking(CBRS_NOALIGN);
//DockControlBar(&mySegmentPanel);
FloatControlBar(mySegmentPara, CPoint(x, y), CBRS_ALIGN_TOP);
mySegmentPara->ShowWindow(SW_SHOW);
*/
// CG: The following line was added by the Splash Screen component. CSplashWnd::ShowSplashScreen(this);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnDbConnect()
{
CDbConnectDlg myconnect;
myconnect.DoModal();
dbServer = myconnect.dbServer;
dbName = myconnect.dbName;
tableName = myconnect.tableName;
userName = myconnect.userName;
passWord = myconnect.passWord;
seginfoTableName = "segregioninfo";//这两个表名暂时固定;
trainpointTableName = "trainpoints";
strConnection.Format("Driver={SQL Server};Server=%s;Database=%s;Uid=;Pwd=;", dbServer, dbName);
myAdoDb.SetConnectionString(strConnection);
BOOL isok = myAdoDb.Open();
CString sqlquery;
if (!isok)
{
CString tempstr;
tempstr.Format("怎么搞的??打不开图像数据库!!!,:)");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}else
{
myRs = new CADORecordset(&myAdoDb);
//正常连接了数据库;
sqlquery.Format("select id,name,width,height,his1dlen,rank from %s",
tableName);
if (!myRs->Open(sqlquery, CADORecordset::openUnknown))
//if (!myRs->Open(tableName, CADORecordset::openTable))
{
//未正常连接指定表;
CString tempstr;
tempstr.Format("又怎么了?打不开图像数据表!!!,:)");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}
isDbOK = TRUE;
}
recordCount = myRs->GetRecordCount();//得到表中的记录数;
//以下打开区域分割类表与训练点信息表;
seginfoRs = new CADORecordset(&myAdoDb);
sqlquery.Format("select * from %s",
seginfoTableName);
if (!seginfoRs->Open(sqlquery, CADORecordset::openUnknown))
{
CString tempstr;
tempstr.Format("打不开分割信息表!!!,:)");
AfxMessageBox(tempstr,NULL,MB_OK);
isSegInfoDbOK = FALSE;
return;
}else
{
isSegInfoDbOK = TRUE;
}
trainpointRs = new CADORecordset(&myAdoDb);
sqlquery.Format("select * from %s",
trainpointTableName);
if (!trainpointRs->Open(sqlquery, CADORecordset::openUnknown))
{
CString tempstr;
tempstr.Format("打不开点类信息表!!!,:)");
AfxMessageBox(tempstr,NULL,MB_OK);
isTrainPointDbOK = FALSE;
return;
}else
{
isTrainPointDbOK = TRUE;
//以下刷新训练点信息表;
}
//刷新数据表(包括图像数据表与分割类信息);
pDataGridView->UpdateGridDetails(tableName);
}
void CMainFrame::RefreshPtTableID(LONG deleteID, CString regionclass)
//删除指定记录,并重排ID, 参数regionclass在本函数中不使用,只传递给DelPtInExistClass;
{
trainpointRs->Close();
trainpointRs = new CADORecordset(&myAdoDb);
CString sqlquery;
sqlquery.Format("select id from %s",
trainpointTableName);
if (!trainpointRs->Open(sqlquery, CADORecordset::openUnknown))
{
//未正常连接指定表;
CString tempstr;
tempstr.Format("打不开训练点数据表!!!");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}
trainpointRs->Edit();
LONG allcount = trainpointRs->GetRecordCount();
if ( allcount == deleteID)
{
trainpointRs->MoveLast();
trainpointRs->Delete();
trainpointRs->MoveFirst();
trainpointRs->Update();
RefreshRs();
return;//直接删除最后一条记录;
}
trainpointRs->MoveFirst();
while( !trainpointRs->IsEOF() )
{
INT tempid = -1;
BOOL tempbool = trainpointRs->GetFieldValue("id", tempid);
if ( tempid==deleteID )
{
tempbool = trainpointRs->SetFieldValue("id", -1);
break;
}
trainpointRs->MoveNext();
}
trainpointRs->MoveLast();
trainpointRs->SetFieldValue("id", deleteID);//将最后一条记录放到被删位置;
trainpointRs->MoveFirst();
trainpointRs->Update();//首先修改该记录ID;
trainpointRs->MoveFirst();
//以下将该记录删除;
while( !trainpointRs->IsEOF() )
{
INT tempid = 1;
BOOL tempbool = trainpointRs->GetFieldValue("id", tempid);
if ( tempid==-1 )
{
recordCount = recordCount - 1;//记录数减1
tempbool = trainpointRs->Delete();
break;
}
trainpointRs->MoveNext();
}
trainpointRs->MoveFirst();
trainpointRs->Update();//删除该记录;
RefreshPointsRs();
//刷新该所属类所在表(将类记录的训练点数减一,并刷新各相关信息);
DelPtInExistClass(regionclass);
isDbOK = TRUE;
}
void CMainFrame::RefreshTableID(LONG deleteID)
//刷新图像表记录ID;
{
myRs->Close();
myRs = new CADORecordset(&myAdoDb);
CString sqlquery;
sqlquery.Format("select id from %s",
tableName);
if (!myRs->Open(sqlquery, CADORecordset::openUnknown))
{
//未正常连接指定表;
CString tempstr;
tempstr.Format("打不开图像数据表!!!");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}
myRs->Edit();
LONG allcount = myRs->GetRecordCount();
if ( allcount == deleteID)
{
myRs->MoveLast();
myRs->Delete();
myRs->MoveFirst();
myRs->Update();
RefreshRs();
return;//直接删除最后一条记录;
}
myRs->MoveFirst();
while( !myRs->IsEOF() )
{
INT tempid = -1;
BOOL tempbool = myRs->GetFieldValue("id", tempid);
if ( tempid==deleteID )
{
tempbool = myRs->SetFieldValue("id", -1);
break;
}
myRs->MoveNext();
}
myRs->MoveLast();
myRs->SetFieldValue("id", deleteID);//将最后一条记录放到被删位置;
myRs->MoveFirst();
myRs->Update();//首先修改该记录ID;
myRs->MoveFirst();
//以下将该记录删除;
while( !myRs->IsEOF() )
{
INT tempid = 1;
BOOL tempbool = myRs->GetFieldValue("id", tempid);
if ( tempid==-1 )
{
recordCount = recordCount - 1;//记录数减1
tempbool = myRs->Delete();
break;
}
myRs->MoveNext();
}
myRs->MoveFirst();
myRs->Update();//删除该记录;
RefreshRs();
isDbOK = TRUE;
}
void CMainFrame::RefreshPointsRs()
//刷新训练点记录集;
{
INT tempcount = trainpointRs->GetRecordCount();
if (trainpointRs!=NULL)
{
trainpointRs->Close();
}
trainpointRs = new CADORecordset(&myAdoDb);
//正常连接了数据库;
CString sqlquery;
sqlquery.Format("select * from %s", trainpointTableName);
if (!trainpointRs->Open(sqlquery, CADORecordset::openUnknown))
{
//未正常连接指定表;
CString tempstr;
tempstr.Format("打不开训练点数据表!!!");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -