Support us on YouTube by Subscribing our YouTube Channel. Click here to Subscribe our YouTube Channel

Monday 29 December 2014

CheckBox Widget in Xamarin

In this Article, We will see How to use CheckBox widget control and CheckBox's CheckedChange Event in Xamarin.For Demonstration, I am going to create a Simple application in which if user accept the terms and condition(using CheckBox) then Submit button become enabled. Before starting, I suggest you read my previous articles of this series.


Let's Begin:
1) Create a New Android Application.
Create Android Application in Xamarin
2) Drop a CheckBox (with id="@+id/checkBox1") and Button (with id="@+id/btn_Submit") control onto the Layout, Main.axml.
CheckBox Widget in Xamarin
Set the Text of CheckBox as Accept Terms and Condition and Button's Text as Submit.
CheckBox and Button in Xamarin
Main.axml Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <CheckBox
        android:text="Accept Terms and Conditions"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/checkBox1" />
    <Button
        android:text="Submit"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btn_Submit"
        android:enabled="false" />
</LinearLayout>
In Activity1.cs, We have created CheckBox CheckedChange Event. The following is Activity1.cs Code:
using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace CheckBoxDemo
{
    [Activity(Label = "CheckBoxDemo", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity
    {
        //Create instance of Button
        Button btn_Submit;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            //setting the view for the Activity 
            SetContentView(Resource.Layout.Main);
            //Get btn_Submit Button and checkBox1 CheckBox control from the Main.xaml Layout.
            btn_Submit = FindViewById<Button>(Resource.Id.btn_Submit);
            CheckBox checkBox1 = FindViewById<CheckBox>(Resource.Id.checkBox1);
            //CheckBox CheckedChange Event
            checkBox1.CheckedChange += checkBox1_CheckedChange;
            //btn_Submit Click Event
            btn_Submit.Click += btn_Submit_Click;
        }

        void checkBox1_CheckedChange(object sender, CompoundButton.CheckedChangeEventArgs e)
        {
            //If CheckBox is Checked
            if(e.IsChecked==true)
            {
                btn_Submit.Enabled = true;
            }
            else
            {
                btn_Submit.Enabled = false;
            }
        }

        void btn_Submit_Click(object sender, EventArgs e)
        {
            Toast.MakeText(this,"Thanks for accepting Terms and Condition",ToastLength.Short).Show();
        }
    }
}
Final Preview:
CheckBox and Button in Xamarin / Mono for Android
Hope you like it. Thanks.
[Download Source Code via Google Drive]

Friday 26 December 2014

Create RDLC Report using DataSet in ASP.NET Website

In this Article, We will learn How to create RDLC Report using DataSet in ASP.NET Website / Web Application. In Previous Article, We saw how to create a RDLC Report in ASP.Net using Visual Studio Report Designer. If you missed that, visit the following link:


You have seen that in previous example, We havn't type even a single line of Code. In this Article, we will create RDLC Report using DataSet and type few lines of code for filling the DataSet with Data and use that DataSet as a ReportDataSource.
For demonstration, I have created a database (named as Sample) and created a table tbl_Employee in it. The following is the table design for creating tbl_Employee.
RDLC Reports image1
Add some records to tbl_Employee. I have attached the script of the database along with the source code for download.

Let's Begin:
1. Create New Website.
2. Right Click on Website -> Add New Item -> Select DataSet
3. You will see Empty DataSet. Right Click on the DataSet -> Go to Add -> Select DataTable.
4. Right click on DataTable and Add the Columns name. Column Name must match with the Name of Column added in the the tbl_Employee.
Set the DataType of Each column same as declared in tbl_Employee. Save the DataSet(i.e. dsEmployee).
5. Right Click on Website -> Add new item -> Select Report Wizard -> Click on Add.
6. Now the Report Wizard opens. Select the DataSource as Dataset (i.e. dsEmployee).
7. Drag and drop the required fields from the Available fields into the Values section.
Click on "Next" because we didn't want to display a subtotal in our report.
8. Choose a style for your report then click on "Finish". I have selected Slate as the style for my report.
You will see the report named Report.rdlc is created.
9. Add ScriptManager and ReportViewer Control on a Webform. I have added them on Default.aspx.
Now Go to the Code behind file of Default.aspx Webform.
10. Add System.Data.SqlClient and Microsoft.Reporting.WebForms namespace(contains methods and properties for the ReportViewer Web server control). After that add the following code in Page_Load Event of Default.aspx.
using System;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //set Processing Mode of Report as Local
            ReportViewer1.ProcessingMode = ProcessingMode.Local;
            //set path of the Local report
            ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
            //creating object of DataSet dsEmployee and filling the DataSet using SQLDataAdapter
            dsEmployee dsemp = new dsEmployee();
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Sample;Integrated Security=true;");
            con.Open();
            SqlDataAdapter adapt = new SqlDataAdapter("select * from tbl_Employee", con);
            adapt.Fill(dsemp, "DataTable1");
            con.Close();
            //Providing DataSource for the Report
            ReportDataSource rds = new ReportDataSource("dsEmployee", dsemp.Tables[0]);
            ReportViewer1.LocalReport.DataSources.Clear();
            //Add ReportDataSource
            ReportViewer1.LocalReport.DataSources.Add(rds);
        }
    }
}
Build and Run the Application.
Click on the Save Button in the report and save the entire report in PDF / Excel / Word format.
I hope you like it. Thanks.
[Download Source Code via Google Drive]

Monday 22 December 2014

Create RDLC Reports in ASP.NET Web Application/Website

In this Article, We will learn How to create RDLC Report in ASP.Net using Visual Studio Report Designer. For Demonstration, I have created a Database(named as Sample) and created a table tbl_Employee in it. Table Design for creating tbl_Employee.
Add some Data in tbl_Employee. I have attached the script of Database along with the Source Code for Download.

Let's Begin:

1. Create an Empty ASP.NET Website and Add a Web Form(Default.aspx) in it.
2. Drop ScriptManager and ReportViewer controls from Toolbox on Default.aspx Web form.
3. Click on ReportViewer Tasks and then Click on Design a new report.
After that you will see Data Source Configuration Wizard.
4. Click on New Connection.
then select Microsoft SQL Server as Data Source -> Click on continue.
5. Type Server Name and Select your Database from the drop down list.
then click on OK.
6. Give a name to your connection String and the click on next.
7. Select the database object you want in your dataset and Give a meaningful name to DataSet. Click on Finish.
8. Now Report Wizard Opens. Select the DataSource as Dataset(i.e. EmployeeDS) which you have created earlier -> Click on Next.
9. Drag and drop the required fields from the Available fields into Values section.
Click on Next because we didn't want to display subtotal in our Report
10. Choose a style for your Report -> Click on Finish.
After that you will see Report named as Report1.rdlc is created.
11. Now go to Default.aspx(where you have dropped ReportViewer control) and than Click on ReportViewver Tasks and Select Report1.rdlc.
12. Build and Run the Application.
Click on Save Button in Report and save the Entire report in PDF/Excel/Word format.
Hope you like it. Thanks.
[Download Source Code via Google Drive]

Tuesday 16 December 2014

Text to Speech Converter in C#

In this Article, We will learn How to create Text to Speech Converter in C# Windows Form Application using SpeechSynthesizer Class.

Let's Begin:
1) Create New Project -> Select Windows Form Application in C# -> Give it a name.
Add New Project Image
2) Drop RichTextBox and four Button Controls from the ToolBox.
Text to Speech Converter Image2
3) Right click on Reference Folder -> Click on Add Reference.
Add referece Image3
4) Select System.Speech Assembly and Click on OK.
Add Reference System.Speech Image4
After adding it, you will see System.Speech assembly under References folder.
System.Speech in Reference Image5
5) Go to Form1.cs(Code behind .cs file) and Add System.Speech(System.Speech namespaces contain types that support speech recognition) and System.Speech.Synthesis namespace (System.Speech.Synthesis namespace contains classes for initializing and configuring a speech synthesis engine and for generating speech etc.)
using System;
using System.Windows.Forms;
using System.Speech;
using System.Speech.Synthesis;

namespace TextToSpeechConverter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //SpeechSynthesizer Class Provides access to the functionality of an installed a speech synthesis engine.
        SpeechSynthesizer speechSynthesizerObj;
        private void Form1_Load(object sender, EventArgs e)
        {
            speechSynthesizerObj = new SpeechSynthesizer();
            btn_Resume.Enabled = false;
            btn_Pause.Enabled = false;
            btn_Stop.Enabled = false;
        }
       

        private void btn_Speak_Click(object sender, EventArgs e)
        {
            //Disposes the SpeechSynthesizer object
            speechSynthesizerObj.Dispose();
            if(richTextBox1.Text!="")
            {
                speechSynthesizerObj = new SpeechSynthesizer();
                //Asynchronously speaks the contents present in RichTextBox1
                speechSynthesizerObj.SpeakAsync(richTextBox1.Text);
                btn_Pause.Enabled = true;
                btn_Stop.Enabled = true;
            }
        }

        private void btn_Pause_Click(object sender, EventArgs e)
        {
            if(speechSynthesizerObj!=null)
            {
                //Gets the current speaking state of the SpeechSynthesizer object.
                if(speechSynthesizerObj.State==SynthesizerState.Speaking)
                {
                    //Pauses the SpeechSynthesizer object.
                    speechSynthesizerObj.Pause();
                    btn_Resume.Enabled = true;
                    btn_Speak.Enabled = false;
                }
            }
        }

        private void btn_Resume_Click(object sender, EventArgs e)
        {
            if (speechSynthesizerObj != null)
            {
                if (speechSynthesizerObj.State == SynthesizerState.Paused)
                {
                    //Resumes the SpeechSynthesizer object after it has been paused.
                    speechSynthesizerObj.Resume();
                    btn_Resume.Enabled = false;
                    btn_Speak.Enabled = true;
                }
            }
        }

        private void btn_Stop_Click(object sender, EventArgs e)
        {
            if(speechSynthesizerObj!=null)
            {
                //Disposes the SpeechSynthesizer object
                speechSynthesizerObj.Dispose();
                btn_Speak.Enabled = true;
                btn_Resume.Enabled = false;
                btn_Pause.Enabled = false;
                btn_Stop.Enabled = false;
            }
        }

       
    }
}
Final Preview:
Text to Speech Converter in C# Windows Form Application
Hope you like it. Thanks.
[Download Source Code via Google Drive]


Subscribe us on YouTube

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Like us on Facebook

Blog Archive