Tuesday, June 26, 2012

Example on Windows Service Wothout Setup

Hi Friends,in this post i would like to explain windows service for displaying message box for every 3 seconds.

Step 1:

* Open windows service project with projectName WinService1
* Goto ToolBox-->General-->Right Click-->Select choose items-->Select Timer(Systems.Timers)
* Project-->AddReference-->System.Windows.Forms(Message Box is a part of above reference).
* Place a Timer(System.Timers) with interval-3000 & enabled-false.

Code:

{//timer1_Elapsed event.
System.Windows.Forms.MessageBox.Show("This message from Windows Service.");
}

Code for OnStart() event
{
timer1.Enabled=true;
}

Code for OnStop() event
{
timer1.Enabled=false;
}


Step 2:

* Open service1.cs[design]
Right Click
Add installer(Select).
Then 2 controls will be added to the form.
1)ServiceProcessInstaller-->Choose properties-->Account=LocalSystem.
2)ServiceInstaller-->Properties-->ServiceName=MessageBoxDisplay

* Build the project(Build-->Select Build solution)

Note:
* WinService1.exe is created under:
D:\WinService1\bin\debug folder with a service name called as "MessageBoxDisplay"

Step 3:

* open .Net Command prompt.
Start-->Programs-->MSVisualStudio2005-->VSTools-->.Net Command Prompt.
>installutil -i D:\WinService1\bin\debug\WinService1.exe (press enter)
>....
>....
>....
>transaction install has completed.

Step 4:

* Open service(Start-->run-->services.msc)
* MessageBoxDisplay-->RightClick-->Properties-->Logon-->Check "interact with desktop" checkBox-->OK
(Only service contains MessageBox otherwise above step is not required).
* MessageBoxDisplay-->rightClick-->Start.

Then service will be started & MessageBox with message(This message from Windows Service.) will be displayed for every 3 seconds.


Thank You...

Read more »

What Is Delegate with a simple example

aIntroduction
This article is an attempt to explain a delegate with a simple example. Delegates are similar to function pointers in C++. For simple understanding delegates can be defiend as methods that are used to call other method. Only condition to call

another method from a delegate is that the signature of the calling methods and delegates should match.
Follw This Step
Delegates should have the same signature as the methods to be called by them.
i.e. Say that we are calling an addNumbers method which returns an integer by taking (int, int) as input. Then our

delegate also must have been declared with the same signature.
Delegate Declaration:
public delegate int simpleDelegate (int a, int b);

Method:
public int addNumber(int a, int b)
Step For Create And Cal A Delegate
--Create a delegate. A delegate can be created with the delegate keyword, followed by it's return type, then name of the

delegate with the input patameters.

public delegate int simpleDelegate (int a, int b);

--Define the methods which are having similar signature as the delegate.

public int mulNumber(int a, int b)
public int addNumber(int a, int b)
--Now we are all set to use the delegates. Just instatiate the class and call the methods using the delegates.
Code Use
class clsDelegate
{
public delegate int simpleDelegate (int a, int b);
public int addNumber(int a, int b)
{
return (a+b);
}
public int mulNumber(int a, int b)
{
return (a*b);
}
static void Main(string[] args)
{
clsDelegate RAPatel = new clsDelegate();
simpleDelegate addDelegate = new simpleDelegate(RAPatel.addNumber);
simpleDelegate mulDelegate = new simpleDelegate(RAPatel.mulNumber);
int addAns = addDelegate(10,12);
int mulAns = mulDelegate(10,10);
Console.WriteLine("Result by calling the addNum method using a delegate: {0}",addAns);
Console.WriteLine("Result by calling the mulNum method using a delegate: {0}",mulAns);
Console.Read();
}
}

Read more »

How to Create Setup File And how to install,Start windows service

aaa
Introduction:

Here I will explain how to install windows service and how to start the windows service in our local machine.

Description:

In previous article I explained clearly how to Create Setup File and how to run windows service in scheduled intervals. Now I will explain how to install windows service in our system.

To install windows service in your follow these steps

Step-1
Create New Project- Select Setup- And Give Setup File Name…….


Step-2
First Bind Both Project..
And Install your Setup File..




Step-3
Open Services And Start Our ScheduledService Service……




Read more »

Monday, June 25, 2012

Moveable Telerik Rad window in WPF

Introduction :
How to Move Telerik Rad Window in WPF

Descritption :
You can move your rad window move any where in your page


Using Code :
In Design View :
Hide Expand


In Coding View :
Hide Expand


Read more »

Display message in your pc Notification Area in WPF


