Tuesday, 4 June 2013

How to use MessageBox object control in Windows phone for any question using c# code

How to use MessageBox object control in Windows phone for any question  using c# code (ok , Cancel)



Step 1 : First create your windows phone application it's may be 7.0,7.1,8.0 application.

Step2: Open MainPage.xaml code file .

Step 3 : Import below code file.

 using  System.Windows;

Step 4 : Paste below code to show message box in windows phone this is simple info message box which will show only message to use not asking any question.
 
MessageBox.Show("Message to show user","Title of Message Box",MessageBoxButton.OK);

Step 5 : Ask question to user and wait for his reply

MessageBoxResult result =MessageBox.Show("Are you male", "Gender Question", MessageBoxButton.OKCancel);

Step 6 : Check user answer using result object

if (object == MessageBoxResult.Ok)
{
       //user is male

else
{
      // cancel part
}

Step 4 : This way you can use message box in windows phone .



How to do Vibration in Windows Phone using C# code

How to do Vibration in Windows Phone using C# code



Step 1 : First create your windows phone application it's may be 7.0,7.1,8.0 application.

Step2: Open MainPage.xaml code file .

Step 3 : Import below code file.

 using Microsoft.Devices;

Step 4 :Declare one VibrateController object

VibrateController vc = VibrateController.Default;

Step 5 : Add button to start vibration.

<Button Content="Vibration" Grid.Row="1" Height="72" HorizontalAlignment="Left"  Name="btnVibration" VerticalAlignment="Top" Width="160" Click="btnVibration_Click" />

 Step 6 : Add code behind to add button click event

private void btnVibration_Click(object sender, RoutedEventArgs e)
        {

           //specify the time span specify time below 5 second this is maximum limitation of vibration.
            vc.Start(TimeSpan.FromSeconds(1));
        }


Step 7 :  You can stop vibration using object Stop() method.

  vc.Stop();


Step 4 : This way you can get  use vibrate services in windows phone.



How to get DeviseId in Windows Phone usig c# code and convert to base64 string

How to get DeviseId in Windows Phone usig c# code and convert to base64 string



Step 1 : First create your windows phone application it's may be 7.0,7.1,8.0 application.

Step2: Open MainPage.xaml code file and paste below code in your file

using Microsoft.Phone.Info;

private string m_DeviceUniqueId;
        public string DeviceId
        {
            get
            {
                if (m_DeviceUniqueId == null)
                {
                    object val;
                    if (Microsoft.Phone.Info.DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out val))
                        m_DeviceUniqueId = Convert.ToBase64String((val as byte[]));
                }
                return m_DeviceUniqueId;
            }
        }

Step 3 : Call DeviseID function and get the Windows Phone Devise Id


Step 4 : This way you can get  deviseId information using c# code and Info class.



How to get Devise Information using c# code in Windows Phone

How to get Devise Information using c# code in Windows Phone



Step 1 : First create your windows phone application it's may be 7.0,7.1,8.0 application.

Step2: Open MainPage.xaml code file and paste below code in your file

using Microsoft.Phone.Info;

long applicationCurrentMemoryUsage = DeviceStatus.ApplicationCurrentMemoryUsage;

            long applicationPeakMemoryUsage = DeviceStatus.ApplicationPeakMemoryUsage;


            string deviceFirmwareVersion = DeviceStatus.DeviceFirmwareVersion;


            string deviceHardwareVersion = DeviceStatus.DeviceHardwareVersion;


            string deviceManufacturer = DeviceStatus.DeviceManufacturer;


            string deviceName = DeviceStatus.DeviceName;


            long deviceTotalMemory = DeviceStatus.DeviceTotalMemory;


            bool isKeyboardDeployed = DeviceStatus.IsKeyboardDeployed;


            bool isKeyboardPresent = DeviceStatus.IsKeyboardPresent;


            PowerSource powerSource = DeviceStatus.PowerSource;

Step 3 : This way you can get all devise information using c# code and Info class.

Monday, 3 June 2013

Create Simple Application in MVC 3

How to create simple application in MVC 3 Using EntityFramework.


Click Below link to download project

http://www.mediafire.com/?f5ay24cq5nm1t36

Step 1 : Software requirement

  •  The ASP.NET MVC 3 run-time components require the following software:
  •  NET Framework version 4. 
  • Visual Studio 2010 or Visual Web Developer 2010 Express. 
  • ASP.NET MVC 3 Visual Studio 2010 tools require the following software.

Step 2 :

    Click on Microsoft Visual Studio 2010

  1. Click on File menu select new project 
  2. Select  

3.   Enter your project name and location where you want to save this project
4.   Click on ok button for next step and get this screen



5. Select project template
          Empty ,internet Application ,Internet Application
         I go with Internet Application
6.   Select View Engine
       Aspx view  :- View which is we used in all last .net application   Extension is .aspx
       Razor view :- Is good as compare to aspx view rendering is fast . Extension is   .cshtml
7.   Keep "Create a unit test project"  box UN-check we will learn later on about this.
8.   Check us HTML5 semantic markup
9.   Click on ok button
10. View solution explorer all the file and folder is created for your project..




    Adding Entity Framework in MVC3 Application

    How to add Entity Frame work in MVC 3 Application


    Step 1 :   First you have to know how to create MVC3  application so view my post about 

             http://mvc3withanuj.blogspot.in/2013/01/create-simple-application-in-mvc-3.html

    Step 2 :  Right click on Model folder in solution bar

    Step 3 : Select ADD option and then select ADD NEW one windows is open


    Step 4 : Click in Data option in Left menu

    Step 5 : Select ADO.NET Entity Data Model  give the name of the model  Like StudentModel and click on Add button.

    Step 6 : One new windows open click on Generate from database option and click on next

    Step 7 : Add New Database connection and Select the database you want to add in your project..

    • Click on New Connection .
    • Select Microsoft SQL server click on continue .
    •  Select server name or enter .   (dot)  .
    • Fill authentication details you have to access to database .
    • Select database you want to use in this application.
    • Once test the connection if they return Test Connection is Succeeded.
    • Click on OK button  


    Step 8 : Enter your entity name you like or keep it same..

    Step 9 : Click on NEXT button and Choose your Database objects..

    Step 10 : Select your Tables and Store Procedures you want to add in your application..



    Step 11 : And keep all check box selected ..

    Step 12 : Click on FINISH Button to create the entity model..

    Step 13 :This way you can add entity model in your Application


    Thank You

    Send Push Notification to android mobile using MVC,Asp.net

    Send Push Notification to android mobile using MVC  Code C#


    Step 1 : First create your [MVC ,Asp.net Application] .

    Step 2 : Paste the below code in your application.

    public void NotifyTest(string regId)
            {
                var applicationID = "xxxxxxxxxxxxxxxxxxxx";

                var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://android.googleapis.com/gcm/send");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method = "POST";
                httpWebRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"registration_ids\":[\"" + regId + "\"]," +
                                "\"data\": {\"title\": \"This is testing.\"}}";
                    Console.WriteLine(json);
                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();

                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        var result = streamReader.ReadToEnd();
                        Console.WriteLine(result);
                    }
                }
            }

    Step 3  : Call the function  NotifyTest(regID) with one Register ID of mobile  parameter.

    Step 4 : This way you can send push notification.