Friday, 1 August 2014

WPF Collapsible :Grid, StackPanel, WrapPanel (or any container you want) with out re sizing the inner controls



                    <Grid.Style>

                        <Style TargetType="Grid">

                            <Style.Triggers>

                                <MultiDataTrigger>

                                    <MultiDataTrigger.Conditions>
                                        <Condition Binding="{Binding ElementName=HelpDest_Control, Path=_Email_Expanded}" Value="True" />
                                    </MultiDataTrigger.Conditions>


                                    <MultiDataTrigger.EnterActions>
                                        <BeginStoryboard>
                                            <Storyboard>

                                                <!-- this line is working but it is resizing inner controls as well
                                                <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="2"/>
                                                -->
                                             
                                                <DoubleAnimation Duration="0:0:0.150" From="50" To="350" Storyboard.TargetProperty="Height" />

                                            </Storyboard>
                                        </BeginStoryboard>
                                    </MultiDataTrigger.EnterActions>



                                    <MultiDataTrigger.ExitActions>
                                        <BeginStoryboard>
                                            <Storyboard>

                                                <DoubleAnimation Duration="0:0:0.150" To="50" Storyboard.TargetProperty="Height" />

                                            </Storyboard>
                                        </BeginStoryboard>
                                    </MultiDataTrigger.ExitActions>

                                </MultiDataTrigger>

                            </Style.Triggers>

                        </Style>

                    </Grid.Style>

Wednesday, 30 July 2014

Drag window by clicking anywhere - WPF

XAML

MouseDown="Window_MouseDown_1"


.CS
 private void Window_MouseDown_1(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }

Thursday, 17 July 2014

How to copy whole database to another database on some other server

  void transfer(string table_name)
        {
            // Establishing connection

            SqlConnection cnn = existing_database;

            // Getting source data
            SqlCommand cmd = new SqlCommand("SELECT * FROM " + table_name, cnn);
            cnn.Open();
            SqlDataReader rdr = cmd.ExecuteReader();

            // Initializing an SqlBulkCopy object
            SqlBulkCopy sbc = new SqlBulkCopy(destination_database);

            destination_database.Open();
            // Copying data to destination
            sbc.DestinationTableName = table_name;
            sbc.WriteToServer(rdr);

            // Closing connection and the others
            sbc.Close();
            rdr.Close();
            cnn.Close();

        }

Enjoy :) Jai Mata Di, Jai SiyaRam

Wednesday, 11 December 2013

C# - divide a long database (e.g. SQL) query into peices.

Description: 
recently i was having problems while passing a long query and executing it. it was getting really confusing so, i divided into pieces so that it could be easy to understand. Code is given below:

Data Table Design and Script:


Script:
USE [Temp]
GO

/****** Object:  Table [dbo].[Table_1]    Script Date: 12/11/2013 22:46:36 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Table_1](
[DIST_NAME] [nvarchar](50) NULL,
[CREATED_BY] [nvarchar](50) NULL,
[led_code] [smallint] NULL,
[LED_ADDRESS] [nvarchar](50) NULL,
[LED_CITY] [nvarchar](50) NULL,
[LED_STATE] [nvarchar](50) NULL
) ON [PRIMARY]

GO

Code:
       
        string DIST_NAME = "dist", CREATED_BY = "created", led_code = "1", LED_ADDRESS = "led add,re,.234u)&&(^*%*%", LED_CITY = "N delhi", LED_STATE ="delhi";

        private void Form1_Load(object sender, EventArgs e)
        {
            /// change the connection string according to you
            string conne=@"Data Source=HTCS-PC\SQLEXPRESS;Initial Catalog=Temp;Integrated Security=True";
            SqlConnection scon =new SqlConnection (conne);

            string comand =""; /// copy this query as it is

            comand += "insert into Table_1 (DIST_NAME,CREATED_BY, led_code,LED_ADDRESS,LED_CITY,LED_STATE) values (";
            comand +="'"+DIST_NAME+"'";
            comand +=",'" + CREATED_BY + "'";
            comand += "," + led_code;
            comand +=",'"+LED_ADDRESS+"'";
            comand +=",'"+LED_CITY+"'";
            comand +=",'"+LED_STATE+"')";


            SqlCommand scom = new SqlCommand(comand, scon);

            scon.Open();

            scom.ExecuteNonQuery();

            scon.Close();
        }