Wednesday, July 6, 2011

LINQ-Language INtegrated Query

LINQ-Language integrated Query, new language library which can be used to Query the Implementation of interface's IEnumerable, List, T[], HashSet.

Normally LINQ methods are supplied with Lambas expression, Anonymous methods and normal methods.

LINQ methods are classified into Different category.

  • Chiaining – (Where, Select)
  • Combine and Reduce – (Concat, Distinct, Union)
  • First and Match – (First , FirstOrDefault)
  • Other and Match – (Last, ElementAt, Single)
  • Set – (Except, Intersect, Union)
  • Membership and Count – (Contains, Count)
  • Aggregate – (Sum, Avarage, Min, Max, Aggregate)
  • Grouping – (GroupBy)
  • Ordering – (OrderBy, OrderByDescending, ThenBy, ThenBydescending)
  • Export – (ToArray, ToList, ToDictionary, ToLookup)
For more information on MSDN - http://msdn.microsoft.com/en-us/netframework/aa904594

Sunday, March 6, 2011

SQL Server 2008 Joins

Joining is basic functionality of SQL Server to get the results combine of more than one table. There are three types of joinings
1) CROSS JOIN
CROSS JOIN is Cartesian product of both table records.
i) SELF JOIN
SELF JOIN is Cartesian product of same table records.
2) INNER JOIN
INNER JOIN is Cartesian product + Filter predicate on ON
i) COMPOSITE JOIN
COMPOSITE JOIN is Cartesian product + Filter predicate on more than on attribute on joins tables
ii) NON-EQU JOIN
NON-EQU JOIN is Cartesian product + Filter predicate on ON with not equal operator
iii) MULTI TABLE JOIN
MULTI TABLE JOIN is Cartesian product + Filter predicate on ON with more than one table and joining applies from left to right direction.
3) OUTER JOIN
OUTER JOIN is Cartesian product + Filter predicate on ON + Add outer rows(Rows from preserved table)
i) LEFT OUTER JOIN
LEFT OUTER JOIN is Cartesian product + Filter predicate on ON + Add outer rows(Rows from LEFT preserved table)
ii) RIGHT OUTER JOIN
RIGHT OUTER JOIN is Cartesian product + Filter predicate on ON + Add outer rows(Rows from RIGHT preserved table)
iii) FULL OUTER JOIN
FULL OUTER JOIN is Cartesian product + Filter predicate on ON + Add outer rows(Rows from BOTH preserved table)

Write what you want to say about this article.

Monday, December 22, 2008

Read AssemblyInfo file in runtime

Sometime we need to read the information which is there in the assemblyinfo.cs file for about formbox. I googled in internet, finally found an answer.

Assembly currentAssembly = Assembly.GetExecutingAssembly();

AssemblyName assemblyName = currentAssembly.GetName();

//If only need version information then use.
assemblyName.Version.ToString();

//Copyright information
AssemblyCopyrightAttribute copyright =
AssemblyCopyrightAttribute.GetCustomAttribute(currentAssembly,
typeof(AssemblyCopyrightAttribute)) as AssemblyCopyrightAttribute;

like this you can get all the attribute information from assemblyinfo.cs file.

AssemblyVersionAttribute
AssemblyProductAttribute
AssemblyDescriptionAttribute
AssemblyCompanyAttribute
AssemblyTitleAttribute

If you need any more information feel free contact me at any time.

Sunday, December 21, 2008

Checkable group box

Some days ago, i have requirement to design the UI in such way that it should contains group box and chack box on top it. so i thought it's very simple somebody might have done it. i searched on internet, i couldn't find a control. so i decided to create a control which will contains check box on the top corner of group box. It has features like ordinary checkbox if click on checkbox then automatically disable/enable the controls within the group box. if you want some action should be performed while clicking on groupbox then subscribe of for checkbox click event also.

Because of blog file upload constrains i am not able upload file here. but i am telling the steps which needs to be done and code.

1) Implement a Groupbox control
2)Override paint event for drawing of checkbox
3)Override mouse down event for changing the status of check box.

