Monday, October 7, 2013

Checkbox Header in Datagrid

                    <sdk:DataGridTemplateColumn Width="47" >
                           <sdk:DataGridTemplateColumn.HeaderStyle>
                                <Style TargetType="sdk:DataGridColumnHeader">
                                    <Setter Property="ContentTemplate">
                                        <Setter.Value>
                                            <DataTemplate>
                                                <CheckBox HorizontalAlignment="Center" Margin="10,0,0,0"  Name="Chk" Checked="Chk_Checked" Unchecked="Chk_Unchecked"></CheckBox>
                                            </DataTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </sdk:DataGridTemplateColumn.HeaderStyle>
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate >
                                    <CheckBox HorizontalAlignment="Center" Margin="3" ></CheckBox>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>

 private void Chk_Checked(object sender, RoutedEventArgs e)
        {
            if (Datagrid1.ItemsSource != null)
            {
                foreach (DataGridRow dr in tsr.GetDataGridRows(Datagrid1))
                {
                    ((CheckBox)((DataGridCell)tsr.GetDataGridCell(Datagrid1, dr, 0)).Content).IsChecked = true;
                }
            }

        }

 private void Chk_Unchecked(object sender, RoutedEventArgs e)
        {
            if (Datagrid1.ItemsSource != null)
            {
                foreach (DataGridRow dr in tsr.GetDataGridRows(Datagrid1))
                {
                    ((CheckBox)((DataGridCell)tsr.GetDataGridCell(Datagrid1, dr, 0)).Content).IsChecked = false;
                }
            }
        }

Column Alignment in Silverlight Datagrid

To align the textbox column values in Silverlight Datagrid

 <sdk:DataGridTextColumn.ElementStyle>
     <Style TargetType="TextBlock">
          <Setter Property="TextAlignment" Value="Right" />
     </Style>
</sdk:DataGridTextColumn.ElementStyle>



To align the texbox column Header in Silverlight Datagrid

<sdk:DataGridTextColumn.HeaderStyle>
    <Style TargetType="sdk:DataGridColumnHeader">
          <Setter Property="HorizontalContentAlignment" Value="Right" />
          <Setter Property="Padding"  Value="0,0,-10,0" />
          <Setter Property="ContentTemplate">
    <Setter.Value>
     <DataTemplate>
                  <TextBlock Text="{Binding}" TextWrapping="Wrap"/>
    </DataTemplate>
   </Setter.Value>
  </Setter>
</Style>
</sdk:DataGridTextColumn.HeaderStyle>

Indian Currency Format in Rdlc Report

 Flow any of the ways
* Report Menu->Report properties option
* Right click on the report and choose the Report properties option

In the pop-up window, Choose the Code option in the left side.
Then in the custom code enter the following function code.

Public Function setcurrency(ByVal a As String) As String
Dim info As New System.Globalization.CultureInfo("hi-IN")
Dim s As String
s=Double.Parse(a).ToString("N2",info)
Return s
End Function



Right click on the cell where you want to change the format,
Choose the Expression option in the pop-up menu list.
Enter the following code.

Code.setcurrency(Field)

Date Formatting in Sql Server

SELECT convert(varchar, getdate(), 100) -- mon dd yyyy hh:mmAM (or PM)  -- Oct  2 2010 11:01AM          

SELECT convert(varchar, getdate(), 101) -- mm/dd/yyyy - 10/02/2010                  

SELECT convert(varchar, getdate(), 102) -- yyyy.mm.dd - 2010.10.02           

SELECT convert(varchar, getdate(), 103) -- dd/mm/yyyy

SELECT convert(varchar, getdate(), 104) -- dd.mm.yyyy

SELECT convert(varchar, getdate(), 105) -- dd-mm-yyyy

SELECT convert(varchar, getdate(), 106) -- dd mon yyyy

SELECT convert(varchar, getdate(), 107) -- mon dd, yyyy

SELECT convert(varchar, getdate(), 108) -- hh:mm:ss

SELECT convert(varchar, getdate(), 109) -- mon dd yyyy hh:mm:ss:mmmAM (or PM)

                                        -- Oct  2 2010 11:02:44:013AM   

SELECT convert(varchar, getdate(), 110) -- mm-dd-yyyy

SELECT convert(varchar, getdate(), 111) -- yyyy/mm/dd

SELECT convert(varchar, getdate(), 112) -- yyyymmdd

SELECT convert(varchar, getdate(), 113) -- dd mon yyyy hh:mm:ss:mmm

                                        -- 02 Oct 2010 11:02:07:577     

SELECT convert(varchar, getdate(), 114) -- hh:mm:ss:mmm(24h)

SELECT convert(varchar, getdate(), 120) -- yyyy-mm-dd hh:mm:ss(24h)

SELECT convert(varchar, getdate(), 121) -- yyyy-mm-dd hh:mm:ss.mmm

SELECT convert(varchar, getdate(), 126) -- yyyy-mm-ddThh:mm:ss.mmm  -- 2010-10-02T10:52:47.513

-- Without century (YY) date / datetime conversion - there are exceptions!

SELECT convert(varchar, getdate(), 0)   -- mon dd yyyy hh:mmAM (or PM)

SELECT convert(varchar, getdate(), 1)   -- mm/dd/yy

SELECT convert(varchar, getdate(), 2)   -- yy.mm.dd          

