A Journey 2 Eternity


DECLARE @startdate SMALLDATETIME = '2011-01-01'
DECLARE @stopdate SMALLDATETIME = '2011-12-31'

-- Create a Table
DECLARE @weekTable TABLE (
Id INT IDENTITY (1, 1),
StartDate SMALLDATETIME,
EndDate SMALLDATETIME
)

-- Find Monday at that week
DECLARE @currentDate SMALLDATETIME = DATEADD(d, 2 - DATEPART(dw, @startdate), @startdate)

WHILE @currentDate <= @stopdate BEGIN
INSERT INTO @weekTable VALUES (@currentDate, DATEADD(d, 6, @currentDate))
SET @currentDate = DATEADD(ww, 1, @currentDate)
END

-- Return the results
SELECT Id 'Week #', StartDate 'Start Date', EndDate 'End Date'
FROM @weekTable

Advertisements
Tags: ,

We can deprecate a method, property, or even an entire class in C++ Builder, using the [[deprecated]] attribute. Deprecating an entity is a way of signalling to other developers that it should no longer be used, typically because there is another – more preferable – way of doing things.

When a deprecated entity is used in code, a compiler warning will be issued.

enum StatModelsType [[deprecated("Use StatisticalModelType instead.")]] {
smtNone = 0,
smtScanModel,
smtExFactoryModel,
smtOptimiserModel
};
DECLARE @Date datetime
SET @Date = '2011/11/16'
SELECT  DATEADD(dd,-(DATEPART(dw, @Date) - 1),@Date) AS 'First day of the week',
DATEADD(dd,-(DATEPART(dw, @Date) - 7),@Date) AS 'Last day of the week',
DAY(DATEADD(d, -DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date))) AS 'Total day of the month'
Tags: ,

The following query retrieving the table column details.

SELECT COLUMN_NAME [Field],DATA_TYPE + '(' + ISNULL(CONVERT(NVARCHAR,CHARACTER_MAXIMUM_LENGTH),'') + ')' + '    ' + CASE WHEN IS_NULLABLE = 'NO' THEN 'NOT ' ELSE '' END + 'NULL' [Type] 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = 'account' 
ORDER BY ORDINAL_POSITION ASC
Tags: ,

Here’s a sample which draws background of a dialog with gradient colors.

BOOL CMyDlg::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(&rect);

TRIVERTEX vert[4] = {
{ rect.left, rect.top, 0xff00, 0xff00, 0xff00, 0 },
{ rect.right, rect.top, 0, 0xff00, 0xff00, 0 },
{ rect.right, rect.bottom, 0xff00, 0, 0xff00, 0 },
{ rect.left, rect.bottom, 0xff00, 0xff00, 0, 0 }
};

GRADIENT_TRIANGLE grad[2] = {
{ 0, 1, 2 },
{ 0, 2, 3 }
};

::GradientFill( pDC->m_hDC, vert, 4, grad, 2, GRADIENT_FILL_TRIANGLE );

return TRUE;
}

void CMyDlg::OnSize(UINT nType, int cx, int cy)
{
// To ensure the background of the whole dialog is re-drawn
Invalidate();
CDialog::OnSize(nType, cx, cy);
}
//! Replaces a color with a fill color in a given area of a
//! Device Context
//!
//! \param hDC                   : Specifies the Device Context
//! \param rcReplaceArea     : Specifies the portion of the DC area to apply the replace operation
//! \param clrColorReplace    : Specifies the color to be replaced
//! \param clrColorFill : Specifies the fill color

void ReplaceColor(HDC hDC, CRect rcReplaceArea, COLORREF clrColorReplace, COLORREF clrColorFill)
{
	CDC* pDC = CDC::FromHandle(hDC);
	CPoint pt = rcReplaceArea.TopLeft();

	CDC memDCMonoChrome;
	memDCMonoChrome.CreateCompatibleDC(pDC);

	CBitmap bmpMonoChrome;
	bmpMonoChrome.CreateCompatibleBitmap(&memDCMonoChrome, rcReplaceArea.Width(), rcReplaceArea.Height());

	CBitmap* pOldMonoBitmap = memDCMonoChrome.SelectObject(&bmpMonoChrome);

	COLORREF nOldBkColor = pDC->SetBkColor(clrColorReplace);

	// BLT to mono dc so that mask color will have 1 set and the other colors 0
	memDCMonoChrome.BitBlt(0, 0, rcReplaceArea.Width(), rcReplaceArea.Height(), pDC, pt.x, pt.y, SRCCOPY);

	CDC memDC;
	memDC.CreateCompatibleDC(pDC);

	CBitmap bmp;
	bmp.CreateCompatibleBitmap(pDC, rcReplaceArea.Width(),

	rcReplaceArea.Height());

	CBitmap* pOldBitmap = memDC.SelectObject(&bmp);
	COLORREF nOldMemDCBkColor = memDC.SetBkColor(clrColorFill);
	COLORREF nOldMemDCTextColor =

	memDC.SetTextColor(RGB(255, 255, 255));

	// BLT to mem DC so that the monochrome white is set to fill color and the monochrome black is set to white
	memDC.BitBlt(0, 0, rcReplaceArea.Width(), rcReplaceArea.Height(), &memDCMonoChrome, 0, 0, SRCCOPY);

	// AND pDC with mem dc so that the replace color part is blackened out and all other colors remains same
	pDC->BitBlt(pt.x, pt.y, rcReplaceArea.Width(), rcReplaceArea.Height(), &memDC, 0, 0, SRCAND);
	memDC.SetTextColor(RGB(0, 0, 0));

	// BLT to mem DC so that the monochrome white is set to fill color and the monochrome black is set to black
	memDC.BitBlt(0, 0, rcReplaceArea.Width(), rcReplaceArea.Height(), &memDCMonoChrome, 0, 0, SRCCOPY);

	// OR pDC with mem dc so that all colors remains as they where except the blackened out (replace color) part receives the fill color
	pDC->BitBlt(pt.x, pt.y, rcReplaceArea.Width(), rcReplaceArea.Height(), &memDC, 0, 0, SRCPAINT);

	// Set the original values back
	memDC.SetTextColor(nOldMemDCTextColor);
	memDC.SetBkColor(nOldMemDCBkColor);
	pDC->SetBkColor(nOldBkColor);

	// Set the original bitmaps back
	memDCMonoChrome.SelectObject(pOldMonoBitmap);
	memDC.SelectObject(pOldBitmap);
}

1. LButtonDown

2. LButtonUp

3. LButtonDblClick

4. LButtonUp

Tags: ,

Pages

Categories

October 2017
M T W T F S S
« Aug    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Blog Stats

  • 27,491 hits