Apr 12, 2013
Returning anonymous from WCF
Can C# return anonymous types from methods? NO! It cannot in any case, not to mention WCF need serialize the value.
So, we should look for other ways.
In general, if we want to serialize one valuable, the type of the val should take the attributes [Serializable] or [DataContract] or other relateds, or implement the interface ISerializable. Anonymous types cannot reach the goal.
But there is one special class in .Net Framework “JavaScriptSerializer” in System.Web.Script.Serialization,System.Web.Extensions.dll, which can serialize any types to json format string!
********************************
public static class JsonSerialization
{
public static string ToJson(this object data)
{
return new JavaScriptSerializer().Serialize(data);
}
}
--------------------------------------------
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(...)]
public class Task
{
[OperationContract]
[WebInvoke(...)]
public string Test(bool s)
{
return new { Enabled = true, Name = "Test" }.ToJson();
}
}
Mar 19, 2013
Generics
http://stackoverflow.com/questions/692540/examples-of-usage-of-generics-in-net-c-vb-net
http://www.dotnetperls.com/generic
Generics
public abstract class BaseDao
{
public string GetConectionString()
{
return "";
}
public abstract void Create(T t);
public abstract T GetById(int id);
public abstract List Search(SearchCriteria obj);
}
public class EmployeeDal : BaseDao
{
public override void Create(Employee t)
{
using (SqlConnection con = new SqlConnection(GetConectionString()))
{
}
}
public override Employee GetById(int id)
{
throw new NotImplementedException();
}
public override List Search(SearchCriteria obj)
{
throw new NotImplementedException();
}
}
public class ITTicketsDal : BaseDao
{
public override void Create(Ticket t)
{
throw new NotImplementedException();
}
public override Ticket GetById(int id)
{
using (SqlConnection con = new SqlConnection(GetConectionString()))
{
return null;
}
}
public override List Search(SearchCriteria obj)
{
throw new NotImplementedException();
}
}
public class Employee
{
public string Name { get; set; }
}
public class Ticket
{
public string TicketId { get; set; }
}
public class SearchCriteria
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Singleton
The singleton pattern is a software design pattern that is used to restrict instantiation of a class to one object. This is useful when we require exactly one object of a class to perform our operations. In this pattern we ensure that the class has only one instance and we provide a global point of access to this object
public class Singleton
{
// Static object of the Singleton class.
private static volatile Singleton _instance = null;
///
/// The static method to provide global access to the singleton object.
///
/// Singleton object of class Singleton.
public static Singleton Instance()
{
if (_instance == null)
{
lock (typeof(Singleton))
{
_instance = new Singleton();
}
}
return _instance;
}
///
/// The constructor is defined private in nature to restrict access.
///
private Singleton() { }
}
Abstraction Vs Encapsulation
Encapsulation is hiding the implementation details which may or may not be for generic or specialized behavior(s).
Abstraction is providing a generalization (say, over a set of behaviors).
Encapsulation: Is hiding unwanted/un-expected/propriety implementation details from the actual users of object. e.g.
List list = new List();
list.Sort(); /* Here, which sorting algorithm is used and hows its
implemented is not useful to the user who wants to perform sort, that's
why its hidden from the user of list. */
Abstraction: Is a way of providing generalization and hence a common way to work with objects of vast diversity. e.g.
class Aeroplane : IFlyable, IFuelable, IMachine
{ // Aeroplane's Design says:
// Aeroplane is a flying object
// Aeroplane can be fueled
// Aeroplane is a Machine
}
// But the code related to Pilot, or Driver of Aeroplane is not bothered
// about Machine or Fuel. Hence,
// pilot code:
IFlyable flyingObj = new Aeroplane();
flyingObj.Fly();
// fighter Pilot related code
IFlyable flyingObj2 = new FighterAeroplane();
flyingObj2.Fly();
// UFO related code
IFlyable ufoObj = new UFO();
ufoObj.Fly();
// **All the 3 Above codes are genaralized using IFlyable,
// Interface Abstraction**
// Fly related code knows how to fly, irrespective of the type of
// flying object they are.
// Similarly, Fuel related code:
// Fueling an Aeroplane
IFuelable fuelableObj = new Aeroplane();
fuelableObj.FillFuel();
// Fueling a Car
IFuelable fuelableObj2 = new Car(); // class Car : IFuelable { }
fuelableObj2.FillFuel();
// ** Fueling code does not need know what kind of vehicle it is, so far
// as it can Fill Fuel**
Sep 20, 2011
Number and Decimal restricted Textboxes
Numbers : 'input tag id="Text1" class="numeric" type="text" '
Decimals With Two Precision : 'input tag id="Text2" class="decimal" type="text" '
// script
$(".numeric").keypress(function (event) { OnlyNumber(event); });
$(".decimal").keypress(function (event) { OnlyDecimal(this, event, 3); }); // defaulted to 3 decimal points.
var controlKeys = [8, 9, 13, 35, 36, 37, 39];
function OnlyDecimal(obj, event, noOfDecPlaces) {
var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
var uiVal = $(obj).val();
var isValid = new Boolean(true);
if (uiVal.indexOf('.') > 0) {
var arr = uiVal.split(".");
if (arr[1].length >= noOfDecPlaces) isValid = false;
}
if ((!event.which || (48 <= event.which && event.which <= 57) || // Always 1 through 9
(46 == event.which && uiVal && uiVal.indexOf('.') < 0) || isControlKey) && isValid) {
return;
} else {
event.preventDefault();
}
}
function OnlyNumber(event) {
var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
if (!event.which || (48 <= event.which && event.which <= 57) || isControlKey) {
return;
} else {
event.preventDefault();
}
}
Decimals With Two Precision : 'input tag id="Text2" class="decimal" type="text" '
// script
$(".numeric").keypress(function (event) { OnlyNumber(event); });
$(".decimal").keypress(function (event) { OnlyDecimal(this, event, 3); }); // defaulted to 3 decimal points.
var controlKeys = [8, 9, 13, 35, 36, 37, 39];
function OnlyDecimal(obj, event, noOfDecPlaces) {
var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
var uiVal = $(obj).val();
var isValid = new Boolean(true);
if (uiVal.indexOf('.') > 0) {
var arr = uiVal.split(".");
if (arr[1].length >= noOfDecPlaces) isValid = false;
}
if ((!event.which || (48 <= event.which && event.which <= 57) || // Always 1 through 9
(46 == event.which && uiVal && uiVal.indexOf('.') < 0) || isControlKey) && isValid) {
return;
} else {
event.preventDefault();
}
}
function OnlyNumber(event) {
var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
if (!event.which || (48 <= event.which && event.which <= 57) || isControlKey) {
return;
} else {
event.preventDefault();
}
}
Jan 21, 2011
Adding dynamic Web References
[SecurityPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
internal object CallWebService(string webServiceAsmxUrl, string serviceName, string methodName, object[] args)
{
System.Net.WebClient client = new System.Net.WebClient();
// Connect To the web service
System.IO.Stream stream = client.OpenRead(webServiceAsmxUrl + "?wsdl");
// Now read the WSDL file describing a service.
ServiceDescription description = ServiceDescription.Read(stream);
///// LOAD THE DOM /////////
// Initialize a service description importer.
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.ProtocolName = "Soap12"; // Use SOAP 1.2.
importer.AddServiceDescription(description, null, null);
// Generate a proxy client.
importer.Style = ServiceDescriptionImportStyle.Client;
// Generate properties to represent primitive values.
importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties;
// Initialize a Code-DOM tree into which we will import the service.
CodeNamespace nmspace = new CodeNamespace();
CodeCompileUnit unit1 = new CodeCompileUnit();
unit1.Namespaces.Add(nmspace);
// Import the service into the Code-DOM tree. This creates proxy code that uses the service.
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit1);
if (warning == 0) // If zero then we are good to go
{
// Generate the proxy code
CodeDomProvider provider1 = CodeDomProvider.CreateProvider("CSharp");
// Compile the assembly proxy with the appropriate references
string[] assemblyReferences = new string[5] { "System.dll", "System.Web.Services.dll", "System.Web.dll", "System.Xml.dll", "System.Data.dll" };
CompilerParameters parms = new CompilerParameters(assemblyReferences);
CompilerResults results = provider1.CompileAssemblyFromDom(parms, unit1);
// Check For Errors
if (results.Errors.Count > 0)
{
foreach (CompilerError oops in results.Errors)
{
System.Diagnostics.Debug.WriteLine("========Compiler error============");
System.Diagnostics.Debug.WriteLine(oops.ErrorText);
}
throw new System.Exception("Compile Error Occured calling webservice. Check Debug ouput window.");
}
// Finally, Invoke the web service method
object wsvcClass = results.CompiledAssembly.CreateInstance(serviceName);
MethodInfo mi = wsvcClass.GetType().GetMethod(methodName);
return mi.Invoke(wsvcClass, args);
}
else
{
return null;
}
}
internal object CallWebService(string webServiceAsmxUrl, string serviceName, string methodName, object[] args)
{
System.Net.WebClient client = new System.Net.WebClient();
// Connect To the web service
System.IO.Stream stream = client.OpenRead(webServiceAsmxUrl + "?wsdl");
// Now read the WSDL file describing a service.
ServiceDescription description = ServiceDescription.Read(stream);
///// LOAD THE DOM /////////
// Initialize a service description importer.
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.ProtocolName = "Soap12"; // Use SOAP 1.2.
importer.AddServiceDescription(description, null, null);
// Generate a proxy client.
importer.Style = ServiceDescriptionImportStyle.Client;
// Generate properties to represent primitive values.
importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties;
// Initialize a Code-DOM tree into which we will import the service.
CodeNamespace nmspace = new CodeNamespace();
CodeCompileUnit unit1 = new CodeCompileUnit();
unit1.Namespaces.Add(nmspace);
// Import the service into the Code-DOM tree. This creates proxy code that uses the service.
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit1);
if (warning == 0) // If zero then we are good to go
{
// Generate the proxy code
CodeDomProvider provider1 = CodeDomProvider.CreateProvider("CSharp");
// Compile the assembly proxy with the appropriate references
string[] assemblyReferences = new string[5] { "System.dll", "System.Web.Services.dll", "System.Web.dll", "System.Xml.dll", "System.Data.dll" };
CompilerParameters parms = new CompilerParameters(assemblyReferences);
CompilerResults results = provider1.CompileAssemblyFromDom(parms, unit1);
// Check For Errors
if (results.Errors.Count > 0)
{
foreach (CompilerError oops in results.Errors)
{
System.Diagnostics.Debug.WriteLine("========Compiler error============");
System.Diagnostics.Debug.WriteLine(oops.ErrorText);
}
throw new System.Exception("Compile Error Occured calling webservice. Check Debug ouput window.");
}
// Finally, Invoke the web service method
object wsvcClass = results.CompiledAssembly.CreateInstance(serviceName);
MethodInfo mi = wsvcClass.GetType().GetMethod(methodName);
return mi.Invoke(wsvcClass, args);
}
else
{
return null;
}
}
Oct 22, 2010
விகடன் தாமரை பேட்டி
'காலை எழுந்ததும் என் கண்கள் முதலில் தேடிப் பிடிப்பது உந்தன் முகமே' என்று
பாடல் வரிகளில் பனியின் இதம், 'கண்ணகி மண்ணில் இருந்து ஒரு கருஞ் சாபம்' என்று இந்திய அரசைச் சாடும் கவிதையில் வெடிகுண்டு வீரியம்... நெருப்பும் மழையும் நிரம்பியவை தாமரையின் எழுத்துக்கள். கவிஞர், பாடலாசிரியர், பெண்ணியவாதி, மரண தண்டனையை ஒழிக்கக் கோரும் மனித உரிமைப் போராளி என இந்தத் தாமரைக்கு இதழ்கள் பல!
"எனக்கு இலக்கியம் எப்படி முக்கியமோ... அரசியல் அதைவிட முக்கியம்!" என்கிறார்.
"சினிமா என்பதே ஆணாதிக்கம் நிறைந்த சூழல்தான். பெண்ணியம் பேசும் உங்களால், சுதந்திரமாக இயங்க முடிகிறதா? பெண்ணாக நீங்கள் ஏதேனும் அவதிகளைச் சந்தித்தது உண்டா?"
"திரைப்படத் துறை மட்டும்தான் ஆணாதிக்கம் நிறைந்ததா? அரசாங்கம், நிர்வாகம், பத்திரிகை, பொறியியல், மருத்துவம், விவசாயம் உள்ளிட்ட துறைகள் எல்லாம் 'சரிநிகர் சமானமாக' இயங்குகின்றனவா? வீட்டுச் சமையல் அறையில் ஆரம்பித்து, வான்வெளிப் பயணம் வரை ஆணாதிக்கம் இல்லாத இடமே கிடையாது என்பதைப் புரிந்துகொண்டால், இந்த சிக்கலைச் சமாளிக்கலாம். 'ஆண்கள் எல்லோரும் எதிரிகள், அவர்களை விலக்கிவிட்டு இயங்க வேண்டும்' என்ற வறட்டுப் பெண்ணியம் அல்ல என்னு டையது. 'பெண்ணும் ஒரு மனித உயிரே' என் பதைப் புரியவைத்து, ஆண்களை வென்றெ டுப்பதில் (Winning over) அடங்கி இருக்கிறது வெற்றியின் சூட்சுமம்! எனக்கென்று வரையறைகள், நிலைப்பாடுகள் உண்டு. அவற்றில் சமரசம் செய்துகொள்வது கிடையாது. எந்தத் துறையைக் காட்டிலும் திரைத் துறையில் எனக்கு அதிக மதிப்பும் மரியாதையும் கிடைக்கிறது. என்னுடைய புரிதலும் அணுகுமுறையும் முதன்மையான காரணங்கள் எனச் சொல்லலாம்!"
"நளினியை விடுதலை செய்வது குறித்து நீங்கள் எடுத்த முயற்சிகள், உங்களுக்கு என்ன மாதிரியான அனுபவங்களைத் தந்தது?"
"நளினி, ராஜீவ் கொலை வழக்கில் குற்றம் சாட்டப்பட்ட ஒருவரே தவிர, அவர் கொலையாளி அல்ல. நடக்கப்போகும் விபரீ தத்தைத் திருப்பெரும்புதூர் சென்றடையும் வரை நளினி அறிந்திருக்கவில்லை என்பதை உச்ச நீதிமன்ற நீதிபதி தாமஸ் தன் தீர்ப்பிலேயே குறிப்பிட்டார். சந்தர்ப்ப சூழ்நிலையில் குற்றவாளியாக்கப் பட்ட ஒரு பெண்ணை, அவர் இத்தனை ஆண்டுகள் சீரிய முறையில் சிறையில் கழித்த பிறகும் விடுதலை செய்ய மறுப்பது, மனித உரிமைகளுக்கு எதிரானது என்ற அடிப்படையில்தான் நளினி விடுதலைக்கான 'கையெழுத்து இயக்கம்' தொடங்கினோம். முதல்வரிடம் விண்ணப்பத்தைக் கையளித்தபோது, அவரும் நளினி விடுதலையையே விரும்புவதாகக் கூறினார். பிறகு, நடந்தவற்றை நாடறியும். நளினி விடுதலையை மறுப்பதற்குப் பின்னணியில், மிகப் பெரிய அரசியல் இருப்பது புரிகிறது. இப்போதும் அரசிடம் நாங்கள் வேண்டுவது, மனித உரிமைகளின் பெயரால் நளினியை விடுதலை செய்யுங்கள் என்பதே!"
"பொதுவாக, எல்லா சினிமாப் பாடலாசிரியர்களும் பாராட்டுக் கவிஞர்களாக மாறிவிட, நீங்கள் மட்டும் அரசுக்கு எதிராகத் தொடர்ந்து இயங்குவது எப்படி?"
"அரசுக்கு எதிராக இயங்க வேண்டும் என்று எனக்கு 'வேண்டுதல்' ஒன்றும் இல்லை. நான் மக்களில் ஒருத்தி. மக்களுக்கு எதிராக அரசு மாறும்போது, அரசுக்கு எதிராக நான் மாறுகிறேன். இந்த அரசு மட்டுமல்ல; வேறு எந்த அரசு வந்தாலும் இதே நிலைப்பாடுதான். அரசு, தமிழினத்துக்கும் தமிழ்நாட்டின் உரிமைகளுக்கும் கேடு செய்யும்போது, எதிர்த்துக் குரல் கொடுக்கிறேன். அது ஒரு படைப்பாளியாக என்னுடைய கடமை. அதுவே தமிழினத்துக்கு நல்லது செய்தால் பாராட்டத் தயங்க மாட்டேன்.
தமிழ்நாட்டில் மரண தண்டனையை ஒழிக்கட்டும். பாராட்டுகிறேன்; அனைவருக்கும் தமிழில் கல்வி கிடைக்கச் செய்யட்டும். பாராட்டுகிறேன். நளினி உள்ளிட்டோரை விடுதலை செய்யட்டும். பாராட்டுகிறேன். மதுவை ஒழிக்கட்டும். பாராட்டுகிறேன். ராஜபக்ஷே கும்பலைப் போர்க் குற்றவாளிகள் என்று சட்டப் பேரவையில் தீர்மானம் இயற்றட்டும்... பாராட்டுப் பத்திரமே வாசித்து விடுகிறேன்!"
"ஈழப் பிரச்னைக்காகப் போராடியவர்களில் ஒருவர் நீங்கள். மே 18-க்குப் பிறகு, 'இந்த எல்லாப் போராட்டங்களும் வீண்' என்ற அயர்ச்சி ஏற்பட்டதா?"
"போரோடு முடிந்துவிடவில்லையே ஈழத்துக் கொடுமைகள். முள்வேலி முகாம் கொடுமைகள், சரண் அடைந்தவர்கள் சித்ரவதை, பாலியல் வதை, கொடூரக் கொலைகள், தமிழர் நிலம் சிங்களமயமாக்கல் என்று இன்னமும் தொடர்கின்றனவே. புண் பட்டுக்கிடந்தால் வேலைக்கு ஆகாது என்று துள்ளி எழுந்து, இலங்கைப் புறக்கணிப்பு, போர்க் குற்றவாளிகளைக் கூண்டில் ஏற்றுவது தொடர்பாக முன்னிலும் அதிகமாகவே வேலை செய்கிறேன். ஈழம்... என் நெஞ்சில் ஆறாத, மாறாத காயம்!"
"இன்றைய இந்திய காங்கிரஸ் அரசின் போக்கு குறித்து?"
"இந்திய காங்கிரஸ் அரசு யாருக்காக எப்படி எல்லாம் செயல்படுகிறது, எப்படிப் பெருங் குழுமங்களுக்கு ஏவல் செய்கிறது என்பதை அருந்ததி ராய் போன்ற எழுத்தாளர்கள் பிட்டுப் பிட்டுவைத்துள்ளார்கள். நான் புதி தாகச் சொல்ல வேண்டியது ஏதும் இல்லை. என்னைப் பொறுத்தவரை, இது தமிழினத் தைக் கருவறுக்கப் புறப்பட்ட அரசு. தமிழி னம் வாழ வேண்டும் எனில், தமிழ்நாட்டில் இருந்து காங்கிரஸை அடியோடு ஒழித்தாக வேண்டும். தமிழ்நாட்டில் காங்கிரஸுக்கு ஒரு செல்வாக்கு இருக்கும் வரையில்தான், இரு பெரும் கழகங்களும் மாறி மாறி அதைத் தோளில் சுமக்கவும், அதற்காகத் தமிழனைக் காட்டிக்கொடுக்கவும் போட்டியிடும். தமிழர் நலன், தமிழ்நாட்டின் உரிமைகள் இவற்றை முன்னிறுத்தினால் மட்டுமே, தமிழ்நாட்டில் அரசியல் செய்ய முடியும் என்ற நிலையைத் தோற்றுவிப்பது நம் கையில் உள்ளது. அதற்கு முதல் வேலை, காங்கிரஸை வேரோடும் வேரடி மண்ணோடும் பெயர்த்தெறிவதுதான். நல்ல வாய்ப்பாக சட்டப் பேரவைத் தேர்தல் வருகிறது. இந்தத் தேர்தலில் காங்கிரஸ் ஒரு தொகுதியில்கூட வெல்லக் கூடாது என்பதை மனதில்கொள்வோம்!"
"ஈழப் பிரச்னையில் கருணாநிதி - ஜெயலலிதா இருவரின் நிலைப்பாடு குறித்த உங்கள் கருத்து என்ன?"
"ஈழத் தமிழர்களைக் கொன்று குவித்து, பிணக் குவியல்களின் மீது ஏறி வெறியாட்டம் போட்ட காங்கிரஸின் குருதிக் கறை படிந்த கையை இறுகப் பற்றி, அதை இழந்துவிடக் கூடாதெனத் துடிப்பவர் கருணாநிதி. அந்தக் கையை எப்படியாவது கைப்பற்றத் துடிப்பவர் ஜெயலலிதா. 'ஆமாண்டா, அப்படித்தான் செய்வேன், உன்னால முடிஞ்சதைப் பாரு' என்று தெனாவெட்டாகக் காட்டிக்கொடுப் பார் ஒருவர். 'ஐயகோ, என் செய்வேன், அழிகிறதே என் தமிழினமே!' என்று அழுது கொண்டே காட்டிக்கொடுப்பவர் இன்னொ ருவர். இருவருக்கும் இடையே என்ன பெரிய வேறுபாடு? சாயலில் வேறுபட்டாலும், சாரத்தில் இருவரும் ஒன்றுதான்!"
"'ஈழப் போராட்டத்தின் தோல்வி (அ) பின்னடை வுக்கு எது அல்லது, யார் காரணம் என்று கருதுகிறீர்கள்?"
"சிங்களனுக்கு ஆயுதம் கொடுத்து, ஆதரவு கொடுத்து, உலக நாடுகள் தலையிட்டுக் காப்பாற்றி விடாமல் தடுத்து, வேவு பார்த்து, வழிகாட்டிக் கூட்டுச் சதி செய்து, இனப் படுகொலைப் போரைப் பின்னால் இருந்து நடத்திய இந்திய அரசே முதற்பெரும் காரணம்! எப்பாடுபட்டேனும் இதைத் தடுத்து நிறுத்த வேண்டிய பொறுப்பைக் கை கழுவிவிட்டு, கபட நாடகங்கள் நடத்தி, இனப் படுகொலைக்குத் துணைபோன தமிழக அரசு, இரண்டாவது காரணம்! இதை வெளிச்சம் போட்டுக் காட்டி, வீதிக்கு வந்து போராடி இனப் படுகொலையைத் தடுக்காமல், 'போர் என்றால் மக்கள் சாகத்தான் செய்வார்கள்' என்று அருட்பெரும் பொன் மொழியை உதிர்த்துவிட்டு, உறங்கப் போய் விட்ட எதிர்க் கட்சித் தலைவி ஜெயலலிதா, மூன்றாவது காரணம்! இந்த நாடகங்களை எல்லாம் ஒரு கட்டத்தில் அறிந்துகொண்ட பிறகு, கொதித்தெழுந்து போராடித் தம் தொப்புள் கொடி உறவுகளைக் காப்பாற்றா மல், கையைப் பிசைந்து முகத்தைத் திருப்பிக்கொண்டதோடு முடித்துக்கொண்ட தமிழக மக்கள், நான்காவது காரணம்!"
விகடன் தாமரை பேட்டிக்குஎனது பின்னூட்டம்
எனது உள்ளக்குமுறல்களை அப்படியே பிரதிபலிக்கிறது இந்த பேட்டி. தாமரை அவர்களுக்கு என் மனமார்ந்த நன்றி.
அன்பர் செந்தில் குமார் (மிக கேவலமான பின்னூட்டம் கொடுத்த உயர்ந்த உள்ளம் ) போன்ற தமிழ்வாதிகள் இருக்கும் வரை, இந்த உலகம் இந்த தமிழ் சமூகத்தை ஏளனமாக பார்ப்பதில் ஆச்சரியமில்லை. முத்துக்குமார் பிறந்த அதே மண்ணிலா நீங்கள் பிறந்தீர்கள் ?
அரசாங்கம் என்பது மக்களுக்காக, மக்கள் உருவாக்குவது, இவ்வளவு தமிழ் மக்களின் உணர்வை மீறி தனது சபதத்தை நிறைவேற்றிக்கொண்ட நமது மத்திய அரசியல்வாதிகளும் , அதற்க்கு சுத்தி தப்பாமல் ஜால்ரா போட்டு, கூடவே இருந்து காட்டி கொடுத்த நமது தமிழக அரசியல்வாதிகளும். பழுத்த ஞானி போல் பின்னூட்டம் எழுதும் செந்தில் குமார் போன்ற அன்பர்களும், இருக்கும் வரை இந்த உலகம் நம்மை ஏளனமாக பார்ப்பதில் ஆச்சரியமில்லை.
ஒரு ஜெர்மானிய பழமொழி ஞாபகம் வருகிறது.
"திங்களன்று பக்கத்துக்கு வீட்டுக்காரனை கைது செய்தனர்,
நான் ஏனென்று கேட்கவில்லை,
செவ்வாயன்று எதிர்புற வீட்டுக்காரனை கைது செய்தனர்,
நான் ஏனென்று கேட்கவில்லை,
புதனன்று என்னை கைது செய்தனர்,
ஏனென்று கேட்க யாருமில்லை "
உங்களுக்கு இனப்பற்று வேண்டாம், அது ஊட்டி வருவது அல்ல. ஒரு மனிதாபிமானம் கூடவா கிடையாது ?
ஒரு காக்கை இறந்தால் கூட நூறு காக்கைகள் அலறுமடா.
ஒரு இனம் கண் முன்னே அளிக்கபடுகிறது, கேட்க கூடாதம், கேட்டால் இறையாண்மைக்கு எதிராம், அதை நக்கல் செய்ய வேறு ஒரு கூட்டம்.
நீங்களும் வேண்டாம் உங்கள் கட்சிகளும் வேண்டாம்.
கேவலத்தின் உட்சம் இன்றைய அரசியல்வாதிகளுக்கு ஒட்டு போடுவது,
அதனின் கேவலம் அதற்க்கு பணம் வாங்குவது.
தயவு செய்து அனைவரும் "49 - O " பிரிவால் வாக்களித்து நமது எதிர்ப்பை அகிம்சை முறையில் வெளிப்படுத்துமாறு கேட்டுக்கொள்கிறேன்.
-சரவணன்
http://www.vikatan.com/av/2010/oct/27102010/av0105.asp
அன்பர் செந்தில் குமார் (மிக கேவலமான பின்னூட்டம் கொடுத்த உயர்ந்த உள்ளம் ) போன்ற தமிழ்வாதிகள் இருக்கும் வரை, இந்த உலகம் இந்த தமிழ் சமூகத்தை ஏளனமாக பார்ப்பதில் ஆச்சரியமில்லை. முத்துக்குமார் பிறந்த அதே மண்ணிலா நீங்கள் பிறந்தீர்கள் ?
அரசாங்கம் என்பது மக்களுக்காக, மக்கள் உருவாக்குவது, இவ்வளவு தமிழ் மக்களின் உணர்வை மீறி தனது சபதத்தை நிறைவேற்றிக்கொண்ட நமது மத்திய அரசியல்வாதிகளும் , அதற்க்கு சுத்தி தப்பாமல் ஜால்ரா போட்டு, கூடவே இருந்து காட்டி கொடுத்த நமது தமிழக அரசியல்வாதிகளும். பழுத்த ஞானி போல் பின்னூட்டம் எழுதும் செந்தில் குமார் போன்ற அன்பர்களும், இருக்கும் வரை இந்த உலகம் நம்மை ஏளனமாக பார்ப்பதில் ஆச்சரியமில்லை.
ஒரு ஜெர்மானிய பழமொழி ஞாபகம் வருகிறது.
"திங்களன்று பக்கத்துக்கு வீட்டுக்காரனை கைது செய்தனர்,
நான் ஏனென்று கேட்கவில்லை,
செவ்வாயன்று எதிர்புற வீட்டுக்காரனை கைது செய்தனர்,
நான் ஏனென்று கேட்கவில்லை,
புதனன்று என்னை கைது செய்தனர்,
ஏனென்று கேட்க யாருமில்லை "
உங்களுக்கு இனப்பற்று வேண்டாம், அது ஊட்டி வருவது அல்ல. ஒரு மனிதாபிமானம் கூடவா கிடையாது ?
ஒரு காக்கை இறந்தால் கூட நூறு காக்கைகள் அலறுமடா.
ஒரு இனம் கண் முன்னே அளிக்கபடுகிறது, கேட்க கூடாதம், கேட்டால் இறையாண்மைக்கு எதிராம், அதை நக்கல் செய்ய வேறு ஒரு கூட்டம்.
நீங்களும் வேண்டாம் உங்கள் கட்சிகளும் வேண்டாம்.
கேவலத்தின் உட்சம் இன்றைய அரசியல்வாதிகளுக்கு ஒட்டு போடுவது,
அதனின் கேவலம் அதற்க்கு பணம் வாங்குவது.
தயவு செய்து அனைவரும் "49 - O " பிரிவால் வாக்களித்து நமது எதிர்ப்பை அகிம்சை முறையில் வெளிப்படுத்துமாறு கேட்டுக்கொள்கிறேன்.
-சரவணன்
http://www.vikatan.com/av/2010/oct/27102010/av0105.asp
Aug 30, 2010
Image Align or Object Align in Excel using C# .Net
currentWorkSheet.Shapes.Item(imgIndex).IncrementLeft(3.75F);
currentWorkSheet.Shapes.Item(imgIndex).IncrementTop(3.0F);
currentWorkSheet.Shapes.Item(imgIndex).IncrementTop(3.0F);
Aug 27, 2010
Dec 16, 2009
Search Option in ListView Control
private ListView textListView = new ListView();
private TextBox searchBox = new TextBox();
private void InitializeTextSearchListView()
{
searchBox.Location = new Point(10, 60);
textListView.Scrollable = true;
textListView.Width = 80;
textListView.Height = 50;
// Set the View to list to use the FindItemWithText method.
textListView.View = View.List;
// Populate the ListViewWithItems
textListView.Items.AddRange(new ListViewItem[]{
new ListViewItem("Amy Alberts"),
new ListViewItem("Amy Recker"),
new ListViewItem("Erin Hagens"),
new ListViewItem("Barry Johnson"),
new ListViewItem("Jay Hamlin"),
new ListViewItem("Brian Valentine"),
new ListViewItem("Brian Welker"),
new ListViewItem("Daniel Weisman") });
// Handle the TextChanged to get the text for our search.
searchBox.TextChanged += new EventHandler(searchBox_TextChanged);
// Add the controls to the form.
this.Controls.Add(textListView);
this.Controls.Add(searchBox);
}
private void searchBox_TextChanged(object sender, EventArgs e)
{
// Call FindItemWithText with the contents of the textbox.
ListViewItem foundItem =
textListView.FindItemWithText(searchBox.Text, false, 0, true);
if (foundItem != null)
{
textListView.TopItem = foundItem;
}
}
private TextBox searchBox = new TextBox();
private void InitializeTextSearchListView()
{
searchBox.Location = new Point(10, 60);
textListView.Scrollable = true;
textListView.Width = 80;
textListView.Height = 50;
// Set the View to list to use the FindItemWithText method.
textListView.View = View.List;
// Populate the ListViewWithItems
textListView.Items.AddRange(new ListViewItem[]{
new ListViewItem("Amy Alberts"),
new ListViewItem("Amy Recker"),
new ListViewItem("Erin Hagens"),
new ListViewItem("Barry Johnson"),
new ListViewItem("Jay Hamlin"),
new ListViewItem("Brian Valentine"),
new ListViewItem("Brian Welker"),
new ListViewItem("Daniel Weisman") });
// Handle the TextChanged to get the text for our search.
searchBox.TextChanged += new EventHandler(searchBox_TextChanged);
// Add the controls to the form.
this.Controls.Add(textListView);
this.Controls.Add(searchBox);
}
private void searchBox_TextChanged(object sender, EventArgs e)
{
// Call FindItemWithText with the contents of the textbox.
ListViewItem foundItem =
textListView.FindItemWithText(searchBox.Text, false, 0, true);
if (foundItem != null)
{
textListView.TopItem = foundItem;
}
}
Nov 4, 2009
Changing IE Proxy from C#
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace ChangeIEProxy
{
public class Proxies
{
public static bool UnsetProxy()
{
return SetProxy(null, null);
}
public static bool SetProxy(string strProxy)
{
return SetProxy(strProxy, null);
}
public static bool SetProxy(string strProxy, string exceptions)
{
InternetPerConnOptionList list = new InternetPerConnOptionList();
int optionCount = string.IsNullOrEmpty(strProxy) ? 1 : (string.IsNullOrEmpty(exceptions) ? 2 : 3);
InternetConnectionOption[] options = new InternetConnectionOption[optionCount];
// USE a proxy server ...
options[0].m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
options[0].m_Value.m_Int = (int)((optionCount < 2) ? PerConnFlags.PROXY_TYPE_DIRECT : (PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY));
// use THIS proxy server
if (optionCount > 1)
{
options[1].m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_SERVER;
options[1].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(strProxy);
// except for these addresses ...
if (optionCount > 2)
{
options[2].m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_BYPASS;
options[2].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(exceptions);
}
}
// default stuff
list.dwSize = Marshal.SizeOf(list);
list.szConnection = IntPtr.Zero;
list.dwOptionCount = options.Length;
list.dwOptionError = 0;
int optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
// make a pointer out of all that ...
IntPtr optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length);
// copy the array over into that spot in memory ...
for (int i = 0; i < options.Length; ++i)
{
IntPtr opt = new IntPtr(optionsPtr.ToInt32() + (i * optSize));
Marshal.StructureToPtr(options[i], opt, false);
}
list.options = optionsPtr;
// and then make a pointer out of the whole list
IntPtr ipcoListPtr = Marshal.AllocCoTaskMem((Int32)list.dwSize);
Marshal.StructureToPtr(list, ipcoListPtr, false);
// and finally, call the API method!
int returnvalue = NativeMethods.InternetSetOption(IntPtr.Zero,
InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,
ipcoListPtr, list.dwSize) ? -1 : 0;
if (returnvalue == 0)
{ // get the error codes, they might be helpful
returnvalue = Marshal.GetLastWin32Error();
}
// FREE the data ASAP
Marshal.FreeCoTaskMem(optionsPtr);
Marshal.FreeCoTaskMem(ipcoListPtr);
if (returnvalue > 0)
{ // throw the error codes, they might be helpful
throw new Win32Exception(Marshal.GetLastWin32Error());
}
return (returnvalue < 0);
}
}
#region WinInet structures
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetPerConnOptionList
{
public int dwSize; // size of the INTERNET_PER_CONN_OPTION_LIST struct
public IntPtr szConnection; // connection name to set/query options
public int dwOptionCount; // number of options to set/query
public int dwOptionError; // on error, which option failed
//[MarshalAs(UnmanagedType.)]
public IntPtr options;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetConnectionOption
{
static readonly int Size;
public PerConnOption m_Option;
public InternetConnectionOptionValue m_Value;
static InternetConnectionOption()
{
InternetConnectionOption.Size = Marshal.SizeOf(typeof(InternetConnectionOption));
}
// Nested Types
[StructLayout(LayoutKind.Explicit)]
public struct InternetConnectionOptionValue
{
// Fields
[FieldOffset(0)]
public System.Runtime.InteropServices.ComTypes.FILETIME m_FileTime;
[FieldOffset(0)]
public int m_Int;
[FieldOffset(0)]
public IntPtr m_StringPtr;
}
}
#endregion
#region WinInet enums
//
// options manifests for Internet{Query|Set}Option
//
public enum InternetOption : uint
{
INTERNET_OPTION_PER_CONNECTION_OPTION = 75
}
//
// Options used in INTERNET_PER_CONN_OPTON struct
//
public enum PerConnOption
{
INTERNET_PER_CONN_FLAGS = 1, // Sets or retrieves the connection type. The Value member will contain one or more of the values from PerConnFlags
INTERNET_PER_CONN_PROXY_SERVER = 2, // Sets or retrieves a string containing the proxy servers.
INTERNET_PER_CONN_PROXY_BYPASS = 3, // Sets or retrieves a string containing the URLs that do not use the proxy server.
INTERNET_PER_CONN_AUTOCONFIG_URL = 4//, // Sets or retrieves a string containing the URL to the automatic configuration script.
}
//
// PER_CONN_FLAGS
//
[Flags]
public enum PerConnFlags
{
PROXY_TYPE_DIRECT = 0x00000001, // direct to net
PROXY_TYPE_PROXY = 0x00000002, // via named proxy
PROXY_TYPE_AUTO_PROXY_URL = 0x00000004, // autoproxy URL
PROXY_TYPE_AUTO_DETECT = 0x00000008 // use autoproxy detection
}
#endregion
internal static class NativeMethods
{
[DllImport("WinInet.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InternetSetOption(IntPtr hInternet, InternetOption dwOption, IntPtr lpBuffer, int dwBufferLength);
}
}
using System.ComponentModel;
namespace ChangeIEProxy
{
public class Proxies
{
public static bool UnsetProxy()
{
return SetProxy(null, null);
}
public static bool SetProxy(string strProxy)
{
return SetProxy(strProxy, null);
}
public static bool SetProxy(string strProxy, string exceptions)
{
InternetPerConnOptionList list = new InternetPerConnOptionList();
int optionCount = string.IsNullOrEmpty(strProxy) ? 1 : (string.IsNullOrEmpty(exceptions) ? 2 : 3);
InternetConnectionOption[] options = new InternetConnectionOption[optionCount];
// USE a proxy server ...
options[0].m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
options[0].m_Value.m_Int = (int)((optionCount < 2) ? PerConnFlags.PROXY_TYPE_DIRECT : (PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY));
// use THIS proxy server
if (optionCount > 1)
{
options[1].m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_SERVER;
options[1].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(strProxy);
// except for these addresses ...
if (optionCount > 2)
{
options[2].m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_BYPASS;
options[2].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(exceptions);
}
}
// default stuff
list.dwSize = Marshal.SizeOf(list);
list.szConnection = IntPtr.Zero;
list.dwOptionCount = options.Length;
list.dwOptionError = 0;
int optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
// make a pointer out of all that ...
IntPtr optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length);
// copy the array over into that spot in memory ...
for (int i = 0; i < options.Length; ++i)
{
IntPtr opt = new IntPtr(optionsPtr.ToInt32() + (i * optSize));
Marshal.StructureToPtr(options[i], opt, false);
}
list.options = optionsPtr;
// and then make a pointer out of the whole list
IntPtr ipcoListPtr = Marshal.AllocCoTaskMem((Int32)list.dwSize);
Marshal.StructureToPtr(list, ipcoListPtr, false);
// and finally, call the API method!
int returnvalue = NativeMethods.InternetSetOption(IntPtr.Zero,
InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,
ipcoListPtr, list.dwSize) ? -1 : 0;
if (returnvalue == 0)
{ // get the error codes, they might be helpful
returnvalue = Marshal.GetLastWin32Error();
}
// FREE the data ASAP
Marshal.FreeCoTaskMem(optionsPtr);
Marshal.FreeCoTaskMem(ipcoListPtr);
if (returnvalue > 0)
{ // throw the error codes, they might be helpful
throw new Win32Exception(Marshal.GetLastWin32Error());
}
return (returnvalue < 0);
}
}
#region WinInet structures
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetPerConnOptionList
{
public int dwSize; // size of the INTERNET_PER_CONN_OPTION_LIST struct
public IntPtr szConnection; // connection name to set/query options
public int dwOptionCount; // number of options to set/query
public int dwOptionError; // on error, which option failed
//[MarshalAs(UnmanagedType.)]
public IntPtr options;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetConnectionOption
{
static readonly int Size;
public PerConnOption m_Option;
public InternetConnectionOptionValue m_Value;
static InternetConnectionOption()
{
InternetConnectionOption.Size = Marshal.SizeOf(typeof(InternetConnectionOption));
}
// Nested Types
[StructLayout(LayoutKind.Explicit)]
public struct InternetConnectionOptionValue
{
// Fields
[FieldOffset(0)]
public System.Runtime.InteropServices.ComTypes.FILETIME m_FileTime;
[FieldOffset(0)]
public int m_Int;
[FieldOffset(0)]
public IntPtr m_StringPtr;
}
}
#endregion
#region WinInet enums
//
// options manifests for Internet{Query|Set}Option
//
public enum InternetOption : uint
{
INTERNET_OPTION_PER_CONNECTION_OPTION = 75
}
//
// Options used in INTERNET_PER_CONN_OPTON struct
//
public enum PerConnOption
{
INTERNET_PER_CONN_FLAGS = 1, // Sets or retrieves the connection type. The Value member will contain one or more of the values from PerConnFlags
INTERNET_PER_CONN_PROXY_SERVER = 2, // Sets or retrieves a string containing the proxy servers.
INTERNET_PER_CONN_PROXY_BYPASS = 3, // Sets or retrieves a string containing the URLs that do not use the proxy server.
INTERNET_PER_CONN_AUTOCONFIG_URL = 4//, // Sets or retrieves a string containing the URL to the automatic configuration script.
}
//
// PER_CONN_FLAGS
//
[Flags]
public enum PerConnFlags
{
PROXY_TYPE_DIRECT = 0x00000001, // direct to net
PROXY_TYPE_PROXY = 0x00000002, // via named proxy
PROXY_TYPE_AUTO_PROXY_URL = 0x00000004, // autoproxy URL
PROXY_TYPE_AUTO_DETECT = 0x00000008 // use autoproxy detection
}
#endregion
internal static class NativeMethods
{
[DllImport("WinInet.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InternetSetOption(IntPtr hInternet, InternetOption dwOption, IntPtr lpBuffer, int dwBufferLength);
}
}
Feb 23, 2009
Handling the slected item in a Multisimple ListBox
List indexList = new List();
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
Point pt = new Point(e.X, e.Y);
int index = ((ListBox)sender).IndexFromPoint(pt);
listBox1.ClearSelected();
if (indexList.Contains(index))
indexList.Remove(index);
else
indexList.Add(index);
if (0 == index)
{
listBox1.SelectedIndex = index;
indexList.Clear();
}
else
{
foreach (int tempIndx in episodeTypeIndxList)
{
listBox1.SelectedIndices.Add(tempIndx);
}
}
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
Point pt = new Point(e.X, e.Y);
int index = ((ListBox)sender).IndexFromPoint(pt);
listBox1.ClearSelected();
if (indexList.Contains(index))
indexList.Remove(index);
else
indexList.Add(index);
if (0 == index)
{
listBox1.SelectedIndex = index;
indexList.Clear();
}
else
{
foreach (int tempIndx in episodeTypeIndxList)
{
listBox1.SelectedIndices.Add(tempIndx);
}
}
}
Feb 5, 2009
Restrict the Number of Chars in Text Area
Javascript Function:
function ValidateTA(obj)
{
var str = new String(obj.value);
if(str.length >= 10)// Here the Max char is 10
{
window.event.returnValue = 0;
}
}
HTML Control:
textarea id="TextArea1" onkeydown="ValidateTA(this)" cols="20" rows="2"
Note: We can implement the same logic for the requiremens like, "only char should be entered or Only numbers should be entered in a text box"
function ValidateTA(obj)
{
var str = new String(obj.value);
if(str.length >= 10)// Here the Max char is 10
{
window.event.returnValue = 0;
}
}
HTML Control:
textarea id="TextArea1" onkeydown="ValidateTA(this)" cols="20" rows="2"
Note: We can implement the same logic for the requiremens like, "only char should be entered or Only numbers should be entered in a text box"
Dec 3, 2008
My Soap
Nov 19, 2008
ArrayList Sorting
using System;
using System.Collections;
public class Person : IComparable
{
#region Private Members
private string _firstname;
private string _lastname;
private int _age;
#endregion
#region Properties
public string Firstname
{
get { return _firstname; }
set { _firstname = value; }
}
public string Lastname
{
get { return _lastname; }
set { _lastname = value; }
}
public int Age
{
get { return _age; }
set { _age = value; }
}
#endregion
#region Contructors
public Person(string firstname, string lastname, int age)
{
_firstname = firstname;
_lastname = lastname;
_age = age;
}
#endregion
#region ToString()
public override string ToString()
{
return String.Format("{0} {1}, Age = {2}", _firstname,
_lastname, _age.ToString());
}
#endregion
#region IComparable Members
public int CompareTo(object obj)
{
if (obj is Person)
{
Person p2 = (Person)obj;
return _firstname.CompareTo(p2._firstname);
}
else
throw new ArgumentException("Object is not a Person.");
}
#endregion
public int CompareTo(Person p2, PersonComparer.ComparisonType comparisonMethod)
{
switch (comparisonMethod)
{
case PersonComparer.ComparisonType.Lastname:
return _lastname.CompareTo(p2._lastname);
case PersonComparer.ComparisonType.Age:
return _age.CompareTo(p2._age);
case PersonComparer.ComparisonType.Firstname:
default:
return _firstname.CompareTo(p2._firstname);
}
}
#region PersonComparer
public class PersonComparer : IComparer
{
public enum ComparisonType
{ Firstname = 1, Lastname = 2, Age = 3 }
private ComparisonType _comparisonType;
public ComparisonType ComparisonMethod
{
get { return _comparisonType; }
set { _comparisonType = value; }
}
#region IComparer Members
public int Compare(object x, object y)
{
Person p1;
Person p2;
if (x is Person)
p1 = x as Person;
else
throw new ArgumentException("Object is not of type Person.");
if (y is Person)
p2 = y as Person;
else
throw new ArgumentException("Object is not of type Person.");
return p1.CompareTo(p2, _comparisonType);
}
#endregion
}
#endregion
}
public class TestClass
{
public static void Main()
{
// Create ArrayList
ArrayList people = new ArrayList();
people.Add(new Person("John", "Doe", 76));
people.Add(new Person("Abby", "Normal", 25));
people.Add(new Person("Jane", "Doe", 84));
// Create Person Comparer Class
Person.PersonComparer comparer = new Person.PersonComparer();
// Sort By Lastname
comparer.ComparisonMethod = Person.PersonComparer.ComparisonType.Lastname;
people.Sort(comparer);
Console.WriteLine("Last Name");
TestClass.DisplayPeople(people);
// Sort By Age
comparer.ComparisonMethod = Person.PersonComparer.ComparisonType.Age;
people.Sort(comparer);
Console.WriteLine("Age");
TestClass.DisplayPeople(people);
// Sort By Firstname
comparer.ComparisonMethod = Person.PersonComparer.ComparisonType.Firstname;
people.Sort(comparer);
Console.WriteLine("First Name");
TestClass.DisplayPeople(people);
}
public static void DisplayPeople(ArrayList people)
{
foreach (Person p in people)
Console.WriteLine(p);
Console.ReadLine();
}
}
using System.Collections;
public class Person : IComparable
{
#region Private Members
private string _firstname;
private string _lastname;
private int _age;
#endregion
#region Properties
public string Firstname
{
get { return _firstname; }
set { _firstname = value; }
}
public string Lastname
{
get { return _lastname; }
set { _lastname = value; }
}
public int Age
{
get { return _age; }
set { _age = value; }
}
#endregion
#region Contructors
public Person(string firstname, string lastname, int age)
{
_firstname = firstname;
_lastname = lastname;
_age = age;
}
#endregion
#region ToString()
public override string ToString()
{
return String.Format("{0} {1}, Age = {2}", _firstname,
_lastname, _age.ToString());
}
#endregion
#region IComparable Members
public int CompareTo(object obj)
{
if (obj is Person)
{
Person p2 = (Person)obj;
return _firstname.CompareTo(p2._firstname);
}
else
throw new ArgumentException("Object is not a Person.");
}
#endregion
public int CompareTo(Person p2, PersonComparer.ComparisonType comparisonMethod)
{
switch (comparisonMethod)
{
case PersonComparer.ComparisonType.Lastname:
return _lastname.CompareTo(p2._lastname);
case PersonComparer.ComparisonType.Age:
return _age.CompareTo(p2._age);
case PersonComparer.ComparisonType.Firstname:
default:
return _firstname.CompareTo(p2._firstname);
}
}
#region PersonComparer
public class PersonComparer : IComparer
{
public enum ComparisonType
{ Firstname = 1, Lastname = 2, Age = 3 }
private ComparisonType _comparisonType;
public ComparisonType ComparisonMethod
{
get { return _comparisonType; }
set { _comparisonType = value; }
}
#region IComparer Members
public int Compare(object x, object y)
{
Person p1;
Person p2;
if (x is Person)
p1 = x as Person;
else
throw new ArgumentException("Object is not of type Person.");
if (y is Person)
p2 = y as Person;
else
throw new ArgumentException("Object is not of type Person.");
return p1.CompareTo(p2, _comparisonType);
}
#endregion
}
#endregion
}
public class TestClass
{
public static void Main()
{
// Create ArrayList
ArrayList people = new ArrayList();
people.Add(new Person("John", "Doe", 76));
people.Add(new Person("Abby", "Normal", 25));
people.Add(new Person("Jane", "Doe", 84));
// Create Person Comparer Class
Person.PersonComparer comparer = new Person.PersonComparer();
// Sort By Lastname
comparer.ComparisonMethod = Person.PersonComparer.ComparisonType.Lastname;
people.Sort(comparer);
Console.WriteLine("Last Name");
TestClass.DisplayPeople(people);
// Sort By Age
comparer.ComparisonMethod = Person.PersonComparer.ComparisonType.Age;
people.Sort(comparer);
Console.WriteLine("Age");
TestClass.DisplayPeople(people);
// Sort By Firstname
comparer.ComparisonMethod = Person.PersonComparer.ComparisonType.Firstname;
people.Sort(comparer);
Console.WriteLine("First Name");
TestClass.DisplayPeople(people);
}
public static void DisplayPeople(ArrayList people)
{
foreach (Person p in people)
Console.WriteLine(p);
Console.ReadLine();
}
}
Oct 24, 2008
***************CPp start ******************
# include
#include "resource.h"
class CMyMainWindow: public CFrameWnd
{
CMenu cMenu;
public:
CMyMainWindow()
{
Create(0,_T("Window"));
cMenu.LoadMenuA(MAKEINTRESOURCE(IDR_MENU1));
SetMenu(&cMenu);
ShowWindow(SW_RESTORE);
}
DECLARE_MESSAGE_MAP()
/*int OnLButtonDown(UINT nFlags, CPoint point )
{
AfxMessageBox(_T("sarav123"));
}*/
void CreateMenu()
{
//AfxMessageBox("Jus A Tets");
cMenu.AppendMenu(MF_STRING,IDR_MENU2,"New");
cMenu.InsertMenuItemA(0,"lpMenuItemInfo",2001);
DrawMenuBar();
}
void DeleteMenu()
{
cMenu.RemoveMenu(IDR_MENU2,MF_STRING);
DrawMenuBar();
}
};
BEGIN_MESSAGE_MAP(CMyMainWindow,CFrameWnd)
ON_WM_LBUTTONDBLCLK()
//ON_COMMAND(MAKEINTRESOURCE(ID_FILE_OPEN),MyTest)
ON_COMMAND(MAKEINTRESOURCE(ID_FILE_CREATE),CreateMenu)
ON_COMMAND(MAKEINTRESOURCE(ID_FILE_DELETE),DeleteMenu)
END_MESSAGE_MAP()
class CMyApp: public CWinApp
{
public:
BOOL InitInstance()
{
//AfxMessageBox("sarav");
CMyMainWindow *MyMainWnd = new CMyMainWindow();
m_pMainWnd = MyMainWnd;
return TRUE;
}
};
CMyApp obj;
***************CPp End ******************
***************Resource********************
// Microsoft Visual C++ generated include file.
// Used by Menu.rc
//
#define IDR_MENU1 101
#define ID_FILE_OPEN40001 40001
#define ID_FILE_CREATE 40002
#define ID_FILE_DELETE 40003
#define IDR_MENU2 201
#define ID_FILE_OPEN2 20001
#define ID_FILE_SAVE2 20002
#define ID_FILE_DELETE2 20003
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40004
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
# include
#include "resource.h"
class CMyMainWindow: public CFrameWnd
{
CMenu cMenu;
public:
CMyMainWindow()
{
Create(0,_T("Window"));
cMenu.LoadMenuA(MAKEINTRESOURCE(IDR_MENU1));
SetMenu(&cMenu);
ShowWindow(SW_RESTORE);
}
DECLARE_MESSAGE_MAP()
/*int OnLButtonDown(UINT nFlags, CPoint point )
{
AfxMessageBox(_T("sarav123"));
}*/
void CreateMenu()
{
//AfxMessageBox("Jus A Tets");
cMenu.AppendMenu(MF_STRING,IDR_MENU2,"New");
cMenu.InsertMenuItemA(0,"lpMenuItemInfo",2001);
DrawMenuBar();
}
void DeleteMenu()
{
cMenu.RemoveMenu(IDR_MENU2,MF_STRING);
DrawMenuBar();
}
};
BEGIN_MESSAGE_MAP(CMyMainWindow,CFrameWnd)
ON_WM_LBUTTONDBLCLK()
//ON_COMMAND(MAKEINTRESOURCE(ID_FILE_OPEN),MyTest)
ON_COMMAND(MAKEINTRESOURCE(ID_FILE_CREATE),CreateMenu)
ON_COMMAND(MAKEINTRESOURCE(ID_FILE_DELETE),DeleteMenu)
END_MESSAGE_MAP()
class CMyApp: public CWinApp
{
public:
BOOL InitInstance()
{
//AfxMessageBox("sarav");
CMyMainWindow *MyMainWnd = new CMyMainWindow();
m_pMainWnd = MyMainWnd;
return TRUE;
}
};
CMyApp obj;
***************CPp End ******************
***************Resource********************
// Microsoft Visual C++ generated include file.
// Used by Menu.rc
//
#define IDR_MENU1 101
#define ID_FILE_OPEN40001 40001
#define ID_FILE_CREATE 40002
#define ID_FILE_DELETE 40003
#define IDR_MENU2 201
#define ID_FILE_OPEN2 20001
#define ID_FILE_SAVE2 20002
#define ID_FILE_DELETE2 20003
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40004
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Aug 21, 2008
Using Timers in Asp.Net application.
client side functionalities window.setTimeout(functionName,1000);
This shud be placed inside a script tag.
First parameter 'functionName' is the function name or any functionality which should be called after s particular time.
Second parameter '1000' is the delay time in milli seconds. If we give 5000, then the function will be called after 5 seconds.
Server side(C#)
Thread.Sleep(1000); // In the next line u can call a function u need.
// functionName
This shud be placed inside a script tag.
First parameter 'functionName' is the function name or any functionality which should be called after s particular time.
Second parameter '1000' is the delay time in milli seconds. If we give 5000, then the function will be called after 5 seconds.
Server side(C#)
Thread.Sleep(1000); // In the next line u can call a function u need.
// functionName
Subscribe to:
Posts (Atom)