SELECT convert(varchar, getdate(), 3)   -- dd/mm/yy

SELECT convert(varchar, getdate(), 4)   -- dd.mm.yy

SELECT convert(varchar, getdate(), 5)   -- dd-mm-yy

SELECT convert(varchar, getdate(), 6)   -- dd mon yy

SELECT convert(varchar, getdate(), 7)   -- mon dd, yy

SELECT convert(varchar, getdate(), 8)   -- hh:mm:ss

SELECT convert(varchar, getdate(), 9)   -- mon dd yyyy hh:mm:ss:mmmAM (or PM)

SELECT convert(varchar, getdate(), 10)  -- mm-dd-yy

SELECT convert(varchar, getdate(), 11)  -- yy/mm/dd

SELECT convert(varchar, getdate(), 12)  -- yymmdd

SELECT convert(varchar, getdate(), 13)  -- dd mon yyyy hh:mm:ss:mmm

SELECT convert(varchar, getdate(), 14)  -- hh:mm:ss:mmm(24h)

SELECT convert(varchar, getdate(), 20)  -- yyyy-mm-dd hh:mm:ss(24h)

SELECT convert(varchar, getdate(), 21)  -- yyyy-mm-dd hh:mm:ss.mmm

SELECT convert(varchar, getdate(), 22)  -- mm/dd/yy hh:mm:ss AM (or PM)

SELECT convert(varchar, getdate(), 23)  -- yyyy-mm-dd

SELECT convert(varchar, getdate(), 24)  -- hh:mm:ss

SELECT convert(varchar, getdate(), 25)  -- yyyy-mm-dd hh:mm:ss.mmm

-- SQL create different date styles with t-sql string functions

SELECT replace(convert(varchar, getdate(), 111), '/', ' ') -- yyyy mm dd

SELECT convert(varchar(7), getdate(), 126)                 -- yyyy-mm

SELECT right(convert(varchar, getdate(), 106), 8)          -- mon yyyy
SELECT substring(convert(varchar, getdate(), 120),6, 11)   -- mm-dd hh:mm


SELECT DATENAME(year, GETDATE())

,DATENAME(month, GETDATE())

,DATENAME(day, GETDATE())

,DATENAME(dayofyear, GETDATE())

,DATENAME(weekday, GETDATE());


----Last Day of Previous Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))

LastDay_PreviousMonth
----Last Day of Current Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))

LastDay_CurrentMonth
----Last Day of Next Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))



First Day
--------------
 CONVERT(VARCHAR(10),dateadd(MM,-1,DATEADD(dd,-(DAY(@processdate)-1),@processdate)),23)

Naming Conventions

There used to be many naming conventions back in the days, but lately it seems that two conventions are emerging as the two most popular among programmers. Underscore naming convention and camel case naming convention. Someone might argue that there are other popular conventions, but for now let’s compare these two and ask programmers out there which one they prefer. In the end a programmer might be bound to whatever is the standard for the language he is using, but this doesn’t prevent us from doing an out-of-context comparison.

Underscore naming convention uses all lower case words, and separate them with underscores. The common is to use this for variable and function names, and to use Pascal convention for classes, structures, enumerations, and interfaces. Underscores were used by C programmers, then C++ adopted the same convention for its keywords and Standard Templates Library, and later on Boost used the same convention, making this convention quite popular among C++ programmers, but not dominant as other programmers used various other conventions including Pascal and camel case conventions. Underscore convention is also used by PHP’s standard libraries and is pretty much the standard for PHP developers. Ruby also uses underscores, or so I heard.
On the other hand, camel case naming convention is mostly known to be the standard for Java and its little sister JavaScript, although you can find it in use in various other places. Camel case simply starts each word with an uppercase letter, except for the first word which remains in lower case. The words are not separated by any underscore, obviously. Like in the underscore convention, this applies mainly to variables and functions, while type names (classes, structures, interfaces, enumerations) remain in Pascal convention. C# uses a variation of this convention by limiting the camelcase to function parameters and local variables.
Of course each of the two conventions has its own strengths and weaknesses. The following list summarizes the strengths and weaknesses of the two:
  • Underscores make phrases easier to read. Compare the underscore_naming_convention to the camelCaseNamingConvention.
  • Camel case makes paragraphs easier to read! Of course, when you read code what’s important for you is to understand the overall operation or algorithm, not the words in a phrase. Compare the following:
    my_first_variable=my_second_variable-my_third_variable;
    to this:
    myFirstVariable=mySecondVariable-myThirdVariable;
    Obviously in this case the camel case is easier to read. From the first glance you realize it’s a subtraction between two variables, while in the case of underscores you need to concentrate before you realize where the minus sign is. You may even mistake it for being one long variable instead of two. This is a strong disadvantage for the underscore convention, however, coloring can solve this problem if the editor gives identifiers a different color from operators, but that’s dependent on the editor.
  • Camel case is the negative of English. In english, the first word in a sentence starts with an upper case and the rest remains in lower case. This is probably true for many other human languages. Camel case is the exact opposite. This is mind itching indeed.
  • Underscores are harder to type. Even with the availability of intellisense, you still need to type the underscore in many cases.
  • Camel case is not consistent because with constants (which is all in upper case) you still need the underscores. On the other hand, the underscore convention CAN be consistent (if you decide to use underscores even for type names, which is doable, i.e. My_Type instead of MyType)