65.9K
CodeProject 正在变化。 阅读更多。
Home

iServer 网吧

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.54/5 (17投票s)

2005年4月7日

2分钟阅读

viewsIcon

114697

downloadIcon

10694

用于跟踪业务的网吧软件。

Sample Image

Sample Image

引言

Iserver 是一款帮助您运营网吧的新产品。当计算机在线时,计时器会计算在线时间并直接写入数据库。当客户完成时,他按下STOP按钮。这将注销计算机,服务器将自动打印收据。服务器具有添加额外饮料、零食和您定义的所有费用到客户账单中的选项。会员可以购买 1、2 或 3 小时的卡,或全周卡。服务器将计算剩余时间并从卡中扣除在线分钟数(如果您将会员链接到计算机)。

重要

‘sa’ 用户拥有特权,可以还原 InterServer 数据库。它会询问您是否要还原数据库。之后,关闭 Iserver 并重新启动它。

报告

您可以获取在线时间消耗和会员计算机使用情况报告。此功能仅在管理员模式下可用,因此您需要登录。

最低要求

服务器:配备 512 MB RAM 的 PII 350。您需要硬盘上至少有 1 GB 的可用空间。

我们建议不要在您的网络中放置名称为 BAR 的计算机,也不要给计算机几乎相同的名称,例如 Bcomputer1 和 computer1。

使用代码

打印到行式打印机确实是一个挑战。但是您可以看到我们已经解决了它!

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;
        }
    }
}

关注点

SQL Server 配置

Server name = name of the PC.
Database name = InterServer
User = sa
Password =

从这里开始,并确保无法从互联网访问此 PC。因此,必须安装一个好的防火墙。首次运行 Iserver 时,您应该能够连接到 SQL Server。它将提示您输入一些变量

Server name = name of the PC.
Database name = InterServer
User = sa
Password =
Server Password = anything you like
© . All rights reserved.