C#键盘钩子(client和server)
1、本程序是用C#技术调用window API和socket通信实现的。
2、程序分客户端【frmClient.exe】和服务器【RecordMachine.exe】。
3、本程序适用于局域网内的监听。
4、客户端通过调用window api,实现捕捉键盘动作,把捕捉的按键动作转换为网络流发送给服务器端,
服务器端通过接受socket套接字转换字符,最后显示服务器控件上。
OleDb 的方式操作excel表
* 此类包含的方法:
* 1、获取excel的工作簿名称【GetExcelSheetNames】。
* 2、获取指定工作簿的数据【GetExcelData】。
* 3、判断Excel工作簿是否存在【IsExist】。
* 4、对注册表的操作,解决读取Excel表格数据位数的限制【OperateRegedit】。
* 5、删除磁盘上指定的文件【ClearExcelFile】。
* 6、根据传入的Datatable数据源,生成Excel数据表【CreateAndWriteExcelByDatatable】。
* 7、根据传入的Datatable数据源,生成Excel数据表(带进度条指示)--【CreateAndWriteExcelByDatatable】。
* 8、删除临时表DataTable里面的数据【RemoveDatatableRow】。
* 9、操作日志的生成【OperateLog】。
64K动画大赛作品
文件列表 精品3D作品
3D exe
64K动画大赛作品之一:幽灵古堡 exe
64K动画大赛作品之三:火域幻境 exe
64K动画大赛作品之二:第七天堂 exe
64K动画大赛作品之五:死亡阴影 exe
64K动画大赛作品之六:金属迷城 exe
64K动画大赛作品之四:爱之记忆 exe
flybye exe
fr 030 candytron party exe
kkino64 exe
ltoo exe
《彗星撞地球》 exe
光影 exe
卡通 exe
Windows Phone 开发键盘控制帮助文档
Default, FileName, FullFilePath, Hanja, Hiragana, KatakanaFullWidth, KatakanaHalfWidth, LogOnName, OneChar, Password, PersonalFullName, PersonalGivenName, PersonalMiddleName, PersonalNamePrefix, PersonalNameSuffix, Yomi
*当手机或模拟器上的键盘语言设置为除英语、法语、菲律宾语、马来语和印度尼西亚语以外的语言时,AddressStreet 将生成此键盘。
AddressStreet*, CurrencyAmountAndSymbol, CurrencyChinese, PostalAddress, PostalCode, Time
*当手机或模拟器上的键盘语言设置为英语、法语、菲律宾语、马来语或印度尼西亚语时,AddressStreet 将生成此键盘。
疯狂JS特效
javascript特效,有:菜单特效、窗口特效、时间特效、图片特效、文字特效……
例子:仿真计算器代码
<style type="text/css">
<!--
body {font-family: helvetica}
p {font-size: 12pt}
.red {color: red}
.blue {color: blue}
-->
</style>
[removed]
<!-- Begin
var Memory = 0;
var Number1 = "";
var Number2 = "";
var NewNumber = "blank";
var opvalue = "";
function Display(displaynumber) {
document.calculator.answer.value = displaynumber;
}
<!-- 此特效使用《轻松网页特效》编辑制作-->
<!-- 国文工作室-->
function MemoryClear() {
Memory = 0;
document.calculator.mem.value = "";
}
function MemoryRecall(answer) {
if(NewNumber != "blank") {
Number2 += answer;
} else {
Number1 = answer;
}
NewNumber = "blank";
Display(answer);
}
function MemorySubtract(answer) {
Memory = Memory - eval(answer);
}
function MemoryAdd(answer) {
Memory = Memory + eval(answer);
document.calculator.mem.value = " M ";
NewNumber = "blank";
}
function ClearCalc() {
Number1 = "";
Number2 = "";
NewNumber = "blank";
Display("");
}
function Backspace(answer) {
answerlength = answer.length;
answer = answer.substring(0, answerlength - 1);
if (Number2 != "") {
Number2 = answer.toString();
Display(Number2);
} else {
Number1 = answer.toString();
Display(Number1);
}
}
function CECalc() {
Number2 = "";
NewNumber = "yes";
Display("");
}
function CheckNumber(answer) {
if(answer == ".") {
Number = document.calculator.answer.value;
if(Number.indexOf(".") != -1) {
answer = "";
}
}
if(NewNumber == "yes") {
Number2 += answer;
Display(Number2);
}
else {
if(NewNumber == "blank") {
Number1 = answer;
Number2 = "";
NewNumber = "no";
}
else {
Number1 += answer;
}
Display(Number1);
}
}
function AddButton(x) {
if(x == 1) EqualButton();
if(Number2 != "") {
Number1 = parseFloat(Number1) + parseFloat(Number2);
}
NewNumber = "yes";
opvalue = '+';
Display(Number1);
}
function SubButton(x) {
if(x == 1) EqualButton();
if(Number2 != "") {
Number1 = parseFloat(Number1) - parseFloat(Number2);
}
NewNumber = "yes";
opvalue = '-';
Display(Number1);
}
function MultButton(x) {
if(x == 1) EqualButton();
if(Number2 != "") {
Number1 = parseFloat(Number1) * parseFloat(Number2);
}
NewNumber = "yes";
opvalue = '*';
Display(Number1);
}
function DivButton(x) {
if(x == 1) EqualButton();
if(Number2 != "") {
Number1 = parseFloat(Number1) / parseFloat(Number2);
}
NewNumber = "yes";
opvalue = '/';
Display(Number1);
}
function SqrtButton() {
Number1 = Math.sqrt(Number1);
NewNumber = "blank";
Display(Number1);
}
function PercentButton() {
if(NewNumber != "blank") {
Number2 *= .01;
NewNumber = "blank";
Display(Number2);
}
}
function RecipButton() {
Number1 = 1/Number1;
NewNumber = "blank";
Display(Number1);
}
function NegateButton() {
Number1 = parseFloat(-Number1);
NewNumber = "no";
Display(Number1);
}
function EqualButton() {
if(opvalue == '+') AddButton(0);
if(opvalue == '-') SubButton(0);
if(opvalue == '*') MultButton(0);
if(opvalue == '/') DivButton(0);
Number2 = "";
opvalue = "";
}
// End -->
[removed]
<body>
<center>
<form name="calculator">
<table bgcolor="#aaaaaa" width=220>
<tr><td>
<table bgcolor="#cccccc" border=1>
<tr><td>
<table border=0 cellpadding=0>
<tr>
<td bgcolor="#000080">
<div align="center"><span>b>
计算器</b></span></div>
</td>
</tr>
<tr><td>
<table width="100%" border=0>
<tr><td colspan=6><input type="text" name="answer" size=30 maxlength=30>/td></tr>
<tr><td colspan=6>
<table border=0 cellpadding=0>
<tr><td>
<input type="text" name="mem" size=3 maxlength=3> <input type="button" name="backspace" class="red" value="Backspace">
<input type="button" name="CE" class="red" value=" CE ">
<input type="reset" name="C" class="red" value=" C ">
</td></tr>
</table>
</td></tr>
<tr><td><input type="button" name="MC" class="red" value=" MC ">/td>
<td>
<input type="button" name="calc7" class="blue" value=" 7 ">/td>
<td>
<input type="button" name="calc8" class="blue" value=" 8 ">/td>
<td>
<input type="button" name="calc9" class="blue" value=" 9 ">/td>
<td>
<input type="button" name="divide" class="red" value=" / ">/td>
<td><input type="button" name="sqrt" class="blue" value="sqrt">/td></tr>
<tr><td><input type="button" name="MR" class="red" value=" MR ">/td>
<td>
<input type="button" name="calc4" class="blue" value=" 4 ">/td>
<td>
<input type="button" name="calc5" class="blue" value=" 5 ">/td>
<td>
<input type="button" name="calc6" class="blue" value=" 6 ">/td>
<td>
<input type="button" name="multiply" class="red" value=" * ">/td>
<td><input type="button" name="percent" class="blue" value=" % ">/td></tr>
<tr><td><input type="button" name="MS" class="red" value=" MS ">/td>
<td>
<input type="button" name="calc1" class="blue" value=" 1 ">/td>
<td>
<input type="button" name="calc2" class="blue" value=" 2 ">/td>
<td>
<input type="button" name="calc3" class="blue" value=" 3 ">/td>
<td>
<input type="button" name="minus" class="red" value=" - ">/td>
<td><input type="button" name="recip" class="blue" value="1/x ">/td></tr>
<tr><td>
<input type="button" name="Mplus" class="red" value=" M+ ">/td>
<td>
<input type="button" name="calc0" class="blue" value=" 0 ">/td>
<td>
<input type="button" name="negate" class="blue" value="+/-">/td>
<td>
<input type="button" name="dot" class="blue" value=" . ">/td>
<td>
<input type="button" name="plus" class="red" value=" + ">/td>
<td>
<input type="button" name="equal" class="red" value=" = ">/td>
</tr>
</table>
</td></tr>
</table>
</td></tr>
</table>
</td></tr>
</table>
</form>
</center>
C#编程实例代码集合
Example002-渐显的窗体
Example003-使程序始终在前面
Example004-将窗体编译成类库
Example005-继承窗体的设计
Example006-设计多边形窗体
Example007-用获取路径的方法得到圆形窗体
Example008-分割窗体
Example009-在菜单中加入图标
Example010-渐变的窗口背景
Example011-使用任务栏的状态区
Example012-在运行时更新状态栏信息
Example013-无标题窗体的拖动
Example014-设置应用程序的图标
Example015-共享菜单项
Example016-动态设置窗体的光标
Example017-自己绘制菜单
Example018-向窗体的系统菜单添加菜单项
namespace Example018_向窗体的系统菜单添加菜单项
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Exit";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr GetSystemMenu(IntPtr hwnd,bool bRevert);
[System.Runtime.InteropServices.DllImport("user32")]
private static extern IntPtr AppendMenu(IntPtr hMenu,int wFlags,IntPtr wIDNewItem,string lpNewItem);
const int MF_POPUP = 0x0010;
const int MF_SEPARATOR = 0x0800;
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
IntPtr mnuSystem;
mnuSystem=GetSystemMenu(this.Handle,false);
AppendMenu(mnuSystem, MF_SEPARATOR, (IntPtr)0, "");
for(int i= 0;i<this.mainMenu1.MenuItems.Count;i++)
{
AppendMenu(mnuSystem,MF_POPUP,this.mainMenu1.MenuItems[i].Handle,this.mainMenu1.MenuItems[i].Text);
}
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
namespace Example019_本地化Windows窗体_1_
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
Thread.CurrentThread.CurrentUICulture=new CultureInfo("zh-cn");
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.AccessibleDescription = ((string)(resources.GetObject("button1.AccessibleDescription")));
this.button1.AccessibleName = ((string)(resources.GetObject("button1.AccessibleName")));
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("button1.Anchor")));
this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage")));
this.button1.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("button1.Dock")));
this.button1.Enabled = ((bool)(resources.GetObject("button1.Enabled")));
this.button1.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("button1.FlatStyle")));
this.button1.Font = ((System.Drawing.Font)(resources.GetObject("button1.Font")));
this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image")));
this.button1.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("button1.ImageAlign")));
this.button1.ImageIndex = ((int)(resources.GetObject("button1.ImageIndex")));
this.button1.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("button1.ImeMode")));
this.button1.Location = ((System.Drawing.Point)(resources.GetObject("button1.Location")));
this.button1.Name = "button1";
this.button1.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("button1.RightToLeft")));
this.button1.Size = ((System.Drawing.Size)(resources.GetObject("button1.Size")));
this.button1.TabIndex = ((int)(resources.GetObject("button1.TabIndex")));
this.button1.Text = resources.GetString("button1.Text");
this.button1.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("button1.TextAlign")));
this.button1.Visible = ((bool)(resources.GetObject("button1.Visible")));
//
// Form1
//
this.AccessibleDescription = ((string)(resources.GetObject("$this.AccessibleDescription")));
this.AccessibleName = ((string)(resources.GetObject("$this.AccessibleName")));
this.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("$this.Anchor")));
this.AutoScaleBaseSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScaleBaseSize")));
this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll")));
this.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMargin")));
this.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMinSize")));
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize")));
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("$this.Dock")));
this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("$this.ImeMode")));
this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
this.MaximumSize = ((System.Drawing.Size)(resources.GetObject("$this.MaximumSize")));
this.MinimumSize = ((System.Drawing.Size)(resources.GetObject("$this.MinimumSize")));
this.Name = "Form1";
this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("$this.RightToLeft")));
this.StartPosition = ((System.Windows.Forms.FormStartPosition)(resources.GetObject("$this.StartPosition")));
this.Text = resources.GetString("$this.Text");
this.Visible = ((bool)(resources.GetObject("$this.Visible")));
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
C#做的QQ程序源代码
this.IP地址 = new System.Windows.Forms.ColumnHeader();
this.端口 = new System.Windows.Forms.ColumnHeader();
this.状态 = new System.Windows.Forms.ColumnHeader();
this.部门 = new System.Windows.Forms.ColumnHeader();
this.姓名 = new System.Windows.Forms.ColumnHeader();
this.Version = new System.Windows.Forms.ColumnHeader();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.panel1.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// sockUDP1
//
this.sockUDP1.Server = ((System.Net.IPEndPoint)(resources.GetObject("sockUDP1.Server")));
this.sockUDP1.DataArrival += new LanMsg.Controls.SockUDP.DataArrivalEventHandler(this.sockUDP1_DataArrival);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemControl,
this.menuItem1});
//
// menuItemControl
//
this.menuItemControl.Index = 0;
this.menuItemControl.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemControlServer,
this.menuItem3,
this.menuItemControlExit});
this.menuItemControl.Text = "控件台(&C)";
this.menuItemControl.Click += new System.EventHandler(this.menuItemControl_Click);
//
// menuItemControlServer
//
this.menuItemControlServer.Index = 0;
this.menuItemControlServer.Text = "开始服务(&B)";
this.menuItemControlServer.Click += new System.EventHandler(this.menuItemControlServer_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "-";
//
// menuItemControlExit
//
this.menuItemControlExit.Index = 2;
this.menuItemControlExit.Text = "退出(&E)";
this.menuItemControlExit.Click += new System.EventHandler(this.menuItemControlExit_Click);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "帮助(&H)";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "关于(&C)";
//
// toolBar1
//
this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(632, 28);
this.toolBar1.TabIndex = 0;
this.toolBar1.Visible = false;
//
// toolBarButton1
//
this.toolBarButton1.ImageIndex = 0;
this.toolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 371);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(632, 22);
this.statusBar1.TabIndex = 1;
//
// TreeView1
//
this.TreeView1.Dock = System.Windows.Forms.DockStyle.Left;
this.TreeView1.ImageIndex = -1;
this.TreeView1.ItemHeight = 14;
this.TreeView1.Location = new System.Drawing.Point(0, 28);
this.TreeView1.Name = "TreeView1";
this.TreeView1.SelectedImageIndex = -1;
this.TreeView1.Size = new System.Drawing.Size(121, 343);
this.TreeView1.TabIndex = 6;
this.TreeView1.Visible = false;
//
// Splitter1
//
this.Splitter1.Location = new System.Drawing.Point(121, 28);
this.Splitter1.Name = "Splitter1";
this.Splitter1.Size = new System.Drawing.Size(4, 343);
this.Splitter1.TabIndex = 7;
this.Splitter1.TabStop = false;
this.Splitter1.Visible = false;
//
// TimerCheckOnlineSta
//
this.TimerCheckOnlineSta.Enabled = true;
this.TimerCheckOnlineSta.Interval = 60000;
this.TimerCheckOnlineSta.Tick += new System.EventHandler(this.TimerCheckOnlineSta_Tick);
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.tabControl1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(125, 28);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(507, 343);
this.panel1.TabIndex = 8;
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(503, 339);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.LV_SysUser);
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(495, 314);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "系统用户";
//
// LV_SysUser
//
this.LV_SysUser.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.ColumnHeader1,
this.ColumnHeader2,
this.ColumnHeader3,
this.ColumnHeader4,
this.ColumnHeader5,
this.ColumnHeader6,
this.columnHeader7});
this.LV_SysUser.Dock = System.Windows.Forms.DockStyle.Fill;
this.LV_SysUser.FullRowSelect = true;
this.LV_SysUser.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.LV_SysUser.Location = new System.Drawing.Point(0, 0);
this.LV_SysUser.Name = "LV_SysUser";
this.LV_SysUser.Size = new System.Drawing.Size(495, 314);
this.LV_SysUser.TabIndex = 14;
this.LV_SysUser.View = System.Windows.Forms.View.Details;
//
// ColumnHeader1
//
this.ColumnHeader1.Text = "ID";
this.ColumnHeader1.Width = 72;
//
// ColumnHeader2
//
this.ColumnHeader2.Text = "IP地址";
this.ColumnHeader2.Width = 122;
//
// ColumnHeader3
//
this.ColumnHeader3.Text = "端口";
//
// ColumnHeader4
//
this.ColumnHeader4.Text = "状态";
this.ColumnHeader4.Width = 44;
//
// ColumnHeader5
//
this.ColumnHeader5.Text = "部门";
this.ColumnHeader5.Width = 40;
//
// ColumnHeader6
//
this.ColumnHeader6.Text = "姓名";
this.ColumnHeader6.Width = 90;
//
// columnHeader7
//
this.columnHeader7.Text = "Version";
this.columnHeader7.Width = 120;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.LV_OnlineUser);
this.tabPage2.Location = new System.Drawing.Point(4, 21);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(495, 314);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "在线用户";
//
// LV_OnlineUser
//
this.LV_OnlineUser.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.ID,
this.IP地址,
this.端口,
this.状态,
this.部门,
this.姓名,
this.Version});
this.LV_OnlineUser.Dock = System.Windows.Forms.DockStyle.Fill;
this.LV_OnlineUser.FullRowSelect = true;
this.LV_OnlineUser.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.LV_OnlineUser.Location = new System.Drawing.Point(0, 0);
this.LV_OnlineUser.Name = "LV_OnlineUser";
this.LV_OnlineUser.Size = new System.Drawing.Size(495, 314);
this.LV_OnlineUser.TabIndex = 13;
this.LV_OnlineUser.View = System.Windows.Forms.View.Details;
//
// ID
//
this.ID.Text = "ID";
this.ID.Width = 72;
//
// IP地址
//
this.IP地址.Text = "IP地址";
this.IP地址.Width = 122;
//
// 端口
//
this.端口.Text = "端口";
//
// 状态
//
this.状态.Text = "状态";
this.状态.Width = 44;
//
// 部门
//
this.部门.Text = "部门";
this.部门.Width = 40;
//
// 姓名
//
this.姓名.Text = "姓名";
this.姓名.Width = 90;
//
// Version
//
this.Version.Text = "Version";
this.Version.Width = 120;
//
// notifyIcon1
//
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "LanMsg服务";
this.notifyIcon1.Visible = true;
this.notifyIcon1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDown);
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// FormMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(632, 393);
this.Controls.Add(this.panel1);
this.Controls.Add(this.Splitter1);
this.Controls.Add(this.TreeView1);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.toolBar1);
this.Menu = this.mainMenu1;
this.Name = "FormMain";
this.Text = "LanMsg服务";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Resize += new System.EventHandler(this.FormMain_Resize);
this.Closing += new System.ComponentModel.CancelEventHandler(this.FormMain_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
this.panel1.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FormMain());
}
private void Form1_Load(object sender, System.EventArgs e)
{
// GetAllUserInfo();
}
private void Server(bool IsServer)//开始或停止服务
{
if(IsServer)
this.sockUDP1.Listen(3211);
else
this.sockUDP1.CloseSock();
}
private void sockUDP1_DataArrival(byte[] Data, System.Net.IPAddress Ip, int Port)//当有数据到达后调用新的处理进程
{
DataArrivaldelegate outdelegate = new DataArrivaldelegate( DataArrival);
this.BeginInvoke (outdelegate, new object[]{ Data,Ip,Port});
}
private delegate void DataArrivaldelegate(byte[] Data, System.Net.IPAddress Ip, int Port);
private void DataArrival(byte[] Data, System.Net.IPAddress Ip, int Port) //当有数据到达后的处理进程
{
try
{
LanMsg.Controls.ClassMsg msg=new LanMsg.Controls.ClassSerializers().DeSerializeBinary((new System.IO.MemoryStream(Data))) as LanMsg.Controls.ClassMsg;
switch(msg.MsgInfoClass)
{
case 1://处理用户登录过程
NewUserLogin(msg,Ip,Port);
break;
case 2://用户询问自己是否在线,并更改其在线状态
updateUserState(msg,Ip, Port);//更新用户状态信息
break;
}
}
catch(Exception e)
{}
}
private void updateUserState(Controls.ClassMsg msg, System.Net.IPAddress Ip, int Port)//更新用户状态信息
{
try
{
//this.textBox1.AppendText ("用户"+ msg.ID +"状态更新\n");
string state=System.Text.Encoding.Unicode.GetString((msg.MsgContent ));
System.Windows.Forms.ListViewItem item=FindUser(msg.ID ,this.LV_OnlineUser );
if(item!=null)
{
item.SubItems[3].Text =state;
if(state=="0")
this.LV_OnlineUser.Items.Remove(item);
}
item=FindUser(msg.ID ,this.LV_SysUser );
if(item!=null)
{
item.SubItems[3].Text =state;
if(state=="0" && item.SubItems[4].Text =="10")
this.LV_SysUser.Items.Remove(item);
}
this.SendMsgToOne(Ip,Port,new Controls.ClassMsg( 2,"",null));//告诉用户在线
}
catch(Exception e){}
}
private void NewUserLogin(Controls.ClassMsg msg, System.Net.IPAddress Ip, int Port)//处理用户登录过程
{
try
{
// this.textBox1.AppendText ("用户"+ msg.ID +"登录\n");
ClassUserInfo selfInfo=new ClassUserInfo();//准备添加新用户的资料
selfInfo.ID=msg.ID;
selfInfo.UserName =msg.ID;
selfInfo.IP=Ip;
selfInfo.Port=Port;
selfInfo.State =1;
selfInfo.Dep =10;
selfInfo.AssemblyVersion=System.Text.Encoding.Unicode.GetString(msg.MsgContent);
System.Windows.Forms.ListViewItem item=FindUser(msg.ID ,this.LV_SysUser);
if(item!=null)//如果此用户是sysuser,那么更改其上线信息,并把他的所有联系人的信息发送给它
{
item.SubItems[1].Text=Ip.ToString();
item.SubItems[2].Text=Port.ToString();
item.SubItems[3].Text="1";//1表示用户在线状态为联机
item.SubItems[6].Text =selfInfo.AssemblyVersion;//更新其版本号
selfInfo.UserName =item.SubItems[5].Text;
selfInfo.Dep =Convert.ToInt32(item.SubItems[4].Text);
//在在线用户表中查找此用户是否存在,如果不存在则添加,如果存在就不做任何操作
System.Windows.Forms.ListViewItem items=FindUser(msg.ID ,this.LV_OnlineUser );
if(items!=null)//如果用户不在在线用户列表里面,则添加
{
items.SubItems[1].Text=Ip.ToString();
items.SubItems[2].Text=Port.ToString();
items.SubItems[3].Text="1";//1表示用户在线状态为联机
items.SubItems[6].Text =selfInfo.AssemblyVersion;//更新其版本号
}
else//如果是用户不在在线列表中,则添加
{
System.Windows.Forms.ListViewItem NewItem=new ListViewItem();
NewItem=item.Clone() as ListViewItem;
this.LV_OnlineUser.Items.Add(NewItem);
}
}
else//如果此用户不是sysuser,那么将其添加入系统用户列表与在线用户列表并更改其上线信息,并把他的所有联系人的信息发送给它
{
System.Windows.Forms.ListViewItem NewItem=new ListViewItem();
NewItem.Text=msg.ID;
NewItem.SubItems.Add(Ip.ToString());
NewItem.SubItems.Add(Port.ToString());
NewItem.SubItems.Add("1");//1表示用户在线状态为联机
NewItem.SubItems.Add("10");//10表示用户为未知组用户
NewItem.SubItems.Add(msg.ID);// 未知组用户的姓名均为ID
NewItem.SubItems.Add(selfInfo.AssemblyVersion);//表示用户软件版本号
this.LV_SysUser.Items.Add (NewItem);
this.LV_OnlineUser.Items.Add(NewItem.Clone() as ListViewItem);
}
//发送消息告诉用户已经登录到服务器,并将其服务器上的个人资料发回
LanMsg.Controls.ClassMsg ToOneMsg =new LanMsg.Controls.ClassMsg(1,"",new Controls.ClassSerializers().SerializeBinary(selfInfo).ToArray() );
this.SendMsgToOne(Ip,Port,ToOneMsg);
// this.textBox1.AppendText ("将其服务器上的个人资料发回"+ Ip.ToString() + Port.ToString() +msg.ID +"\n");
System.Threading.Thread.Sleep(100);
//发回此用户所有联系人的资料
LanMsg.Controls.ClassUsers allUsers=Users();//返回所有用户联系人的资料
System.Threading.Thread.Sleep(100);
ToOneMsg =new LanMsg.Controls.ClassMsg(4,"",new Controls.ClassSerializers().SerializeBinary(allUsers).ToArray());
this.SendMsgToOne(Ip,Port,ToOneMsg);
// this.textBox1.AppendText ("返回所有用户联系人的资料"+ msg.ID +"\n");
//将登录用户资料发送给其全部联系人,告之用户登录
System.Threading.Thread.Sleep(100);
ToOneMsg =new LanMsg.Controls.ClassMsg(3,"",new Controls.ClassSerializers().SerializeBinary(selfInfo).ToArray());
this.SendMsgToAll( ToOneMsg);
// this.textBox1.AppendText ("告之用户登录"+ msg.ID +"\n");
}
catch(Exception e){}
}
private LanMsg.Controls.ClassUsers Users()//返回所有用户联系人的资料
{
try
{
LanMsg.Controls.ClassUsers allUsers=new LanMsg.Controls.ClassUsers();
foreach(System.Windows.Forms.ListViewItem item in this.LV_SysUser.Items )
{
ClassUserInfo userInfo=new ClassUserInfo();
userInfo.ID=item.Text;
userInfo.IP=System.Net.IPAddress.Parse(item.SubItems[1].Text);
userInfo.Port =Convert.ToInt32(item.SubItems[2].Text) ;
userInfo.State =Convert.ToInt32(item.SubItems[3].Text) ;
userInfo.Dep =Convert.ToInt32(item.SubItems[4].Text) ;
userInfo.UserName = item.SubItems[5].Text;
userInfo.AssemblyVersion= item.SubItems[6].Text;
allUsers.add(userInfo);
}
return allUsers;
}
catch(Exception e){return null;}
}
private System.Windows.Forms.ListViewItem FindUser(string UserID,System.Windows.Forms.ListView LV)//在相应的ListView里查找用户
{
try
{
foreach(System.Windows.Forms.ListViewItem item in LV.Items)
if(item.Text.ToLower()==UserID.ToLower())//找到用户,说明是系统用户,返回它的值
return item;
return null;
}
catch(Exception e){return null;}
}
private void menuItemControlExit_Click(object sender, System.EventArgs e)
{
FormMain_Closing(sender,null);
}
private void FormMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(menuItemControlServer.Text=="停止服务(&S)")
if(MessageBox.Show("确定要关闭服务并退出程序吗?","提示",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question) ==System.Windows.Forms.DialogResult.Yes)
{
this.sockUDP1.CloseSock();
Application.Exit();
}
}
private void menuItemControlServer_Click(object sender, System.EventArgs e)
{
if (menuItemControlServer.Text=="开始服务(&B)")
{
menuItemControlServer.Text="停止服务(&S)";
Server(true);//开始服务
this.statusBar1.Text="服务已经启动";
}
else
{
menuItemControlServer.Text="开始服务(&B)";
Server(false);//停止服务
this.statusBar1.Text="服务已经关闭";
}
}
private void TimerCheckOnlineSta_Tick(object sender, System.EventArgs e)
{
CheckOnlineSta();//系统每隔一分钟检查一次用户在线状态,不在线的则删除并通知其联系人
}
private void CheckOnlineSta()//系统每隔一分钟检查一次用户在线状态,不在线的则删除并通知其联系人
{
try
{
foreach(System.Windows.Forms.ListViewItem item in this.LV_OnlineUser.Items)
{
if(item.SubItems[3].Text=="0")//如果用户已经脱机,则删除并通知其全部联系人
{
System.Windows.Forms.ListViewItem TempItem=FindUser(item.Text,this.LV_SysUser);//在系统用户表中查找此用户的信息
if(TempItem!=null)
{
if(item.SubItems[4].Text=="10")//如果部门为未知,则在系统用户表中删除此用户
this.LV_SysUser.Items.Remove(TempItem);
else//如果是本系统用户则更新状态
TempItem.SubItems[3].Text="0";//更新系统用户的在线状态
}
LanMsg.Controls.ClassMsg msg =new LanMsg.Controls.ClassMsg(0,item.Text, null);
SendMsgToAll(msg);//发送消息给所有此用户的联系人,告之用户掉线
this.LV_OnlineUser.Items.Remove(item);//在在线用户列表中删除此用户信息
}
else
{
item.SubItems[3].Text ="0";//假设此用户已经掉线
}
}
}
catch(Exception e){}
}
private void SendMsgToOne(System.Net.IPAddress ip,int port,Controls.ClassMsg msg)//发送消息给一个用户
{
try
{
System.IO.MemoryStream stream= new Controls.ClassSerializers().SerializeBinary(msg);
LanMsg.Controls.SockUDP udp=new LanMsg.Controls.SockUDP();
udp.Send(ip,port,stream.ToArray());
}
catch(Exception e){}
}
private void SendMsgToAll(Controls.ClassMsg msg)//发送消息给所有用户
{
try
{
foreach(System.Windows.Forms.ListViewItem item in this.LV_OnlineUser.Items)
{
System.Net.IPAddress ip=System.Net.IPAddress.Parse(item.SubItems[1].Text);
int port=Convert.ToInt32 (item.SubItems[2].Text);
System.IO.MemoryStream stream= new Controls.ClassSerializers().SerializeBinary(msg);
LanMsg.Controls.SockUDP udp=new LanMsg.Controls.SockUDP();
udp.Send(ip,port,stream.ToArray());
}
}
catch(Exception e){}
}
private void GetAllUserInfo() //读取数据库中所有用户数据到列表中
{
try
{
System.Data.OleDb.OleDbDataReader dr;
string SQLstr= "select Sys_Users.UserName as computer,Mp_EmpLoyee.DepID as Dept,Mp_EmpLoyee.EmpName as UserName from Sys_Users,Mp_EmpLoyee where Mp_EmpLoyee.EmpID=Sys_Users.EmpID and (Sys_Users.IsWork is null or Sys_Users.IsWork>0)";
dr=new ClassOptionData().ExSQLReDr(SQLstr);
while(dr.Read())
{
AllOneUserInfoToLV(LV_SysUser, Convert.ToString(dr["computer"]), "127.0.0.1", "0", "0",Convert.ToString(dr["dept"]), Convert.ToString(dr["UserName"]));
}
dr.Close();
}
catch(Exception e){}
}
private void AllOneUserInfoToLV( System.Windows.Forms.ListView LV, string Computer, string IpAddress,string port, string OnlineSta, string Dept, string UserName )//'处理新登录用户的信息数据)
{
try
{
System.Windows.Forms.ListViewItem NewItem =new ListViewItem();
NewItem.Text = Computer.Trim().ToLower(); // '添加用户计算机名与端口号信息
NewItem.SubItems.Add(IpAddress); //'添加用户IP地址信息
NewItem.SubItems.Add(port); // '添加用户端口信息
NewItem.SubItems.Add(OnlineSta);// '在线状态
NewItem.SubItems.Add(getDept(Dept));//'设置用户部门为未知
NewItem.SubItems.Add(UserName.Trim());//'添加用户姓名信息
NewItem.SubItems.Add("");//'添加用户姓名信息
LV.Items.Add(NewItem);// '添加此登录用户的所有信息到系统列表中
}
catch(Exception e){}
}
private string getDept(string Dept)
{
switch(Dept)
{
case "12":
return "0";//院领导
break;
case "8":
return "1";//院领导
break;
case "13":
return "1";//院领导
break;
case "14":
return "1";//院领导
break;
case "15":
return "1";//综合部
break;
case "3":
return "2";//财务部
break;
case "5":
return "3";//市场部
break;
case "2":
return "3";//市场部
break;
case "11":
return "4";//设备所
break;
case "9":
return "5";//传输所
break;
case "10":
return "6";//计算机所
break;
case "4":
return "7";//规划所
break;
case "16":
return "8";//无线所
break;
case "6":
return "9";//建筑分院
break;
}
return "10";
}
private void menuItemControl_Click(object sender, System.EventArgs e)
{
}
private void notifyIcon1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
}
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
this.WindowState=System.Windows.Forms.FormWindowState.Maximized ;
this.Show();
this.Activate();
}
private void FormMain_Resize(object sender, System.EventArgs e)
{
if(this.WindowState==System.Windows.Forms.FormWindowState.Minimized)
this.Hide();
}
}
}
SQL Server 资料
CREATE DATABASE TeachingLib
ON
(
NAME='TeachingLib_data', --主数据文件的逻辑名
FILENAME='D:\SQL\TeachingLib_data.mdf', --主数据文件的物理名
SIZE=3MB, http://passport.youkuaiyun.com/account/active?user=yangyangli123&active=3C4AB36C50A261894CB61A29E45D2CF1 --主数据文件初始大小
MAXSIZE=10MB, --主数据文件增长的最大值
FILEGROWTH=10% --主数据文件的增长率
)
LOG ON
(
NAME='TeachingLib_log',
FILENAME='D:\SQL\TeachingLib_log.ldf'
)
GO
用于定义表一级的完整性约束,一般包括:
PRIMARY KEY约束(复合属性构成的主关键字说明)
FOREIGN KEY约束(外部关键字及参照关系说明)
CHECK约束(同时涉及到多个属性的域完整性约束)
删除属性
删除订购单关系中的“完成日期”属性:
ALTER TABLE 订购单 DROP COLUMN 完成日期
注意:有些系统的ALTER TABLE命令不允许删除属性,如果必须要删除属性,一般步骤是:先将旧表中的数据备份,然后删除旧表、并建立新表,最后将原来的数据恢复到新表中。