Example #1
0
/*----------------------------------------------------------------------------------------------
	Fill in the string with the given "Date Created" or "Date Modified" value.

	@param flid Field id for either "DateCreated" or "DateModified".
	@param strb Reference to the output string.
----------------------------------------------------------------------------------------------*/
void GeneralPropDlgTab::GetDateString(int flid, StrAppBuf & strb)
{
	strb.Clear();
	try
	{
		AfLpInfo * plpi = m_ppropd->GetLangProjInfo();
		AssertPtr(plpi);
		CustViewDaPtr qcvd;
		plpi->GetDataAccess(&qcvd);
		AssertPtr(qcvd);
		int64 ntim = 0;
		SilTime tim;
		SYSTEMTIME stim;
		achar rgchDate[50]; // Tuesday, August 15, 2000		mardi 15 août 2000
		achar rgchTime[50]; // 10:17:09 PM					22:20:08
		int cch;
		HVO hvo = m_ppropd->GetObjId();
		HRESULT hr;
		CheckHr(hr = qcvd->get_TimeProp(hvo, flid, &ntim));
		if (hr == S_FALSE && !ntim)
		{
			int clid = MAKECLIDFROMFLID(flid);
			AfDbInfo * pdbi = plpi->GetDbInfo();
			AssertPtr(pdbi);
			IOleDbEncapPtr qode;
			pdbi->GetDbAccess(&qode);
			AssertPtr(qode);
			IFwMetaDataCachePtr qmdc;
			pdbi->GetFwMetaDataCache(&qmdc);
			AssertPtr(qmdc);
			SmartBstr sbstrField;
			CheckHr(qmdc->GetFieldName(flid, &sbstrField));
			IOleDbCommandPtr qodc;
			CheckHr(qode->CreateCommand(&qodc));
			StrUni stu;
			ComBool fIsNull;
			ComBool fMoreRows;
			ULONG cbSpaceTaken;

			SmartBstr sbstrClass;
			CheckHr(qmdc->GetClassName(clid, &sbstrClass));
			// Note that we need the view, not just the class table proper, in case the
			// attribute is defined on a superclass (such as CmMajorObject).
			stu.Format(L"select [%b] from [%b_] where [Id] = %d",
				sbstrField.Bstr(), sbstrClass.Bstr(), hvo);
			CheckHr(qodc->ExecCommand(stu.Bstr(), knSqlStmtSelectWithOneRowset));
			CheckHr(qodc->GetRowset(0));
			CheckHr(qodc->NextRow(&fMoreRows));
			if (fMoreRows)
			{
				DBTIMESTAMP dbtim;
				CheckHr(qodc->GetColValue(1, reinterpret_cast <BYTE *>(&dbtim),
					sizeof(DBTIMESTAMP), &cbSpaceTaken, &fIsNull, 0));
				if (!fIsNull)
				{
					stim.wYear = (unsigned short)dbtim.year;
					stim.wMonth = (unsigned short)dbtim.month;
					stim.wDayOfWeek = 0;
					stim.wDay = (unsigned short)dbtim.day;
					stim.wHour = (unsigned short)dbtim.hour;
					stim.wMinute = (unsigned short)dbtim.minute;
					stim.wSecond = (unsigned short)dbtim.second;
					stim.wMilliseconds = (unsigned short)(dbtim.fraction/1000000);
					cch = ::GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stim, NULL,
						rgchDate, 50);
					rgchDate[cch] = 0;
					cch = ::GetTimeFormat(LOCALE_USER_DEFAULT, NULL, &stim, NULL,
						rgchTime, 50);
					rgchTime[cch] = 0;
					strb.Format(_T("%s %s"), rgchDate, rgchTime);
				}
			}

		}
		else if (ntim)
		{
			tim = ntim;
			// Convert the date to a system date.
			// Then format it to a time based on the current user locale.
			stim.wYear = (unsigned short)tim.Year();
			stim.wMonth = (unsigned short)tim.Month();
			stim.wDayOfWeek = (unsigned short)tim.WeekDay();
			stim.wDay = (unsigned short)tim.Date();
			stim.wHour = (unsigned short)tim.Hour();
			stim.wMinute = (unsigned short)tim.Minute();
			stim.wSecond = (unsigned short)tim.Second();
			stim.wMilliseconds = (unsigned short)tim.MilliSecond();
			cch = ::GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stim, NULL, rgchDate,
				50);
			rgchDate[cch] = 0;
			cch = ::GetTimeFormat(LOCALE_USER_DEFAULT, NULL, &stim, NULL, rgchTime, 50);
			rgchTime[cch] = 0;
			strb.Format(_T("%s %s"), rgchDate, rgchTime);
		}
	}
	catch (...)	// Was empty.
	{
		throw;	// For now we have nothing to add, so pass it on up.
	}
}
Example #2
0
/*----------------------------------------------------------------------------------------------
	Check to see if the edit box has valid data.  if so return true.  If not then put up a
	message to the user, then return false.
----------------------------------------------------------------------------------------------*/
bool CleDeFeString::IsOkToClose(bool fWarn)
{
	CleMainWnd * pcmw = dynamic_cast<CleMainWnd *>(m_qadsc->MainWindow());
	Assert(pcmw);

	IVwSelectionPtr qvwsel;
	CheckHr(m_qrootb->get_Selection(&qvwsel));
	if (qvwsel)
	{
		ComBool fOk;
		CheckHr(qvwsel->Commit(&fOk));
	}

	PossListInfoPtr qpli = pcmw->GetPossListInfoPtr();
	int ipss = qpli->GetIndexFromId(m_hvoObj);
	StrUni stuNew;

	const OLECHAR * prgwch;
	int cch;
	ITsStringPtr qtss;
	CustViewDaPtr qcvd;

	GetDataAccess(&qcvd);
	AssertPtr(qcvd);
	int ws = m_qsvc->WritingSystems()[0];

	CheckHr(qcvd->get_MultiStringAlt(m_hvoObj, m_flid, ws, &qtss));
	Assert(qtss);
	qtss->LockText(&prgwch, &cch);
	qtss->UnlockText(prgwch);

	// Trim leading and trailing space characters.
	UnicodeString ust(prgwch, cch);
	ust.trim();
	stuNew.Assign(ust.getBuffer(), ust.length());

	//  Obtain pointer to IOleDbEncap interface.
	IOleDbEncapPtr qode;
	IOleDbCommandPtr qodc;
	StrUni stuSql;
	ComBool fIsNull;
	ComBool fMoreRows;
	AssertPtr(m_qadsc->MainWindow());
	AfLpInfo * plpi = m_qadsc->MainWindow()->GetLpInfo();
	AssertPtr(plpi);
	AfDbInfo * pdbi = plpi->GetDbInfo();
	AssertPtr(pdbi);
	pdbi->GetDbAccess(&qode);
	AssertPtr(qode);
	CheckHr(qode->CreateCommand(&qodc));
	int cpii = qpli->GetCount();

	if ((m_flid == kflidCmPossibility_Name) || (m_flid == kflidCmPossibility_Abbreviation))
	{
		// Make sure it does not have a ":" or a " - " in the string
		int ich = stuNew.FindStr(L":");
		StrUni stuTmp;
		bool fFixed = false;
		while (ich > 0)
		{
			stuNew.Replace(ich,ich + 1,"-");
			fFixed = true;
			ich = stuNew.FindStr(L":");
		}
		ich = stuNew.FindStr(L" - ");
		while (ich > 0)
		{
			stuNew.Replace(ich,ich + 3,"-");
			fFixed = true;
			ich = stuNew.FindStr(L" - ");
		}
		if (fFixed)
		{
			if (fWarn)
			{
				ITsStrFactoryPtr qtsf;
				qtsf.CreateInstance(CLSID_TsStrFactory);
				qtsf->MakeStringRgch(stuNew.Chars(), stuNew.Length(), pcmw->UserWs(), &qtss);
				CheckHr(qcvd->SetMultiStringAlt(m_hvoObj, m_flid, ws, qtss));
				CheckHr(qcvd->PropChanged(NULL, kpctNotifyAll, m_hvoObj, m_flid, 0, 1, 1));
				StrApp strMsg(kstidFixedStr);
				StrApp strTitle(kstidFixedStrTitle);
				::MessageBox(m_hwnd, strMsg.Chars(), strTitle.Chars(),
					MB_OK | MB_ICONINFORMATION);
			}
			return false;
		}
	}

	if (qpli->GetAllowDup())
		return true;

	ILgWritingSystemFactoryPtr qwsf;
	pdbi->GetLgWritingSystemFactory(&qwsf);
	AssertPtr(qwsf);
	switch (m_flid)
	{
		case kflidCmPossibility_Name:
		{
			for (int ipii = 0; ipii < cpii; ipii++)
			{
				if (ipii == ipss)
					continue;
				PossItemInfo * ppii = qpli->GetPssFromIndex(ipii);
				AssertPtr(ppii);
				StrUni stu;
				ppii->GetName(stu, kpntName);
				if (stu == stuNew)
				{
					stuSql.Format(L"select ws from CmPossibility_Name "
						L"where obj = %d and ws = %d",
						ppii->GetPssId(), ws);
					CheckHr(qode->CreateCommand(&qodc));
					CheckHr(qodc->ExecCommand(stuSql.Bstr(), knSqlStmtSelectWithOneRowset));
					CheckHr(qodc->GetRowset(0));
					CheckHr(qodc->NextRow(&fMoreRows));

					if (fMoreRows)
					{
						if (fWarn)
						{
							// this name already exists
							IWritingSystemPtr qws;
							CheckHr(qwsf->get_EngineOrNull(ws, &qws));
							AssertPtr(qws);
							SmartBstr sbstr;
							qws->get_Name(ws, &sbstr);

							StrUni stu(kstidDupItemName);
							StrUni stuMsg;
							stuMsg.Format(stu,sbstr.Chars());
							StrApp str(stuMsg);
							StrApp strTitle(kstidDupItemTitle);
							::MessageBox(m_hwnd, str.Chars(), strTitle.Chars(),
								MB_OK | MB_ICONINFORMATION);
						}
						return false;
					}
				}
			}
			break;
		}
		case kflidCmPossibility_Abbreviation:
		{
			for (int ipii = 0; ipii < cpii; ipii++)
			{
				if (ipii == ipss)
					continue;
				PossItemInfo * ppii = qpli->GetPssFromIndex(ipii);
				AssertPtr(ppii);
				StrUni stu;
				ppii->GetName(stu, kpntAbbreviation);
				if (stu == stuNew)
				{
					stuSql.Format(L"select ws from CmPossibility_Abbreviation "
						L"where obj = %d and ws = %d",
						ppii->GetPssId(), ws);
					CheckHr(qode->CreateCommand(&qodc));
					CheckHr(qodc->ExecCommand(stuSql.Bstr(), knSqlStmtSelectWithOneRowset));
					CheckHr(qodc->GetRowset(0));
					CheckHr(qodc->NextRow(&fMoreRows));

					if (fMoreRows)
					{
						if (fWarn)
						{
							// this abbreviation already exists
							IWritingSystemPtr qws;
							CheckHr(qwsf->get_EngineOrNull(ws, &qws));
							AssertPtr(qws);
							SmartBstr sbstr;
							qws->get_Name(ws, &sbstr);

							StrUni stu(kstidDupItemAbbr);
							StrUni stuMsg;
							stuMsg.Format(stu,sbstr.Chars());
							StrApp str(stuMsg);
							StrApp strTitle(kstidDupItemTitle);
							::MessageBox(m_hwnd, str.Chars(), strTitle.Chars(),
								MB_OK | MB_ICONINFORMATION);
						}
						return false;
					}
				}
			}
			break;
		}
	}
	return true;
}