Thursday, May 12, 2011

MVC 3 Datalist like funcion using Razor viewengine


@foreach (var item in ViewBag.MyDataSource)
{

@item.CustomerName Edit or Delete

}


OR

@foreach (var item in ViewBag.MyDataSource)
{

@item.CustomerName Edit or Delete

}


$(function(){
$('.row .edit-button').click(edit());
$('.row .delete-button').click(delete());
})

Monday, September 6, 2010

Add Text to image using c#

Bitmap myBitmap = new Bitmap("D:\\Projects\\WebSite5\\IMAGE_176.jpg");
Graphics g = Graphics.FromImage(myBitmap);
g.DrawString("My Text", new Font("Arial", 40), Brushes.Gold, new PointF(100, 20));

myBitmap.Save("D:\\Projects\\WebSite5\\sas.jpg");111

Sunday, December 13, 2009

How to disable the dates which are less than the current day?

AjaxControlToolkit Calendar is a very DatePicker for us. Sometimes, the customers hope some specific date in Calendar should be disabled or hidden so that we can not select these dates.

For example,
* how to disable the dates which are less than the current date?
* how to disable the dates other than sunday?

Actually, you can modify the original CalendarBehavior.js to achieve it.

1.Please go to CalendarBehavior.js in AjaxControlToolkit original project.
2.Please use the below code instead of section ‘case "days": ' in function _cell_onclick: case "day":

var _currentDay=new Date();
if(target.date.getDate()>=_currentDay.getDate())
{
this.set_selectedDate(target.date);
this._switchMonth(target.date);
this._blur.post(true);
this.raiseDateSelectionChanged();
}
break;

3.If you want to change the dates' style which are less than current day, you can use other css class on the related date cell when the calendar was created in _performLayout method.
The below code can be used to apply the different css calss on the related date cell in _performLayout method.
Sys.UI.DomElement.addCssClass(dayCell.parentNode, this._getCssClass(dayCell.date, 'name'));

4.And then please rebuild the project and add it as reference again.

Thursday, April 16, 2009

Shut down system using C#

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

// Remember to add a reference to the System.Management assembly

using System.Management;



namespace ShutDown

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}



private void btnShutDown_Click(object sender, EventArgs e)

{

ManagementBaseObject mboShutdown = null;

ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");

mcWin32.Get();

// You can't shutdown without security privileges

mcWin32.Scope.Options.EnablePrivileges = true;

ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");

// Flag 1 means we want to shut down the system

mboShutdownParams["Flags"] = "1";

mboShutdownParams["Reserved"] = "0";

foreach (ManagementObject manObj in mcWin32.GetInstances())

{

mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);

}

}

}

}

Generate random password

private string GenerateRandomPassword(int Length)

{

// We want all popular characters except for the ones that can easily be confused (e.g., l and 1)

string[] Characters = new string[56];

Characters[0] = "a";

Characters[1] = "b";

Characters[2] = "c";

Characters[3] = "d";

Characters[4] = "e";

Characters[5] = "f";

Characters[6] = "g";

Characters[7] = "h";

Characters[8] = "j";

Characters[9] = "k";

Characters[10] = "m";

Characters[11] = "n";

Characters[12] = "p";

Characters[13] = "q";

Characters[14] = "r";

Characters[15] = "s";

Characters[16] = "t";

Characters[17] = "u";

Characters[18] = "v";

Characters[19] = "w";

Characters[20] = "x";

Characters[21] = "y";

Characters[22] = "z";

Characters[23] = "A";

Characters[24] = "B";

Characters[25] = "C";

Characters[26] = "D";

Characters[27] = "E";

Characters[28] = "F";

Characters[29] = "G";

Characters[30] = "H";

Characters[31] = "J";

Characters[32] = "K";

Characters[33] = "L";

Characters[34] = "M";

Characters[35] = "N";

Characters[36] = "P";

Characters[37] = "Q";

Characters[38] = "R";

Characters[39] = "S";

Characters[40] = "T";

Characters[41] = "U";

Characters[42] = "V";

Characters[43] = "W";

Characters[44] = "X";

Characters[45] = "Y";

Characters[46] = "Z";

Characters[47] = "2";

Characters[48] = "3";

Characters[49] = "4";

Characters[50] = "5";

Characters[51] = "6";

Characters[52] = "7";

Characters[53] = "8";

Characters[54] = "9";



Random RandChar = new Random();

string Password = "";



for (int i = 0; i < Length; i++)

{

Password += Characters[RandChar.Next(0, 55)];

}



return Password;

}

Back, Forward and Refresh using JavaScript









Delete all temparary file of Internet explorer

using System.IO;


public static void Main()
#
{

ClearFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache))); // Execute ClearFolder() on the IE's cache folder

}



void ClearFolder(DirectoryInfo diPath)

{

foreach (FileInfo fiCurrFile in diPath.GetFiles())

{

fiCurrFile.Delete();

}

foreach (DirectoryInfo diSubFolder in diPath.GetDirectories())

{

ClearFolder(diSubFolder); // Call recursively for all subfolders
}