Pages

Showing posts with label .net. Show all posts
Showing posts with label .net. Show all posts

Thursday 10 December 2015

SQL VIEW

View
A VIEW in SQL in completely based on the concept of Virtual Table which comes as a result of some SQL query. It behaves like a real table and you can perform all SQL statements and function on a VIEW.


Tech-spoon.com - SQL-VIEW


How to create a VIEW:

Syntax:

CREATE VIEW [dbo].[View_Name] as
select A.Name, A.Email, A.Phone
from tbl_name as A
where A.status = 1

Example:

For example let me create a table as tblEmployee
CREATE TABLE [dbo].[tblEmployee]
(
id int identity(1,1),
Emp_Code varchar(20) primary key,
Emp_Name varchar(500),
Emp_Email nvarchar(500),
Emp_Salary decimal,
Emp_Dept int,
Emp_Status int
)

Now I am going to create another table with the name tblDepartment

CREATE TABLE [dbo].[tblDepartment]
(
id int identity(1,1),
Dept_Id int primary key,
Dept_Name varchar(500),
Dept_Status int
)

Now based on these two tables I want to get details of those employees who are currently working for the organization i.e. has Emp_Status as 1, for this I am going to create a VIEW named as View_Emp_Active.

CREATE VIEW [dbo].[View_Emp_Active] as
select A.Emp_Code, A.Emp_Name, A.Emp_Email, A.Emp_Salary, B.Dept_Name
from tblEmployee A inner join tblDepartment B
on A.Emp_Dept = B.Dept_Id
where a.Emp_Status = 1

So, whenever you need to get the list of active employees just call this View rather than writing the full code of the select statement from two tables using join statement.

Some Important things you should know about the SQL VIEW:
1.    A view can only be updated i.e. insert, delete, update statement can only applied on the View if it is formed from s single table, otherwise you cannot perform these actions on a View.
2.    You cannot have a view having more than 1000+ columns.

For more information about website development please visit http://www.jalwaltechnologies.com.

Thursday 9 July 2015

List Box Control

Introduction :
This code will show how to use ListBox to Select/Filter items :
Design Code :
<div style="width: 100%; float: left;">
            <div style="width: 25%; float: left; margin-top: 10px;">
                <asp:ListBox ID="ListBox1" runat="server" Height="150px" Width="98%" SelectionMode="Multiple">
                    <asp:ListItem>A</asp:ListItem>
                    <asp:ListItem>B</asp:ListItem>
                    <asp:ListItem>C</asp:ListItem>
                    <asp:ListItem>D</asp:ListItem>
                    <asp:ListItem>E</asp:ListItem>
                    <asp:ListItem>F</asp:ListItem>
                </asp:ListBox>
            </div>
            <div style="width: 8%; float: left; margin: 10px;">
                <asp:Button ID="btn01" runat="server" OnClick="btn01_Click" Text=">" Style="margin: 3px 14px;" />
                <asp:Button ID="Button2" runat="server" OnClick="Button1_Click" Text=">>" Style="margin: 3px 14px;" />
                <asp:Button ID="Button3" runat="server" OnClick="Button2_Click" Text="<" Style="margin: 3px 14px;" />
                <asp:Button ID="Button4" runat="server" OnClick="Button3_Click" Text="<<" Style="margin: 3px 14px;" />
            </div>

            <div style="width: 25%; float: left; margin-top: 10px;">
                <asp:ListBox ID="ListBox2" runat="server" Height="150px" Width="98%" SelectionMode="Multiple"></asp:ListBox>
            </div>
            <asp:Label ID="lbltxt" runat="server" ForeColor="Red"></asp:Label>
        </div>


Code Behind : 

