Search This Blog

Saturday, September 4, 2010

Static DroupDownList Us In DataGridView

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.Data.OleDb;
using System.Data.SqlClient;
namespace Bar_nd_Hotel
{
   
    public partial class SearchAll : Form
    {
        DAL obj = new DAL();
        DataTable dt = new DataTable();
        public SearchAll()
        {
            InitializeComponent();
        }

        private void SearchAll_Load(object sender, EventArgs e)
        {
          
        }

        private void btnsearch_Click(object sender, EventArgs e)
        {
            string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
            SqlConnection con = new SqlConnection(constring);



            string selectval = Cmboselectitem.SelectedItem.ToString();

            if (selectval == "Staff Details")
            {
                //string qry = "";
                SqlCommand cmd = new SqlCommand();
                string sqlqry = "Select * from crtstaff ";
                if (txtname.Text != "")
                {
                    sqlqry += "where stfname = '" + txtname.Text + "' ";
                }
                else if (txtpost.Text != "")
                {
                    sqlqry += "where post = '" + txtpost.Text + "' ";
                }
                else if (txtsalary.Text != "")
                {
                    sqlqry += "where salary='" + txtsalary.Text + "'";
                }
                else if (txtmobileno.Text != "")
                {
                    sqlqry += "where mobile_no='" + txtmobileno.Text + "'";
                }
                else if (dateTimePicker1.Value.ToShortDateString() != "")
                {
                    sqlqry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
                }

                Searchgrid.DataSource = "";
                cmd.CommandText = sqlqry;
                cmd.CommandType = CommandType.Text;
                cmd.Connection = con;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.SelectCommand = cmd;
                DataSet ds = new DataSet();
                da.Fill(ds, "crtstaff");

                Searchgrid.DataSource = ds.Tables["crtstaff"].DefaultView;


            }




            if (selectval == "Salary Details")
            {
                string sqlry = "Select * from salarystatus ";
                if (txtname.Text != "")
                {
                    sqlry += "where stfname = '" + txtname.Text + "' ";
                }
                else if (txtworkdays.Text != "")
                {
                    sqlry += "where workdays ='" + txtworkdays.Text + "' ";
                }
                else if (chkdueamount.Checked == true)
                {
                    sqlry += "where dueamt != '' and dueamt != '0'";
                }
                else if (chkpaidamount.Checked == true)
                {
                    sqlry += "where paidamt !='' and paidamt != '0'";
                }
                else if (chkabsent.Checked == true)
                {
                    sqlry += "where absent !='' and absent != '0'";
                }
                else if (chkdayshift.Checked == true)
                {
                    sqlry += "where dayshift !='' and dayshift != '0'";
                }
                else if (chknight.Checked == true)
                {
                    sqlry += "where nightshift !='' and nightshift != '0'";
                }
                else if (dateTimePicker1.Value.ToShortDateString() != "")
                {
                    sqlry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
                }
                SqlCommand cmd = new SqlCommand();
                Searchgrid.DataSource = "";
                cmd.CommandText = sqlry;
                cmd.CommandType = CommandType.Text;
                cmd.Connection = con;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.SelectCommand = cmd;
                DataSet ds = new DataSet();
                da.Fill(ds, "salarystatus");

                Searchgrid.DataSource = ds.Tables["salarystatus"].DefaultView;

            }
         


        }
     

        private void Cmboselectitem_SelectedIndexChanged(object sender, EventArgs e)
        {
         
        }

    
       
    }
}

No comments:

Post a Comment