Introduction
Iserver is a new product that helps you run an Internet cafe. When the computer is online, a timer counts the online time and writes it directly in the database. When the client is finished, he presses a button STOP. This will logoff the computer and the server will print the receipt automatically. The server has options like: adding the cost of extra drinks, sweets and all that you define, to the bill of your client. Members can buy cards for 1, 2, or 3 hours, or all week. The server will calculate how much time is left and deduct the online minutes from the card (if you link the member to a computer).
Important
�sa� user is privileged so it can restore the database InterServer. It will ask you if you want to restore the database. After that, close the Iserver and start it again.
Reporting
You can get reports of consumption of online time and memberwise usage of the computers. This feature is available only in the admin mode, so you will have to login.
Minimum requirements:
Server: PII 350 with 512 MB RAM. You will need 1 GB free space on your hard disk.
We advice you to not place computers in your network with the name BAR, or give computers almost equal names, like Bcomputer1 and computer1.
Using the code
Printing to a line printer was a real challenge. But you can see that we solved it!
using System;
using System.IO;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
namespace System.Drawing
{
public class LinePrinting
{
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
struct DOCINFOW
{
[MarshalAs(UnmanagedType.LPWStr)] public string pDocName;
[MarshalAs(UnmanagedType.LPWStr)] public string pOutputFile;
[MarshalAs(UnmanagedType.LPWStr)] public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint="OpenPrinterW",
CharSet=CharSet.Unicode, SetLastError=true,
ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
static extern bool OpenPrinter(string src, ref IntPtr hPrinter, long pd);
[DllImport("winspool.Drv", EntryPoint="ClosePrinter",
CharSet=CharSet.Unicode, SetLastError=true,
ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint="StartDocPrinterW",
CharSet=CharSet.Unicode, SetLastError=true,
ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
static extern bool StartDocPrinter(IntPtr hPrinter,
int level, ref DOCINFOW pDI );
[DllImport("winspool.Drv", EntryPoint="EndDocPrinter",
CharSet=CharSet.Unicode, SetLastError=true,
ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint="StartPagePrinter",
CharSet=CharSet.Unicode, SetLastError=true,
ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
static extern bool StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint="EndPagePrinter",
CharSet=CharSet.Unicode, SetLastError=true,
ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint="WritePrinter",
CharSet=CharSet.Unicode, SetLastError=true,
ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
static extern bool WritePrinter(IntPtr hPrinter,
IntPtr pBytes, int dwCount ,ref int dwWritten );
public bool SendBytesToPrinter(string szPrinterName,
IntPtr pBytes, int dwCount)
{
IntPtr hPrinter = new IntPtr(0);
int dwError;
DOCINFOW di = new DOCINFOW();
int dwWritten = 0;
bool bSuccess;
di.pDocName = "My C# .NET RAW Document";
di.pDataType = "RAW";
bSuccess = false;
if (OpenPrinter(szPrinterName, ref hPrinter, 0))
{
if (StartDocPrinter(hPrinter, 1, ref di))
{
if (StartPagePrinter(hPrinter))
{
bSuccess = WritePrinter(hPrinter, pBytes,
dwCount, ref dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
if (bSuccess == false)
{
dwError = Marshal.GetLastWin32Error();
}
return bSuccess;
}
public bool SendFileToPrinter(string szPrinterName, string szFileName )
{
FileStream fs = new FileStream(szFileName, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] bytes = new byte[fs.Length];
bool bSuccess;
IntPtr pUnmanagedBytes;
bytes = br.ReadBytes(Convert.ToInt32(fs.Length));
pUnmanagedBytes = Marshal.AllocCoTaskMem(Convert.ToInt32(fs.Length));
Marshal.Copy(bytes, 0, pUnmanagedBytes, Convert.ToInt32(fs.Length));
bSuccess = SendBytesToPrinter(szPrinterName,
pUnmanagedBytes, Convert.ToInt32(fs.Length));
Marshal.FreeCoTaskMem(pUnmanagedBytes);
return bSuccess;
}
public bool SendStringToPrinter(string szPrinterName , string szString )
{
bool bSuccess;
IntPtr pBytes = new IntPtr(0);
int dwCount;
dwCount = szString.Length;
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
bSuccess = SendBytesToPrinter(szPrinterName, pBytes, dwCount);
Marshal.FreeCoTaskMem(pBytes);
return bSuccess;
}
}
}
Points of Interest
SQL server configuration:
Server name = name of the PC.
Database name = InterServer
User = sa
Password =
Begin like this and make sure that you cannot get to this PC from the Internet. So there has to be a good firewall installed. When you run the Iserver the first time, you have be able to connect to a SQL Server. It will prompt for some variables:
Server name = name of the PC.
Database name = InterServer
User = sa
Password =
Server Password = anything you like