RSS

Tag Archives: C#

Using MySQL with C# (III): Coding in C#


  • Install the nuget package: in the nuget management console, type below line and run

Install-Package MySql.Data

  • Let’s create a class SqlUtils, and in the static constructor, type below code:
                
                  static
    SqlUtils()
            {
                try
                {
                    con = new MySqlConnection(connectionStr);
                    con.Open(); //open the connection
                    Console.WriteLine(“Successfully opened database.”);
                }
                catch (MySqlException err) //Catch MySql errors
                {
                    Console.WriteLine(“Error: “ + err.ToString());
                }
            }

where the connection string is:

Read the rest of this entry »

 
1 Comment

Posted by on July 13, 2015 in Dotnet/C#, Programming

 

Tags: , , , , , ,

Using MySQL with C# (II): Creating a DB for programming


You might be interested in how to install MySQL in windows, check up this link for details.

  • Run MySQL workbench after clicking Finish

image_thumb[23]  image_thumb[24]

  • In the MySQL workbench, copy below scripts to create a new database called “MyBooks”:

create database MyBooks

  • Select the above script line, then click the thunder icon to execute the sql statement
  • A new DB is created, as shown in the left DB group:

image   image

Read the rest of this entry »

 
1 Comment

Posted by on July 13, 2015 in Dotnet/C#, Programming

 

Tags: , , , , , ,

Using MySQL with C# (I): MySQL Installation


MySQL is a free database and can be easily used in your .Net Applications. This quick-start goes through the typical process that involves installation, up and running your “Hello MySQL” application.

If you are not interested in the MySQL installation, skip this and go directly to the below topics:

Using MySQL with C# (II): Creating a DB for programming
Using MySQL with C# (III): Coding in C#

  • Download MySQL server here or if you already had an oracle account, go directly here.
  • Accept the license, and select the product/platform to download, click “Go”
  • Download the installer

image  image

  • Unzip and run the installer, follow the instructions.
  • Select the options, in my case, I choose “Full”

Read the rest of this entry »

 
1 Comment

Posted by on July 13, 2015 in Dotnet/C#, Programming

 

Tags: , , , , , , ,

Embedding web browsers in Winform applications


Winform ships with a built-in WebBrowser control where you can use it to embed a web browser in a Winform Application. It is relatively trivial to implement it:

  • In Visual Studio Toolbox, Search “Web Browser”, and you will find the WebBrowser control

    image

  • Drag it to the winform designer
  • In Form Load event handler, add below code:

browser.Navigate(Github.com);

  • Now if you run the application, a browser is embedded into your winform application:

    image

 

There are several problems using this approach:

  • This browser control is based on IE browser, which has many limitations that IE has. 
  • It is not easy to implement the zoom-fit or Zoom-content features to make sure the web page is all visible in this embedded browser

Read the rest of this entry »

 
5 Comments

Posted by on July 4, 2015 in Dotnet/C#, Programming

 

Tags: , , , , , , , , , , , , ,

Unity3D: how to implement Tabbed UI


Unity3D does not ship with the tabbed UI, however, we can cheat to implement this!

The key ideas include:

  • To use Toggle control
  • To make Toggle control look like a tab control

UnityTabDemo

The following code illustrates how this is done:

Read the rest of this entry »

 
3 Comments

Posted by on December 27, 2014 in Programming, Unity 3d

 

Tags: , , , , , , , , , ,

Google Search in C#: A step by step walk-through tutorial


In previous post, the implementation of Google book search in C# is discussed. In this post, the similar approach is used to implement Google Custom Search in C#.

image

Download the source project at Github here.

Read the rest of this entry »

 
8 Comments

Posted by on December 23, 2014 in Dotnet/C#, Programming

 

Tags: , , , , , , , , , , , , , , ,

Uniy3D: How to implement scrolled UI with texts


Unity3D 4.6+ comes with the new UI system that makes implementation of scrolled texts a piece of cake. This article explains, step-by-step, how to make such scrolled effects.

ScrolledText1

Read the rest of this entry »

 
3 Comments

Posted by on December 20, 2014 in Programming, Unity 3d

 

Tags: , , , , , , , , , , ,

Google Book Search in C#: A step by step walk-through tutorial


Several years earlier, I wrote a python script to perform ISBN book search: given the isbn number, the python script simply dumps the books title, publisher and author information, which are then used to rename the pdf that is downloaded into a more informational file name:

123456789a.pdf –> Elsevier_2010_A simple and effective geometric representation for irregular porous structure modeling.pdf

It is a handy script but unfortunately I lost it after a hard disk failure!

And then I decide to recover this from my brain, but I would like to implement it in another my favorite language, C#.

image

Source code of this project can be downloaded from GitHub here.

Read the rest of this entry »

 
14 Comments

Posted by on December 18, 2014 in Dotnet/C#, Java, Programming

 

Tags: , , , , , , , , , , , ,

Open Scene Graph: Render scene to image


OSG ships with many examples including several applications that renders the scene to image, for instance OsgAutoCapture, and OsgScreenCapture.

Whilst these applications are information rich, yet they lack sufficient conciseness and are not right to the point sometimes. It took me hours to get what I need, and for my specific task, I just need such a simple class OsgSnapshotHelper:

void Capture(osgViewer::Viewer* pViewer, std::string outputImagePath)
{
OsgSnapshotHelper* osh = new OsgSnapshotHelper(pViewer);
osh>Capture(outputImagePath);
delete osh;
osh = NULL;
std::cout << Ending Capture: << outputImagePath  << std::endl;
}

image

And here is my implementation, based on OsgAutoCapture example. I wrapped it to what I need and removed all unnecessary stuff into one single class, which would be very portable then.

image

Read the rest of this entry »

 
5 Comments

Posted by on June 30, 2014 in osg, Programming

 

Tags: , , , , , , ,

Apple Swift: top 5 familiar code patterns for java or C# coders


Apple just released its new Swift programming languages, and java and C# coders may be happy about this as there are many features that you will feel familiar with:

  • Type inference and var keyword:

var str =”Some String”
var iValue = 32

  • Nullable (Nil-able)

int? a=3;

  • Comments and block comments

// Single line comment
/* This
   is
  block comment
*/

  • Ternary Conditional Operators

boolean AreYouHappy = TodayIsWeekend? true: false;

  • String format (String Interpolation): the C# {0} equivalent in String.Format():

int money = 123456
string money_str = “We have \(money) dollars”  // We have 123456 dollars

See online documentation here.

 
Leave a comment

Posted by on June 21, 2014 in Programming

 

Tags: , , , , , , , , , ,