Introduction :
How To Display message in your pc Notification Area in WPF


Descritption :
You can set Custom icon and Custom Message in Your Pc Notification Area


Using Code :

This code for Notify Icon 
Hide Expand

This Code for Notify Icon Double 
Hide Expand

This Code for Balloon Icon Double click
Hide Expand

Read more »

Friday, June 22, 2012

List Operation In C#

    This Blog  Use For Major operation of List<> in C#
   Introduction
     Lists are considered generics and constructed types. You need to use < and > in the List declaration.
     List <>  is Following Step
1)    Create Class for List
Hide Expand

2) Create object For List and Add Value in List
Hide Expand

3)List Operation Related SpecificId one column,ordr by,Gorup by
Hide Expand
4) List Operation Related Find Index
Hide Expand

5) List Operation Related to Find Operation
Hide Expand

      6)List Operation Related Remove Operation
Hide Expand
This Very useful in WPF 

Read more »

Wednesday, June 6, 2012

Set Lost Focus and cusrosr go same control

    Method 1 
    setFocus(txts_StockNo);
  //set focus
        public static void setFocus(UIElement element)
        {
            if (!element.Focus())
            {
                element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(delegate()
                {
                    element.Focus();
                }));
            }
            else
            {
                element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(delegate()
                    {
                        element.Focus();
                    }));
            }
        }
    Method 2

    Write Down code on lost focus instead of PreviewLostKeyboardFocus_1

  private void txtPhone_PreviewLostKeyboardFocus_1(object sender, KeyboardFocusChangedEventArgs e)
        {
            if (txtPhone.Value.ToString().Length < 10 && txtPhone.Value.ToString().Length != 0)
            {
                MessageBox.Show("Enter 10 digit home number", "DMS", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                //txtPhone.Focus();
                e.Handled = true;
            }
            else
            {
                if (Convert.ToString(txtPhone.Value) != "")
                {


                 //// wrote down ur code


                }
            }

Read more »

Friday, June 1, 2012

Encrypt or Decrypt password using c# in ASP.Net

Introduction
How to Convert Encrypt or Decrypt password using c# with asp.net

Using the code

Enter Your Password and first click on Encrypt button and then after click on Decrypt.
1. Example Of First Enter Password = "tejasbhalani"
2. EncodePasswordToBase64 function convert your string and give output
ans= "cnJhYW5uYWFtbWVldHQ="
3. DecodeFrom64 function convert your strring and give output
ans=" tejasbhalani "

//this function Convert to Encord your Password 
public static string EncodePasswordToBase64(string password) 
{
  try 
  {
      byte[] encData_byte = new byte[password.Length]; 

      encData_byte = System.Text.Encoding.UTF8.GetBytes(password); 
      string encodedData = Convert.ToBase64String(encData_byte); 
      return encodedData; 
  } 
  catch (Exception ex) 
  { 
      throw new Exception("Error in base64Encode" + ex.Message); 
  } 

}

   
//this function Convert to Decord your Password
public string DecodeFrom64(string encodedData) 
{

     System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); 
     System.Text.Decoder utf8Decode = encoder.GetDecoder();
     byte[] todecode_byte = Convert.FromBase64String(encodedData); 
     int charCount = utf8Decode.GetCharCount
(todecode_byte, 0, todecode_byte.Length); 
     char[] decoded_char = new char[charCount]; 
     utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); 
     string result = new String(decoded_char); 
     return result;
}



protected void Button1_Click(object sender, EventArgs e)
{ 
     Label1.Text=EncodePasswordToBase64(TextBox1.Text); 
}


protected void Button2_Click(object sender, EventArgs e)
{
     Label1.Text = DecodeFrom64(Label1.Text);
}


This Code Successfully Run in C#

Read more »

Send Mail With Attachment File Using C# in ASP.NET

Introduction
This article lists code to send a mail with an attachment file.

Background
We send mail using System.Net.Mail.

Using the code
string ToAddress = TextBox3.Text; const string FromAddress = YourGmailId; //ForExample:tejasbhalani@gmail.com

string Subject = TextBox6.Text;
String Body = TextBox4.Text;
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(ToAddress);
mail.From = new MailAddress(FromAddress);
mail.Subject = Subject;
          
