📄 paramodeformview.cpp
字号:
// ParaModeFormView.cpp : implementation file
//
#include "stdafx.h"
#include "datasvr.h"
#include "ParaModeFormView.h"
#include "dbgrid32.h"
#include "glovar.h"
#include "mainfrm.h"
#include "VisualFX.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CParaModeFormView
IMPLEMENT_DYNCREATE(CParaModeFormView, TVisualFormView)
CParaModeFormView::CParaModeFormView()
: TVisualFormView(CParaModeFormView::IDD)
{
//{{AFX_DATA_INIT(CParaModeFormView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_iMaxRow=0;
type=1;
m_bAllowSave=TRUE;
}
CParaModeFormView::~CParaModeFormView()
{
}
void CParaModeFormView::DoDataExchange(CDataExchange* pDX)
{
TVisualFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CParaModeFormView)
DDX_Control(pDX, IDC_LIST1, m_ListBox);
DDX_Control(pDX, IDC_DBGRID1, m_dbgrid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CParaModeFormView, TVisualFormView)
//{{AFX_MSG_MAP(CParaModeFormView)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_LBN_KILLFOCUS(IDC_LIST1, OnKillfocusList1)
ON_WM_DESTROY()
ON_BN_CLICKED(IDT_OK, OnSave)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CParaModeFormView diagnostics
#ifdef _DEBUG
void CParaModeFormView::AssertValid() const
{
CFormView::AssertValid();
}
void CParaModeFormView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CParaModeFormView message handlers
BEGIN_EVENTSINK_MAP(CParaModeFormView, TVisualFormView)
//{{AFX_EVENTSINK_MAP(CParaModeFormView)
ON_EVENT(CParaModeFormView, IDC_DBGRID1, 18 /* UnboundReadData */, OnUnboundReadDataDbgrid1, VTS_DISPATCH VTS_PVARIANT VTS_BOOL)
ON_EVENT(CParaModeFormView, IDC_DBGRID1, 19 /* UnboundWriteData */, OnUnboundWriteDataDbgrid1, VTS_DISPATCH VTS_PVARIANT)
ON_EVENT(CParaModeFormView, IDC_DBGRID1, 20 /* UnboundAddData */, OnUnboundAddDataDbgrid1, VTS_DISPATCH VTS_PVARIANT)
ON_EVENT(CParaModeFormView, IDC_DBGRID1, 21 /* UnboundDeleteRow */, OnUnboundDeleteRowDbgrid1, VTS_PVARIANT)
ON_EVENT(CParaModeFormView, IDC_DBGRID1, 33 /* ButtonClick */, OnButtonClickDbgrid1, VTS_I2)
ON_EVENT(CParaModeFormView, IDC_DBGRID1, 14 /* Scroll */, OnScrollDbgrid1, VTS_PI2)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CParaModeFormView::OnUnboundReadDataDbgrid1(LPDISPATCH RowBuf, VARIANT FAR* StartLocation, BOOL ReadPriorRows)
{
long lRowsFetched = 0L, lCurRow = 0L, i = 0L;
short incr = 0;
if(ReadPriorRows)
incr = -1; //从后往前读
else
incr = 1; //从前往后读
if(StartLocation->vt == VT_NULL)
{
if(ReadPriorRows)
lCurRow = m_iMaxRow - 1L; //从最后一行开始读
else
lCurRow = 0L; //从第一行开始读
}
else //从StartLocation的后一行或前一行开始读
lCurRow = StartLocation->lVal + incr;
RowBuffer Rowbuf;
Rowbuf.AttachDispatch(RowBuf);
long lRowCount = Rowbuf.GetRowCount(); //总行数
short nColCount = Rowbuf.GetColumnCount(); //总列数
CString sCellText; //单元格中的内容
while(i < lRowCount)
{
if(lCurRow < 0L || lCurRow >= m_iMaxRow)
{ //数据读完了,返回读取的行数
Rowbuf.SetRowCount(lRowsFetched);
Rowbuf.DetachDispatch();
return;
}
for(short j = 0; j < nColCount; j ++)
{ //将数据读入表格单元格
sCellText = m_aData[lCurRow]->GetAt(j);
COleVariant newVariant(sCellText);
Rowbuf.SetValue(i, j, newVariant);
}
//将行索引作为该行的Bookmark
COleVariant varValue(lCurRow);
Rowbuf.SetBookmark(i, varValue);
lCurRow += incr;
lRowsFetched ++; i ++;
}
Rowbuf.SetRowCount(lRowsFetched);
Rowbuf.DetachDispatch();
}
void CParaModeFormView::OnUnboundWriteDataDbgrid1(LPDISPATCH RowBuf, VARIANT FAR* WriteLocation)
{
VARIANT varResult; //接收返回的字符串
CString str;
RowBuffer Rowbuf;
Rowbuf.AttachDispatch(RowBuf);
short nColCount = Rowbuf.GetColumnCount();//总列数
long lCurRow = WriteLocation->lVal;//得到被编辑的行的索引
for(short i = 0; i < nColCount; i ++)
{
varResult = Rowbuf.GetValue(0L, i);
if(varResult.vt != VT_NULL)//表明此单元格内容被修改
{
str = varResult.bstrVal;
m_aData[lCurRow]->SetAt(i, str);//记录结果
}
}
Rowbuf.DetachDispatch();
}
void CParaModeFormView::OnUnboundAddDataDbgrid1(LPDISPATCH RowBuf, VARIANT FAR* NewRowBookmark)
{
VARIANT varResult; CString str;
RowBuffer Rowbuf;
Rowbuf.AttachDispatch(RowBuf);
short nColCount = Rowbuf.GetColumnCount(); //总列数
CStringArray * pRowData = new CStringArray; //为新数据分配空间
pRowData->SetSize(nColCount);
m_aData.SetAtGrow(m_iMaxRow, pRowData);
for(short i = 0; i < nColCount; i ++)
{ //记录新输入的数据
varResult = Rowbuf.GetValue(0L, i);
if(varResult.vt != VT_NULL) //当前单元格输入了数据
{
str = varResult.bstrVal;
m_aData[m_iMaxRow]->SetAt(i, str);
}
}
Rowbuf.DetachDispatch();
//为新增的行设置Bookmark
NewRowBookmark->vt = VT_I4;
NewRowBookmark->lVal = m_iMaxRow;
m_iMaxRow ++;
}
void CParaModeFormView::OnUnboundDeleteRowDbgrid1(VARIANT FAR* Bookmark)
{
long lCurRow = Bookmark->lVal; //获得用户删除的行的索引
CStringArray * pDelRow = m_aData[lCurRow]; // 获得指向该行的指针
m_aData.RemoveAt(lCurRow); //删除数据
delete pDelRow;
m_iMaxRow --; //行数减一
}
void CParaModeFormView::OnButtonClickDbgrid1(short ColIndex)
{
RECT rect; Column Col;
COleVariant CurCol(ColIndex);
LPDISPATCH pCol = m_dbgrid.GetColumns(CurCol);
Col.AttachDispatch(pCol);
//得到当前单元格的位置和宽度、高度
float LeftEdge = Col.GetLeft();
float Width = Col.GetWidth();
float Height = m_dbgrid.GetRowHeight();
short nCurRow = m_dbgrid.GetRow();
float Top = m_dbgrid.RowTop(nCurRow);
Col.DetachDispatch();
//将列表框移到合适的位置并设置其大小
m_dbgrid.GetWindowRect(&rect);
ScreenToClient(&rect);
m_ListBox.MoveWindow((short)(rect.left + LeftEdge + Width),
(short)(-Top+rect.top), (int)Width, (int)(5*Height));
int oldcol;
oldcol=m_dbgrid.GetCol();
m_ListBox.ResetContent();
switch(type)
{
case 1: //仪表设置
if(ColIndex==2) //仪表类型
{
m_ListBox.AddString("XLF-51");
m_ListBox.AddString("YB-2");
m_ListBox.AddString("YB-3");
m_ListBox.AddString("其他");
}
if(ColIndex==3) //COM口地址
{
m_ListBox.AddString("COM1");
m_ListBox.AddString("COM2");
m_ListBox.AddString("COM3");
m_ListBox.AddString("COM4");
m_ListBox.AddString("COM5");
m_ListBox.AddString("COM6");
m_ListBox.AddString("COM7");
m_ListBox.AddString("COM8");
m_ListBox.AddString("COM9");
m_ListBox.AddString("COM10");
m_ListBox.AddString("COM11");
m_ListBox.AddString("COM12");
m_ListBox.AddString("COM13");
m_ListBox.AddString("COM14");
m_ListBox.AddString("COM15");
m_ListBox.AddString("COM16");
m_ListBox.AddString("COM17");
m_ListBox.AddString("COM18");
m_ListBox.AddString("COM19");
m_ListBox.AddString("COM20");
m_ListBox.AddString("COM21");
m_ListBox.AddString("COM22");
m_ListBox.AddString("COM23");
m_ListBox.AddString("COM24");
m_ListBox.AddString("COM25");
}
if(ColIndex==4) //仪表地址
{
m_ListBox.AddString("01");
m_ListBox.AddString("02");
m_ListBox.AddString("03");
m_ListBox.AddString("04");
m_ListBox.AddString("05");
m_ListBox.AddString("06");
m_ListBox.AddString("07");
m_ListBox.AddString("08");
m_ListBox.AddString("09");
m_ListBox.AddString("0A");
m_ListBox.AddString("0B");
m_ListBox.AddString("0C");
m_ListBox.AddString("0D");
m_ListBox.AddString("0E");
m_ListBox.AddString("0F");
m_ListBox.AddString("10");
m_ListBox.AddString("11");
m_ListBox.AddString("12");
m_ListBox.AddString("13");
m_ListBox.AddString("14");
m_ListBox.AddString("15");
m_ListBox.AddString("16");
m_ListBox.AddString("17");
m_ListBox.AddString("18");
m_ListBox.AddString("19");
m_ListBox.AddString("1A");
m_ListBox.AddString("1B");
m_ListBox.AddString("1C");
m_ListBox.AddString("1D");
m_ListBox.AddString("1E");
m_ListBox.AddString("1F");
}
break;
case 2: //测点维护
if(ColIndex==4) //仪表地址
{
m_ListBox.AddString("01");
}
break;
case 3: //仪表参数名称维护
break;
case 4: //实时数据采集参数维护
break;
default:
break;
}
m_dbgrid.SetCol(oldcol);
m_ListBox.BringWindowToTop();
m_ListBox.ShowWindow(SW_SHOW); //从隐藏变为显示
m_ListBox.SetFocus();
}
void CParaModeFormView::OnScrollDbgrid1(short FAR* Cancel)
{
if(m_ListBox.IsWindowVisible())
*Cancel = TRUE;
}
void CParaModeFormView::OnSelchangeList1()
{
CString sText;
int iOption = m_ListBox.GetCurSel();
m_ListBox.GetText(iOption, sText); //得到选中项的文本
m_ListBox.ResetContent();
m_ListBox.ShowWindow(SW_HIDE); //隐藏列表框
int oldcol;
oldcol=m_dbgrid.GetCol();
/*8 if(oldcol==0)
{
m_dbgrid.SetText(sText);
m_dbgrid.SetCol(1);
m_dbgrid.SetText("");
m_dbgrid.SetCol(2);
m_dbgrid.SetText(m_aId.GetAt(iOption));
}
else if(oldcol==1)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -