Wednesday, December 17, 2014

Multi Select DropDown with CheckBox

Add the following Scripts

Add the Following Scripts

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"
        rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>

    <link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"
        rel="stylesheet" type="text/css" />

    <script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"
        type="text/javascript"></script>

    <script type="text/javascript">
        $(function () {
            $('[id*=lsNames]').multiselect({
                includeSelectAllOption: true
            });
        });
    </script>



<asp:ListBox ID="lsNames" runat="server" SelectionMode="Multiple">
        <asp:ListItem Text="a" Value="1" />
        <asp:ListItem Text="b" Value="2" />
        <asp:ListItem Text="c" Value="3" />
        <asp:ListItem Text="d" Value="4" />
        <asp:ListItem Text="e" Value="5" />

    </asp:ListBox>
       <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />


on button click 
write the following code

string message = "";
        foreach (ListItem item in lsNames.Items)
        {
            if (item.Selected)
            {
                message += item.Text + " " + item.Value + "\\n";
            }
        }
        ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + message + "');", true);


Output





Dynamic Font in Crystal Report

First create a Data Set

Click on Add Button
It prompts for a message saying as




Click on Yes Button



Click on Table Adapter.



Click on New Connection



Click on Continue


Give your Server Name
User Name
Password

And Click on Test Connection.


And click on Ok 


 And Click on Next Button


You can write your own query or u can use the stored procedure






Click on Finish





Select crystal report.rpt file and the below screen is visible


And Click on Ok button

And then press ctrl +alt +T


Double Click on ADO.NET(XML)



Give the dataset path of the folder in FileNamePath

Click on Finish

And Build the solution


And Click on Ok Button

Delete Print Date and Page N  from the crystal Report

Go to field explorer and drag your fields to Detail View



In case if you want to Add your own Header Name, like Company Name and Address then, write the following code in .cs page as below


Go to Crystal Report  
Press Ctrl+Alt+T
Field Explorer 




Similary Add Address

Now, the Report is Ready a Default page as below
write the following code as follows
Design the Form as Follows


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var fontCollection = new System.Drawing.Text.InstalledFontCollection();
            foreach (var font in fontCollection.Families)
            {
             ListBox1.Items.Add(font.Name);
            }
        }
}



Declare the Following Fields Globally.
private ReportDocument _reportDocument;
string selectedfont = string.Empty;

Namespaces
using CrystalDecisions.CrystalReports.Engine;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using CrystalDecisions.Shared;
using System.Drawing;
using System.Windows;
using System.Diagnostics;
using System.IO;
using System.Threading;


Write the following Code in Button Click 

protected void Button2_Click(object sender, EventArgs e)
{
        string selectedfont = string.Empty;
        selectedfont = Convert.ToString(ListBox1.SelectedItem);
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "GetDepartmentInformation";
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        _reportDocument = new ReportDocument();
        _reportDocument.Load(Server.MapPath("CrystalReport.rpt"));
        _reportDocument.SetDataSource(ds.Tables[1]);

        FieldObject fieldObject;
        FieldFormat fieldFormat;
        Section section;
        // Get the Section object by name.
        section = _reportDocument.ReportDefinition.Sections["Section3"];
        fieldObject = section.ReportObjects[0] as FieldObject;

        // Check if the FieldObject is null.
        if (fieldObject != null)
        {
            // Get the FieldFormat object.
            fieldFormat = fieldObject.FieldFormat;
            fieldObject.Color = Color.Red;
            Font fo = new Font(selectedfont, 10F, FontStyle.Regular);
            fieldObject.ApplyFont(fo);
        }

        CrystalReportViewer1.ReportSource = _reportDocument;
        CrystalReportViewer1.DataBind();
        string CompanyName = "abc";
        string Address = "Hyd";
        _reportDocument.DataDefinition.FormulaFields["Company"].Text = "'" + CompanyName + "'";
        _reportDocument.DataDefinition.FormulaFields["Address1"].Text = "'" + Address + "'";
        ShowReport();
}


private void ShowReport()
    {
        Response.Buffer = false;
        Response.ClearContent();
        Response.ClearHeaders();
       
 //for pdf format
        _reportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false"abc");

//forexcel   //_reportDocument.ExportToHttpResponse(ExportFormatType.Excel, Response, false, "abc");

//forrichtext    //_reportDocument.ExportToHttpResponse(ExportFormatType.RichText, Response, false, "abc");
//forword    //_reportDocument.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, false, "abc");
   }



Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...