📄 dlgftypeattr.cpp
字号:
{
int index = m_lbAttributes.GetCurSel();
if (index != LB_ERR)
{
CFTypeAttr* pFTypeAttr = (CFTypeAttr*)m_lbAttributes.GetItemDataPtr(index);
ASSERT(pFTypeAttr != NULL);
delete pFTypeAttr;
m_lbAttributes.DeleteString(index);
m_eAttrName.SetWindowText("");
m_bUpdate = FALSE;
}
}
///////////////////////////////////////////////////////////
void CDlgFTypeAttr::OnSelchangeAttrtype()
{
CFTypeAttr* pFTypeAttr = NULL;
CString sName;
// Enable ftype link only for links
m_cbFTypeLink.EnableWindow(FALSE);
int index = m_cbAttrType.GetCurSel();
if (index != CB_ERR)
{
if (m_cbAttrType.GetItemData(index) == BDLINK)
{
m_cbFTypeLink.EnableWindow(TRUE);
}
}
}
///////////////////////////////////////////////////////////////////////////////
void CDlgFTypeAttr::OnSelchangeFtypelink()
{
OnSelchangeAttrtype();
m_bUpdate = TRUE;
}
///////////////////////////////////////////////////////////
void CDlgFTypeAttr::OnSelchangeParentfytpe()
{
m_cbManyToOne.EnableWindow(!m_bEdit);
int index = m_cbParentFType.GetCurSel();
if (index != LB_ERR)
{
if (m_cbParentFType.GetItemData(index) == 0)
{
m_cbManyToOne.EnableWindow(FALSE);
}
}
}
///////////////////////////////////////////////////////////
void CDlgFTypeAttr::OnOK()
{
BOOL bOK = TRUE;
CAttrArray aAttr;
CFeatureType ftype;
CFTypeAttr ftypeattr;
// Make sure whole window is visible
if (!m_bShowAttr && m_lType == 0)
{
OnSelchangeDictionary();
return;
}
// If editing then obtain a copy of the existing attributes
if (bOK && m_bEdit)
{
bOK = BDFTypeAttrInit(BDHandle(), m_lFTypeId, &aAttr);
}
BDBeginTrans(BDHandle());
TRY
{
// If there is a name in the attribute edit control and it doesn't exist
// in the list box then add it
if (m_bUpdate)
{
if (AfxMessageBox(BDString(IDS_NOTSAVED), MB_YESNO|MB_DEFBUTTON2) == IDNO)
{
BDRollBack(BDHandle());
return;
}
}
// Retrieve name of feature type
if (!m_bEdit)
{
m_eFTypeName.GetWindowText(ftype.m_sInternal);
} else
{
ftype.m_sInternal = m_ftypeEdit.m_sInternal;
}
m_eFTypeName.GetWindowText(ftype.m_sDesc);
// Retrieve feature type
int index = m_cbParentFType.GetCurSel();
if (index != CB_ERR)
{
ftype.m_lParentFType = m_cbParentFType.GetItemData(index);
ftype.m_bManyToOne = m_cbManyToOne.GetCurSel();
} else
{
AfxMessageBox(BDString(IDS_NOPARENTFTYPE));
bOK = FALSE;
}
// Retrieve dictionary
if (bOK)
{
index = m_cbDictionary.GetCurSel();
if (index != CB_ERR)
{
ftype.m_lDictionary = m_cbDictionary.GetItemData(index);
} else
{
AfxMessageBox(BDString(IDS_NOSECTOR));
bOK = FALSE;
}
};
// Save if okay
if (bOK && ftype.m_sDesc[0] != '\0')
{
// Save feature type
ftype.m_lId = m_lFTypeId;
if (BDFeatureType(BDHandle(), &ftype, m_iFlag))
{
BDEnd(BDHandle());
// Delete existing attributes
CFTypeAttr ftypeattr;
ftypeattr.m_lFType = ftype.m_lId;
BDFTypeAttr(BDHandle(), &ftypeattr, BDDELETEALL);
BDEnd(BDHandle());
// Save corresponding attributes
for (int i = 0; bOK && i < m_lbAttributes.GetCount(); i++)
{
CFTypeAttr* pFTypeAttr = (CFTypeAttr*)m_lbAttributes.GetItemDataPtr(i);
if (pFTypeAttr->GetDataType() != BDFTYPE &&
pFTypeAttr->GetDataType() != BDDATE)
{
m_lbAttributes.GetText(i, pFTypeAttr->m_sDesc);
pFTypeAttr->m_lAttrId = i+1;
// Create auto create link
if (pFTypeAttr->m_lDataType == BDLINK && pFTypeAttr->m_lFTypeLink == -1)
{
CFeatureType ftypeL;
BDNextId(BDHandle(), BDFTYPE, 0, &ftypeL.m_lId);
ftypeL.m_sDesc = ftype.m_sDesc + " " + pFTypeAttr->m_sDesc;
ftypeL.m_sInternal = ftypeL.m_sDesc;
ftypeL.m_lParentFType = 0;
ftypeL.m_bManyToOne = FALSE;
ftypeL.m_lDictionary = ftype.m_lDictionary;
if (BDFeatureType(BDHandle(), &ftypeL, BDADD) &&
BDFTypeCreate(BDHandle(), ftypeL.m_lId))
{
pFTypeAttr->m_lFTypeLink = ftypeL.m_lId;
}
BDEnd(BDHandle());
}
if (pFTypeAttr->m_lDataType != BDLINK ||
(pFTypeAttr->m_lDataType == BDLINK && pFTypeAttr->m_lFTypeLink > 0))
{
bOK = BDFTypeAttr(BDHandle(), pFTypeAttr, BDADD);
} else
{
AfxMessageBox(BDString(IDS_LINKSNOTDEFINE));
bOK = FALSE;
}
};
};
BDEnd(BDHandle());
// Create the corresponding table
if (bOK)
{
if (m_bEdit)
{
bOK = BDFTypeUpdate(BDHandle(), m_lFTypeId, &aAttr);
} else
{
bOK = BDFTypeCreate(BDHandle(), m_lFTypeId);
};
};
};
} else
{
bOK = FALSE;
}
}
CATCH (CDBException, pEx)
{
AfxMessageBox(pEx->m_strError);
bOK = FALSE;
}
END_CATCH
if (bOK)
{
BDCommit(BDHandle());
CDialog::OnOK();
} else
{
BDRollBack(BDHandle());
}
}
///////////////////////////////////////////////////////////////////////////////
//
// Allow the changing of the order of attributes
//
void CDlgFTypeAttr::OnDeltaposUpdown(NMHDR* pNMHDR, LRESULT* pResult)
{
CString s;
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
int iSwap = -1;
int i = m_lbAttributes.GetCurSel();
// Determine which items to swap
if (pNMUpDown->iDelta == -1 && i > 0)
{
iSwap = i-1;
}
else if (pNMUpDown->iDelta == 1 && i != LB_ERR && i+1 < m_lbAttributes.GetCount())
{
iSwap = i+1;
};
// Disable move of ftype and date
if (i <=1 || iSwap <=1 ) return;
// Swap the items
if (iSwap != -1)
{
m_lbAttributes.GetText(i, s);
CFTypeAttr* pFTypeAttr = (CFTypeAttr*)m_lbAttributes.GetItemDataPtr(i);
m_lbAttributes.DeleteString(i);
m_lbAttributes.InsertString(iSwap, s);
m_lbAttributes.SetItemDataPtr(iSwap, pFTypeAttr);
m_lbAttributes.SetCurSel(iSwap);
};
*pResult = 0;
}
///////////////////////////////////////////////////////////////////////////////
void CDlgFTypeAttr::OnClose()
{
CDialog::OnClose();
}
///////////////////////////////////////////////////////////////////////////////
void CDlgFTypeAttr::OnUpdate()
{
CFTypeAttr* pFTypeAttr = NULL;
CString sName;
// Retrieve the currently selected attribute
int index = m_lbAttributes.GetCurSel();
if (index != LB_ERR)
{
pFTypeAttr = (CFTypeAttr*)m_lbAttributes.GetItemDataPtr(index);
}
if (pFTypeAttr != NULL)
{
// Retrieve name
m_eAttrName.GetWindowText(sName);
// Validate name
if (!IsNameValid(sName))
{
return;
}
pFTypeAttr->m_sDesc = sName;
// Ensure column name is unique
if (!m_bEdit)
{
pFTypeAttr->m_sColName = sName;
}
// Retrieve the data type
int iType = m_cbAttrType.GetCurSel();
if (iType != CB_ERR)
{
long lDataType = m_cbAttrType.GetItemData(iType);
// Re-insert the item with the new name
m_lbAttributes.DeleteString(index);
index = m_lbAttributes.InsertString(index, pFTypeAttr->m_sDesc);
m_lbAttributes.SetItemDataPtr(index, pFTypeAttr);
m_lbAttributes.SetCurSel(index);
// If editing, then warn of losing data
if (lDataType != pFTypeAttr->m_lDataType &&
AfxMessageBox(BDString(IDS_DATATYPECHANGE), MB_YESNO) != IDYES)
{
return;
}
pFTypeAttr->m_lDataType = lDataType;
// Retrieve the link
m_cbFTypeLink.EnableWindow(pFTypeAttr->m_lDataType == BDLINK);
if (pFTypeAttr->m_lDataType == BDLINK)
{
int index = m_cbFTypeLink.GetCurSel();
pFTypeAttr->m_lFTypeLink = m_cbFTypeLink.GetItemData(index);
}
// Retrieve the primary key
pFTypeAttr->m_bPrimaryKey = m_cbPrimaryKey.GetCurSel();
};
};
m_bUpdate = FALSE;
}
///////////////////////////////////////////////////////////////////////////////
void CDlgFTypeAttr::OnChangeAttrname()
{
CString(s);
m_eAttrName.GetWindowText(s);
GetDlgItem(IDC_ADD)->EnableWindow(!s.IsEmpty());
m_bUpdate = TRUE;
}
///////////////////////////////////////////////////////////////////////////////
BOOL CDlgFTypeAttr::DestroyWindow()
{
for (int i = 0; i < m_lbAttributes.GetCount(); i++)
{
CFTypeAttr* p = (CFTypeAttr*)m_lbAttributes.GetItemDataPtr(i);
ASSERT(p != NULL);
delete p;
}
m_lbAttributes.ResetContent();
return CDialog::DestroyWindow();
}
///////////////////////////////////////////////////////////////////////////////
BOOL CDlgFTypeAttr::IsNameValid(CString& sName)
{
sName.TrimLeft();
sName.TrimRight();
if (sName.FindOneOf(".[]'") != -1)
{
AfxMessageBox(BDString(IDS_ATTRNAMEINVALID) + " .[]'");
return FALSE;
}
if (sName == "")
{
AfxMessageBox(BDString(IDS_NOTBLANK));
return FALSE;
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//
// Ensure that all internal names are unique
//
void CDlgFTypeAttr::CheckNameUnique(CString& sName)
{
int iCount = 0;
CString s;
int i = 0;
do
{
if (iCount > 0) s.Format("%s%i", sName, iCount);
else s = sName;
for (i = 0; i < m_lbAttributes.GetCount(); i++)
{
CFTypeAttr* pFTypeAttr = (CFTypeAttr*)m_lbAttributes.GetItemDataPtr(i);
if (pFTypeAttr->m_sColName == s)
{
break;
}
};
iCount++;
} while (i != m_lbAttributes.GetCount());
sName = s;
};
///////////////////////////////////////////////////////////////////////////////
//
// Allow users to add new sectors here
//
void CDlgFTypeAttr::OnSector()
{
CComboBoxFType cbFType;
cbFType.InitDictionary();
cbFType.ShowDictionary();
// Initialise the dictionary settings
InitSectors();
}
///////////////////////////////////////////////////////////////////////////////
//
// Update list of sectors, retaining old list
void CDlgFTypeAttr::InitSectors()
{
long lId = 0;
int index = m_cbDictionary.GetCurSel();
if (index != CB_ERR) lId = m_cbDictionary.GetItemData(index);
m_cbDictionary.ResetContent();
CDictionary dictionary;
BOOL bFound = BDDictionary(BDHandle(), &dictionary, BDGETINIT);
while (bFound)
{
int index = m_cbDictionary.AddString(dictionary.m_sDesc);
m_cbDictionary.SetItemData(index, dictionary.m_lId);
if (lId == dictionary.m_lId)
{
m_cbDictionary.SetCurSel(index);
}
bFound = BDGetNext(BDHandle());
}
BDEnd(BDHandle());
if (m_cbDictionary.GetCurSel() == CB_ERR) m_cbDictionary.SetCurSel(0);
}
///////////////////////////////////////////////////////////////////////////////
void CDlgFTypeAttr::OnSelchangeDictionary()
{
// Display whole window
ResizeWindow(IDS_ATTR);
m_bShowAttr = TRUE;
m_eAttrName.SetFocus();
}
///////////////////////////////////////////////////////////////////////////////
void CDlgFTypeAttr::OnKillfocusDictionary()
{
OnSelchangeDictionary();
}
///////////////////////////////////////////////////////////////////////////////
void CDlgFTypeAttr::ResizeWindow(int nControl)
{
CRect rectW, rectC;
GetWindowRect(rectW);
GetDlgItem(nControl)->GetWindowRect(rectC);
int nSpace = GetDC()->GetTextExtent("ABC").cy;
SetWindowPos(NULL,rectW.left,rectW.left,
rectW.Width(), rectC.bottom - rectW.top +nSpace/2,
SWP_NOZORDER);
CenterWindow();
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -