The Jimzland

                           The land of language research…

RSS
和谐,创造更美好的世界!

Throwing Away Your “‘System.IO.File’ does not contain a definition for ‘ReadAllLines’” Error Message!

Note: You can also read this post on http://students.netindonesia.net/blogs/mrjimoy_05/archive/2011/08/18/throwing-away-your-quot-system-io-file-does-not-contain-a-definition-for-readalllines-quot-error-message.aspx

It’s a simple post but hope it’s helpful for you who need it. Recently I am in doing my project (using Microsoft Visual Studio 2010) and it was annoying! I can’t throw away these message after trying a lot of fixing. Take a look on the code below:

      if (File.Exists(_file))
      {
        string[] linesArray = File.ReadAllLines(yourFile);
        _lines = linesArray.ToList();
      }

For some computer, maybe the error doesn’t appear and the solution running slightly without any constraint. But if you get an error message sounds: ‘System.IO.File’ does not contain a definition for ‘ReadAllLines’, look at the figure below:

Then try to change your code become:

      if (File.Exists(yourFile))
      {
        using (StreamReader sr = new StreamReader(yourFile))
        {
          string line;
          while ((line = sr.ReadLine()) != null)
            _lines.Add(line);
        }
      }

It will fixed your problem :)

Notes: If you have anything to say about the article, please leave a comment. Please show a detail explanation (just like if you’ve got any error, attach the error message) so it should be easier for me to help you.
(attach the file if needed (Only: jpg, jpeg, png, gif, zip files can be uploaded)).

Comments Off | Tags:

A Simple Graphic Movement Build on XNA

Note: You can also read this post on http://students.netindonesia.net/blogs/mrjimoy_05/archive/2011/08/10/a-simple-graphic-movement-build-on-xna.aspx

XNA is a set of tools with a managed runtime environment provided by Microsoft that facilitates video game development and management (Wikipedia.com). This article will covered the very basic of game development before you can building the real game :)

It will be very simply displaying a moving graphic on the screen from left to right. If you are familiar with HTML then it will be so easy, just adding a snippet code <marquee> and close it with the </marquee> and voila!

Although you have installed Visual Studio 2010 for Windows Phone on your computer, you needs a software called Zune. While you’re running the solution without the application, you will receive an error message. Zune is used for all data transfer and synchronization between your PC and your device (Phone/Emulator). Moreover, Zune is a great application you can used for playing your library content such as MP3, your video, pictures, etc. You can download it on http://www.zune.net/.

Open your Visual Studio 2010 for Windows Phone, select the XNA Game Studio 4.0 (Visual C#) and then select the template for Windows Phone Game (4.0), and give your project and solution a name, or just leave it default, then click OK. Right-click the content project node on Solution Explorer, sort “Add” then select “Existing Item“. Choose a graphic file, for example a round image or others. Select “Add”.

Based on the figure above, I am using smiley.png as my graphic file. Make sure your Game1.cs open in the code editor. The object type for the graphic file we stored is Texture2D. Declare the Texture2D object below the spriteBatch declaration.

public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        private Texture2D _smileyTexture; // the Texture2D object for the graphic
        private Vector2 _smileyPosition; // a variable to hold the position of the graphic
        // ... //

Set the initial position for the graphic by creating a new procedure called ResetGame.

private void ResetGame()
        {
            // Set the initial smiley position
            _smileyPosition = new Vector2(100, 100);
        }

To get this code to run, call the procedure from the existing Initialize procedure.

protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            ResetGame(); // Reset the game

            base.Initialize();
        }

Then, we need to load the graphic into the variable that we’ve created on LoadContent procedure (note this procedure has been generated automatically).

protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            _smileyTexture = Content.Load<Texture2D>("smiley"); // load your content here
        }

The next step is to display the content loaded on the screen on Draw procedure.

protected override void Draw(GameTime gameTime)
        {
            // Clear the background
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // Declare a position for the graphic using a Vector2 structure
            Vector2 position = new Vector2(100, 100);

            // Begin a sprite batch
            spriteBatch.Begin();
            spriteBatch.Draw(_smileyTexture, _smileyPosition, Color.White);
            spriteBatch.End(); // End a sprite batch

            base.Draw(gameTime);
        }

Set the back buffer size and orientation on Game1() class contructor, below the TargetElapsedTime.

public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);

            // Set backbuffer size and orientation
            graphics.PreferredBackBufferWidth = 480;
            graphics.PreferredBackBufferHeight = 800;
        }

Finally, we need to change the position stored in the _smileyPosition variable so the graphic moves. The bigger value you provide, it looks faster the graphic moves. So, we will try to give it 5 and will move on Y axis. If you want to moves your graphic horizontally, then try to changes Y to X.

protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Update the game state
            _smileyPosition.Y += 5;
            if (_smileyPosition.Y >= Window.ClientBounds.Bottom) _smileyPosition.Y = 0;

            base.Update(gameTime);
        }

Run it!

If you get your graphic moves, then you have succeed to create your application :)

Thanks for reading.

Notes: If you have anything to say about the article, please leave a comment. Please show a detail explanation (just like if you’ve got any error, attach the error message) so it should be easier for me to help you.
(attach the file if needed (Only: jpg, jpeg, png, gif, zip files can be uploaded)).

Comments Off | Tags: , , ,

Building a Simple Mobile Application using Windows Phone 7 + Expression Blend 4 for Absolutely Beginner!

Note: You can also read this post on http://students.netindonesia.net/blogs/mrjimoy_05/archive/2011/08/08/building-a-simple-mobile-application-using-windows-phone-7-expression-blend-4-for-absolutely-beginner.aspx

Hi everybody! And wow, it has been a long time not writing a blog anymore, 6 months maybe :)

Today I am going to share you how to make a really basic application using a very amazing tools, called Microsoft Visual Studio 2010 Express for Windows Phone 7 and Expression Blend 4. If you have no installed the tools yet on your computer, then you have to install it first. Watch http://bit.ly/9kIjQo for installing guide.

First, open your Microsoft Visual Studio 2010 Express for Windows Phone 7 (notice the Windows Phone 7, because there is Microsoft Visual Studio 2010 Express also without the “Windows Phone 7”), then click the “New Project” on the File Menu (or simply press ctrl+shift+N key). It should launch the “New Project” dialog. Make sure the Windows Phone Application’s template is selected and so for the Silverlight for Windows Phone’s tree on the left side. Give your project name and click OK.

You will get a new project page as shown in above figure. Then, select the Page Title ‘TextBlock’ property (it should be “page name” in above figure) and change the value to “my first page” or whatever, on properties tab (ctrl+w+p, and it should be on the bottom-right-side). And do so for the Application Title ‘TextBlock’ property which currently says “My Application”.

Then, drag a textbox from the toolbox into the main area (below the Page Title ‘TextBlock’ property), then give it a name, “MyTextBox”. Then set the following properties:

  1. Reset the ‘HorizontalAlignment’, ‘Width’, ‘Text’ properties by clicking right the property, then choose Reset Value;
  2. Set the ‘VerticalAlignment’ to “Top”;
  3. Set the ‘Margin’ to “0,0,160,0”.

You can change the property value to getting familiar to the tools. Then you should call it ‘a small experiment’. :)

Drag a button from the toolbox to the right side of the textbox, called it “SubmitButton”. Set the following properties:

  1. Follow the first process on the previous, except for the ‘Text’ properties;
  2. Change the ‘Content’ property to “Submit”;
  3. Set the ‘HorizontalAlignment’ to “Right”;
  4. Set the ‘Margin’ to “0”.

Then finally, drag a textblock to the bottom of the textbox, called it “SubmittedText”, and set the ‘Text’ property blank.

Now, double click the button called ‘Submit’ which has created before, to automatically wire up an event handler for the Click event. Add the code below between the SearchButton_Click event handler:

private void SearchButton_Click(object sender, RoutedEventArgs e) {
          string Value;
          Value = Convert.ToString(MyTextBox.Text);

          SubmittedText.Text = Value;
}

After you do that, then try it by pressing F5 button and select the ‘Windows Phone 7 Emulator’ then click OK. Wait for the emulator to load the application you’ve made. If it succeed, then it should be like the figure below.

Try to insert some text to the textbox, and then click the submit button. You’ll get your text copied to the bottom of the textbox.

Okay, now we will add a motion to the button using Expression Blend 4. Open your Expression Blend 4, and open the solution file that you’ve been working on Visual Studio 2010 Express for Windows Phone (the above solution of course). You’ll get this show on your computer:

Now, in the Object and Timeline window, click the + button, then click New.

This will make a new storyboard and prompted you to give it a name. Enter “SubmitPressedAnimation” followed by clicking the OK button. Click over the course of 0.5 second mark (shown by yellow vertical line),

make sure the ‘submit’ button clicked, then set the rotate angle to -20 on the RenderTransform section on below the Transform window.

Then, move the yellow vertical line to 1 second mark, and set the rotate angle to 20. Finally, move the yellow vertical line to 1.5 second mark, and set the rotate angle to 0. Now the timeline should be like the figure below.

