Thursday, 29 August 2013

Generic Collection:Stack By:Tanuj Kumar

Share your conscience

Stack<t>: simple .net program to show working of stack collection.

The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
An introduction to DOT NET:
Generic collection: Stack
Generic means it support specific data type (int,float string..etc) 
Stack is LIFO Last in first out manner.
Here stack is used to save data and retrieved it in LIFO manner.
You can run program and see the working procedure of it.

Stack

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace stackgenriccollection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Stack<string> st = new Stack<string>();

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {

                MessageBox.Show("enter value in textbox");
            }
            else
            {
                st.Push(textBox1.Text);
                MessageBox.Show("inserted");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (st.Count > 0)
            {
                Object obj = new Object();
                obj = st.Pop();
                MessageBox.Show(obj.ToString());
            }
            else
            {

                MessageBox.Show("no element in stack");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

            if (st.Count <= 0)
            {

                MessageBox.Show("stack is empty");
            }
            else
            {
                Object obj = new Object();
                obj = st.Peek();
                MessageBox.Show(obj.ToString());
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(st.Count.ToString());
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (st.Count <= 0)
            {

                MessageBox.Show("stack is empty");
            }
            else
            {
                if (st.Contains(textBox2.Text))
                {

                    MessageBox.Show("available");
                }
                else
                {
                    MessageBox.Show("not available");} } }  }     }


Posted By:Tanuj Kumar 
On:Shareyourconscience
Read More
Posted on 1:21:00 am
Categories:

Event:Adding a button on run time: By:Tanuj Kumar

Event    
Adding a button on run time:
Adding a button on run time

Adding a button on run time
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace eventbuttonexample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Button b1 = new Button();
            this.Controls.Add(b1);
            b1.Location = new Point(50, 50);
            b1.Size = new Size(100, 50);
            b1.BackColor = System.Drawing.Color.Aqua;
            b1.Text = "tanuj";
            b1.Click += new EventHandler(a);
        }
        private void  a(Object sender, EventArgs e)
        {
  MessageBox .Show ("button is clicked");}      }}
Adding a textbox on run time:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            TextBox tb = new TextBox();
            this.Controls.Add(tb);
            tb.Location = new Point(50, 50);
            tb.TextChanged +=new EventHandler(a);
            tb.BackColor = System.Drawing.Color.Aqua;
        }
        private void a(Object sender, EventArgs e) {

            MessageBox.Show("text is changed");
        }
    }
}


Posted By:Tanuj Kumar 
Read More
Posted on 1:19:00 am
Categories:

Event:Insert TextBox on RUN TIME By:Tanuj Kumar


Insert TextBox on RUN TIME

Insert TextBox on RUN TIME:-

Assignment1:
texbox on runtime

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace eventassignment1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int a, b=100, c=100;
        private void button1_Click(object sender, EventArgs e)
        {
           
            a = int.Parse(textBox1.Text);
            for (int i = 0; i < a; i++) {


                TextBox tb = new TextBox();
                this.Controls.Add(tb);
                tb.Location = new Point(b, c);
                b = b + 10;
                c = c + 10;
            }
        }
    }

}
Posted By:Tanuj Kumar 
On:Shareyourconscience
Read More
Posted on 1:19:00 am
Categories:

Saturday, 17 August 2013

SortedList By:Tanuj Kumar

Sortedlist collection
Sorted list
Sortedlist:
Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
An introduction to DOT NET:
AddAdds an element with the specified key and value to a SortedList object.
ClearRemoves all elements from a SortedList object.
CloneCreates a shallow copy of a SortedList object.
ContainsDetermines whether a SortedList object contains a specific key.
ContainsKeyDetermines whether a SortedList object contains a specific key.
ContainsValueDetermines whether a SortedList object contains a specific value.
CopyToCopies SortedList elements to a one-dimensional Array object, starting at the specified index in the array.
Sorted list


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;


namespace sortedlistcollectionprogram
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        SortedList sl = new SortedList();
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {

                MessageBox.Show("Enter value in textboxes");
            }
            else
            {
                sl.Add(textBox1.Text, textBox2.Text);
                show();
                MessageBox.Show("added");
            }

        }
        public void show() {

            listBox1.Items.Clear();

            foreach (DictionaryEntry de in sl)
            {

                listBox1.Items.Add(de.Key +" "+de.Value);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (sl.Count <= 0)
            {

                MessageBox.Show("sortedlist is empty");
            }
            else
            {
                sl.Remove(textBox3.Text);
                show(); MessageBox.Show("removed successfully");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (sl.Contains(textBox4.Text))
            {
                MessageBox.Show("available");
            }
            else {

                MessageBox.Show("not available");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(sl.Count.ToString());
        }

       
    }
}

Posted By:Tanuj Kumar 
On:Shareyourconscience

Read More
Posted on 10:55:00 pm
Categories:

Tuesday, 13 August 2013

Enabled multiple instance in Sql Server. By:Tanuj Kumar


You must have Sql server express installed in your system



Step 1. Enabling User Instances on your SQL Server installation.First we are  make sure we have enabled User Instances for SQL Server 2005 installation.

Go to Query Window in SQL Server Management Studio and type this:

exec sp_configure 'user instances enabled', 1.

Go
Reconfigure
execute this query

Step 2. Deleting old files
Now we need to delete any old User Instances.
Go to your C drive and find and completely DELETE this path (and all files inside):

C:\Documents and Settings\YOUR_USERNAME\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS
After deleting this folder you can go to Visual Studio2008, create ASP.NET Web Site and click on your App_Data folder and choose Add New Item and then choose SQL Server Database2005 and it should work!

Posted By:Tanuj Kumar 
On:Shareyourconscience

Read More
Posted on 6:28:00 am
Categories:

Thursday, 1 August 2013

MessageBox on closing event By:Tanuj Kumar

MessageBox on closing event

MessageBox on closing a form:

MessageBox on closing event:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
                        {
                           
 if (MessageBox.Show("Are You want To Close","Warning",MessageBoxButtons.YesNo) == DialogResult.No )
                           
                         {

                               
                                e.Cancel = true;
                            
                            }



Posted By:Tanuj Kumar 
Read More
Posted on 4:57:00 am
Categories: