Showing posts with label Sowftware development. Show all posts
Showing posts with label Sowftware development. Show all posts

2009-02-19

How to generate INSERT scripts from SQL Server?

Download and install SQL Server Dumper, connect to the database, click Execute and generate the scripts.

2008-01-08

Scott's ToDo list video

A ToDo list ASP .Net application is built from scratch in Microsoft Visual WebDeveloper 2005 Express Edition, using the ASP.NET AJAX Extensions
Duration: 20 minutes, 23 seconds.

Source: The official Microsoft AJAX.NET site

2007-12-17

How To Use ADO with Excel Data


I am working with ADO and Excel. I kept reveiving an error message: "Deleting data in a linked table is not supported by this ISAM." I found the solution on the following Microsoft support page: How To Use ADO with Excel Data from Visual Basic or VBA. The sample code is written in VB but this is the least important thing.
The article is good, everyone should read it before starting to work with ADO and Excel.

Read a Stream into a String in C# .Net

using (MemoryStream ms = new MemoryStream())
{
//
// Write stuff into the memory stream with ms.Write();
//

// Jump to the start position of the stream
ms.Seek(0, SeekOrigin.Begin);

StreamReader rdr = new StreamReader(ms);
string str = rdr.ReadToEnd();
}

2007-12-11

How to convert absolute path to relative path in C# .Net

public static string Absolute2RelativePath(string basePath, string absolutePath)
{
string[] baseDirectories = basePath.Split('\\');
string[] absoluteDirectories = absolutePath.Split('\\');

// Get the shortest of the two paths
int length = baseDirectories.Length <>

// Use to determine where in the loop we exited
int lastCommonRoot = -1;
int index;

// Find common root
for (index = 0; index <>
{
if (baseDirectories[index] == absoluteDirectories[index])
{
lastCommonRoot = index;
}
else
{
break;
}
}

// If we didn't find a common prefix then throw
if (lastCommonRoot == -1)
{
return absolutePath;
}

// Build up the relative path
StringBuilder relativePath = new StringBuilder();

// Add on the ..
for (index = lastCommonRoot + 1; index <>
{
if (baseDirectories[index].Length > 0)
{
relativePath.Append("..\\");
}
}

// Add on the folders
for (index = lastCommonRoot + 1; index <>
{
relativePath.Append(absoluteDirectories[index] + "\\");
}
relativePath.Append(absoluteDirectories[absoluteDirectories.Length - 1]);

return relativePath;
}

This code was found on an another Blogger page, bit re-aligned and posted here.

2007-10-12

A Visual Explanation of SQL Joins



I found a great article on Coding horror about SQL joins.

Article here.

2007-07-21

How to Get the Current Page URL in PHP




function CurrentURL()
{
$url = 'http';

if ($_SERVER["HTTPS"] == "on")
{
$url .= "s";
}

$url .= "://";

if ($_SERVER["SERVER_PORT"] != "80")
{
$url .= $_SERVER["SERVER_NAME"].":".
$_SERVER["SERVER_PORT"].
$_SERVER["REQUEST_URI"];
}
else
{
$url .= $_SERVER["SERVER_NAME"].
$_SERVER["REQUEST_URI"];
}

return $url;
}
?>

2007-05-08

Fortech joblog



See IT on Fortech’s new jobs blog:

www.fortech.ro/wearehiring

This page was created to host an up-to-date overview of the job openings in our company.
Just stay tuned and we’ll show you how a dynamic company like Fortech can change your whole career perspective.

We are eager to hear from you, so do not hesitate to send your feedback and post your comments.

Keep in touch!

2007-03-12

Simple query

A few days ago we sat down with my cousin to write a simple query on his database.
"Very simple" he said. "Just two or three lines" said I.
Please enjoy the clipped version:

DECLARE @dateMin DATETIME, @dateMax DATETIME

-- Give values

DECLARE @noOfDays DECIMAL(18,2)

SET @noOfDays = DATEDIFF(DAY, @dateMin, @dateMax)

SELECT [VW_RoomDetails].[Name] [Room], [RoomType], [OccupancyCount], [Charges], [TotalCharges], [TVA], (CASE WHEN ISNULL([OccupancyCount], 0.00) = 0 THEN 0 ELSE ISNULL([Charges], 0.00)/ISNULL([OccupancyCount],0.00) END) [ADR_Net],

(CASE WHEN ISNULL([OccupancyCount], 0.00) = 0 THEN 0 ELSE ISNULL([TotalCharges], 0.00)/ISNULL([OccupancyCount],0.00) END) [ADR_Brut], ISNULL([OccupancyCount], 0.00) / ISNULL(@noOfDays,0.00) *100 [OccupancyPercent]

FROM

VW_RoomDetails

LEFT JOIN

(
SELECT [ID_Room],

SUM (DATEDIFF(DAY, (CASE WHEN [CheckInDate] > @dateMin THEN [CheckInDate] ELSE @dateMin END),

(CASE WHEN [CheckOutDate] < @dateMax THEN [CheckOutDate] ELSE @dateMax END))) [OccupancyCount]

FROM [VW_RoomStayInfoDetails]

WHERE [StayType] = 1 AND

(([CheckInDate] >= @dateMin AND [CheckOutDate] <= @dateMax)

OR ([CheckInDate] <= @dateMin AND [CheckOutDate] >= @dateMin)

OR ([CheckOutDate] <= @dateMax AND [CheckOutDate] >= @dateMax)

OR [CheckInDate] <= @dateMin AND [CheckOutDate] > @dateMax )

GROUP BY [ID_Room]) [rooms]

ON VW_RoomDetails.ID_Room = rooms.ID_Room


LEFT JOIN
(
SELECT [ID_Room], SUM([Amount]) [Charges], SUM([Amount] + [TVA]) [TotalCharges], SUM ([TVA]) [TVA] FROM [TBL_Charge]
GROUP BY [ID_Room]
) [charges]

ON [rooms].[ID_Room] = [charges].[ID_Room]


2007-03-06

Programming tools - Microsoft FxCop 1.35



FxCop is a code analysis tool that checks .NET managed code assemblies for conformance to the Microsoft .NET Framework Design Guidelines. It uses reflection, MSIL parsing, and callgraph analysis to inspect assemblies for more than 200 defects in the following areas:

* Library design
* Localization
* Naming conventions
* Performance
* Security

FxCop includes both GUI and command line versions of the tool.

Homepage: here.

Download: here.

Documentation: here.

2007-03-01

The "FizzBuzz" problem


Some days ago I read a post on CodingHorror in which the author talks about the importance of including a simple test in a job interview for programmers. He is talking about small and easy task that has to solved on paper by the applier in a few minutes to prove that he/she is capable of programming.
The author calls these "FizzBuzz" questions. Example:
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

A colleague of mine, Valeriu, decided to solve this problem. He uses .Net Reflection, because it is elegant; with .Net Reflection Emit he generates in runtime the dll that contains the solution for the problem above and executes it. The algorithm itself is written in Intermediate Language (IL) to keep things simple.


"This kind of approach to the problem is extremely simple, efficient and elegant"


he states. He honored me by naming this simple approach "Vencel Algorithm". Here is the code:



class Program

{

static void Main(string[] args)

{

VencelAlgorithm();

Console.ReadLine();

}

public static void VencelAlgorithm()

{

Type type = CodeGenerator.EmitClass();

type.GetMethod("Print").Invoke(null, null);

}

}

class CodeGenerator

{

public static Type EmitClass()

{

AssemblyName asmName = new AssemblyName();

asmName.Name = "VencelAlghoritm";

AssemblyBuilder asmBuilder =

Thread.GetDomain().DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);

ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule("Vencel.dll");

TypeBuilder typeBuilder = modBuilder.DefineType(

"Algorithm",

TypeAttributes.Public | TypeAttributes.Class);

MethodBuilder methodBuilder = typeBuilder.DefineMethod("Print",

MethodAttributes.Static | MethodAttributes.Public,

typeof(void),

new Type[] {typeof(Int32)});

EmitFunction(methodBuilder);

Type type = typeBuilder.CreateType();

asmBuilder.Save("Vencel.dll");

return type;

}

private static void EmitFunction(MethodBuilder methodBuilder)

{

Type[] intType = { typeof(Int32) };

MethodInfo writeLineInt = typeof(Console).GetMethod("WriteLine", intType);

Type[] stringType = { typeof(string) };

MethodInfo writeLineString = typeof(Console).GetMethod("WriteLine", stringType);

ILGenerator ilGenerator = methodBuilder.GetILGenerator();

//am nevoie de cateva etichete pentru a implementa un for si 4 if-uri

Label IL_0046 = ilGenerator.DefineLabel();

Label IL_001a = ilGenerator.DefineLabel();

Label IL_0042 = ilGenerator.DefineLabel();

Label IL_002b = ilGenerator.DefineLabel();

Label IL_003c = ilGenerator.DefineLabel();

Label IL_0004 = ilGenerator.DefineLabel();

//declar variabila contor pentru for (denumita variabila locala de index 0)

ilGenerator.DeclareLocal(typeof(int));

//se pune valoarea 1 in stiva

ilGenerator.Emit(OpCodes.Ldc_I4_1);

//se scoate valoarea de pe stiva (operatia pop) si se pune in variabila locala de index 0

ilGenerator.Emit(OpCodes.Stloc_0);

//salt la eticheta IL_0046

ilGenerator.Emit(OpCodes.Br_S, IL_0046);

//marchez urmatoarea instructiune cu o eticheta (pt revenire la o noua iteratie in for)

ilGenerator.MarkLabel(IL_0004);

//se incarca variabila locala de index in stack

ilGenerator.Emit(OpCodes.Ldloc_0);

//se incarca valoarea 3 in stack

ilGenerator.Emit(OpCodes.Ldc_I4_3);

//se calculeaza restul impartirii celor 2 valori puse pe stack

//rem - remainder

//rezultatul se pune pe stiva

ilGenerator.Emit(OpCodes.Rem);

//sare la eticheta IL_001a daca operatia anterioara este evaluata la true

//(un fel de je din 8086)

ilGenerator.Emit(OpCodes.Brtrue_S, IL_001a);

ilGenerator.Emit(OpCodes.Ldloc_0);

ilGenerator.Emit(OpCodes.Ldc_I4_5);

ilGenerator.Emit(OpCodes.Rem);

ilGenerator.Emit(OpCodes.Brtrue_S, IL_001a);

//se pune referinta stringului "FizzBuzz" pe stiva

ilGenerator.Emit(OpCodes.Ldstr, "FizzBuzz");

//se apeleaza functia Console.WriteLine cu parametrul string

//(pentru afisarea la consola)

ilGenerator.Emit(OpCodes.Call, writeLineString);

//salt neconditionat (echivalentul instructiunii jmp din 8086)

ilGenerator.Emit(OpCodes.Br_S, IL_0042);

ilGenerator.MarkLabel(IL_001a);

ilGenerator.Emit(OpCodes.Ldloc_0);

ilGenerator.Emit(OpCodes.Ldc_I4_3);

ilGenerator.Emit(OpCodes.Rem);

ilGenerator.Emit(OpCodes.Brtrue_S, IL_002b);

ilGenerator.Emit(OpCodes.Ldstr, "Fizz");

//se apeleaza functia Console.WriteLine cu parametrul string

//(pentru afisarea la consola a string-ului "Fizz")

ilGenerator.Emit(OpCodes.Call, writeLineString);

ilGenerator.Emit(OpCodes.Br_S, IL_0042);

ilGenerator.MarkLabel(IL_002b);

ilGenerator.Emit(OpCodes.Ldloc_0);

ilGenerator.Emit(OpCodes.Ldc_I4_5);

ilGenerator.Emit(OpCodes.Rem);

ilGenerator.Emit(OpCodes.Brtrue_S, IL_003c);

ilGenerator.Emit(OpCodes.Ldstr, "Buzz");

//se apeleaza functia Console.WriteLine cu parametrul string

//(pentru afisarea la consola a string-ului "Buzz")

ilGenerator.Emit(OpCodes.Call, writeLineString);

ilGenerator.Emit(OpCodes.Br_S, IL_0042);

ilGenerator.MarkLabel(IL_003c);

ilGenerator.Emit(OpCodes.Ldloc_0);

//se apeleaza functia Console.WriteLine cu parametrul int

//(pentru afisarea la consola a numarului curent)

ilGenerator.Emit(OpCodes.Call, writeLineInt);

ilGenerator.MarkLabel(IL_0042);

ilGenerator.Emit(OpCodes.Ldloc_0);

ilGenerator.Emit(OpCodes.Ldc_I4_1);

ilGenerator.Emit(OpCodes.Add);

ilGenerator.Emit(OpCodes.Stloc_0);

ilGenerator.MarkLabel(IL_0046);

ilGenerator.Emit(OpCodes.Ldloc_0);

ilGenerator.Emit(OpCodes.Ldc_I4_S, 100);

ilGenerator.Emit(OpCodes.Ble_S, IL_0004);

//return din funtie

ilGenerator.Emit(OpCodes.Ret);

}

}