Windows Presentation Foundation (WPF) Command-Line Compile Using CSC

August 16, 2012

If you choose to use csc, the C# compiler, then you may only compile C# files, extensible application markup language (XAML) files are none inclusive.

MyWpfApplication.cs

using System;
using System.Windows;
using System.Windows.Controls;

  class MyWpfApplication : Application
  {
    [STAThread]
    static void Main()
    {
      MyWpfApplication app = new MyWpfApplication();
      app.Startup += AppStartUp;
      app.Exit += AppExit;
      app.Run();
    }

    static void AppExit(object sender, ExitEventArgs e)
    {
      MessageBox.Show("Application exiting.");
    }

    static void AppStartUp(object sender, StartupEventArgs e)
    {
      MainWindow wnd = new MainWindow("WPF Application.", 300, 300);
    }
  }

  class MainWindow : Window
  {
    Button btnExitApp = new Button();

    public MainWindow(string windowTitle, int height, int width)
    {
      btnExitApp.Click += new RoutedEventHandler(btnExitApp_Clicked);
      btnExitApp.Content = "Exit Application";
      btnExitApp.Height = 25;
      btnExitApp.Width = 100;
      this.AddChild(btnExitApp);

      this.Title = windowTitle;
      this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
      this.Height = height;
      this.Width = width;
      this.Show();
    }

    private void btnExitApp_Clicked(object sender, RoutedEventArgs e)
    {   
      Application.Current.Shutdown();
    }
  }

MyWpfApplicationBuild.bat

csc.exe /out:MyWpfApplication.exe /target:winexe MyWpfApplication.cs 

/reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\presentationframework.dll" 
/reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\windowsbase.dll" 
/reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\presentationcore.dll" 

Working together – Node.js and mysql

July 17, 2012

This article assumes that Node.js and mysql are installed.

Type in, the command below, to install the mysql module.

npm install mysql@2.0.0-alpha3

Listed below, is a sample program, mysql.js, for connecting to mysql.

var mysql      = require('mysql');

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'user',
  password : 'secret',
  database : 'database name'
});

connection.connect();

connection.query('SELECT * from contact', function(err, rows, fields) {
  if (err) throw err;

  console.log("Number of rows: " + rows.length);
  console.log('Query result: ', rows);

  var columns=new Array(fields.length);
  for (var j = 0; j < fields.length; ++j) {
	columns[j] = fields[j]['name'];
  }

  for (var i in rows) {
	var row = rows[i];
	//console.log(row.FirstName);
	for (var j = 0; j < fields.length; ++j) {
		console.log(columns[j], ': ', row[columns[j]]);
	}	
  }

});

//Escaping query values
var contactId = 1;
var sql    = 'SELECT * FROM Contact WHERE ContactID = ' + connection.escape(contactId);
connection.query(sql, function(err, rows, fields) {
  if (err) throw err;

  console.log("Number of rows: " + rows.length);
  console.log('Query result: ', rows);
});

//Escaping query values  
var contactId = 2;
var sql    = 'SELECT * FROM Contact WHERE Contactid = ?';
connection.query(sql, [contactId], function(err, rows, fields) {
  if (err) throw err;

  console.log("Number of rows: " + rows.length);
  console.log('Query result: ', rows);
});

//Insert
var post  = {Dated: new Date(), FirstName: 'Jane', LastName: 'Smith'};
var query = connection.query('INSERT INTO Contact SET ?', post, function(err, rows, fields) {
  if (err) throw err;
  console.log(query.sql); 
  console.log(rows.insertId);
});

connection.end();

References

felixge / node-mysql

Two tables, identical schema, two columns only, table A and table B. For each product, select the maximum price.

September 2, 2009

/*
Two tables, identical schema, two columns only, table A and table B.
First column is product number, second column is price.
Table A Product 1, $20. Product 2, $20.
Table B Product 2, $30. Product 3, $20.
For each product, select the maximum price.
*/

CREATE TABLE TableA
(
ProductNumber     VARCHAR(20) NOT NULL,
Price        DECIMAL
)
GO

CREATE TABLE TableB
(
ProductNumber     VARCHAR(20) NOT NULL,
Price        DECIMAL
)
GO

INSERT INTO TableA
(
ProductNumber,
Price
)
VALUES
(
‘Product 1’,
20
)
GO

INSERT INTO TableA
(
ProductNumber,
Price
)
VALUES
(
‘Product 2’,
20
)
GO

INSERT INTO TableB
(
ProductNumber,
Price
)
VALUES
(
‘Product 2’,
30
)
GO

INSERT INTO TableB
(
ProductNumber,
Price
)
VALUES
(
‘Product 3’,
20
)
GO

CREATE PROCEDURE TwoIdenticalTablesMaxPrice
AS
–For each product, select the maximum price.

–Declare work table variable.
DECLARE @MultipleTablesGrouping AS Table(ProductNumber VARCHAR(20), Price DECIMAL)

–Populate work table variable.
INSERT INTO @MultipleTablesGrouping
SELECT
ProductNumber,
Max(Price)
FROM
TableA
GROUP BY
ProductNumber
UNION
SELECT
ProductNumber,
Max(Price)
FROM
TableB
GROUP BY
ProductNumber

–Declare work table variable.
DECLARE @SingleTableMaximumPrice AS Table(ProductNumber VARCHAR(20), Price DECIMAL)

INSERT INTO @SingleTableMaximumPrice
SELECT
ProductNumber,
Max(Price)
FROM
@MultipleTablesGrouping
GROUP BY
ProductNumber

–Display result
SELECT * FROM @SingleTableMaximumPrice
GO

EXEC TwoIdenticalTablesMaxPrice
GO

DROP PROCEDURE TwoIdenticalTablesMaxPrice
GO

DROP TABLE TableA
GO

DROP TABLE TableB
GO

SQL Server – Integration Services – How To

August 30, 2009

Group Tasks

Click a task, hold down the control key, click another task, right click, and select Group.

Add Annotation

Right click, and select Add Annotation. To add a line separator, press control-enter.

Variables

Right click, and select Variables.

Derived Column

For example, add a derived column between the source and destination of a data flow task.

A sample expression is ISNULL(ScriptureReference) || LTRIM(RTRIM(ScriptureReference)) == “” ? Commentary : Commentary + ” (” + ScriptureReference + “)”

Script Task

System.Windows.Forms.MessageBox.Show
(
“greeting=” +
Dts.Variables[“User::greeting”].Value.ToString()
);

Remember to register the variables as ReadOnlyVariables or ReadWriteVariables.

DataProfileViewer

Suitable natural keys that are candidate primary keys is one of the offering of this extensive tool.