Monday, March 31, 2014
Friday, March 28, 2014
Thursday, March 27, 2014
C# after enter text and press enter, then trigger a button click
private void textBox_Enter(object sender, EventArgs e)
{
ActiveForm.AcceptButton = Button1; // Button1 will be 'clicked' when user presses return
}
private void textBox_Leave(object sender, EventArgs e)
{
ActiveForm.AcceptButton = null; // remove "return" button behavior
}
http://stackoverflow.com/questions/2212237/c-how-to-make-pressing-enter-in-a-text-box-trigger-a-button-yet-still-allow-s
Form.CenterToScreen
Wednesday, March 26, 2014
C# SQLMgr access SQL class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace xxxx
{
public class SQLMgr
{
public SqlConnection mConnection;
public SQLMgr()
{
try
{
if (Properties.Settings.Default.Prod)
{
mConnection = new SqlConnection(Properties.Settings.Default.ConnProd);
}
{
mConnection = new SqlConnection(Properties.Settings.Default.ConnTest);
}
if (mConnection.State != ConnectionState.Open)
{
mConnection.Open();
}
}
catch (Exception Ex)
{
throw Ex;
}
}
public bool CheckIfXXX(int iXXX)
{
bool bRC = false;
try
{
string sSQL = string.Empty;
if (mConnection.State != ConnectionState.Open)
{
mConnection.Open();
}
sSQL = "xxxx where yyy = " + zzz;
using (SqlCommand sqlCmd = new SqlCommand(sSQL, mConnection))
{
using (SqlDataReader myReader = sqlCmd.ExecuteReader())
{
if (myReader.HasRows)
{
bRC = true;
}
}
}
}
catch (Exception Ex)
{
throw Ex;
}
return bRC;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace xxxx
{
public class SQLMgr
{
public SqlConnection mConnection;
public SQLMgr()
{
try
{
if (Properties.Settings.Default.Prod)
{
mConnection = new SqlConnection(Properties.Settings.Default.ConnProd);
}
{
mConnection = new SqlConnection(Properties.Settings.Default.ConnTest);
}
if (mConnection.State != ConnectionState.Open)
{
mConnection.Open();
}
}
catch (Exception Ex)
{
throw Ex;
}
}
public bool CheckIfXXX(int iXXX)
{
bool bRC = false;
try
{
string sSQL = string.Empty;
if (mConnection.State != ConnectionState.Open)
{
mConnection.Open();
}
sSQL = "xxxx where yyy = " + zzz;
using (SqlCommand sqlCmd = new SqlCommand(sSQL, mConnection))
{
using (SqlDataReader myReader = sqlCmd.ExecuteReader())
{
if (myReader.HasRows)
{
bRC = true;
}
}
}
}
catch (Exception Ex)
{
throw Ex;
}
return bRC;
}
}
}
Tuesday, March 25, 2014
Saturday, March 22, 2014
HTML5 sandbox iframe
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_iframe_sandbox
https://github.com/writeline/HTML5-Sandbox-Demo
https://github.com/writeline/HTML5-Sandbox-Demo
Connect two monitors to two PC without HDMI connectors
I have two older monitors that I use at home for my PC. Now I got a Mac Mini so what to do? Sometimes I need to use Windows 8.1, sometimes I need to use Mac. Do I need to get more monitors? The answer is no.
Solution is to use two Plugable UGA-2K-A USB to VGA/DVI/HDMI adaptor
website below:
http://plugable.com/products/uga-2k-a
When I need to switch, just swap the two USB.
I can buy a USB switch, so I do not need to swap them, but I don't understand why it is kind of expensive.
http://www.amazon.com/SIIG-SuperSpeed-Switch-Adapter-JU-SW0012-S1/dp/B005EHND30
https://www.youtube.com/watch?v=KviBmjC7BDg
Solution is to use two Plugable UGA-2K-A USB to VGA/DVI/HDMI adaptor
website below:
http://plugable.com/products/uga-2k-a
When I need to switch, just swap the two USB.
I can buy a USB switch, so I do not need to swap them, but I don't understand why it is kind of expensive.
http://www.amazon.com/SIIG-SuperSpeed-Switch-Adapter-JU-SW0012-S1/dp/B005EHND30
https://www.youtube.com/watch?v=KviBmjC7BDg
Friday, March 21, 2014
VB.Net fill SqldataReader to listview
Private Sub FillListViewQueryData(ByRef sqlData As SqlDataReader)
Dim lvTemp As ListViewItem = New ListViewItem()
'Dim dSet As New DataSet
'Dim dr As DataRow
Dim lvwColumn As ColumnHeader
Dim itmListItem As ListViewItem
Dim shtCntr As Short
Dim shtLC As Short
Me.Cursor = Cursors.WaitCursor
'Remove any existing contents from our listview.
lv.Clear()
Try
For shtCntr = 0 To sqlData.FieldCount() - 1
lvwColumn = New ColumnHeader()
lvwColumn.Text = sqlData.GetName(shtCntr)
lv.Columns.Add(lvwColumn)
Next
shtLC = 1 'Initialize loop counter.
Do While sqlData.Read
itmListItem = New ListViewItem()
itmListItem.Text = sqlData(0)
For shtCntr = 1 To sqlData.FieldCount() - 1
If sqlData.IsDBNull(shtCntr) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(sqlData.GetValue(shtCntr).ToString)
End If
Next shtCntr
lv.Items.Add(itmListItem)
Loop
'lblRecdCtr.Text = "Records: " & lv.Items.Count
'Resize each column to the size of the text in the column header.
For Each lvwColumn In lv.Columns
lvwColumn.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize)
Next
sub_ShadeRows()
Catch ex As Exception
MessageBox.Show(ex.Message, vbNullString, MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
lvwColumn = Nothing
lvTemp = Nothing
End Try
lblRecordCount.Text = "Record count: " & lv.Items.Count
Me.Cursor = Cursors.Default
End Sub
Private Sub sub_ShadeRows()
Dim itm As ListViewItem
Dim iLC As Integer = 0
For Each itm In lv.Items
'Shade every other row for easier readability
If (iLC Mod 2) Then
itm.BackColor = Color.Silver
Else
itm.BackColor = Color.White
End If
iLC += 1
Next itm
lv.Refresh()
End Sub
Dim lvTemp As ListViewItem = New ListViewItem()
'Dim dSet As New DataSet
'Dim dr As DataRow
Dim lvwColumn As ColumnHeader
Dim itmListItem As ListViewItem
Dim shtCntr As Short
Dim shtLC As Short
Me.Cursor = Cursors.WaitCursor
'Remove any existing contents from our listview.
lv.Clear()
Try
For shtCntr = 0 To sqlData.FieldCount() - 1
lvwColumn = New ColumnHeader()
lvwColumn.Text = sqlData.GetName(shtCntr)
lv.Columns.Add(lvwColumn)
Next
shtLC = 1 'Initialize loop counter.
Do While sqlData.Read
itmListItem = New ListViewItem()
itmListItem.Text = sqlData(0)
For shtCntr = 1 To sqlData.FieldCount() - 1
If sqlData.IsDBNull(shtCntr) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(sqlData.GetValue(shtCntr).ToString)
End If
Next shtCntr
lv.Items.Add(itmListItem)
Loop
'lblRecdCtr.Text = "Records: " & lv.Items.Count
'Resize each column to the size of the text in the column header.
For Each lvwColumn In lv.Columns
lvwColumn.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize)
Next
sub_ShadeRows()
Catch ex As Exception
MessageBox.Show(ex.Message, vbNullString, MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
lvwColumn = Nothing
lvTemp = Nothing
End Try
lblRecordCount.Text = "Record count: " & lv.Items.Count
Me.Cursor = Cursors.Default
End Sub
Private Sub sub_ShadeRows()
Dim itm As ListViewItem
Dim iLC As Integer = 0
For Each itm In lv.Items
'Shade every other row for easier readability
If (iLC Mod 2) Then
itm.BackColor = Color.Silver
Else
itm.BackColor = Color.White
End If
iLC += 1
Next itm
lv.Refresh()
End Sub
Developing in HTML5 with JavaScript and CSS3 Jump Start
http://www.microsoftvirtualacademy.com/training-courses/learn-html5-with-javascript-css3-jumpstart-training#?fbid=_K6VJoMq9yM
codeshow.codeplex.com
http://www.microsoft.com/learning/en-us/exam-70-480.aspx
http://www.microsoft.com/learning/en-us/exam-70-480.aspx
Thursday, March 20, 2014
when c# properties does not work on app config
You have to add global::
if (global::YourClassName.Properties.Settings.Default.xyz)
if (global::YourClassName.Properties.Settings.Default.xyz)
HTML point one-seventy-second of an inch
http://printwiki.org/Point_Size
http://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/
http://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/
Wednesday, March 19, 2014
Creating tasks from emails in Outlook
http://www.priacta.com/troblog/2008/05/14/training/create-tasks-from-outlook-emails/
Creating tasks from emails in Outlook is as simple as:
- Click. Click on the email. (You can also right click and get more options. See below.)
- Drag. Hold the mouse button down and drag the email to the Tasks icon in the navigation bar (usually at the left). You can also drag it to the Tasks window button in the Windows task bar if you have a separate Tasks window open.
- Hover. Without releasing the mouse button, hover a couple of seconds until the Tasks window opens.
- Drop. Let go of the mouse button. A new task is created. (If you want to create the new task in a specific task list, move the cursor over that task list first.)
Tuesday, March 18, 2014
Getting a User Control to display in Toolbox pane
http://stackoverflow.com/questions/3829328/getting-a-user-control-to-display-in-toolbox-pane
answer:
You should right-click the Toolbox area, click on "Choose Items", in the ".Net Framwork Components" tab click on "Browse". Then select the .dll where your user control is and click OK. Then make sure the line of your newly added control is marked and click OK. It should be available now in the Toolbox.
Alternatively you could add the project of your user control in the solution and it should automatically be added to the toolbox (at the top).
more:
You still need to add the reference of the DLL.
more:
You still need to add the reference of the DLL.
Thursday, March 13, 2014
Mac Xcode to hide keyboard
-(void)touchesBegan:(NSSet *)touches withEvent:
(UIEvent *)event{
[self.view endEditing:TRUE];
}
access windows folder from mac
from mac, finder, go, connect to server, then use smb with windows IP address.
have to share windows folder first.
also need to create a user id password, setup permisson of the folder, so from mac, can login.
have to share windows folder first.
also need to create a user id password, setup permisson of the folder, so from mac, can login.
IOS XCODE how to rename a view controller
click the .h file, to open it up.
right click on the @interface line the view controller name , then click on Refactor, then rename
right click on the @interface line the view controller name , then click on Refactor, then rename
Wednesday, March 12, 2014
Started IOS XCODE application progamming
Bought a Mac mini refurbished from Apple store about one week ago. And it moves faster that my newest Dell Windows 8.1 machine.
Pluralsight courses below are good starting point:
Pluralsight courses below are good starting point:
Beginning iOS 7 Development
Introduction to iOS for .NET Developers
http://www.tutorialspoint.com/ios/index.htm
Monday, March 10, 2014
Thursday, March 6, 2014
Wednesday, March 5, 2014
C# windows service install service and start service
create windows service project
add project installer
configure project installer
add setup project
add custom events to setup project (including project output to every event)
add code to enable debugging
static class Program
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger("YourProject");
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
m_log.Info("started");
if (Environment.UserInteractive)
{
// This used to run the service as a console (development phase only)
YourProject ServiceToRun = new YourProject();
ServiceToRun.callStart();
Console.WriteLine("Press Enter to terminate ...");
Console.ReadLine();
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]{new YourProject};
ServiceBase.Run(ServicesToRun);
}
}
public partial class YourApplication : ServiceBase
{
public static readonly log4net.ILog m_log = log4net.LogManager.GetLogger("YourApplication");
public YourApplication()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
m_log.Info("started");
}
protected override void OnStop()
{
m_log.Info("stoped");
}
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
m_log.Info("created");
}
//below is for debugging purpose
public void callStart()
{
m_log.Info("call start");
OnStart(new string[] { "" });
}
}
below is code to auto start the service after install
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
using log4net;
using log4net.Config;
using log4net.Layout;
namespace YourApplication
{
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
private const string SERVICE_NAME = "YourApplication";
private ServiceController m_Service;
public ProjectInstaller()
{
InitializeComponent();
HandleService();
}
private void HandleService()
{
object[] parameters;
string sMeth = "HandleService";
string sCallingMethodName;
try
{
m_Service = new ServiceController(SERVICE_NAME);
if (m_Service != null)
{
m_Service.Start();
}
else
{
}
}
catch (Exception ex)
{
//
}
finally
{
//
}
}
}
}
add project installer
configure project installer
add setup project
add custom events to setup project (including project output to every event)
add code to enable debugging
static class Program
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger("YourProject");
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
m_log.Info("started");
if (Environment.UserInteractive)
{
// This used to run the service as a console (development phase only)
YourProject ServiceToRun = new YourProject();
ServiceToRun.callStart();
Console.WriteLine("Press Enter to terminate ...");
Console.ReadLine();
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]{new YourProject};
ServiceBase.Run(ServicesToRun);
}
}
public partial class YourApplication : ServiceBase
{
public static readonly log4net.ILog m_log = log4net.LogManager.GetLogger("YourApplication");
public YourApplication()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
m_log.Info("started");
}
protected override void OnStop()
{
m_log.Info("stoped");
}
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
m_log.Info("created");
}
//below is for debugging purpose
public void callStart()
{
m_log.Info("call start");
OnStart(new string[] { "" });
}
}
below is code to auto start the service after install
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
using log4net;
using log4net.Config;
using log4net.Layout;
namespace YourApplication
{
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
private const string SERVICE_NAME = "YourApplication";
private ServiceController m_Service;
public ProjectInstaller()
{
InitializeComponent();
HandleService();
}
private void HandleService()
{
object[] parameters;
string sMeth = "HandleService";
string sCallingMethodName;
try
{
m_Service = new ServiceController(SERVICE_NAME);
if (m_Service != null)
{
m_Service.Start();
}
else
{
}
}
catch (Exception ex)
{
//
}
finally
{
//
}
}
}
}
Log4net for VB.net and C#
0. add dll reference
1. add YourApplicationName.exe.Log4Net file to project
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<appender name="ExampleAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="E:\Data\Logs\YourApplication\YourApplication_"/>
<param name="RollingStyle" value="Date"/>
<param name="DatePattern" value="yyyy_MM_dd'.log'"/>
<param name="StaticLogFileName" value="false"/>
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="3" />
<maximumFileSize value="100KB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level - [%logger] %C{1}.%M %message%newline" />
</layout>
</appender>
<logger name="YourApplication">
<level value="ALL" />
<appender-ref ref="ExampleAppender" />
</logger>
</log4net>
</configuration>
2. change AssemblyInfo.vb add the line below to end of file
VB.net
<Assembly: log4net.Config.XMLConfigurator(ConfigFile:="YourApplicationName.exe.Log4Net", Watch:=True)>
C#
[assembly: log4net.Config.XmlConfigurator(ConfigFile="YourApplicationName.exe.Log4Net",Watch = true)]
3. configuration file needs to be added to setup project otherwise would not work
4. if ms access mdb access need to change project compile property to dot net framework 4 from framework 4 client
5. while debugging need to copy config file to the debug directory (this is automatically done if step 3 is done)
6. Code
VB.net
Imports log4net
Imports log4net.Config
Imports log4net.Layout
Public m_Log As log4net.ILog
m_Log = log4net.LogManager.GetLogger("YourApplication")
m_Log.Info("Started...")
C#
using log4net;
using log4net.Layout;
using log4net.Config;
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger("YourApplication");
m_log.Info("started");
7. Make sure add the YourApplicationName.exe.Log4Net to setup project. It has to be in the application folder otherwise it would not work.
8. error you may see (http://sadi02.wordpress.com/2008/06/29/log4net-tutorial-in-c-net-how-can-i-show-log-in-a-file/ has the following comments)
If you’re working with Visual Studio 2010 default setup you’ll probably get the error: The name ‘log4Net’ does not exist in the current context.
The reason is that your target framework is “.Net Framework 4 Client profile”.
Right click your project -> properties ->change target framework to “.Net Framework 4″
1. add YourApplicationName.exe.Log4Net file to project
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<appender name="ExampleAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="E:\Data\Logs\YourApplication\YourApplication_"/>
<param name="RollingStyle" value="Date"/>
<param name="DatePattern" value="yyyy_MM_dd'.log'"/>
<param name="StaticLogFileName" value="false"/>
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="3" />
<maximumFileSize value="100KB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level - [%logger] %C{1}.%M %message%newline" />
</layout>
</appender>
<logger name="YourApplication">
<level value="ALL" />
<appender-ref ref="ExampleAppender" />
</logger>
</log4net>
</configuration>
2. change AssemblyInfo.vb add the line below to end of file
VB.net
<Assembly: log4net.Config.XMLConfigurator(ConfigFile:="YourApplicationName.exe.Log4Net", Watch:=True)>
C#
[assembly: log4net.Config.XmlConfigurator(ConfigFile="YourApplicationName.exe.Log4Net",Watch = true)]
3. configuration file needs to be added to setup project otherwise would not work
4. if ms access mdb access need to change project compile property to dot net framework 4 from framework 4 client
5. while debugging need to copy config file to the debug directory (this is automatically done if step 3 is done)
6. Code
VB.net
Imports log4net
Imports log4net.Config
Imports log4net.Layout
Public m_Log As log4net.ILog
m_Log = log4net.LogManager.GetLogger("YourApplication")
m_Log.Info("Started...")
C#
using log4net;
using log4net.Layout;
using log4net.Config;
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger("YourApplication");
m_log.Info("started");
7. Make sure add the YourApplicationName.exe.Log4Net to setup project. It has to be in the application folder otherwise it would not work.
8. error you may see (http://sadi02.wordpress.com/2008/06/29/log4net-tutorial-in-c-net-how-can-i-show-log-in-a-file/ has the following comments)
If you’re working with Visual Studio 2010 default setup you’ll probably get the error: The name ‘log4Net’ does not exist in the current context.
The reason is that your target framework is “.Net Framework 4 Client profile”.
Right click your project -> properties ->change target framework to “.Net Framework 4″
Visual studio 2012 2013 change installshield limited edition project configuration to single image and change setup.exe to another name
Click on "Build" on the standard tool bar or right click on solution explorer to show configuration manager .
Then you can select what kind of output for disk image.
To change setup.exe file name you have to double click "Releases" in the setup project which will show "Build" (see figure below next), then click on "Express" will show"Setup File Name". (this is very hard to find, so I have to record it here).
You setup file is default to setup.exe, you can change to your application name (see below the setup file name is blank, but then below description says default to Setup.
Then the single exe file generated, and you can use singlefile.exe /S /v/qn to do silent install.
Or if you specify MSI name and change to DVD-5 you will see MSI generated.
Just a lot of work. I have to use Wise installer to remove the previous version then to do silent install after that.
Monday, March 3, 2014
Started leaning Git
created a github free account
watching pluralsight class and safari online books
http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/getting-started-with-git-in-visual-studio-and-team-foundation-service.aspx
watching pluralsight class and safari online books
http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/getting-started-with-git-in-visual-studio-and-team-foundation-service.aspx
Subscribe to:
Posts (Atom)