Stop the storyboard editing by clicking the red button to the left of the storyboard name (look figure below).

It’s very important to do this, because although you have declared some animation, you haven’t linked it to any event until the timeline recording is on. Well, after stopping the recording, go back to your Visual Studio 2010 Express for Windows Phone 7. It will be prompted that you’ve to reload the solution because you’ve made some changes to the solution file on the Expression Blend 4.

Then, double click the ‘submit’ button, and add the code below, above the previous code you’ve inserted:

private void SubmitButton_Click(object sender, RoutedEventArgs e) {
          //Animate the button while clicked
          this.SubmitPressedAnimation.Begin();

          string Value;
          Value = Convert.ToString(MyTextBox.Text);

          SubmittedText.Text = Value;
}

Press F5 button on your keyboard, and try to give some value on the textbox, and click the button. See the difference with the previous one you tried? If so, congratulation for your first application! :)

Thanks for reading. :)

Notes: If you have anything to say about the article, please leave a comment. Please show a detail explanation (just like if you’ve got any error, attach the error message) so it should be easier for me to help you.
(attach the file if needed (Only: jpg, jpeg, png, gif, zip files can be uploaded)).

Comments Off | Tags: , , , ,

Designing System for Gate Displays (Final)

Hi there, ready for the next step? Alright! ^^

If you have not read the previous step, click here for the step to create the database for the system. Now, after we knew the flow of the system, create the base for the data, and here we go.

What should we do first? Create the user interface for the ATC or create the gate displays first? Better we create the gate displays first. Look at the code explained below.

//Create the header of the displays,
//here we placed no title for the displays
print("
  <table cellspacing=\"0\" cellpadding=\"0\" border=\"1\">
	<tr>
      <td width=\"20px\">&nbsp;</td>
      <td width=\"70px\">Flight</td>
      <td width=\"130px\">Departure</td>
      <td width=\"70px\">Time</td>
      <td width=\"130px\">Status</td>
	</tr>");

//Make a connection between your MySQL and PHP,
//change the 'MYSQL_DB_SERVER/USER/PASSWORD/DATABASE
//based on your server setting
$connection = mysql_connect(MYSQL_DB_SERVER, MYSQL_DB_USER, MYSQL_DB_PASSWORD);
$database = mysql_select_db("MYSQL_DATABASE", $connection);

//Get the data from the database and execute it
$getdata = "SELECT flight, departure, time, status " .
           "FROM flight ORDER BY time ASC, flight ASC, departure ASC LIMIT 0, 10";
$execute = mysql_query($getdata, $connection);

//Take it into a variable and show it
while($result = mysql_fetch_array($execute)) {
  $Flight = $result[0];
  $Departure = $result[1];
  $Time = $result[2];
  $Status = $result[3];

  print("
    <tr>
	  <td>&nbsp;</td>
	  <td>$Flight</td>
	  <td>$Departure</td>
	  <td>$Time</td>
	  <td>$Status</td>
	</tr>");
  }

Taadaa, and the Gate Displays ready to use ^^

Now, let’s make the user interface. The code is similarly to the code above, just need to adding some line. Have a look at figure below.

print("
  <table cellspacing=\"0\" cellpadding=\"0\" border=\"1\">
	<tr>
      <td width=\"20px\">&nbsp;</td>
      <td width=\"70px\">Flight</td>
      <td width=\"130px\">Departure</td>
      <td width=\"70px\">Time</td>
      <td width=\"130px\">Status</td>
	  <td width=\"100px\">&nbsp;</td>   //new line added
	</tr>");

$connection = mysql_connect(MYSQL_DB_SERVER, MYSQL_DB_USER, MYSQL_DB_PASSWORD);
$database = mysql_select_db("MYSQL_DATABASE", $connection);

$getdata = "SELECT flight, departure, time, status " .
           "FROM flight ORDER BY time ASC, flight ASC, departure ASC LIMIT 0, 10";
$execute = mysql_query($getdata, $connection);

while($result = mysql_fetch_array($execute)) {
  $Flight = $result[0];
  $Departure = $result[1];
  $Time = $result[2];
  $Status = $result[3];

  print("
    <tr>
	  <td>&nbsp;</td>
	  <td>$Flight</td>
	  <td>$Departure</td>
	  <td>$Time</td>
	  <td>$Status</td>
	  <td><a href=\"changestatus.php?flight=$Flight\">Change Status</a></td>  //new line added
	</tr>");
  }

Now, the view should be like this:

Look at the last line we’ve added, there is a link to ‘changestatus.php’, right? Now, let’s we make a new .php file named ‘changestatus’. We are going to using a variable passing technique called Query String. We will passing the value of the flight number to the ‘changestatus.php’ by using an addition syntax after the URL parameter, ‘?flight=$Flight’. This kind of technique passing the value from the origin file to the file that point by the URL parameter.

//Save the passing value to the new variable
$Flight = $_GET["flight"];

$connection = mysql_connect(MYSQL_DB_SERVER, MYSQL_DB_USER, MYSQL_DB_PASSWORD);
$database = mysql_select_db("MYSQL_DATABASE", $connection);

//Get the data based on passing value,
//in this case the passing value is $Flight.
//Note that $Flight is not passing value anymore,
//because it has saved in a new variable (see top code)
$getdata = "SELECT flight, status FROM flight WHERE flight = '$Flight'";
$execute = mysql_query($getdata, $connection);

//Show it
while($result = mysql_fetch_array($execute)) {
  $Flight = $result[0];
  $Status = $result[1];

  print("$Flight, status: $Status");
  }

//Now make the option to change the value, and send it
//pass through the URL parameter again
//Don't forget to make a new file, named 'dochangestatus.php'
printf("
  Change status:<br>
  <a href=\"dochangestatus.php?flight=$Flight&status=delayed\">Delayed</a>&nbsp;|&nbsp;
  <a href=\"dochangestatus.php?flight=$Flight&status=landed\">Landed</a>
")

Now, we create the ‘dochangestatus.php’ file to execute the change.

//Save the passing value to the new variable
$Flight = $_GET["flight"];
$Status = $_GET["status"];

$connection = mysql_connect(MYSQL_DB_SERVER, MYSQL_DB_USER, MYSQL_DB_PASSWORD);
$database = mysql_select_db("MYSQL_DATABASE", $connection);

$upddata = "UPDATE flight SET status = '$Status' WHERE flight = '$Flight'";
$execute = mysql_query($upddata, $connection);

//If the query failed to execute, then the system
//will show that the operation is failed,
//if succeed, direct to the display gate file
if (empty($execute)) print("Status change failed");
else header("Location: index.php");

Yay! Now let’s just take an experiment into its, just take one of the flight and click the ‘change status’ link, and click the ‘delayed’ or ‘landed’, and taadaa!! You’ll get this view:

You can add some line again to delete the flight after the plane landed. But, in reality, they didn’t delete the flight, but they adding a database called ‘flight history’ and store the flight schedule to the database. It’s a kind of OLAP, Online Analytical Data Processing. ^^

Please let me know if there is any question or comment that popping into your mind, or there is any idea that you want me to show up, it will be nice. But I will do it with my best and can’t promise that I can cover it all. Thanks for Micha that have this idea and let me know and I can realized her idea for all of you to get inspire. Thank you for reading.

Comments Off | Tags: , , ,

Designing System for Gate Displays (Part I)

Hi there! Today we’re gonna to create a database for the system I’ve explained before. At the main-figure (Data flow for the system), there are two database, one refer to the airlines, and the other refer to the airport, click here to see the figure. Here, I just require to create one database refer to the airport.

If you do not have any imagine what we are going to make, just open ICCI Web. But we will not use all of variables exist there. The variables we are going to use are: Flight No., From, Time, and Status.

Well, let’s do it!

Firstly, create a new database, named ‘gatedisplays’, or others name you want to make. Or, you can just create the new table for it. Then, create a table named ‘flight’. Finish? Welldone… Then be ready for the next step. What is the next step? Alright, we are gonna create all of the variables we need. The first variable we are going to create is, ‘Flight’, then ‘From’, ‘Time’, and the last, ‘Status’. Look at the figure below.

Here is the query of the MySQL:

CREATE TABLE  `gatedisplays`.`flight` (
`flight` VARCHAR( 7 ) NOT NULL ,
`departure` VARCHAR( 30 ) NOT NULL ,
`time` TIME NOT NULL ,
`status` VARCHAR( 12 ) NOT NULL ,
PRIMARY KEY (  `flight` )
) ENGINE = INNODB;

Now what we have to do is, adding some data to the table to make it useful. Add 10 up to 20 data to the table as you like. Let’s get an example for it.

Ow, I forget to tell you something. As far as the flight schedule not in the range of the Gate Display, it should be an default value to the status, there is ‘unconfirmed’. That’s just my estimate. The ATC will have an authorization to change it.

Well done, in the next step we will have to do make a simple user interface for ATC to change the status while the plane is approaching the airport. And finally, make the Gate Display! ^^ . Thanks for reading.

– to be continued –

Comments Off | Tags: , , ,