Software consultant, Developer, Codder : SharePoint, Office 365, ASP.NET, MVC, SharePoint, Javascript, JQuery, Ember JS, Angular JS, Entity Framework, Linq, HTML5, DotnetNuke, codding philosophy, blogger 7+ experience in codding and developing web applications, Code 4 Help..
31 December 2012
Useful Code At End of 2012
protected void Page_Load(object sender, EventArgs e)
{
var ip = "192.168.4.159";
var ip1 = "192.168.3.158";
var ip2 = "192.168.5.156";
var v1 = IsGreaterOrEqual(ip1, string.Empty);
var v3 = IsInRange(ip1, ip2, ip);
var v4 = IsEqual(ip1, ip2);
}
public bool IsValidIP(string IP)
{
IPAddress ot;
bool valid = false;
if (string.IsNullOrEmpty(IP))
{
valid = false;
}
else
{
valid = IPAddress.TryParse(IP, out ot);
}
return valid;
}
public bool IsGreaterOrEqual(string IPFrom, string IPTo)
{
return IPAddressToLongBackwards(IPFrom) <= IPAddressToLongBackwards(IPTo);
}
public bool IsInRange(string IPFrom, string IPTo, string IP)
{
var ipf = IPAddressToLongBackwards(IPFrom);
var ip = IPAddressToLongBackwards(IP);
var ipt = IPAddressToLongBackwards(IPTo);
if (ipf <= ip)
{
if (ip <= ipt)
return true;
else
return false;
}
else
return false;
}
public bool IsEqual(string IPFrom, string IP)
{
return IPAddress.Parse(IPFrom).Equals(IPAddress.Parse(IP));
}
private uint IPAddressToLongBackwards(string IPAddr)
{
System.Net.IPAddress oIP = System.Net.IPAddress.Parse(IPAddr);
byte[] byteIP = oIP.GetAddressBytes();
uint ip = (uint)byteIP[0] << 24;
ip += (uint)byteIP[1] << 16;
ip += (uint)byteIP[2] << 8;
ip += (uint)byteIP[3];
return ip;
}
var mydatetime = DateTime.Now;
var aest = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
var cst = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");
//Response.Write(mydatetime.ToString());
//Response.Write(mydatetime.ToUniversalTime());
var tempdate1 = TimeZoneInfo.ConvertTime(mydatetime, aest);
var tempdate2 = TimeZoneInfo.ConvertTime(mydatetime, cst);
var tempoffset1 = cst.GetUtcOffset((tempdate1));
var tempoffset2 = aest.GetUtcOffset((tempdate2));
var ct = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
var tempoffset3 = ct.GetUtcOffset((mydatetime));
Response.Write(tempoffset1);
Response.Write(tempoffset2);
Response.Write(tempoffset3);
Response.Write(tempoffset1 - tempoffset2);
public class ProjectResource
{
public int Id { get; set; }
public string Name { get; set; }
public int Hour { get; set; }
public int Rate { get; set; }
public double Salary { get; set; }
public int Type { get; set; }
}
var p = new ProjectResource { Hour = 2, Id = 8, Name = "project1", Rate = 5, Salary = 40000, Type = 5 };
var p1 = new ProjectResource();
foreach (var item in p.GetType().GetProperties().Where(x => x.Name != "EntityKey" && x.Name != "EntityState"))
{
p1.GetType().GetProperty(item.Name).SetValue(p1, item.GetValue(p, null), null);
}
No comments:
Post a Comment