ArrayList arraylist1 = new ArrayList();
    ArrayList arraylist2 = new ArrayList();
    protected void btn01_Click(object sender, EventArgs e)
    {
        lbltxt.Visible = false;
        if (ListBox1.SelectedIndex >= 0)
        {
            for (int i = 0; i < ListBox1.Items.Count; i++)
            {
                if (ListBox1.Items[i].Selected)
                {
                    if (!arraylist1.Contains(ListBox1.Items[i]))
                    {
                        arraylist1.Add(ListBox1.Items[i]);
                    }
                }
            }
            for (int i = 0; i < arraylist1.Count; i++)
            {
                if (!ListBox2.Items.Contains(((ListItem)arraylist1[i])))
                {
                    ListBox2.Items.Add(((ListItem)arraylist1[i]));
                }
                ListBox1.Items.Remove(((ListItem)arraylist1[i]));
            }
            ListBox2.SelectedIndex = -1;
        }
        else
        {
            lbltxt.Visible = true;
            lbltxt.Text = "Please select atleast one in Listbox1 to move";
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        lbltxt.Visible = false;
        while (ListBox1.Items.Count != 0)
        {
            for (int i = 0; i < ListBox1.Items.Count; i++)
            {
                ListBox2.Items.Add(ListBox1.Items[i]);
                ListBox1.Items.Remove(ListBox1.Items[i]);
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        lbltxt.Visible = false;
        if (ListBox2.SelectedIndex >= 0)
        {
            for (int i = 0; i < ListBox2.Items.Count; i++)
            {
                if (ListBox2.Items[i].Selected)
                {
                    if (!arraylist2.Contains(ListBox2.Items[i]))
                    {
                        arraylist2.Add(ListBox2.Items[i]);
                    }
                }
            }
            for (int i = 0; i < arraylist2.Count; i++)
            {
                if (!ListBox1.Items.Contains(((ListItem)arraylist2[i])))
                {
                    ListBox1.Items.Add(((ListItem)arraylist2[i]));
                }
                ListBox2.Items.Remove(((ListItem)arraylist2[i]));
            }
            ListBox1.SelectedIndex = -1;
        }
        else
        {
            lbltxt.Visible = true;
            lbltxt.Text = "Please select atleast one in Listbox2 to move";
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        lbltxt.Visible = false;
        while (ListBox2.Items.Count != 0)
        {
            for (int i = 0; i < ListBox2.Items.Count; i++)
            {
                ListBox1.Items.Add(ListBox2.Items[i]);
                ListBox2.Items.Remove(ListBox2.Items[i]);
            }
        }

    }

Saturday 20 June 2015

Code to set ShortCut Keys in winforms

Introduction:
The shortcut keys are used to make your application user friendly and easy to use. But as you know there are some default short keys prepared by Microsoft Windows and some times you need to override these shortkeys.

Code:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.B))  //Key combination
            {
                 // your code here
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == Keys.Control) //Single Key
            {
                txtamount.Focus();
                return true;
            }

            // Call the base class
            return base.ProcessCmdKey(ref msg, keyData);
        }


Code to set default startup page in web.config

Introduction:

When someone opens your website by entering your domain name in the web browser then by default it will show the startup page. If you haven't setup an startup page than it will look for Default.aspx or index.html page in the source files. You can setup your startup page in web.config file.

Code:

  <system.webServer>
    <directoryBrowse enabled="false"/>
    <defaultDocument>
      <files>
        <clear/>
        <add value="Default.aspx"/>
      </files>
    </defaultDocument>
  </system.webServer>

Tuesday 25 June 2013

Taking a Snap Shot of screen in .NET

Introduction: Here I need to take a snap shot my screen with my web application on just a button click.

Requirement: For this I need only a Button, by clicking on that the snap shot of screen is taken and saved                            automatically.

Namespaces Required:

using System.Drawing;

using System.Drawing.Imaging;

Click event of Button:

        Bitmap bitmap = new Bitmap(1000, 1000); //declaring size of snap
        Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
        graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
        bitmap.Save(@"c:\Snapshot\screenshot1.bmp", ImageFormat.Bmp); //Path to save image

Result:  
        This code will save the snap shot of screen to the location defined in the code.