Here my control code.
------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Windows.Forms.VisualStyles;
namespace WindowsApplication
{
public class CheckableGroupBox : GroupBox
{
#region Fields
private bool checkedStatus = false;
private string text = "CheckGroupBox";
private Color textColor = Color.Blue;
#endregion
#region Constructor
public CheckableGroupBox()
{
this.SetStyle(ControlStyles.UserPaint ControlStyles.AllPaintingInWmPaint, true);
}
#endregion
#region Properties
public bool Checked
{
get { return this.checkedStatus; }
set
{
this.checkedStatus = value;
foreach (Control ctrl in this.Controls)
{
ctrl.Enabled = value;
}
}
}
public new string Text
{
get { return this.text; }
set { this.text = value; }
}
public Color TextColor
{
get { return this.textColor; }
set { this.textColor = value; }
}
#endregion
#region Events
public event EventHandler CheckStateChanged;
#endregion
#region Protected Methods
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
float totalLength = e.ClipRectangle.Right - e.ClipRectangle.Left;
float quaterLength = ((totalLength / 2) / 4);
int startPoint = (int)(e.ClipRectangle.Left + quaterLength);
Rectangle rectAngle = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y - 1,
e.ClipRectangle.Width, e.ClipRectangle.Height);
rectAngle.X = startPoint + CheckBoxRenderer.GetGlyphSize(e.Graphics,
CheckBoxState.UncheckedNormal).Width;
SizeF sizeF = e.Graphics.MeasureString(Text, this.Font);
rectAngle.Width = (int)sizeF.Width + 2;
rectAngle.Height = this.Font.Height;
CheckBoxRenderer.RenderMatchingApplicationState = true;
Rectangle rectAngleBack = new Rectangle(startPoint - 3, rectAngle.Y,
(rectAngle.X - (startPoint - 3)) + rectAngle.Width, rectAngle.Height);
CheckBoxRenderer.DrawParentBackground(e.Graphics, rectAngleBack, this);
Font font = Font;
CheckBoxRenderer.DrawCheckBox(e.Graphics, new System.Drawing.Point(startPoint, e.ClipRectangle.Y),
rectAngle, Text, this.Font, TextFormatFlags.VerticalCenter, false,
checkedStatus ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal);
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
using (Graphics g = this.CreateGraphics())
{
Rectangle rectAngle = ClientRectangle;
rectAngle.X = ClientRectangle.Left + (((ClientRectangle.Right - ClientRectangle.Left) / 2) / 4);
rectAngle.Y -= 1;
rectAngle.Width = CheckBoxRenderer.GetGlyphSize(g, checkedStatus ?
CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal).Width;
rectAngle.Height = CheckBoxRenderer.GetGlyphSize(g, checkedStatus ?
CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal).Height;
if (rectAngle.Contains(e.Location))
{
Checked = !Checked;
if (CheckStateChanged != null)
{
CheckStateChanged(this, new EventArgs());
}
}
}
Invalidate();
}
}
#endregion
}
}
------------------------------------------------------------------------------------------------
Just create c# file and copy paste above code, compile and use it in your application.

Feel free contact me if you need any more information and also i am very glad accept your suggestion.

Thursday, August 28, 2008

Virtual Cancel Button

You can add a Virtual cancel button by using KeyPreview property and Key Down event of Form. Just add Key Down event method implementation for form and Set KeyPreview property as True.

Below is code Details

This.Form.KeyPreviw = true;

private void SettingsForm_KeyDown(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.Escape)

{

this.DialogResult = DialogResult.Cancel;

}

}

Setting of KeyPreview Property of form, will receive all the keystroke events (KeyPress, KeyDown, KeyUp). After form event handler completed processing the keystroke, the keystroke assigned to the control with focus.By default is false.

Note : If the form doesn’t contains any visible and enable controls then it automatically receive all keyboard events.


For more information


Click Here


This is my first post, Please feel free to give comments if you can send me mail also.