Joseph Michael Pesch
VP Programming

C# Overlay Two Images

by 17. November 2009 21:25

[No text]

Tags: ,

[None]

C# Rotate Image

by 17. November 2009 21:24

Excerpt from: http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate

private Bitmap rotateImage(Bitmap b, float angle)
{
  //create a new empty bitmap to hold rotated image
  Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
  //make a graphics object from the empty bitmap
  Graphics g = Graphics.FromImage(returnBitmap);
  //move rotation point to center of image
  g.TranslateTransform((float)b.Width/2, (float)b.Height / 2);
  //rotate
  g.RotateTransform(angle);
  //move image back
  g.TranslateTransform(-(float)b.Width/2,-(float)b.Height / 2);
  //draw passed in image onto graphics object
  g.DrawImage(b, new Point(0, 0));
  return returnBitmap;
}

Tags: ,

Excel

SQL Server Common Table Expression (CTE)

by 12. November 2009 18:00

Must have semi-colon on last statement before the "WITH" keyword that begins the Common Table Expression (see sample below on "select @Dummy = 0;" line).  Multiple CTE's must be comma delimited under the single "WITH" keyword (i.e. only the first CTE begins with the "WITH" statement, the subsequent ones begin with a comma).

declare

  @BegDate datetime

, @EndDate datetime

, @Dummy int

 

select

  @BegDate ='2/1/2009'

, @EndDate ='2/28/2009 11:59PM'

 

select @Dummy = 0;-- Prepare for the WITH CTE statement

 

with HistoryMax(ModificationID, HistoryDate)as

(

  select ModificationID,max(HistoryDate) HistoryDate

  from LMM.TermsHistory

  where HistoryDate <= @EndDate

  groupby ModificationID

)

, TermSnap(HistoryID)as

(

  select HistoryID

  from LMM.TermsHistory h

  innerjoin HistoryMax hm on h.ModificationID = hm.ModificationID

  and h.HistoryDate = hm.HistoryDate

)

, FilterSet(ModificationID, ModificationStatusCodeDate)as

(

  select ModificationID,max(ModificationStatusCodeDate) ModificationStatusCodeDate

  from LMM.TermsHistory

  where ModificationstatusCode = 600

  groupby ModificationID

)

 

select

  datename(month, h.ModificationStatusCodeDate) ClosedMonth

,sum(isnull(fc1.FeeAmount, 0)+isnull(fc2.FeeAmount, 0)) FeeCollected

,sum(isnull(fp1.FeeAmount, 0)+isnull(fp2.FeeAmount, 0)) FeePending

from

  LMM.TermsHistory t

  innerjoin TermSnap ts

  on t.HistoryID = ts.HistoryID

  innerjoin FilterSet h

  on t.ModificationID = h.ModificationID

  leftouterjoin LMM.ModCalcFee fc1

  on fc1.RecordTypeCode = 100

     and fc1.FeeCollectedFlag = 1

     and t.ModificationID = fc1.ModificationID

  leftouterjoin LMM.ModCalcFee fc2

  on fc2.RecordTypeCode = 200

     and fc2.FeeCollectedFlag = 1

     and t.ModificationID = fc2.ModificationID

  leftouterjoin LMM.ModCalcFee fp1

  on fp1.RecordTypeCode = 100

     and fp1.FeeCollectedFlag = 0

     and t.ModificationID = fp1.ModificationID

  leftouterjoin LMM.ModCalcFee fp2

  on fp2.RecordTypeCode = 200

     and fp2.FeeCollectedFlag = 0

     and t.ModificationID = fp2.ModificationID

where

  h.ModificationStatusCodeDate between @BegDate and @EndDate

  and t.ModificationStatusCode between 600 and 899

groupby

  datename(month, h.ModificationStatusCodeDate)

 

Tags: ,

SQL Server

SQL 2005 Select Into Variable with Multiple Rows

by 10. November 2009 14:50

When using a select statement to set a variable, and the select statement returns multiple rows, the last row returned will be the value stored in the variable. You can use sorting or a TOP statement to change this behaviour (as shown in samples below).
 

createtable #tmp(val int) 

insertinto #tmp values(1)
insertinto #tmp values(2)
insertinto #tmp values(3)
insertinto #tmp values(4)
insertinto #tmp values(5) 

declare @val int

selecttop 1 @val = val
from #tmp
orderby val asc select @val /* returns 1 */ 

select @val = val
from #tmp
orderby val asc select @val /* returns 5 */ 

select @val = val
from #tmp
orderby val desc select @val /* returns 1 */ 

droptable #tmp

Tags: ,

SQL Server

LINQ Dynamic Order By on IQuerable Object

by 2. November 2009 23:24

private IQueryable<ClientInfo> OrderBy(IQueryable obj){

  ParameterExpression param = Expression.Parameter(typeof(ClientInfo), string.Empty);

  MemberExpression property = Expression.PropertyOrField(param, this.SortExpressionLabel.Text);  

  LambdaExpression sort = Expression.Lambda(property, param); 

  string methodName = "OrderBy"; 

  if (SortDirectionLabel.Text == "DESC")  methodName += "Descending"; 

  MethodCallExpression call = Expression.Call(typeof(Queryable), methodName, new[] { typeof(ClientInfo), property.Type },      obj.Expression, Expression.Quote(sort)); 

  return obj.Provider.CreateQuery<ClientInfo>(call);

}

Tags: ,

LINQ to SQL