Click here to Skip to main content
15,880,543 members
Articles / Database Development / SQL Server
Article

Iserver Cyber Cafe

Rate me:
Please Sign up or sign in to vote.
4.54/5 (17 votes)
6 Apr 20052 min read 111.6K   10.7K   69   27
Cyber café software to keep track of buisness.

Sample Image

Sample Image

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!

C#
using System;
using System.IO;
using System.Drawing.Printing;
using System.Runtime.InteropServices;

namespace System.Drawing
{
    /// <summary>
    /// Summary description for LinePrinting.
    /// Written by Marc Platvoet
    /// MarcPlatvoet@hotmail.com
    /// LinePrinter Class for .NET
    /// The one thing that was failing in the framework.
    /// 
    /// Find More Projects on http://www.addfinder.com/
    /// Find More Projects on http://www.addfinder.com/internetcafe/
    /// 
    /// http://support.microsoft.com/default.aspx?scid=kb;EN-US;322091
    /// 
    /// </summary>
    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 );


        //SendBytesToPrinter()
        //When the function is given a printer name and an unmanaged array of
        //bytes, the function sends those bytes to the print queue.
        //Returns True on success or False on failure.
        public bool SendBytesToPrinter(string szPrinterName, 
                                 IntPtr pBytes, int dwCount)
        {
            // The printer handle.
            IntPtr hPrinter = new IntPtr(0);
            // Last error - in case there was trouble.
            int dwError;
            // Describes your document (name, port, data type).
            DOCINFOW di = new DOCINFOW();
            // The number of bytes written by WritePrinter().
            int dwWritten = 0;
            // Your success code.
            bool bSuccess;

            // Set up the DOCINFO structure.
            di.pDocName = "My C# .NET RAW Document";
            di.pDataType = "RAW";
            // Assume failure unless you specifically succeed.
            bSuccess = false;
            if (OpenPrinter(szPrinterName, ref hPrinter, 0))
            {
                if (StartDocPrinter(hPrinter, 1, ref di))
                {
                    if (StartPagePrinter(hPrinter))
                    {
                        // Write your printer-specific bytes to the printer.
                        bSuccess = WritePrinter(hPrinter, pBytes, 
                                         dwCount, ref dwWritten);
                        EndPagePrinter(hPrinter);
                    }
                    EndDocPrinter(hPrinter);
                }
                ClosePrinter(hPrinter);
            }
            // If you did not succeed, GetLastError may give more information
            // about why not.
            if (bSuccess == false)
            {
                dwError = Marshal.GetLastWin32Error();
            }
            return bSuccess;
        }


        // SendFileToPrinter()
        // When the function is given a file name and a printer name, 
        // the function reads the contents of the file and sends the
        // contents to the printer.
        // Presumes that the file contains printer-ready data.
        // Shows how to use the SendBytesToPrinter function.
        // Returns True on success or False on failure.
        public bool SendFileToPrinter(string szPrinterName, string szFileName )
        {    
            // Open the file.
            FileStream fs = new FileStream(szFileName, FileMode.Open);
            // Create a BinaryReader on the file.
            BinaryReader br = new BinaryReader(fs);
            // Dim an array of bytes large enough to hold the file's contents.
            byte[] bytes = new byte[fs.Length];
            bool bSuccess;
            // Your unmanaged pointer
            IntPtr pUnmanagedBytes;

            // Read the contents of the file into the array.
            bytes = br.ReadBytes(Convert.ToInt32(fs.Length));
            // Allocate some unmanaged memory for those bytes.
            pUnmanagedBytes = Marshal.AllocCoTaskMem(Convert.ToInt32(fs.Length));
            // Copy the managed byte array into the unmanaged array.
            Marshal.Copy(bytes, 0, pUnmanagedBytes, Convert.ToInt32(fs.Length));
            // Send the unmanaged bytes to the printer.
            bSuccess = SendBytesToPrinter(szPrinterName, 
                       pUnmanagedBytes, Convert.ToInt32(fs.Length));
            // Free the unmanaged memory that you allocated earlier.
            Marshal.FreeCoTaskMem(pUnmanagedBytes);
            return bSuccess;
        }

        // When the function is given a string and a printer name,
        // the function sends the string to the printer as raw bytes.
        public bool SendStringToPrinter(string szPrinterName , string szString )
        {
            bool bSuccess;
            IntPtr pBytes = new IntPtr(0);
            int dwCount;
            //How many characters are in the string?
            dwCount = szString.Length;
            //Assume that the printer is expecting ANSI text, and then convert
            //the string to ANSI text.
            pBytes = Marshal.StringToCoTaskMemAnsi(szString);
            //Send the converted ANSI string to the printer.
            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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Portugal Portugal
Programmer of all that has code..

Comments and Discussions

 
Questionhey! please someone help me in my C# programming Pin
ronCheL081-Mar-09 20:12
ronCheL081-Mar-09 20:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.