Monday, February 13, 2012

How to change Menu hover color - WINFORMS

To change the Hover (mouse over) color of a Windows application menu

My Problem was :


Solution (from Stackoverflow) :

Override the Menustrip's Renderer property. Here's an example, pick your own colors please.


public partial class Form1 : Form {
public Form1() {
InitializeComponent();
menuStrip1.Renderer = new MyRenderer();
}

private class MyRenderer : ToolStripProfessionalRenderer {
public MyRenderer() : base(new MyColors()) {}
}

private class MyColors : ProfessionalColorTable {
public override Color MenuItemSelected {
get { return Color.Yellow; }
}
public override Color MenuItemSelectedGradientBegin {
get { return Color.Orange; }
}
public override Color MenuItemSelectedGradientEnd {
get { return Color.Yellow; }
}
}
}

Wednesday, November 2, 2011

Tuesday, August 2, 2011

WCF Service with Oracle Database Connection

Hi,
Don't have to worry on a WCF service to connect to Oracle. Just think that you are getting some data from some database and that is Oracle.

I will guide u how to get data from Oracle and How to serve that data using WCF.
More WCF Reference go here
Here is a simple example.

Before that I will explain you what is Data Contract
A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged.

Data contract can be explicit or implicit. Simple type such as int,
string etc has an implicit data contract. User defined object are
explicit or Complex type, for which you have to define a Data contract
using [DataContract] and [DataMember] attribute.

A data contract can be defined as follows:

  • It describes the external format of data passed to and from service operations

  • It defines the structure and types of data exchanged in service messages

  • It maps a CLR type to an XML Schema

  • t defines how data types are serialized and deserialized.
    Through serialization, you convert an object into a sequence of bytes
    that can be transmitted over a network. Through deserialization, you
    reassemble an object from a sequence of bytes that you receive from a
    calling application.

  • It is a versioning system that allows you to manage changes to structured data

We need to include System.Runtime.Serialization reference to the project. This assembly holds the DataContract and DataMember attribute.

Create user defined data type called Employee. This data type should
be identified for serialization and deserialization by mentioning with
[DataContract] and [DataMember] attribute.



 [ServiceContract]
public interface IEmployeeService
{
[OperationContract]
Employee GetEmployeeDetails(int EmpId);
}

[DataContract]
public class Employee
{
private string m_Name;
private int m_Age;
private int m_Salary;
private string m_Designation;
private string m_Manager;

[DataMember]
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}

[DataMember]
public int Age
{
get { return m_Age; }
set { m_Age = value; }
}

[DataMember]
public int Salary
{
get { return m_Salary; }
set { m_Salary = value; }
}

[DataMember]
public string Designation
{
get { return m_Designation; }
set { m_Designation = value; }
}

[DataMember]
public string Manager
{
get { return m_Manager; }
set { m_Manager = value; }
}

}


Implementation of the service class is shown below. In GetEmployee
method we have created the Employee instance and return to the client.
Since we have created the data contract for the Employee class, client
will aware of this instance whenever he creates proxy for the service.



public class EmployeeService : IEmployeeService
{
public Employee GetEmployeeDetails(int empId)
{

Employee empDetail = new Employee();

//Do something to get employee details and assign to 'empDetail' properties
//You can call the below method that connects to the Oracle DB and get data
return empDetail;
}
}


Client side



On client side we can create the proxy for the service and make use of it. The client side code is shown below.


protected void btnGetDetails_Click(object sender, EventArgs e)
{
EmployeeServiceClient objEmployeeClient = new EmployeeServiceClient();
Employee empDetails;
empDetails = objEmployeeClient.GetEmployeeDetails(empId);
//Do something on employee details
}



Now I am going to explain how the Oracle Connection should be.

OLE DB Provider for Oracle OLE DB Provider for Oracle (from Microsoft)


The Microsoft OLE DB Provider for Oracle allows ADO to access Oracle databases.



strConnect = _T("Provider=MSDAORA;Data Source=MyOracleDB;User Id=myUsername;"
"Password=myPassword;");


For more information, see: Microsoft OLE DB Provider for Oracle.



OLE DB Provider for Oracle (from Oracle).

For Standard security:



strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;"
"User Id=myUsername;Password=myPassword;");


For a Trusted connection:



  • OS Authenticated connect setting user ID to "/":

    strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;"
    "User Id=/;Password=;");



  • OS Authenticated connect using OSAuthent:

    strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;")

    Note: "Data Source=" must be set to
    the appropriate Net8 name which is known to the naming method in use.
    For example, for Local Naming, it is the alias in the tnsnames.ora file; for Oracle Names, it is the Net8 Service Name.




For more information, see: Oracle Provider for OLE DB Developer's Guide.

INNER JOIN vs. CROSS APPLY

A good example of when CROSS APPLY makes a difference in those cases where INNER JOIN will work as well

http://explainextended.com/2009/07/16/inner-join-vs-cross-apply/

Monday, August 1, 2011

Changing HTML page direction (Right-Left & Left-Right)

Here is a tip for HTML programmers. Changing the writing direction of the page. For example we can take a case of a Arabic website, where they read from Right to Left.

Now how can you do that ? Here is the solutions.
For example to change the whole html layout
<html dir="rtl">
<!-- Or -->
<body dir="rtl" >

For change the direction of a single textbox
<table dir="ltr" >
<asp:TextBox dir="ltr" >

Hi...I am also staring to BLOG...

Hello friends..

Starting from here, I am blogging..
You can find may useful code snippets, coding practices and other programming related Items.

SREEKUMAR P
Website: www.sreekumar.net
EMail : me@sreekumar.net