📄 batchmodidlg.cpp
字号:
// BatchModiDlg.cpp : implementation file
//
#include "stdafx.h"
#include "datasvr.h"
#include "dbgrid32.h"
#include "glovar.h"
#include "BatchModiDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBatchModiDlg dialog
CBatchModiDlg::CBatchModiDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBatchModiDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBatchModiDlg)
//}}AFX_DATA_INIT
m_iMaxRow=0;
type=1;
m_bAllowSave=TRUE;
title="批修改";
}
void CBatchModiDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBatchModiDlg)
DDX_Control(pDX, IDC_COMBO1, m_combox);
DDX_Control(pDX, IDC_LIST1, m_ListBox);
DDX_Control(pDX, IDC_DBGRID1, m_dbgrid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBatchModiDlg, CDialog)
//{{AFX_MSG_MAP(CBatchModiDlg)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_LBN_KILLFOCUS(IDC_LIST1, OnKillfocusList1)
ON_WM_SIZE()
ON_CBN_SELENDOK(IDC_COMBO1, OnSelendokCombo1)
ON_BN_CLICKED(IDC_DOWNLOAD, OnDownload)
ON_BN_CLICKED(IDC_LOAD, OnLoad)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBatchModiDlg message handlers
BEGIN_EVENTSINK_MAP(CBatchModiDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CBatchModiDlg)
ON_EVENT(CBatchModiDlg, IDC_DBGRID1, 20 /* UnboundAddData */, OnUnboundAddDataDbgrid1, VTS_DISPATCH VTS_PVARIANT)
ON_EVENT(CBatchModiDlg, IDC_DBGRID1, 33 /* ButtonClick */, OnButtonClickDbgrid1, VTS_I2)
ON_EVENT(CBatchModiDlg, IDC_DBGRID1, 21 /* UnboundDeleteRow */, OnUnboundDeleteRowDbgrid1, VTS_PVARIANT)
ON_EVENT(CBatchModiDlg, IDC_DBGRID1, 18 /* UnboundReadData */, OnUnboundReadDataDbgrid1, VTS_DISPATCH VTS_PVARIANT VTS_BOOL)
ON_EVENT(CBatchModiDlg, IDC_DBGRID1, 19 /* UnboundWriteData */, OnUnboundWriteDataDbgrid1, VTS_DISPATCH VTS_PVARIANT)
ON_EVENT(CBatchModiDlg, IDC_DBGRID1, 14 /* Scroll */, OnScrollDbgrid1, VTS_PI2)
ON_EVENT(CBatchModiDlg, IDC_DBGRID1, 6 /* BeforeDelete */, OnBeforeDeleteDbgrid1, VTS_PI2)
ON_EVENT(CBatchModiDlg, IDC_DBGRID1, 3 /* AfterInsert */, OnAfterInsertDbgrid1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CBatchModiDlg::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 CBatchModiDlg::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 CBatchModiDlg::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 CBatchModiDlg::OnUnboundDeleteRowDbgrid1(VARIANT FAR* Bookmark)
{
long lCurRow = Bookmark->lVal; //获得用户删除的行的索引
CStringArray * pDelRow = m_aData[lCurRow]; // 获得指向该行的指针
m_aData.RemoveAt(lCurRow); //删除数据
delete pDelRow;
m_iMaxRow --; //行数减一
}
void CBatchModiDlg::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()*2;
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");
}
if(ColIndex==6) //仪表波特率
{
m_ListBox.AddString("1200");
m_ListBox.AddString("2400");
m_ListBox.AddString("4800");
m_ListBox.AddString("9600");
}
break;
case 2: //测点维护
if(ColIndex==3) //仪表
{
for(int i=0;i<arrYB.GetSize();i++)
{
NPYB npyb=arrYB.GetAt(i);
int cur=m_ListBox.AddString(npyb->ybname);
m_ListBox.SetItemData(cur,npyb->ybid);
}
}
if(ColIndex==4) //通道
{
m_ListBox.AddString("1");
m_ListBox.AddString("2");
m_ListBox.AddString("3");
m_ListBox.AddString("4");
}
break;
case 3: //仪表参数名称维护
if(ColIndex==1) //仪表类型
{
m_ListBox.AddString("XLF-51");
m_ListBox.AddString("YB-2");
m_ListBox.AddString("YB-3");
m_ListBox.AddString("其他");
}
if(ColIndex==4) //参数类型
{
m_ListBox.AddString("长整");
m_ListBox.AddString("短整");
m_ListBox.AddString("浮点");
m_ListBox.AddString("字符");
}
break;
case 4: //实时数据采集参数维护
if(ColIndex==2) //测点
{
for(int i=0;i<arrCD.GetSize();i++)
{
NPCD npcd=arrCD.GetAt(i);
int cur=m_ListBox.AddString(npcd->cdname);
m_ListBox.SetItemData(cur,npcd->cdid);
}
}
if(ColIndex==4) //参数
{
for(int i=0;i<arrCS.GetSize();i++)
{
NPCS npcs=arrCS.GetAt(i);
int cur=m_ListBox.AddString(npcs->csname);
m_ListBox.SetItemData(cur,npcs->csid);
}
}
if(ColIndex==6) //bool
{
m_ListBox.AddString("启用");
m_ListBox.AddString("禁止");
}
if(ColIndex==7) //bool
{
m_ListBox.AddString("启用");
m_ListBox.AddString("禁止");
}
if(ColIndex==12) //保存周期
{
m_ListBox.AddString("0");
m_ListBox.AddString("1");
m_ListBox.AddString("10");
m_ListBox.AddString("30");
m_ListBox.AddString("60");
m_ListBox.AddString("1440");
}
break;
case 5: //仪表参数维护
if(ColIndex==1) //参数
{
for(int i=0;i<arrCS.GetSize();i++)
{
NPCS npcs=arrCS.GetAt(i);
int cur=m_ListBox.AddString(npcs->csname);
m_ListBox.SetItemData(cur,npcs->csid);
}
}
break;
default:
break;
}
m_dbgrid.SetCol(oldcol);
m_ListBox.BringWindowToTop();
m_ListBox.ShowWindow(SW_SHOW); //从隐藏变为显示
m_ListBox.SetFocus();
}
void CBatchModiDlg::OnScrollDbgrid1(short FAR* Cancel)
{
if(m_ListBox.IsWindowVisible())
*Cancel = TRUE;
}
BOOL CBatchModiDlg::OnInitDialog()
{
CDialog::OnInitDialog();
this->SetWindowText(title);
switch(type)
{
case 1: //现场仪表情况
{
filename=".\\misc\\YB.par";
Column Col; //列对象
Columns Cols;//Columns对象
Cols=m_dbgrid.GetColumns();
Col=Cols.GetItem(_variant_t((short)0));
Col.SetCaption("仪表ID");
Col.SetVisible(TRUE);
Col.SetWidth(40);
Col=Cols.GetItem(_variant_t((short)1));
Col.SetCaption("仪表名称");
Col.SetVisible(TRUE);
Col.SetWidth(80);
Col=Cols.GetAdd(2);
Col.SetCaption("仪表类型");
Col.SetVisible(TRUE);
Col.SetButton(TRUE);
Col.SetLocked(TRUE);
Col.SetWidth(80);
Col=Cols.GetAdd(3);
Col.SetCaption("COM口地址");
Col.SetVisible(TRUE);
Col.SetButton(TRUE);
Col.SetLocked(TRUE);
Col.SetWidth(60);
Col=Cols.GetAdd(4);
Col.SetCaption("仪表地址");
Col.SetVisible(TRUE);
Col.SetButton(TRUE);
Col.SetLocked(TRUE);
Col.SetWidth(40);
Col=Cols.GetAdd(5);
Col.SetCaption("安装地点");
Col.SetVisible(TRUE);
Col.SetWidth(120);
Col=Cols.GetAdd(6);
Col.SetCaption("波特率");
Col.SetVisible(TRUE);
Col.SetButton(TRUE);
Col.SetLocked(TRUE);
Col.SetWidth(120);
m_aData.SetSize(arrYB.GetSize());
for(int i=0;i<arrYB.GetSize();i++)
{
CString str;
NPYB npyb=arrYB.GetAt(i);
CStringArray * elem;
elem=new CStringArray();
str.Format("%d",npyb->ybid);
elem->Add(str);
elem->Add(npyb->ybname);
elem->Add(npyb->ybtype);
elem->Add(npyb->comport);
elem->Add(npyb->ybaddr);
elem->Add(npyb->AnZDD);
str.Format("%d",npyb->ybbaud);
elem->Add(str);
m_aData.SetAt(i,elem);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -