Uncategorized

ESC handle by AppleScript

tell application “System Events”
tell application “TextEdit” to activate
tell application “TextEdit” to run
keystroke “s” using {command down}
key code 53
end tell

——————-

tell application “System Events”
tell application “TextEdit” to activate
tell application “TextEdit” to run
keystroke “s” using {command down}
key code 53 –esc
–key code 36 — enter
–key code 32 –space bar

end tell

–tell process “Microsoft Messenger”
–keystroke “omg testing lol”
–key down shift
–delay 0.2 — adjust delay as needed
–key code 36
–key up shift
–keystroke “testing line 2” & return

AppleScript in Cocoa Class

//message= TextEdit:f
NSString *string = message;
// split the text by the : to get an array containing { “AAA”, “BBB” }
NSArray *splitText = [string componentsSeparatedByString:@”:”];

// form a new string of the form “BBB AAA” by using the individual entries in the array
NSString *cellText = [NSString stringWithFormat:@”%@ %@”, [splitText objectAtIndex:1], [splitText objectAtIndex:0]];

NSString *cmdKey = [NSString stringWithFormat:@”%@”, [splitText objectAtIndex:1]];
NSString *app = [NSString stringWithFormat:@”%@”, [splitText objectAtIndex:0]];
//NSLog(cellText);
//NSLog(cmdKey);
//NSLog(app);

textView.string = message ;

//run and activate application
NSString *script = [ NSString stringWithFormat:@”tell application \”%@\” to run”,app];
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:script ];
[run executeAndReturnError:nil];

NSString *script1 = [ NSString stringWithFormat:@”tell application \”%@\” to activate”,app];

NSAppleScript *run1 = [[NSAppleScript alloc] initWithSource:script1 ];
[run1 executeAndReturnError:nil];
NSString *cmd = [NSString stringWithFormat:@”tell application \”System Events\” to keystroke \”%@\” using command down”, cmdKey];
NSAppleScript *playScript;
playScript = [[NSAppleScript alloc] initWithSource:cmd];

if([playScript isCompiled] == NO){
[playScript compileAndReturnError:nil];
}

id exerror = [playScript executeAndReturnError:nil];

if(exerror == nil){
NSLog(@”Script Failed”);
}

NSLog(@”keystorke should be execute”);

Implement Logger in asp.net

First of create LoggingConstant.cs File in that Declare all Pages name as variable without extension.
For ex.
public enum ModuleToLog
{
default,
login
}
public enum LogType
{
DEBUG,
EXCEPTION,
INFO
}

After that create Logger.cs File..

public class Logger
{
public static void Write(LogType eLogType, ModuleToLog eModule, string strMethodName, string LogMessage, string strUserId)
{

string LogFilePath = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath + “/Logs”);

//Create directory for Year/Month/
LogFilePath = string.Format(“{0}/{1}/{2}”, LogFilePath, DateTime.Now.Year.ToString(), DateTime.Now.ToString(“MMM”));
DirectoryInfo ObjDirectoryInfo = new DirectoryInfo(LogFilePath);
//string strLogFile = string.Format(“{0}/{1}.log”, LogFilePath, DateTime.Now.ToString(“dd-MMM-yyyy”));

string strLogFile = string.Format(“{0}/{1}.log”, LogFilePath, strUserId + “_” + DateTime.Now.ToString(“ddMMMyyyy”));
try
{
if (ObjDirectoryInfo.Exists == false)
{
ObjDirectoryInfo.Create();
}

StreamWriter sw = new StreamWriter(strLogFile, true);

sw.WriteLine(string.Format(“[{0}][{1}][{2}][{3}][{4}] {5}”, DateTime.Now.ToString(), eLogType.ToString(), eModule.ToString(), strMethodName, strUserId, LogMessage));
sw.Close();
sw.Dispose();
}
catch (Exception ex)
{

}
}
}

——–call this function —
try
{
Logger.Write(LogType.INFO, ModuleToLog.Default, “btnSave_Click”, “Write Comments”, loggedinUserName);

}
catch (Exception ex)
{
Logger.Write(LogType.EXCEPTION, ModuleToLog.WriteBoardBookComments, “btnSave_Click”, ex.StackTrace.ToString() , userdetail.Name);
}

Windows Users List in Asp.Net c#

using System.Management;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SelectQuery query = new SelectQuery(“Win32_UserAccount”);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject envVar in searcher.Get())
{
Console.WriteLine(“Username : {0}”, envVar[“Name”]);
}

Console.ReadLine();

}
}
}

create xml file dynamically

try
{
if (System.Web.HttpContext.Current.Session[“UserId”] != null && System.Web.HttpContext.Current.Session[“EventId”] != null && System.Web.HttpContext.Current.Session[“EventConfiguration”] != null)
{

Logger.Write(LogType.INFO, ModuleToLog.EventInformation, “WriteEventHistory”, “EventHistory”, HttpContext.Current.Session[“UserName”].ToString());
string pageName = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.ServerVariables[“SCRIPT_NAME”]);
UserService.UserClient proxyFind = new ePlannerPro2Client.UserService.UserClient();

epp2ClientPL.UsersProperties result = proxyFind.LoadById(new Guid(Convert.ToString(System.Web.HttpContext.Current.Session[“UserId”])), new Guid(Convert.ToString(System.Web.HttpContext.Current.Session[“EventId”])));

if (result == null)
{
return;
}
//epp2ClientPL.UsersProperties result = proxyFind.LoadUsersByEventId(new Guid(Convert.ToString(Convert.ToString(System.Web.HttpContext.Current.Session[“EventId”])))).Where(u => u.UserId.Equals(new Guid(Convert.ToString(System.Web.HttpContext.Current.Session[“UserId”])))).SingleOrDefault();

epp2ClientPL.EventConfigurationProperties files = (epp2ClientPL.EventConfigurationProperties)System.Web.HttpContext.Current.Session[“EventConfiguration”];

string FilePath = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath + “/XML”);
DirectoryInfo ObjDirectoryInfo = new DirectoryInfo(FilePath);

string strFileName = FilePath + “/” + files.EventTitle.ToString() + “_History.xml”;

XmlDocument XmlFile = new XmlDocument();

if (ObjDirectoryInfo.Exists == false)
{
ObjDirectoryInfo.Create();
}

FileInfo fi = new FileInfo(strFileName);

if (fi.Exists)
{
XmlFile.Load(strFileName);
}
else
{
XmlNode Declaration = XmlFile.CreateNode(XmlNodeType.XmlDeclaration, “”, “”);
XmlFile.AppendChild(Declaration);
XmlElement OperationElement;
OperationElement = XmlFile.CreateElement(“Operations”);
XmlFile.AppendChild(OperationElement);
XmlFile.Save(strFileName);
}

XmlNode Operations = XmlFile.SelectSingleNode(“Operations”);

XmlNode Operation1;
Operation1 = XmlFile.CreateNode(XmlNodeType.Element, “Operation”, “”);
Operations.AppendChild(Operation1);

XmlNode EventAttendeeId;
EventAttendeeId = XmlFile.CreateNode(XmlNodeType.Element, “EventAttendeeId”, “”);
EventAttendeeId.InnerText = Convert.ToString(result.EventAttendeeId);
Operation1.AppendChild(EventAttendeeId);

XmlNode FullName;
FullName = XmlFile.CreateNode(XmlNodeType.Element, “FullName”, “”);
FullName.InnerText = result.FullName;
Operation1.AppendChild(FullName);

MenusService.MenusClient proxyPage = new ePlannerPro2Client.MenusService.MenusClient();

#region “Get Page Id”
ePlannerPro2Client.MenusService.MenusClient proxyMenus = new ePlannerPro2Client.MenusService.MenusClient();
epp2ClientPL.MenusProperties[] data = proxyMenus.LoadPageMasterNameId(pageName).ToArray();
if (data == null)
return;
if (data.Count() == 0)
return;
#endregion

XmlNode PageId;
PageId = XmlFile.CreateNode(XmlNodeType.Element, “PageId”, “”);
PageId.InnerText = data[0].Id.ToString();
Operation1.AppendChild(PageId);

XmlNode OT;
OT = XmlFile.CreateNode(XmlNodeType.Element, “OperationType”, “”);
OT.InnerText = OperationType;
Operation1.AppendChild(OT);

XmlNode OperationMessage;
OperationMessage = XmlFile.CreateNode(XmlNodeType.Element, “OperationMessage”, “”);

// string strOperation = result.FullName + ” ” + Operation;

string strOperation = Operation;
OperationMessage.InnerText = strOperation;
Operation1.AppendChild(OperationMessage);

#region “Get Time Zone Name”
ePlannerPro2Client.TimeZoneService.TimeZone timeZone = LoadTimeZonesById(new Guid(files.TimeZoneId.ToString()));
#endregion

XmlNode OperationDate;
OperationDate = XmlFile.CreateNode(XmlNodeType.Element, “OperationDate”, “”);
// OperationDate.InnerText = DateTime.Now.ToString(“MMM dd yyyy, hh:mm:ss tt”);
OperationDate.InnerText = DateTime.Now.ToString(“MM/dd/yyyy, hh:mm:ss tt”);
Operation1.AppendChild(OperationDate);

XmlFile.Save(strFileName);
}
}
catch (Exception ex)
{
Logger.Write(LogType.EXCEPTION, ModuleToLog.EventInformation, “WriteEventHistory”, ex.StackTrace, HttpContext.Current.Session[“UserName”].ToString());
}

Fine Duplicate rows & Delete duplicate rows

Fine duplicate row
SELECT ColumnName,
COUNT(ColumnName) AS ColumnName
FROM tbl_Employee_M
GROUP BY ColumnName
HAVING ( COUNT(ColumnName) > 1 )


Delete duplicate rows

WITH DUPLICATE(ROW,GROUPROW,ID,FNAME,LNAME)
AS
(
SELECT ROW,GROUPROW= CASE WHEN ID=ID
THEN
(SELECT COUNT(*) FROM (SELECT ROW_NUMBER() OVER (ORDER BY ID) AS ROW,
ID,LNAME,FNAME FROM MYTABLE
) AS A WHERE A.ID=B.ID AND
A.ROW<B.ROW)+1 END,ID,FNAME,LNAME FROM (SELECT ROW_NUMBER() OVER (ORDER
BY ID) AS ROW,
ID,LNAME,FNAME FROM MYTABLE
)AS B
)
DELETE FROM DUPLICATE WHERE GROUPROW1

Pivot in SQL Server

Declare @table1 table (
SalesPerson varchar(50), Product varchar(50), SalesAmount float )

insert into @table1(SalesPerson,Product, SalesAmount) values (‘Bob’, ‘Pickles’, 100)
insert into @table1(SalesPerson,Product, SalesAmount) values (‘Sue’, ‘Oranges’, 50)
insert into @table1(SalesPerson,Product, SalesAmount) values (‘Bob’, ‘Pickles’, 25)
insert into @table1(SalesPerson,Product, SalesAmount) values (‘Bob’, ‘Oranges’, 300)
insert into @table1(SalesPerson,Product, SalesAmount) values (‘Sue’, ‘Oranges’, 500)

select * from @table1

SELECT SalesPerson, [Oranges] AS Oranges, [Pickles] AS Pickles
FROM
(SELECT SalesPerson, Product, SalesAmount
FROM @table1 ) ps
PIVOT
(
SUM (SalesAmount)
FOR Product IN
( [Oranges], [Pickles])
) AS pvt

Crystal report XML file as DataSource

Namespace:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;

Global variable:
CrystalDecisions.Web.Report rpt = new CrystalDecisions.Web.Report();
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt1;

Onbutton or Page Load or any event
rpt.FileName = Server.MapPath(“EventHistory.rpt”);
crdata.Report = rpt;

rpt1 = crdata.ReportDocument;

crp.ReportSource = rpt1;
crp.RefreshReport();

crp.DataBind();

Client System TimeZone Offset

The getTimezoneOffset method returns an integer value representing the number of minutes between the time on the current machine and UTC. These values are appropriate to the computer the script is executed on. If it is called from a server script, the return value is appropriate to the server. If it is called from a client script, the return value is appropriate to the client.

This number will be positive if you are behind UTC (e.g., Pacific Daylight Time), and negative if you are ahead of UTC (e.g., Japan).

For example, suppose a server in New York City is contacted by a client in Los Angeles on December 1. getTimezoneOffset returns 480 if executed on the client, or 300 if executed on the server.

function TZDemo()
{
var d = new Date();
var minutes = d.getTimezoneOffset();

var s = “”;
s += “The current local time is “;
s += minutes / 60;
if (minutes < 0)
s += " hours after UTC";
else
s += " hours before UTC";

return(s);
}