資源簡介
該系統是基于vs2008+Sql2005開發平臺的一個純軟件系統,能實現簡單的刷卡和充值功能

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Data;
using?System.Data.SqlClient;
using?System.IO?;
using?System.Net?;
using?System.Net?.Sockets?;
using?System.Runtime.InteropServices;
using?System.Text;
namespace?server.connect
{
????class?connectDB
????{
????????public?static?string?sConnectString?=?“Data?Source=.;Initial?Catalog=CardDB;Integrated?Security=True?“;
????????//告訴編譯器?這個結構體需要使用順序布局,CharSet屬性有連個CharSet.Ansi和CharSet.Unicode
????????[StructLayout?(LayoutKind.Sequential?CharSet?=CharSet?.Ansi?Pack?=1)]
????????public?struct?Message
????????{
????????????public?int?flags;//用于辨別是哪種消息
????????????[MarshalAs(UnmanagedType.ByValTStr?SizeConst?=?256)]
????????????public?string?handInfor;
????????????[MarshalAs(UnmanagedType.ByValTStr?SizeConst?=?11)]
????????????public?string?cardID;//卡號
????????????[MarshalAs(UnmanagedType.ByValTStr?SizeConst?=?16)]
????????????public?string?password;//密碼
????????????[MarshalAs(UnmanagedType.ByValTStr?SizeConst?=?21)]
????????????public?string?time;//代表各種時間,如消費時間,掛失時間等
????????????public?float?restMoney;//余額
????????????public?float?consumeMoney;//刷卡金額
????????}
????????//結構體轉byte數組
????????public?static?byte[]?StructToBytes(object?structObj)
????????{
????????????//得到結構體的大小
????????????int?size?=?Marshal.SizeOf(structObj);
????????????//Marshal提供了一個方法集,這些方法用于分配非托管內存、復制非托管內存塊、將托管類型轉換為非托管類型,此外還提供了在與非托管代碼交互時使用的其他雜項方法。?
????????????//創建byte數組
????????????byte[]?bytes?=?new?byte[size];
????????????//分配結構體大小的內存空間
????????????IntPtr?structPtr?=?Marshal.AllocHGlobal(size?);
????????????//將結構體拷到分配好的內存空間
????????????Marshal.StructureToPtr(structObj?structPtr?false);//設置為?true?可在執行?Marshal.DestroyStructure?方法前對?ptr?參數調用此方法。?請注意,傳遞?false?可導致內存泄漏
????????????//從內存空間拷到byte數組
????????????Marshal.Copy(structPtr?bytes0size?);
????????????//釋放內存空間
????????????Marshal?.FreeHGlobal(structPtr);
????????????//返回byte數組
????????????return?bytes;
????????}
????????//byte數組轉結構體
????????public?static?object?BytesToStruct(byte[]?bytes?Type?type)
????????{?
?????????????//得到結構體的大小
????????????int?size?=?Marshal.SizeOf(type);
????????????//byte數組長度小于結構體的大小
????????????if?(size?>?bytes.Length)
????????????{
????????????????return?null;
????????????}
????????????//分配結構體大小的內存空間
????????????IntPtr?structPtr?=?Marshal.AllocHGlobal(size?);
????????????//將byte數組拷到分配好的內存空間
????????????Marshal.Copy(bytes?0structPtr?size?);
????????????//將內存空間轉換為目標結構體
????????????object?obj?=?Marshal.PtrToStructure(structPtr?type?);
????????????//釋放內存空間
????????????Marshal.FreeHGlobal(structPtr?);
????????????//返回結構體
????????????return?obj;
?????????}
???????//?public?static?bool?TestConnection(out?string?sError)
????????//{
???????????///?SqlConnection?connection=new?SqlConnection?(sConnectString);
????????????//try
???????????//?{
???????????///?????connection.Open();
???????????//?????sError?=?string.Em
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????3145728??2011-09-14?19:28??項目源代碼\CardDB\CardDB.mdf
?????文件????1048576??2011-09-14?19:28??項目源代碼\CardDB\CardDB_log.ldf
?????文件??????11264??2011-09-17?10:53??項目源代碼\server\bin\Debug\server.exe
?????文件??????26112??2011-09-17?10:53??項目源代碼\server\bin\Debug\server.pdb
?????文件??????14328??2011-09-23?15:45??項目源代碼\server\bin\Debug\server.vshost.exe
?????文件????????490??2007-07-21?01:33??項目源代碼\server\bin\Debug\server.vshost.exe.manifest
?????文件????3145728??2011-09-01?23:04??項目源代碼\server\CardDB\CardDB.mdf
?????文件????1048576??2011-09-01?23:04??項目源代碼\server\CardDB\CardDB_log.ldf
?????文件???????6341??2011-09-17?10:51??項目源代碼\server\connectDB.cs
?????文件???????4996??2011-09-23?15:45??項目源代碼\server\obj\Debug\server.csproj.FileListAbsolute.txt
?????文件??????11264??2011-09-17?10:53??項目源代碼\server\obj\Debug\server.exe
?????文件??????26112??2011-09-17?10:53??項目源代碼\server\obj\Debug\server.pdb
?????文件???????1344??2011-08-30?21:29??項目源代碼\server\Properties\AssemblyInfo.cs
?????文件??????12275??2011-09-17?10:33??項目源代碼\server\server.cs
?????文件???????2524??2011-08-30?22:12??項目源代碼\server\server.csproj
?????文件?????????77??2011-09-23?15:38??項目源代碼\公交刷卡系統\app.config
?????文件?????357888??2011-09-23?15:38??項目源代碼\公交刷卡系統\bin\Debug\公交刷卡系統.exe
?????文件?????????77??2011-09-23?15:38??項目源代碼\公交刷卡系統\bin\Debug\公交刷卡系統.exe.config
?????文件??????69120??2011-09-23?15:38??項目源代碼\公交刷卡系統\bin\Debug\公交刷卡系統.pdb
?????文件??????14328??2011-09-23?15:45??項目源代碼\公交刷卡系統\bin\Debug\公交刷卡系統.vshost.exe
?????文件?????????77??2011-09-23?15:38??項目源代碼\公交刷卡系統\bin\Debug\公交刷卡系統.vshost.exe.config
?????文件????????490??2007-07-21?01:33??項目源代碼\公交刷卡系統\bin\Debug\公交刷卡系統.vshost.exe.manifest
?????文件???????2848??2011-09-16?22:18??項目源代碼\公交刷卡系統\Class1.cs
?????文件???????5195??2011-09-22?21:31??項目源代碼\公交刷卡系統\consumefrm_.cs
?????文件???????9467??2011-09-22?21:31??項目源代碼\公交刷卡系統\consumefrm_.Designer.cs
?????文件?????241649??2011-09-22?21:31??項目源代碼\公交刷卡系統\consumefrm_.resx
?????文件???????1876??2011-09-22?21:14??項目源代碼\公交刷卡系統\frmMain.cs
?????文件???????6624??2011-09-22?21:14??項目源代碼\公交刷卡系統\frmMain.Designer.cs
?????文件??????16237??2011-09-22?21:14??項目源代碼\公交刷卡系統\frmMain.resx
?????文件???????6344??2011-09-22?21:31??項目源代碼\公交刷卡系統\frm_AddMoney.cs
............此處省略47個文件信息
評論
共有 條評論