#include "stdafx.h" #include "CalcFeedSettingDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //#ifdef _WIN64 #include"TGAs.h" //#endif WDGridForFeedSet::WDGridForFeedSet() { AppendCol(_T("管径"), 96); AppendCol(_T("流速"), 96); // SetNoAppendButton(); FitLastCol(); } //单元内容将改变为text,返回值代表是否确定 bool WDGridForFeedSet::OnModified(WDGridCell&cell,CString &text) { WDGrid::OnModified(cell,text); int nRow = cell.GetRowIndex(); int nCol = cell.GetColIndex(); if(!IsValidRow(nRow)) return true; double dR = 0.0,dSpeed = 0.0; CString strT = _T(""); if (nCol == 0) // 修改管径 { strT = GetCell(nRow,1).GetText(); dR = _tstof(text);; dSpeed = _tstof(strT); } else if (nCol == 1) // 修改流速 { strT = GetCell(nRow,0).GetText(); dR = _tstof(strT);; dSpeed = _tstof(text); } if (dSpeed < 0) { AfxMessageBox(_T("流速值应大于0!")); return false; } if (dR < 0) { AfxMessageBox(_T("管径值应大于0!")); return false; } if (dR >= 15 && dR <= 20) { if (dSpeed > 1.0) { AfxMessageBox(_T("流速值应小于或等于1.0!")); return false; } } else if (dR >= 25 && dR <= 40) { if (dSpeed > 1.2) { AfxMessageBox(_T("流速值应小于或等于1.2!")); return false; } } else if (dR >= 50 && dR <= 70) { if (dSpeed > 1.5) { AfxMessageBox(_T("流速值应小于或等于1.5!")); return false; } } else if (dR >= 80) { if (dSpeed > 1.8) { AfxMessageBox(_T("流速值应小于或等于1.8!")); return false; } } return true; } CCalcFeedSettingDlg::CCalcFeedSettingDlg(CWnd* pParent /*=NULL*/) : CDialog(CCalcFeedSettingDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCalcFeedSettingDlg) //}}AFX_DATA_INIT } void CCalcFeedSettingDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCalcFeedSettingDlg) DDX_Control(pDX, IDC_LIST_DN, m_gridData); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCalcFeedSettingDlg, CDialog) //{{AFX_MSG_MAP(CCalcFeedSettingDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() BOOL CCalcFeedSettingDlg::OnInitDialog() { CDialog::OnInitDialog(); m_gridData.Clear(); m_gridData.Create(this, IDC_LIST_DN); // 初始化设置列表数据 InitFeedSettingData(); return TRUE; } // 初始化设置列表数据 void CCalcFeedSettingDlg::InitFeedSettingData() { XString fullFile; if(!GlobalFunc::FindFile(_T("datastore.dbf"), fullFile)) { AfxMessageBox(_T("对不起,没有发现datastore.dbf文件!")); return; } CodeBase db; db.read_only = 1; DbfTable *pTable = db.Open(fullFile); if(!pTable) return; int nType = 0,nRowCount = 0; CString strName = _T(""),strValue = _T(""); for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()) { GET_FIELD(pTable, _T("typenumber"), nType); if (nType == 42) { GET_FIELD(pTable, _T("typename"), strName); GET_FIELD(pTable, _T("typevalue"), strValue); m_gridData.AppendRow(); nRowCount = m_gridData.GetRowNum(); m_gridData.GetCell(nRowCount-1,0).SetText(strName); m_gridData.GetCell(nRowCount-1,1).SetText(strValue); } } } void CCalcFeedSettingDlg::OnOK() { if (!MakesureNoRepeatData()) { AfxMessageBox(_T("管径尺寸不能重复!")); return; } // 先删除原有数据 XString fullFile; if(!GlobalFunc::FindFile(_T("datastore.dbf"), fullFile)) { AfxMessageBox(_T("对不起,没有发现datastore.dbf文件!")); return; } CodeBase db; DbfTable *pTable = db.Open(fullFile); if(!pTable) return; int nType = 0; for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()) { GET_FIELD(pTable, _T("typenumber"), nType); if (nType == 42) { pTable->Delete(); } } // 写入当前数据 int nRowCount = m_gridData.GetRowNum(); int nColCount = m_gridData.GetColNum(); if (nColCount < 2) { return; } CString strName = _T(""),strValue = _T(""); for (int i = 0;i < nRowCount;i++) { strName = m_gridData.GetCell(i,0).GetText(); strValue = m_gridData.GetCell(i,1).GetText(); if (!strName.IsEmpty() && !strValue.IsEmpty()) { pTable->AppendBegin(); SET_FIELD(pTable, _T("typenumber"), 42); SET_FIELD(pTable, _T("typename"), (const TCHAR*)strName); SET_FIELD(pTable, _T("typevalue"),(const TCHAR*)strValue); pTable->AppendEnd(); } } CDialog::OnOK(); } // 判断是否有重复的管径 true 无重复 BOOL CCalcFeedSettingDlg::MakesureNoRepeatData() { int nRowCont = m_gridData.GetRowNum(); int nColCount = m_gridData.GetColNum(); if (nColCount < 2) { return FALSE; } CString strName = _T(""),strT = _T(""); int nEqu = 0; for (int i = 0;i < nRowCont;i++) { strT = m_gridData.GetCell(i,0).GetText(); if (strT.IsEmpty()) { continue; } for (int j = 0;j < nRowCont;j++) { strName = m_gridData.GetCell(j,0).GetText(); if (strName == strT) { nEqu++; } if (nEqu > 1) { return FALSE; } } nEqu = 0; } return TRUE; }