Friday, May 14, 2010

Explicit and Implicit Interface Implementation

Interface Implementation in c#

There are two way to implement interface in c#

Implicit

Example
interface First{
void Method();
}
interface Second
{
void Method();
}
class Common : First, Second
{
public void Method()
{
Console.WriteLine("Hello world");
}
}
In the above case both interfaces have same method name. Class which will implement it can not give different implementations to both interfaces function having same name if implicit implementation is used.
Explicit Implementation
In this kind of implementation you need to provide fully qualified name e.g.
InterfaceName.MethodName()
This is helpful to provide different implementation to the method having same name but belongs to different interfaces.
class Common : First, Second
{
public void First.Method()
{
Console.WriteLine("First interface");
}
public void Second.Method() {
Console.WriteLine("Second interface");
}
}
We can not make function virtual and abstract if explicit implementation is used where as it is possible with implicit one. For Further Detail refer to any of these books
Illustrated C# 2008 (Windows.Net)C# BibleProgramming C#C# How to ProgramMastering Visual C# .NET

Thursday, April 2, 2009

Encrypt and decrypt config file of .net window application

/*Thsi code can be used to encrypt and decrypt the config file of window application developed in .net for security purpose*/
static void EncryptionandDecyption(string exeConfigName)
{
try
{
Configuration config = ConfigurationManager.OpenExeConfiguration(exeConfigName);
AppSettingsSection section = config.GetSection("appSettings") as AppSettingsSection;
if (section.SectionInformation.IsProtected)
{
//section.SectionInformation.UnprotectSection();
}
else
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}
config.Save();
}
catch (Exception ex)
{
}
}

For Further detail refer to these books.

Programming .NET 3.5Programming .NET Components, 2nd EditionProgramming Microsoft .NET (Core reference)Beginning ASP.NET 3.5: In C# and VB (Programmer to Programmer)Pro C# 2010 and the .NET 4 Platform, Fifth Edition

Thursday, March 5, 2009

Diabetes remedy

http://www.diabeteshormone.com/

Mission of this site is simplifying the science of Diabetes and Endocrinology for layman and to provide a platform of discussion and interaction among professionals.

You need not waste time in browsing and looking around for information; just by a single click of mouse you will reach your area of interest.

In this site, information about hormonal problems including Diabetes is provided by various modes of communication like text, animation, slide shows, videos, etc. with expectation that it will generate great interest for the patients and their families and will solve most of the unanswered queries.

Diabetes School is the area full of practical info of day to day use. In addition, site has a huge collection of recipes and a number of useful Health tools. Parents can know about health of their kids in health tools.

For Hindi speaking population; we have a Hindi section of website Madhumeha.com.

I hope diabeteshormone.com will serve its purpose.


Other Resources and gadgets usefull for diabetic patient.
The First Year: Type 2 Diabetes: An Essential Guide for the Newly DiagnosedDr. Neal Barnard's Program for Reversing Diabetes: The Scientifically Proven System for Reversing Diabetes without DrugsBayer Contour Blood Glucose, 100 Test StripsHome Diagnostics TrueTrack Test Strips, 100 CountBetty Crocker's Diabetes Cookbook: Everyday Meals, Easy as 1-2-3Diabetes Cookbook For Dummies

Export data from excel to database using c#

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Odbc;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/* This code requires there should be same name of column in sql table as well as in excel file and name of sheet of excel file should be abc */
}
protected void Button1_Click(object sender, EventArgs e)
{
ExportExcelTOSql();
}
public void ExportExcelTOSql()
{
OdbcConnection connection;
SqlBulkCopy bulkCopy;
string strExcelPath = Server.MapPath("abc.xls");
string ConnectionString = @"server=DEL-SKUMAR\SPLENDIDCRM;database=TestDatabase;Integrated Security=SSPI;";
string conn = @"Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" + strExcelPath;
using (connection = new OdbcConnection(conn))
{
//To place in sql
OdbcCommand command = new OdbcCommand("Select * FROM [abc$]", connection);
connection.Open();
using (OdbcDataReader dr = command.ExecuteReader())
{
using (bulkCopy = new SqlBulkCopy(ConnectionString))
{
bulkCopy.DestinationTableName = "EmployeeNotSentReport";
bulkCopy.WriteToServer(dr);
}
dr.Close();
}
//To place in dataset and manipulate at the time of insertion
//here abc is name of sheet in excel or you can place sheet1 the default name of sheet if not changed in excel file.
OdbcDataAdapter placeindataset = new OdbcDataAdapter("Select * FROM [abc$]", connection);
DataSet ds = new DataSet();
placeindataset.Fill(ds);
}
bulkCopy.Close();
connection.Close();
}
}

For further detail please refer to these books.

Microsoft Visual C# 2008 Step by StepLearning C# 3.0C#: A Beginners GuideC# 4.0 in a Nutshell: The Definitive Reference