Thursday, 3 March 2016

Source code



using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.Common;
using System.Configuration;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
using System.IO;
using Microsoft.VisualBasic;



public partial class Login : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AMSConnectionString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LoginButton_Click(object sender, EventArgs e)
    {
        checklogin();
    }
    public void checklogin()
    {
        try
        {
            con.Open();
            string encriptedpass;
            string username;
            string decrpytpass;

            encriptedpass = EncryptText(txtpassword.Text);

            decrpytpass = DecryptText("ua0+vLQjpRC5vZmCnXGl7w==");

            SqlCommand cmd = new SqlCommand("usp_checklogin", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@username", txtusername.Text);
            cmd.Parameters.AddWithValue("@pass_word", encriptedpass.ToString());
            DataSet ds = new DataSet();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);
            if (ds.Tables[0].Rows[0]["userid"].ToString() != "0") //check valid user
            {
                username = ds.Tables[1].Rows[0]["username"].ToString();
                Session["username"] = username.ToString();
                Session["userid"] = ds.Tables[0].Rows[0]["userid"].ToString();
                Session["ispss_chg"] = ds.Tables[1].Rows[0]["ispss_chg"].ToString();

                if (ds.Tables[1].Rows[0]["ispss_chg"].ToString() == "Y")
                {

                    Response.Redirect("Home.aspx");
                }
                else
                {
                    Response.Redirect("Change_password.aspx");
                }
         
            }
            else // invalid user
            {
                lblmessage.Text = "Invalid User, Please Check Username or Password";
            }
        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }

    }


    public static string EncryptText(string strText)
    {
        return Encrypt(strText, "+%#@?,:*");
    }

    public static string DecryptText(string strText)
    {
        return Decrypt(strText, "+%#@?,:*");
    }
    private static string Encrypt(string strText, string strEncrKey)
    {
        byte[] byKey = { };
        //ReDim byKey(8) as by Byte = {}
        byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };

        try
        {
            byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey);

            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();

            return Convert.ToBase64String(ms.ToArray());
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }

    private static string Decrypt(string strText, string sDecrKey)
    {
        byte[] byKey = { };
        byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };
        byte[] inputByteArray = new byte[strText.Length + 1];
        try
        {
            byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey);
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            inputByteArray = Convert.FromBase64String(strText);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            System.Text.Encoding encoding = System.Text.Encoding.UTF8;
            return encoding.GetString(ms.ToArray());
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }

}








  protected void Submit_Click(object sender, EventArgs e)
    {

        createuser();
    }
    private void MessageBox(string msg)
    {
        Label lbl = new Label();
        lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
        Page.Controls.Add(lbl);
    }

    public void createuser()
    {
        try
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("insert_user", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@fname", txtfname.Text);
            cmd.Parameters.AddWithValue("@lname", txtlname.Text);
            string username;
            username = txtfname.Text + '.' + txtlname.Text;
            if (username != "")
            {
                cmd.Parameters.AddWithValue("@username", username.ToString());
            }
            else
            {
                MessageBox("Please Enter First name & Last Name");
                return;
            }

            cmd.Parameters.AddWithValue("@email_id", txtemailid.Text);

            string cont;
            cont = txtcontectno.Text;
            if (cont.Length == 10)
            {
                cmd.Parameters.AddWithValue("@cont_no", txtcontectno.Text);
            }
            else
            {
                MessageBox("Please Enter 10 digits only....");
                return;
            }

            cmd.Parameters.AddWithValue("@doj", txtdoj.Text);
            cmd.Parameters.AddWithValue("@dept_id", cmbdept.SelectedValue);
            cmd.Parameters.AddWithValue("@desg_id", cmbdesg.SelectedValue);
            cmd.Parameters.AddWithValue("@loc_id", cmbloction.SelectedValue);
            cmd.Parameters.AddWithValue("@login_uid", Session["userid"]);
            cmd.Parameters.AddWithValue("@ip_add", Request.UserHostAddress);
            string password = txtfname.Text.ToLower() + "@123";
            string encryptpassword = EncryptText(password);
            cmd.Parameters.AddWithValue("@pass_word", encryptpassword);
            cmd.ExecuteNonQuery();
            MessageBox("User Created Successfully....");
        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
            fill_grid();
        }

    }




  protected void Submit_Click(object sender, EventArgs e)
    {
        try
        {
            con.Open();

            SqlCommand cmd1 = new SqlCommand("show_dublication_entry", con);
            cmd1.CommandType = CommandType.StoredProcedure;
            cmd1.Parameters.AddWithValue("@item_name", txtItemname.Text.Trim());
            cmd1.Parameters.AddWithValue("@item_code", txtitemcode.Text.Trim());
            DataSet ds = new DataSet();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd1);
            adpt.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["cnt"].ToString() != "0")
                {
                    lblmsg.Text = "Item already Exists....";
                    return;
                }
                if (ds.Tables[1].Rows[0]["cnt"].ToString() != "0")
                {
                    lblmsg.Text = "Item code already Exists....";
                    return;
                }
            }

            SqlCommand cmd = new SqlCommand("insert_item_master", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@item_name", txtItemname.Text);
            cmd.Parameters.AddWithValue("@item_desc", txtdescription.Text);
            cmd.Parameters.AddWithValue("@catg_id", ddlcatgory.SelectedValue);
            cmd.Parameters.AddWithValue("@atype_id", ddlasettype.SelectedValue);
            cmd.Parameters.AddWithValue("@item_code", txtitemcode.Text);
            cmd.Parameters.AddWithValue("@ip_add", Request.UserHostAddress);
            cmd.Parameters.AddWithValue("@userid", Session["userid"]);
            cmd.ExecuteNonQuery();
            lblmsg.Text = "Record Saved Successfully......";
          

        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
            fill_grid();
        }
    }






 protected void addtolist_Click(object sender, EventArgs e)
    {
        try
        {
            con.Open();



            SqlCommand cmd = new SqlCommand("usp_cnt_of_purchase", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@catg_id", ddlcategory.SelectedValue);
            cmd.Parameters.AddWithValue("@item_id", ddlitem.SelectedValue);
            DataSet ds = new DataSet();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                itemcnt = Convert.ToInt32(ds.Tables[0].Rows[0]["cnt"].ToString());
                code = ds.Tables[1].Rows[0]["code"].ToString();
            }





            DataTable dt = new DataTable();

            dt.Columns.Add("catg_name", typeof(string));  //0
            dt.Columns.Add("item_name", typeof(string));    //1
            dt.Columns.Add("Supp_name", typeof(string));      //2
            dt.Columns.Add("Location", typeof(string));       //3
            dt.Columns.Add("Bill_no", typeof(string));        //4
            dt.Columns.Add("bill_date", typeof(string));        //5
            dt.Columns.Add("qty", typeof(string));   //6
            dt.Columns.Add("amt", typeof(string));//7
            dt.Columns.Add("barcode", typeof(string)); //8
            dt.Columns.Add("cat_id", typeof(string)); //9
            dt.Columns.Add("item_id", typeof(string)); //10
            dt.Columns.Add("supp_id", typeof(string)); //11

            int i = 0;
            DataRow dr = null;
            bool StrFlag = false;
            while (i < GridView1.Rows.Count)
            {

                dr = dt.NewRow();
                dr[0] = GridView1.Rows[i].Cells[1].Text;
                dr[1] = GridView1.Rows[i].Cells[2].Text;
                dr[2] = GridView1.Rows[i].Cells[3].Text;
                dr[3] = GridView1.Rows[i].Cells[4].Text;
                dr[4] = GridView1.Rows[i].Cells[5].Text;
                dr[5] = GridView1.Rows[i].Cells[6].Text;
                dr[6] = GridView1.Rows[i].Cells[7].Text;
                dr[7] = GridView1.Rows[i].Cells[8].Text;
                dr[8] = GridView1.Rows[i].Cells[9].Text;
                dr[9] = GridView1.Rows[i].Cells[10].Text;
                dr[10] = GridView1.Rows[i].Cells[11].Text;
                dr[11] = GridView1.Rows[i].Cells[12].Text;
                dt.Rows.Add(dr);
                i = i + 1;
            }
            i = 0;
            int count = 0;




            if (StrFlag == false)
            {
                while (count < Convert.ToInt32(txtqty.Text))
                {
                    dr = dt.NewRow();
                    dr[0] = ddlcategory.SelectedItem.Text;
                    dr[1] = ddlitem.SelectedItem.Text;
                    dr[2] = ddlsupplier.SelectedItem.Text;
                    dr[3] = "Mumbai";
                    dr[4] = txtbillno.Text;
                    dr[5] = txtbilldate.Text;
                    dr[6] = 1;
                    dr[7] = txtrate.Text.ToString();

                    itemcnt = itemcnt + 1;

                    if (itemcnt.ToString().Length == 1)
                    {
                        barcode = code.Trim() + "000000" + itemcnt;
                    }
                    else if (itemcnt.ToString().Length == 2)
                    {
                        barcode = code.Trim() + "00000" + itemcnt;
                    }
                    else if (itemcnt.ToString().Length == 3)
                    {
                        barcode = code.Trim() + "0000" + itemcnt;
                    }
                    else if (itemcnt.ToString().Length == 4)
                    {
                        barcode = code.Trim() + "000" + itemcnt;
                    }
                    else if (itemcnt.ToString().Length == 5)
                    {
                        barcode = code.Trim() + "00" + itemcnt;
                    }
                    else if (itemcnt.ToString().Length == 6)
                    {
                        barcode = code.Trim() + "0" + itemcnt;
                    }
                    else if (itemcnt.ToString().Length == 7)
                    {
                        barcode = code.Trim() + itemcnt;
                    }
                    dr[8] = barcode.ToString();
                    dr[9] = ddlcategory.SelectedValue;
                    dr[10] = ddlitem.SelectedValue;
                    dr[11] = ddlsupplier.SelectedValue;
                    dt.Rows.Add(dr);

                    count = count + 1;
                }

            }

            GridView1.DataSource = dt;
            GridView1.DataBind();

            if (GridView1.Rows.Count > 0)
            {
                Submit.Visible = true;
                Reset.Visible = true;
            }
            else
            {
                Submit.Visible = false;
                Reset.Visible = false;
            }

        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        try
        {
            con.Open();
            int i = 0;
            while (i < GridView1.Rows.Count)
            {

                SqlCommand cmd = new SqlCommand("usp_insert_asset", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@catg_id", GridView1.Rows[i].Cells[10].Text);
                cmd.Parameters.AddWithValue("@item_id", GridView1.Rows[i].Cells[11].Text);
                cmd.Parameters.AddWithValue("@supp_id", GridView1.Rows[i].Cells[12].Text);
                cmd.Parameters.AddWithValue("@loc_id", 1000);
                cmd.Parameters.AddWithValue("@bill_no", GridView1.Rows[i].Cells[5].Text);
                cmd.Parameters.AddWithValue("@bill_date", GridView1.Rows[i].Cells[6].Text);
                cmd.Parameters.AddWithValue("@qty", GridView1.Rows[i].Cells[7].Text);
                cmd.Parameters.AddWithValue("@amount", GridView1.Rows[i].Cells[8].Text);
                cmd.Parameters.AddWithValue("@ip_add", Request.UserHostAddress);
                cmd.Parameters.AddWithValue("@userid", Session["userid"]);
                cmd.Parameters.AddWithValue("@barcode", GridView1.Rows[i].Cells[9].Text);
                cmd.ExecuteNonQuery();
                i = i + 1;
            }

            GridView1.DataSource = "";
            GridView1.DataBind();

            lblmsg.Text = "Record Saved Successfully.....";

        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }
    }











protected void addtolist_Click(object sender, EventArgs e)
    {
        try
        {
            con.Open();
            DataTable dt = new DataTable();

            dt.Columns.Add("frml", typeof(string));  //0
            dt.Columns.Add("tol", typeof(string));    //1
            dt.Columns.Add("catg_name", typeof(string));      //2
            dt.Columns.Add("item_name", typeof(string));       //3
            dt.Columns.Add("barcode", typeof(string));        //4
            dt.Columns.Add("rec", typeof(string));        //5
            dt.Columns.Add("frm_id", typeof(string));   //6
            dt.Columns.Add("to_id", typeof(string));//7
            dt.Columns.Add("catg_id", typeof(string)); //8
            dt.Columns.Add("item_id", typeof(string)); //9
            dt.Columns.Add("rec_id", typeof(string)); //10


            int i = 0;
            DataRow dr = null;
            bool StrFlag = false;
            while (i < GridView1.Rows.Count)
            {

                dr = dt.NewRow();
                dr[0] = GridView1.Rows[i].Cells[1].Text;
                dr[1] = GridView1.Rows[i].Cells[2].Text;
                dr[2] = GridView1.Rows[i].Cells[3].Text;
                dr[3] = GridView1.Rows[i].Cells[4].Text;
                dr[4] = GridView1.Rows[i].Cells[5].Text;
                dr[5] = GridView1.Rows[i].Cells[6].Text;
                dr[6] = GridView1.Rows[i].Cells[7].Text;
                dr[7] = GridView1.Rows[i].Cells[8].Text;
                dr[8] = GridView1.Rows[i].Cells[9].Text;
                dr[9] = GridView1.Rows[i].Cells[10].Text;
                dr[10] = GridView1.Rows[i].Cells[11].Text;
                dt.Rows.Add(dr);
                i = i + 1;
            }
            i = 0;
            int count = 0;




            if (StrFlag == false)
            {

                dr = dt.NewRow();
                dr[0] = ddlfromlocation.SelectedItem.Text;
                dr[1] = ddltolocation.SelectedItem.Text;
                dr[2] = ddlcategory.SelectedItem.Text;
                dr[3] = ddlitem.SelectedItem.Text;
                dr[4] = ddlbarcode.SelectedItem.Text;
                dr[5] = ddlreceiver.SelectedItem.Text;
                dr[6] = ddlfromlocation.SelectedValue;
                dr[7] = ddltolocation.SelectedValue;
                dr[8] = ddlcategory.SelectedValue;
                dr[9] = ddlitem.SelectedValue;
                dr[10] = ddlreceiver.SelectedValue;
                dt.Rows.Add(dr);



            }

            GridView1.DataSource = dt;
            GridView1.DataBind();

            if (GridView1.Rows.Count > 0)
            {
                Submit.Visible = true;
                Reset.Visible = true;
            }
            else
            {
                Submit.Visible = false;
                Reset.Visible = false;
            }

        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
      

        try
        {
            con.Open();
            int x = 0;

            while (x < GridView1.Rows.Count)
            {
                SqlCommand cmd = new SqlCommand("insert_deliverd_details", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@receiver_uerid", GridView1.Rows[x].Cells[11].Text);
                cmd.Parameters.AddWithValue("@catg_id", GridView1.Rows[x].Cells[9].Text);
                cmd.Parameters.AddWithValue("@item_id", GridView1.Rows[x].Cells[10].Text);
                cmd.Parameters.AddWithValue("@receiverloc_id", GridView1.Rows[x].Cells[8].Text);
                cmd.Parameters.AddWithValue("@barcode", GridView1.Rows[x].Cells[5].Text);
                cmd.Parameters.AddWithValue("@ipadd", Request.UserHostAddress);
                cmd.Parameters.AddWithValue("@userid",Session["userid"]);
                cmd.ExecuteNonQuery();
                x = x + 1;
            }
            GridView1.DataSource = "";
            GridView1.DataBind();
            lblmsg .Text ="Record Saved Successfully.....";
            clear();
        }
        catch
        {
            throw;
        }
        finally { con.Close(); }

    }










using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class crnt_asset_details : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AMSConnectionString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fill_category();
            fill_tolocation();
            fill_user();
            get_item();
         
        }

    }
     public void fill_user()
    {
        try
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AMSConnectionString"].ConnectionString);
            con.Open();
            SqlCommand cmd = new SqlCommand("get_username", con);
            cmd.CommandType = CommandType.StoredProcedure;
            DataSet ds = new DataSet();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                ddluser.DataSource = ds.Tables[0];
                ddluser.DataTextField = ds.Tables[0].Columns["username"].ColumnName;
                ddluser.DataValueField = ds.Tables[0].Columns["userid"].ColumnName;
                ddluser.DataBind();
                ddluser.Items.Insert(0, new ListItem("--Select One--", "-1"));
                ddluser.Items.Insert(1, new ListItem("--Select All--", "0"));
            }
        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }
    }

    public void fill_category()
    {
        try
        {
            con.Open();

            SqlCommand cmd = new SqlCommand("fill_Category", con);
            cmd.CommandType = CommandType.StoredProcedure;
            DataSet ds = new DataSet();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                ddlcatgname.DataSource = ds.Tables[0];
                ddlcatgname.DataTextField = ds.Tables[0].Columns["catg_name"].ColumnName;
                ddlcatgname.DataValueField = ds.Tables[0].Columns["catg_id"].ColumnName;
                ddlcatgname.DataBind();
                ddlcatgname.Items.Insert(0, new ListItem("--Select One--", "-1"));
                ddlcatgname.Items.Insert(1, new ListItem("--Select All--", "0"));
            }
        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }
    }
    public void show_user_details()
    {
        try
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("asset_Curnt_status", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@catg_id", ddlcatgname.SelectedValue);
            cmd.Parameters.AddWithValue("@item_id", ddlitemname.SelectedValue);
            cmd.Parameters.AddWithValue("@loc_id", ddllocname.SelectedValue);
            cmd.Parameters.AddWithValue("@userid", ddluser.SelectedValue);
            DataSet ds = new DataSet();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridView1.DataSource = ds.Tables[0];
                GridView1.DataBind();
                lblmsg.Visible = false;
            }
            else
            {
                GridView1.DataSource = "";
                GridView1.DataBind();
                lblmsg.Visible = true;
            }
          
        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }
   
    }



    protected void ddlcatgname_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            con.Open();

            SqlCommand cmd = new SqlCommand("usp_get_item", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@category_id", ddlcatgname.SelectedValue);
            DataSet ds = new DataSet();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);

            if (ds.Tables[0].Rows.Count > 0)
            {
                ddlitemname.DataSource = ds.Tables[0];
                ddlitemname.DataTextField = ds.Tables[0].Columns["item_name"].ColumnName;
                ddlitemname.DataValueField = ds.Tables[0].Columns["item_id"].ColumnName;
                ddlitemname.DataBind();
                ddlitemname.Items.Insert(0, new ListItem("--Select One--", "-1"));
                ddlitemname.Items.Insert(1, new ListItem("--Select All--", "0"));

            }
        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }
    }
    public void get_item()
    {
        try
        {
            con.Open();

            SqlCommand cmd = new SqlCommand("usp_get_itemlist", con);
            cmd.CommandType = CommandType.StoredProcedure;
          
            DataSet ds = new DataSet();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);

            if (ds.Tables[0].Rows.Count > 0)
            {
                ddlitemname.DataSource = ds.Tables[0];
                ddlitemname.DataTextField = ds.Tables[0].Columns["item_name"].ColumnName;
                ddlitemname.DataValueField = ds.Tables[0].Columns["item_id"].ColumnName;
                ddlitemname.DataBind();
                ddlitemname.Items.Insert(0, new ListItem("--Select One--", "-1"));
                ddlitemname.Items.Insert(1, new ListItem("--Select All--", "0"));

            }
        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }
   
    }
    public void fill_tolocation()
    {
        try
        {
            con.Open();

            SqlCommand cmd = new SqlCommand("get_tolocation_fromto", con);
            cmd.CommandType = CommandType.StoredProcedure;
            DataSet ds = new DataSet();
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                ddllocname.DataSource = ds.Tables[0];
                ddllocname.DataTextField = ds.Tables[0].Columns["loc_name"].ColumnName;
                ddllocname.DataValueField = ds.Tables[0].Columns["Loc_id"].ColumnName;
                ddllocname.DataBind();
                ddllocname.Items.Insert(0, new ListItem("--Select One--", "-1"));
                ddllocname.Items.Insert(1, new ListItem("--Select All--", "0"));
            }
        }
        catch
        {
            throw;
        }
        finally
        {
            con.Close();
        }}