Example #1
0
    private void TicketDataGrid()
    {
        SqlConnection con = new SqlConnection(constr);

        con.Open();

        using (con)
        {
            using (SqlCommand cmd = new SqlCommand("select * from Asset_Master Where AMS_Date_of_Purchase between'" + string.Format("{0:yyyy-MM-dd}", DateTime.Parse(fromDate.Text, new CultureInfo("gu-IN", false))) + "'AND '" + string.Format("{0:yyyy-MM-dd}", DateTime.Parse(todate.Text, new CultureInfo("gu-IN", false))) + "' AND AMS_AssetType Like'" + '%' + ReportAssetType.SelectedValue + '%' + "'"))
            {
                SqlDataAdapter dt = new SqlDataAdapter();
                try
                {
                    cmd.Connection = con;

                    dt.SelectCommand = cmd;

                    DataTable dTable = new DataTable();
                    dt.Fill(dTable);
                    SqlDataReader sdr = cmd.ExecuteReader();
                    GridTicketData.DataSource = dTable;
                    GridTicketData.DataBind();

                    if (GridTicketData.Rows.Count != 0)
                    {
                        exportToExcel.Visible = true;

                        GridTicketData.CssClass            = "table table-bordered table-striped  table-inverse nomargin";
                        GridTicketData.UseAccessibleHeader = true;
                        //GridTicketData.HeaderRow.TableSection = TableRowSection.TableHeader;
                        //GridTicketData.FooterRow.TableSection = TableRowSection.TableFooter;
                    }
                    else
                    {
                        exportToExcel.Visible = false;
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('There is no data');", true);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        con.Close();
    }
Example #2
0
 //Other text export code
 private void BindGrid()
 {
     using (SqlConnection con = new SqlConnection(constr))
     {
         using (SqlCommand cmd = new SqlCommand("SELECT * FROM HardwareDbTable"))
         {
             using (SqlDataAdapter sda = new SqlDataAdapter())
             {
                 cmd.Connection    = con;
                 sda.SelectCommand = cmd;
                 using (DataTable dt = new DataTable())
                 {
                     sda.Fill(dt);
                     GridTicketData.DataSource = dt;
                     GridTicketData.DataBind();
                 }
             }
         }
     }
 }
Example #3
0
    private void TicketDataGrid()
    {
        if (DropDownList1.SelectedValue == "All")
        {
            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand("select  TMSTicketID as TicketID ,TMSTicketSubject as Subject,TMSTicketDepartment as Department,TMSTicketDescription as Description,TMSTicketPriority as Priority,TMSTicketStatus as Status,TMSTicketDate as Date,TMSTicketOwnership as Ownership from TMSTicketMaster Where TMSTicketDate>='" + fromDate.Text + "'and TMSTicketDate<='" + todate.Text + "'"))
                {
                    SqlDataAdapter dt = new SqlDataAdapter();
                    try
                    {
                        cmd.Connection = con;
                        con.Open();
                        dt.SelectCommand = cmd;

                        DataTable dTable = new DataTable();
                        dt.Fill(dTable);
                        SqlDataReader sdr = cmd.ExecuteReader();
                        GridTicketData.DataSource = dTable;
                        GridTicketData.DataBind();
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                        // Error msg display here
                    }
                }
            }
        }
        else if (DropDownList1.SelectedValue == "Sla")
        {
            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand("select  TMSTicketID as TicketID ,TMSTicketSubject as Subject,TMSTicketDepartment as Department,TMSTicketDescription as Description,TMSTicketPriority as Priority,TMSTicketStatus as Status,TMSTicketDate as SubmittedDate,TMSTicketOwnership as Ownership,DeviationTime from TMSTicketMaster Where (TMSTicketDate>='" + fromDate.Text + "'and TMSTicketDate<='" + todate.Text + "') and  (Level2Escalation<GETDATE() or Level3Escalation<GETDATE()) "))
                {
                    SqlDataAdapter dt = new SqlDataAdapter();
                    try
                    {
                        cmd.Connection = con;
                        con.Open();
                        dt.SelectCommand = cmd;

                        DataTable dTable = new DataTable();
                        dt.Fill(dTable);
                        SqlDataReader sdr = cmd.ExecuteReader();
                        GridTicketData.DataSource = dTable;
                        GridTicketData.DataBind();
                    }
                    catch (Exception)
                    {
                        // Error msg display here
                    }
                }
            }
        }

        else
        {
            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand("select TMSTicketID as TicketID ,TMSTicketSubject as Subject,TMSTicketDepartment as Department,TMSTicketDescription as Description,TMSTicketPriority as Priority,TMSTicketStatus as Status,TMSTicketDate as SubmittedDate,TMSTicketOwnership as Ownership from TMSTicketMaster Where TMSTicketDate>='" + fromDate.Text + "'and TMSTicketDate<='" + todate.Text + "' and TMSTicketPriority='" + DropDownList1.SelectedValue + "'"))
                {
                    SqlDataAdapter dt = new SqlDataAdapter();
                    try
                    {
                        cmd.Connection = con;
                        con.Open();
                        dt.SelectCommand = cmd;

                        DataTable dTable = new DataTable();
                        dt.Fill(dTable);
                        SqlDataReader sdr = cmd.ExecuteReader();
                        GridTicketData.DataSource = dTable;
                        GridTicketData.DataBind();
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                        // Error msg display here
                    }
                }
            }
        }
    }