#include "T2GuestroomTable.h" #include "T2Tenant.h" #include "T2TenantDef.h" #include "T2TowerDoc.h" #include "T2TowerMainView.h" /*virtual*/ int T2GuestroomTable::OnT2DlgItemCreate(CREATESTRUCT* cs) { return T2DlgItemTable::OnT2DlgItemCreate(cs); } T2GuestroomTable::T2GuestroomTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) : T2VerticalTable(inDoc, inImageObj, inPalette) { mClearBackground = true; SetCellDataSize(sizeof(T2GuestroomItem *)); InsertCols(1, 0, NULL); SetHScrollerStyle(AlwaysHide); SetVScrollerStyle(AlwaysShow); mClickTime = 0; } /*virtual*/ T2GuestroomTable::~T2GuestroomTable() { T2GuestroomItem *item; while (mArray.FetchItemAt(1, &item)) { delete item; mArray.RemoveItemsAt(1, 1); } } /*virtual*/ void T2GuestroomTable::Add(T2GuestroomItem* inItem) { unsigned int index = mRows; InsertRows(1, index, &inItem); } /*virtual*/ void T2GuestroomTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { DrawCell(pDC, inCell); } /*virtual*/ void T2GuestroomTable::DrawCell(CDC* pDC, const TableCellT& inCell) { CFont numberFont; CFont statusFont; int savedDC = pDC->SaveDC(); pDC->SelectPalette(mPalette, false); pDC->RealizePalette(); RECT cellRect; if (FetchLocalCellFrame(inCell, cellRect)) { T2GuestroomItem *item; GetCellData(inCell, &item); if (item) { CString str; int numberFontWeight = FW_DONTCARE; if (item->IsRelation()) numberFontWeight = FW_BOLD; numberFont.CreateFont(-9, 0, 0, 0, numberFontWeight, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_TT_ALWAYS, DRAFT_QUALITY, DEFAULT_PITCH, "Terminal"); pDC->SelectObject(&numberFont); pDC->SetBkMode(TRANSPARENT); int roomNum = item->GetRoomNumber(); if (roomNum < 0) str.Format("B%d", 0 - roomNum); else str.Format("%d", roomNum); pDC->TextOut(cellRect.left + 4, cellRect.bottom - 12, str, strlen(str)); COLORREF colorArray[4]; colorArray[0] = RGB(29, 29, 255); colorArray[1] = RGB(255, 0, 0); colorArray[2] = RGB(235, 0, 235); colorArray[3] = RGB(0, 0, 0); int col = 3; if (item->IsFreeRelation()) { // "未接続" - disconnected str = "\x96\xA2\x90\xDA\x91\xB1"; } else { switch (item->GetRoomStatus()) { case kTenantStatus31: col = 0; // "予約済み" - Reserved str = "\x97\x5C\x96\xF1\x8D\xCF\x82\xDD"; break; case kTenantStatus32: case kTenantStatus33: case kTenantStatus34: col = 0; // "宿泊中" - staying str = "\x8F\x68\x94\x91\x92\x86"; break; case kTenantStatus35: case kTenantStatus36: case kTenantStatus37: col = 1; // "未メンテ" - unmaintained str = "\x96\xA2\x83\x81\x83\x93\x83\x65"; break; case kTenantStatus38: col = 2; // "ゴキブリ" - cockroach str = "\x83\x53\x83\x4C\x83\x75\x83\x8A"; break; default: str = ""; } } statusFont.CreateFont(-9, 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); pDC->SelectObject(&statusFont); pDC->SetTextColor(colorArray[col]); pDC->SetBkMode(TRANSPARENT); pDC->TextOut(cellRect.left + 40, cellRect.bottom - 12, str, strlen(str)); } } pDC->RestoreDC(savedDC); } /*virtual*/ void T2GuestroomTable::ClickCell(const TableCellT& inCell, const CPoint& inPt) { T2DlgItemTable::ClickCell(inCell, inPt); if (IsValidCell(mSelectedCell)) { T2GuestroomItem *item; GetCellData(mSelectedCell, &item); if (item) { DWORD time = GetTickCount(); if ((time - mClickTime) < GetDoubleClickTime()) BroadcastMessage(0xFFFFE40C, NULL); else BroadcastMessage(-GetDlgCtrlID(), item); mClickTime = time; } } } /*virtual*/ void T2GuestroomTable::AddList(T2Tenant* inTenant, int inRoomNumber) { T2GuestroomItem *item = new T2GuestroomItem(inTenant, mFront, inRoomNumber); if (item) mArray.InsertItemsAt(1, mArray.GetCount() + 1, &item); } /*virtual*/ void T2GuestroomTable::ValidRelation() { LArrayIterator iterator(mArray); T2GuestroomItem *item; while (iterator.Next(&item)) { if (item->IsRelation()) item->ValidRelation(); else if (item->WasRelation()) item->InvalidRelation(); } } /*virtual*/ void T2GuestroomTable::RevertRelation() { LArrayIterator iterator(mArray); T2GuestroomItem *item; while (iterator.Next(&item)) { item->RevertRelation(); } } /*virtual*/ void T2GuestroomTable::ResetRoomList(int inRoomType) { Clear(); int what = (inRoomType == 0) ? 1 : (inRoomType * 2); LArrayIterator iterator(mArray); T2GuestroomItem *item; while (iterator.Next(&item)) { if (item->GetRoomType() == inRoomType) Add(item); } Invalidate(false); } /*virtual*/ int T2GuestroomTable::CountRooms(int inRoomType, int inRoomStatus) { int count = 0; LArrayIterator iterator(mArray); T2GuestroomItem *item; while (iterator.Next(&item)) { if (item->IsRelation() && item->GetRoomType() == inRoomType) { if (inRoomStatus == 0 || item->GetRoomStatus() == inRoomStatus) count++; } } return count; } /*virtual*/ void T2GuestroomTable::ToggleRelation(const TableCellT& inCell, int inMoneyIndex) { T2GuestroomItem *item; GetCellData(inCell, &item); if (item) item->ToggleRelation(inMoneyIndex); } /*virtual*/ void T2GuestroomTable::SetInMoneyIndex(int inMoneyIndex) { T2GuestroomItem *item; TableCellT theCell; theCell.row = 1; theCell.col = 1; for (unsigned int i = 1; i <= mRows; i++) { theCell.row = i; GetCellData(theCell, &item); if (item && item->IsRelation() && !item->IsStay()) item->SetInMoneyIndex(inMoneyIndex); } } /*virtual*/ int T2GuestroomTable::GetInMoneyIndex(int inRoomType) { int moneyIndex = 0; LArrayIterator iterator(mArray); T2GuestroomItem *item; while (iterator.Next(&item)) { if (item->GetRoomType() == inRoomType) { if (item->IsRelation()) return item->GetInMoneyIndex(); if (moneyIndex == 0) { T2Tenant *theTenant = item->GetTenant(); T2EquipDef *theDef = theTenant ? theTenant->GetEquipDef() : NULL; if (theDef) { moneyIndex = theDef->GetNumOfInMoney(); moneyIndex = (moneyIndex > 1) ? ((moneyIndex / 2) + 1) : 1; } } } } return (moneyIndex > 0) ? moneyIndex : 1; } /*virtual*/ int T2GuestroomTable::CalcInMoney(int inRoomType) { int result = 0; LArrayIterator iterator(mArray); T2GuestroomItem *item; while (iterator.Next(&item)) { if (item->IsRelation() && item->GetRoomType() == inRoomType) { switch (item->GetRoomStatus()) { case kTenantStatus31: case kTenantStatus32: case kTenantStatus33: case kTenantStatus34: result += item->GetInMoney(); break; } } } return result; } void T2GuestroomTable::UpdateTenantEstimation(T2TowerDoc* inDoc, int inRoomType) { LArrayIterator iterator(mArray); T2GuestroomItem *item; while (iterator.Next(&item)) { if (inRoomType == -1 || item->GetRoomType() == inRoomType) item->UpdateTenantEstimation(inDoc); } } /*virtual*/ void T2GuestroomTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { CPoint pt = inPt; ClientToView(&pt, 1); TableCellT cell; FetchCellHitBy(pt, cell); if (IsValidCell(cell)) ClickCell(cell, inPt); } /*virtual*/ BOOL T2GuestroomTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { T2VerticalTable::OnT2DlgItemEraseBkgnd(pDC); unsigned int numOfRows, numOfColumns, theRow, theColumn; GetTableSize(numOfRows, numOfColumns); for (theColumn = 1; theColumn <= numOfColumns; theColumn++) { for (theRow = 1; theRow <= numOfRows; theRow++) { TableCellT cell; cell.row = theRow; cell.col = theColumn; DrawCell(pDC, cell); } } T2DlgItemTable::HiliteCell(pDC, mSelectedCell); return true; } T2GuestroomItem::T2GuestroomItem(T2Tenant* inTenant, int inSaveTenantID, long inRoomNumber) { mTenant = inTenant; mSaveTenantID = inSaveTenantID; mRoomNumber = inRoomNumber; mRelation = WasRelation(); mDefaultInMoneyIndex = inTenant->GetInMoneyIndex() + 1; } int T2GuestroomItem::GetRoomNumber() { return mRoomNumber; } int T2GuestroomItem::GetRoomStatus() { return mTenant->GetStatus(); } int T2GuestroomItem::GetCapacity() { return mTenant->GetCapacity(); } int T2GuestroomItem::GetRoomType() { return GetRoomType(mTenant); } /*static*/ int T2GuestroomItem::GetRoomType(T2Tenant* inTenant) { int result = -1; T2EquipDef *theEquipDef = inTenant->GetEquipDef(); if (theEquipDef) { switch (theEquipDef->GetToolType()) { case 1401: result = 0; break; case 1402: result = 1; break; case 1403: result = 2; break; case 1481: result = 0; break; case 1482: result = 1; break; } } return result; } void T2GuestroomItem::ToggleRelation(int inMoneyIndex) { mRelation = !mRelation; SetInMoneyIndex(mRelation ? inMoneyIndex : mDefaultInMoneyIndex); } BOOL T2GuestroomItem::IsRelation() { return mRelation; } BOOL T2GuestroomItem::WasRelation() { return mTenant->GetRelatedTenantID() == mSaveTenantID; } void T2GuestroomItem::ValidRelation() { mTenant->SetRelatedTenantID(mSaveTenantID); } void T2GuestroomItem::InvalidRelation() { mTenant->SetRelatedTenantID(0); } void T2GuestroomItem::RevertRelation() { SetInMoneyIndex(mDefaultInMoneyIndex); } BOOL T2GuestroomItem::IsFreeRelation() { return !IsRelation() && (WasRelation() || mTenant->GetRelatedTenantID() == 0); } BOOL T2GuestroomItem::IsStay() { return mTenant->GetTotalBelong() > 0; } void T2GuestroomItem::SetInMoneyIndex(int inIndex) { mTenant->SetInMoneyIndex((inIndex < 1) ? 0 : (inIndex - 1)); } int T2GuestroomItem::GetInMoneyIndex() { return mTenant->GetInMoneyIndex() + 1; } int T2GuestroomItem::GetInMoney() { return mTenant->IsTherePeople() ? mTenant->GetInMoney() : 0; } int T2GuestroomItem::GetOutMoney() { return mTenant->GetOutMoney(); } void T2GuestroomItem::UpdateTenantEstimation(T2TowerDoc* inDoc) { BOOL isChanged = mTenant->UpdateResidencialEstimate(inDoc); int viewMode = inDoc->GetViewMode(); if ((viewMode == kEvalView && isChanged) || (viewMode == kPriceView)) { mTenant->SetDrawMode(DrawMode1); RECT rect; mTenant->GetEquipArea(rect); inDoc->GetMainView()->InvalUnitRect(rect); } }