mail.Body = Body;
if (FileUpload1.PostedFile != null)
{
  HttpPostedFile attFile = FileUpload1.PostedFile;
  int attachFileLength = attFile.ContentLength;
  if (attachFileLength > 0)
  {
     FileNameToAttache = Path.GetFileName(FileUpload1.PostedFile.FileName);
     FileUpload1.PostedFile.SaveAs(Server.MapPath(FileNameToAttache));
     mail.Attachments.Add(new Attachment(Server.MapPath(FileNameToAttache)));
  }
}
mail.Priority = System.Net.Mail.MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(FromAddress, "YourGmailPassword");
client.Port = 587; // Gmail works on this portclient.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layertry
{
   client.Send(mail);
}
catch (Exception error)
{
   throw error;
}

This Code For Succesfully Run............

Read more »

CheckBoxList in Wpf With C#

Introduction

Display Selected Column Dynamically Using checkBoxList in Wpf With C# Demo

Using the code
You Want to Display Selected Column Dynamically run time Using CheckBoxList then Just Use this Code in your application.

First Create one Data base
Example of ->

-- DataBase Name :- db
-- Create Five Column
-- Id Name Address City Phone
-- Enter some data in database

First We Create Form Design
<Grid>

<Grid Margin="20,12,0,180" HorizontalAlignment="Left" Width="256" VerticalAlignment="Top">

<GroupBox Header="Select Column" Margin="0,0,6,-113">

<telerik:RadWrapPanel Name="RadWrapPanel1" VerticalAlignment="Top" Height="auto" HorizontalAlignment="Left" Width="auto"></telerik:RadWrapPanel>

</GroupBox>

</Grid>

<telerik:RadGridView HorizontalAlignment="Left" Margin="0,131,0,0" Name="radGridView1" ShowGroupPanel="False" VerticalAlignment="Top" Width="288" />

</Grid>

This Code Write down in your code file

public partial class onlytestingform : Page
{
        //Declare Connection String and other object
        SqlConnection con = new SqlConnection(@"Enter your Connection String");
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        public List<System.Windows.Controls.CheckBox> checkBoxList = new List<System.Windows.Controls.CheckBox>();
        public System.Windows.Controls.CheckBox chk;
        public onlytestingform()
        {
            InitializeComponent();
        }
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //Call your Function For Fill Your Grid Load Time
            fillgrid();
            //Call your Function For Fill Your RadWrapPanel1 Load Time
            BindParts();
        }
        //Fill Your Grid First
        public void fillgrid()
        {
            con.Open();
            string sql="select * from db";
            cmd = new SqlCommand(sql,con);
            da.SelectCommand = cmd;
            da.Fill(ds);
          
            if (ds.Tables[0].Rows.Count > 0)
            {
                radGridView1.ItemsSource = ds.Tables[0].DefaultView;
            }
            con.Close();
        }

        //Bind Column in RadWrapPanel1 With CheckBox Using GridView Column
        public void BindParts()
        {
            checkBoxList.Clear();
            for (int i = 0; i < radGridView1.Columns.Count; i++)
            {
                chk = new System.Windows.Controls.CheckBox();
                checkBoxList.Add(chk);
                RadWrapPanel1.Children.Add(chk);
                chk.Width = 150;
                chk.Height = 22;
                chk.Content = Convert.ToString(radGridView1.Columns[i].Header);
                chk.IsChecked = true;
                chk.Checked += new RoutedEventHandler(chk_Checked);
                chk.Unchecked += new RoutedEventHandler(chk_Unchecked);
            }
        }
        //Hide Column Code
        void chk_Unchecked(object sender, RoutedEventArgs e)
        {
            List<string> chkUnchekList = new List<string>();
            chkUnchekList.Clear();
            foreach (System.Windows.Controls.CheckBox item in checkBoxList)
            {
                if (item.IsChecked == false)
                {
                    chkUnchekList.Add(item.Content.ToString());
                }
            }
            for (int i = 0; i < radGridView1.Columns.Count; i++)
            {
                if (chkUnchekList.Contains(radGridView1.Columns[i].Header.ToString()))
                {
                    radGridView1.Columns[i].IsVisible = false;
                }
            }
        }
      
        //Un-Hide Column Code
        void chk_Checked(object sender, RoutedEventArgs e)
        {
            List<string> chkCheckList = new List<string>();
            chkCheckList.Clear();
            foreach (System.Windows.Controls.CheckBox item in checkBoxList)
            {
                if (item.IsChecked == true)
                {
                    chkCheckList.Add(item.Content.ToString());
                }
            }
            for (int i = 0; i < radGridView1.Columns.Count; i++)
            {
                if (chkCheckList.Contains(radGridView1.Columns[i].Header.ToString()))
                {
                    radGridView1.Columns[i].IsVisible = true;
                }
            }
        }
}

This Code Succefully Run.............

Read more »

Followers