FormMain.cs
上传用户:lqb116
上传日期:2014-04-04
资源大小:2712k
文件大小:55k
源码类别:

P2P编程

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using DevComponents.DotNetBar;
  7. using DevComponents.DotNetBar.Rendering;
  8. using System.Net;
  9. using LanMsg.CustomUIControls;
  10. namespace LanMsg
  11. {
  12. /// <summary>
  13. /// Form2 的摘要说明。
  14. /// </summary>
  15. public class FormMain :DevComponents.DotNetBar.Office2007RibbonForm //System.Windows.Forms.Form  
  16. {
  17. private DevComponents.DotNetBar.TabItem tabItem1;
  18. private DevComponents.DotNetBar.ItemContainer menuFileContainer;
  19. private DevComponents.DotNetBar.ItemContainer menuFileTwoColumnContainer;
  20. private DevComponents.DotNetBar.ItemContainer menuFileItems;
  21. private DevComponents.DotNetBar.ButtonItem buttonFileSaveAs;
  22. private DevComponents.DotNetBar.ItemContainer menuFileMRU;
  23. private DevComponents.DotNetBar.LabelItem labelItem8;
  24. private DevComponents.DotNetBar.ItemContainer menuFileBottomContainer;
  25. private DevComponents.DotNetBar.ButtonItem buttonOptions;
  26. private DevComponents.DotNetBar.ButtonItem buttonExit;
  27. private DevComponents.DotNetBar.Bar bar1;
  28. private DevComponents.DotNetBar.LabelItem labelStatus;
  29. internal DevComponents.DotNetBar.LabelItem labelPosition;
  30. private DevComponents.DotNetBar.RibbonControl ribbonControl1;
  31. private DevComponents.DotNetBar.RibbonTabItemGroup ribbonTabItemGroup1;
  32. internal System.Windows.Forms.ImageList imageList1;
  33. private System.ComponentModel.IContainer components;
  34. private DevComponents.DotNetBar.ButtonItem butMenuMain;
  35. private DevComponents.DotNetBar.ButtonItem butMeState;
  36. private DevComponents.DotNetBar.ButtonItem butMenuMainExit;
  37. private DevComponents.DotNetBar.RibbonPanel ribbonPanel1;
  38. private System.Windows.Forms.Panel panel1;
  39. private System.Windows.Forms.Panel panel2;
  40. private System.Windows.Forms.Panel panel3;
  41. internal System.Windows.Forms.TreeView TvUsers;
  42. private DevComponents.DotNetBar.RibbonTabItem LabselfName;
  43. public ClassUserInfo selfInfo=new ClassUserInfo();
  44. internal System.Windows.Forms.ImageList imageListFace;
  45. private System.Windows.Forms.Timer timerCheckOnlinState;//保存用户自己的信息
  46. public Controls.ClassForms forms=new LanMsg.Controls.ClassForms(); 
  47. private IPAddress ServerIP=IPAddress.Parse("127.0.0.1");//服务器IP192.168.1.100192.168.2.3
  48. private int ServerPort=3211;//服务器端口
  49. private LanMsg.Controls.SockUDP sockUDP1;
  50. private DevComponents.DotNetBar.ButtonItem butMsgSendGourp;
  51. private System.Windows.Forms.NotifyIcon NotifyIcon;
  52. private DevComponents.DotNetBar.ButtonItem butMsgMis;
  53. public  Controls.ClassUsers MyUsers =new  Controls.ClassUsers();
  54. private DevComponents.DotNetBar.ButtonItem buttonItemState1;
  55. private DevComponents.DotNetBar.ButtonItem buttonItemState2;
  56. private DevComponents.DotNetBar.ButtonItem buttonItemState3;
  57. private DevComponents.DotNetBar.ButtonItem buttonItemState4;
  58. private DevComponents.DotNetBar.ButtonItem buttonItemState5;
  59. private DevComponents.DotNetBar.ButtonItem buttonItemState6;
  60. private DevComponents.DotNetBar.ButtonItem buttonItemClose;
  61. private DevComponents.DotNetBar.ButtonItem butForFormSetting;
  62. private LanMsg.ClassFormMain formmain=new ClassFormMain();
  63.         public  bool IsWindowsExit=false;
  64. public  LanMsg.ClassOptionData optDB;
  65. private DevComponents.DotNetBar.ButtonItem butSendMsg;
  66. private DevComponents.DotNetBar.ButtonItem butOpenShared;
  67. private DevComponents.DotNetBar.ButtonItem butSendFile;
  68. private DevComponents.DotNetBar.ButtonItem ButAbout;
  69. public FormMain()
  70. {
  71. //
  72. // Windows 窗体设计器支持所必需的
  73. //
  74. InitializeComponent();
  75. //DisableX(this);
  76. //
  77. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  78. //
  79. for(int i=0;i<96;i++)
  80. this.imageListFace.Images.Add(System.Drawing.Image.FromStream (System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("LanMsg.Resources."+ i.ToString()  +".gif")) );
  81. }
  82. /// <summary>
  83. /// 清理所有正在使用的资源。
  84. /// </summary>
  85. protected override void Dispose( bool disposing )
  86. {
  87. this.sendMsgToServer(new LanMsg.Controls.ClassMsg(2,selfInfo.ID,System.Text.Encoding.Unicode.GetBytes("0")));
  88. this.sendMsgToAllUser(new LanMsg.Controls.ClassMsg(0,this.selfInfo.ID, null));
  89. this.sockUDP1.CloseSock();
  90. AppExit();
  91. if( disposing )
  92. {
  93. if(components != null)
  94. {
  95. components.Dispose();
  96. }
  97. }
  98. base.Dispose( disposing );
  99. }
  100. #region Windows 窗体设计器生成的代码
  101. /// <summary>
  102. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  103. /// 此方法的内容。
  104. /// </summary>
  105. private void InitializeComponent()
  106. {
  107. this.components = new System.ComponentModel.Container();
  108. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormMain));
  109. this.tabItem1 = new DevComponents.DotNetBar.TabItem(this.components);
  110. this.menuFileContainer = new DevComponents.DotNetBar.ItemContainer();
  111. this.menuFileTwoColumnContainer = new DevComponents.DotNetBar.ItemContainer();
  112. this.menuFileItems = new DevComponents.DotNetBar.ItemContainer();
  113. this.menuFileMRU = new DevComponents.DotNetBar.ItemContainer();
  114. this.menuFileBottomContainer = new DevComponents.DotNetBar.ItemContainer();
  115. this.buttonOptions = new DevComponents.DotNetBar.ButtonItem();
  116. this.buttonExit = new DevComponents.DotNetBar.ButtonItem();
  117. this.buttonFileSaveAs = new DevComponents.DotNetBar.ButtonItem();
  118. this.labelItem8 = new DevComponents.DotNetBar.LabelItem();
  119. this.bar1 = new DevComponents.DotNetBar.Bar();
  120. this.labelStatus = new DevComponents.DotNetBar.LabelItem();
  121. this.labelPosition = new DevComponents.DotNetBar.LabelItem();
  122. this.ribbonControl1 = new DevComponents.DotNetBar.RibbonControl();
  123. this.ribbonPanel1 = new DevComponents.DotNetBar.RibbonPanel();
  124. this.LabselfName = new DevComponents.DotNetBar.RibbonTabItem();
  125. this.butMenuMain = new DevComponents.DotNetBar.ButtonItem();
  126. this.butSendMsg = new DevComponents.DotNetBar.ButtonItem();
  127. this.butSendFile = new DevComponents.DotNetBar.ButtonItem();
  128. this.butOpenShared = new DevComponents.DotNetBar.ButtonItem();
  129. this.butMeState = new DevComponents.DotNetBar.ButtonItem();
  130. this.buttonItemState1 = new DevComponents.DotNetBar.ButtonItem();
  131. this.buttonItemState2 = new DevComponents.DotNetBar.ButtonItem();
  132. this.buttonItemState3 = new DevComponents.DotNetBar.ButtonItem();
  133. this.buttonItemState4 = new DevComponents.DotNetBar.ButtonItem();
  134. this.buttonItemState5 = new DevComponents.DotNetBar.ButtonItem();
  135. this.buttonItemState6 = new DevComponents.DotNetBar.ButtonItem();
  136. this.butMsgSendGourp = new DevComponents.DotNetBar.ButtonItem();
  137. this.butMsgMis = new DevComponents.DotNetBar.ButtonItem();
  138. this.butForFormSetting = new DevComponents.DotNetBar.ButtonItem();
  139. this.buttonItemClose = new DevComponents.DotNetBar.ButtonItem();
  140. this.butMenuMainExit = new DevComponents.DotNetBar.ButtonItem();
  141. this.ButAbout = new DevComponents.DotNetBar.ButtonItem();
  142. this.ribbonTabItemGroup1 = new DevComponents.DotNetBar.RibbonTabItemGroup();
  143. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  144. this.panel1 = new System.Windows.Forms.Panel();
  145. this.panel2 = new System.Windows.Forms.Panel();
  146. this.panel3 = new System.Windows.Forms.Panel();
  147. this.TvUsers = new System.Windows.Forms.TreeView();
  148. this.imageListFace = new System.Windows.Forms.ImageList(this.components);
  149. this.timerCheckOnlinState = new System.Windows.Forms.Timer(this.components);
  150. this.sockUDP1 = new LanMsg.Controls.SockUDP(this.components);
  151. this.NotifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
  152. ((System.ComponentModel.ISupportInitialize)(this.bar1)).BeginInit();
  153. this.ribbonControl1.SuspendLayout();
  154. this.SuspendLayout();
  155. // 
  156. // tabItem1
  157. // 
  158. this.tabItem1.Name = "tabItem1";
  159. this.tabItem1.Text = "tabItem1";
  160. // 
  161. // menuFileContainer
  162. // 
  163. this.menuFileContainer.LayoutOrientation = DevComponents.DotNetBar.eOrientation.Vertical;
  164. this.menuFileContainer.MinimumSize = new System.Drawing.Size(0, 0);
  165. this.menuFileContainer.Name = "menuFileContainer";
  166. this.menuFileContainer.SubItems.AddRange(new DevComponents.DotNetBar.BaseItem[] {
  167. this.menuFileTwoColumnContainer,
  168. this.menuFileBottomContainer});
  169. // 
  170. // menuFileTwoColumnContainer
  171. // 
  172. // 
  173. // menuFileTwoColumnContainer.BackgroundStyle
  174. // 
  175. this.menuFileTwoColumnContainer.BackgroundStyle.PaddingBottom = 2;
  176. this.menuFileTwoColumnContainer.BackgroundStyle.PaddingLeft = 2;
  177. this.menuFileTwoColumnContainer.BackgroundStyle.PaddingRight = 2;
  178. this.menuFileTwoColumnContainer.BackgroundStyle.PaddingTop = 2;
  179. this.menuFileTwoColumnContainer.ItemSpacing = 0;
  180. this.menuFileTwoColumnContainer.MinimumSize = new System.Drawing.Size(0, 0);
  181. this.menuFileTwoColumnContainer.Name = "menuFileTwoColumnContainer";
  182. this.menuFileTwoColumnContainer.SubItems.AddRange(new DevComponents.DotNetBar.BaseItem[] {
  183.  this.menuFileItems,
  184.  this.menuFileMRU});
  185. // 
  186. // menuFileItems
  187. // 
  188. this.menuFileItems.MinimumSize = new System.Drawing.Size(0, 0);
  189. this.menuFileItems.Name = "menuFileItems";
  190. // 
  191. // menuFileMRU
  192. // 
  193. this.menuFileMRU.LayoutOrientation = DevComponents.DotNetBar.eOrientation.Vertical;
  194. this.menuFileMRU.MinimumSize = new System.Drawing.Size(180, 0);
  195. this.menuFileMRU.Name = "menuFileMRU";
  196. // 
  197. // menuFileBottomContainer
  198. // 
  199. this.menuFileBottomContainer.HorizontalItemAlignment = DevComponents.DotNetBar.eHorizontalItemsAlignment.Right;
  200. this.menuFileBottomContainer.MinimumSize = new System.Drawing.Size(0, 0);
  201. this.menuFileBottomContainer.Name = "menuFileBottomContainer";
  202. this.menuFileBottomContainer.SubItems.AddRange(new DevComponents.DotNetBar.BaseItem[] {
  203.   this.buttonOptions,
  204.   this.buttonExit});
  205. // 
  206. // buttonOptions
  207. // 
  208. this.buttonOptions.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText;
  209. this.buttonOptions.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
  210. this.buttonOptions.Image = ((System.Drawing.Image)(resources.GetObject("buttonOptions.Image")));
  211. this.buttonOptions.Name = "buttonOptions";
  212. this.buttonOptions.SubItemsExpandWidth = 24;
  213. this.buttonOptions.Text = "RibbonPad Opt&ions";
  214. // 
  215. // buttonExit
  216. // 
  217. this.buttonExit.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText;
  218. this.buttonExit.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
  219. this.buttonExit.Image = ((System.Drawing.Image)(resources.GetObject("buttonExit.Image")));
  220. this.buttonExit.Name = "buttonExit";
  221. this.buttonExit.SubItemsExpandWidth = 24;
  222. this.buttonExit.Text = "E&xit RibbonPad";
  223. // 
  224. // buttonFileSaveAs
  225. // 
  226. this.buttonFileSaveAs.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText;
  227. this.buttonFileSaveAs.Image = ((System.Drawing.Image)(resources.GetObject("buttonFileSaveAs.Image")));
  228. this.buttonFileSaveAs.Name = "buttonFileSaveAs";
  229. this.buttonFileSaveAs.SubItemsExpandWidth = 24;
  230. this.buttonFileSaveAs.Text = "&Save As...";
  231. // 
  232. // labelItem8
  233. // 
  234. this.labelItem8.BorderSide = DevComponents.DotNetBar.eBorderSide.Bottom;
  235. this.labelItem8.BorderType = DevComponents.DotNetBar.eBorderType.Etched;
  236. this.labelItem8.Name = "labelItem8";
  237. this.labelItem8.PaddingBottom = 2;
  238. this.labelItem8.PaddingTop = 2;
  239. this.labelItem8.Stretch = true;
  240. this.labelItem8.Text = "Recent Documents";
  241. // 
  242. // bar1
  243. // 
  244. this.bar1.AccessibleDescription = "DotNetBar Bar (bar1)";
  245. this.bar1.AccessibleName = "DotNetBar Bar";
  246. this.bar1.AccessibleRole = System.Windows.Forms.AccessibleRole.StatusBar;
  247. this.bar1.AntiAlias = true;
  248. this.bar1.Dock = System.Windows.Forms.DockStyle.Bottom;
  249. this.bar1.GrabHandleStyle = DevComponents.DotNetBar.eGrabHandleStyle.ResizeHandle;
  250. this.bar1.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] {
  251. this.labelStatus,
  252. this.labelPosition});
  253. this.bar1.ItemSpacing = 2;
  254. this.bar1.Location = new System.Drawing.Point(2, 325);
  255. this.bar1.Name = "bar1";
  256. this.bar1.Size = new System.Drawing.Size(172, 17);
  257. this.bar1.Stretch = true;
  258. this.bar1.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2007;
  259. this.bar1.TabIndex = 10;
  260. this.bar1.TabStop = false;
  261. this.bar1.Text = "barStatus";
  262. // 
  263. // labelStatus
  264. // 
  265. this.labelStatus.BorderType = DevComponents.DotNetBar.eBorderType.None;
  266. this.labelStatus.Name = "labelStatus";
  267. this.labelStatus.PaddingLeft = 2;
  268. this.labelStatus.PaddingRight = 2;
  269. this.labelStatus.SingleLineColor = System.Drawing.Color.FromArgb(((System.Byte)(59)), ((System.Byte)(97)), ((System.Byte)(156)));
  270. this.labelStatus.Stretch = true;
  271. // 
  272. // labelPosition
  273. // 
  274. this.labelPosition.BorderType = DevComponents.DotNetBar.eBorderType.None;
  275. this.labelPosition.Name = "labelPosition";
  276. this.labelPosition.PaddingLeft = 2;
  277. this.labelPosition.PaddingRight = 2;
  278. this.labelPosition.SingleLineColor = System.Drawing.Color.FromArgb(((System.Byte)(59)), ((System.Byte)(97)), ((System.Byte)(156)));
  279. this.labelPosition.Width = 100;
  280. // 
  281. // ribbonControl1
  282. // 
  283. this.ribbonControl1.BackColor = System.Drawing.SystemColors.Control;
  284. this.ribbonControl1.CaptionVisible = true;
  285. this.ribbonControl1.CategorizeMode = DevComponents.DotNetBar.eCategorizeMode.Categories;
  286. this.ribbonControl1.Controls.Add(this.ribbonPanel1);
  287. this.ribbonControl1.Dock = System.Windows.Forms.DockStyle.Top;
  288. this.ribbonControl1.DockPadding.Bottom = 2;
  289. this.ribbonControl1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  290. this.ribbonControl1.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] {
  291.   this.LabselfName});
  292. this.ribbonControl1.KeyTipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  293. this.ribbonControl1.Location = new System.Drawing.Point(2, 2);
  294. this.ribbonControl1.MdiSystemItemVisible = false;
  295. this.ribbonControl1.Name = "ribbonControl1";
  296. this.ribbonControl1.QuickToolbarItems.AddRange(new DevComponents.DotNetBar.BaseItem[] {
  297.   this.butMenuMain});
  298. this.ribbonControl1.RibbonStripIndent = 55;
  299. this.ribbonControl1.Size = new System.Drawing.Size(172, 46);
  300. this.ribbonControl1.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2007;
  301. this.ribbonControl1.TabGroupHeight = 14;
  302. this.ribbonControl1.TabGroups.AddRange(new DevComponents.DotNetBar.RibbonTabItemGroup[] {
  303. this.ribbonTabItemGroup1});
  304. this.ribbonControl1.TabGroupsVisible = true;
  305. this.ribbonControl1.TabIndex = 11;
  306. // 
  307. // ribbonPanel1
  308. // 
  309. this.ribbonPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007;
  310. this.ribbonPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
  311. this.ribbonPanel1.DockPadding.Bottom = 3;
  312. this.ribbonPanel1.DockPadding.Left = 3;
  313. this.ribbonPanel1.DockPadding.Right = 3;
  314. this.ribbonPanel1.Location = new System.Drawing.Point(0, 48);
  315. this.ribbonPanel1.Name = "ribbonPanel1";
  316. this.ribbonPanel1.Size = new System.Drawing.Size(172, 0);
  317. this.ribbonPanel1.TabIndex = 1;
  318. // 
  319. // LabselfName
  320. // 
  321. this.LabselfName.Checked = true;
  322. this.LabselfName.Name = "LabselfName";
  323. this.LabselfName.Panel = this.ribbonPanel1;
  324. this.LabselfName.Text = "正在登录...";
  325. this.LabselfName.TextChanged += new System.EventHandler(this.LabselfName_TextChanged);
  326. // 
  327. // butMenuMain
  328. // 
  329. this.butMenuMain.Image = ((System.Drawing.Image)(resources.GetObject("butMenuMain.Image")));
  330. this.butMenuMain.Name = "butMenuMain";
  331. this.butMenuMain.SubItems.AddRange(new DevComponents.DotNetBar.BaseItem[] {
  332.   this.butSendMsg,
  333.   this.butSendFile,
  334.   this.butOpenShared,
  335.   this.butMeState,
  336.   this.butMsgSendGourp,
  337.   this.butMsgMis,
  338.   this.butForFormSetting,
  339.   this.buttonItemClose,
  340.   this.butMenuMainExit,
  341.   this.ButAbout});
  342. this.butMenuMain.Text = "buttonItem1";
  343. this.butMenuMain.PopupClose += new System.EventHandler(this.butMenuMain_PopupClose);
  344. // 
  345. // butSendMsg
  346. // 
  347. this.butSendMsg.Name = "butSendMsg";
  348. this.butSendMsg.Text = "发送消息(&M)";
  349. this.butSendMsg.Visible = false;
  350. this.butSendMsg.Click += new System.EventHandler(this.butSendMsg_Click);
  351. // 
  352. // butSendFile
  353. // 
  354. this.butSendFile.Name = "butSendFile";
  355. this.butSendFile.Text = "发送文件(&F)";
  356. this.butSendFile.Visible = false;
  357. this.butSendFile.Click += new System.EventHandler(this.butSendFile_Click);
  358. // 
  359. // butOpenShared
  360. // 
  361. this.butOpenShared.Name = "butOpenShared";
  362. this.butOpenShared.Text = "打开收件箱";
  363. this.butOpenShared.Visible = false;
  364. this.butOpenShared.Click += new System.EventHandler(this.butOpenShared_Click);
  365. // 
  366. // butMeState
  367. // 
  368. this.butMeState.BeginGroup = true;
  369. this.butMeState.Image = ((System.Drawing.Image)(resources.GetObject("butMeState.Image")));
  370. this.butMeState.Name = "butMeState";
  371. this.butMeState.SubItems.AddRange(new DevComponents.DotNetBar.BaseItem[] {
  372.  this.buttonItemState1,
  373.  this.buttonItemState2,
  374.  this.buttonItemState3,
  375.  this.buttonItemState4,
  376.  this.buttonItemState5,
  377.  this.buttonItemState6});
  378. this.butMeState.Text = "我的状态";
  379. // 
  380. // buttonItemState1
  381. // 
  382. this.buttonItemState1.Checked = true;
  383. this.buttonItemState1.Name = "buttonItemState1";
  384. this.buttonItemState1.Text = "联机";
  385. this.buttonItemState1.Click += new System.EventHandler(this.buttonItemState1_Click);
  386. // 
  387. // buttonItemState2
  388. // 
  389. this.buttonItemState2.Name = "buttonItemState2";
  390. this.buttonItemState2.Text = "忙碌";
  391. this.buttonItemState2.Click += new System.EventHandler(this.buttonItemState2_Click);
  392. // 
  393. // buttonItemState3
  394. // 
  395. this.buttonItemState3.Name = "buttonItemState3";
  396. this.buttonItemState3.Text = "接听电话";
  397. this.buttonItemState3.Click += new System.EventHandler(this.buttonItemState3_Click);
  398. // 
  399. // buttonItemState4
  400. // 
  401. this.buttonItemState4.Name = "buttonItemState4";
  402. this.buttonItemState4.Text = "离开";
  403. this.buttonItemState4.Click += new System.EventHandler(this.buttonItemState4_Click);
  404. // 
  405. // buttonItemState5
  406. // 
  407. this.buttonItemState5.Name = "buttonItemState5";
  408. this.buttonItemState5.Text = "外出就餐";
  409. this.buttonItemState5.Click += new System.EventHandler(this.buttonItemState5_Click);
  410. // 
  411. // buttonItemState6
  412. // 
  413. this.buttonItemState6.Name = "buttonItemState6";
  414. this.buttonItemState6.Text = "脱机";
  415. this.buttonItemState6.Visible = false;
  416. // 
  417. // butMsgSendGourp
  418. // 
  419. this.butMsgSendGourp.BeginGroup = true;
  420. this.butMsgSendGourp.Image = ((System.Drawing.Image)(resources.GetObject("butMsgSendGourp.Image")));
  421. this.butMsgSendGourp.Name = "butMsgSendGourp";
  422. this.butMsgSendGourp.Text = "群发消息";
  423. this.butMsgSendGourp.Click += new System.EventHandler(this.butMsgSendGourp_Click);
  424. // 
  425. // butMsgMis
  426. // 
  427. this.butMsgMis.Icon = ((System.Drawing.Icon)(resources.GetObject("butMsgMis.Icon")));
  428. this.butMsgMis.Name = "butMsgMis";
  429. this.butMsgMis.Text = "信息管理器";
  430. this.butMsgMis.Click += new System.EventHandler(this.butMsgMis_Click);
  431. // 
  432. // butForFormSetting
  433. // 
  434. this.butForFormSetting.Image = ((System.Drawing.Image)(resources.GetObject("butForFormSetting.Image")));
  435. this.butForFormSetting.Name = "butForFormSetting";
  436. this.butForFormSetting.Text = "设置";
  437. this.butForFormSetting.Visible = false;
  438. // 
  439. // buttonItemClose
  440. // 
  441. this.buttonItemClose.Name = "buttonItemClose";
  442. this.buttonItemClose.Text = "关闭";
  443. this.buttonItemClose.Visible = false;
  444. // 
  445. // butMenuMainExit
  446. // 
  447. this.butMenuMainExit.Name = "butMenuMainExit";
  448. this.butMenuMainExit.Text = "退出";
  449. this.butMenuMainExit.Visible = false;
  450. this.butMenuMainExit.Click += new System.EventHandler(this.butMenuMainExit_Click);
  451. // 
  452. // ButAbout
  453. // 
  454. this.ButAbout.BeginGroup = true;
  455. this.ButAbout.Name = "ButAbout";
  456. this.ButAbout.Text = "关于";
  457. this.ButAbout.Click += new System.EventHandler(this.ButAbout_Click);
  458. // 
  459. // ribbonTabItemGroup1
  460. // 
  461. this.ribbonTabItemGroup1.Color = DevComponents.DotNetBar.eRibbonTabGroupColor.Orange;
  462. this.ribbonTabItemGroup1.GroupTitle = "Tab Group";
  463. // 
  464. // ribbonTabItemGroup1.Style
  465. // 
  466. this.ribbonTabItemGroup1.Style.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(240)), ((System.Byte)(158)), ((System.Byte)(159)));
  467. this.ribbonTabItemGroup1.Style.BackColor2 = System.Drawing.Color.FromArgb(((System.Byte)(249)), ((System.Byte)(225)), ((System.Byte)(226)));
  468. this.ribbonTabItemGroup1.Style.BackColorGradientAngle = 90;
  469. this.ribbonTabItemGroup1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid;
  470. this.ribbonTabItemGroup1.Style.BorderBottomWidth = 1;
  471. this.ribbonTabItemGroup1.Style.BorderColor = System.Drawing.Color.FromArgb(((System.Byte)(154)), ((System.Byte)(58)), ((System.Byte)(59)));
  472. this.ribbonTabItemGroup1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid;
  473. this.ribbonTabItemGroup1.Style.BorderLeftWidth = 1;
  474. this.ribbonTabItemGroup1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid;
  475. this.ribbonTabItemGroup1.Style.BorderRightWidth = 1;
  476. this.ribbonTabItemGroup1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid;
  477. this.ribbonTabItemGroup1.Style.BorderTopWidth = 1;
  478. this.ribbonTabItemGroup1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
  479. this.ribbonTabItemGroup1.Style.TextColor = System.Drawing.Color.Black;
  480. this.ribbonTabItemGroup1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
  481. // 
  482. // imageList1
  483. // 
  484. this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
  485. this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
  486. this.imageList1.TransparentColor = System.Drawing.Color.White;
  487. // 
  488. // panel1
  489. // 
  490. this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
  491. this.panel1.Location = new System.Drawing.Point(2, 48);
  492. this.panel1.Name = "panel1";
  493. this.panel1.Size = new System.Drawing.Size(4, 277);
  494. this.panel1.TabIndex = 12;
  495. // 
  496. // panel2
  497. // 
  498. this.panel2.Dock = System.Windows.Forms.DockStyle.Right;
  499. this.panel2.Location = new System.Drawing.Point(170, 48);
  500. this.panel2.Name = "panel2";
  501. this.panel2.Size = new System.Drawing.Size(4, 277);
  502. this.panel2.TabIndex = 13;
  503. // 
  504. // panel3
  505. // 
  506. this.panel3.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
  507. this.panel3.Dock = System.Windows.Forms.DockStyle.Top;
  508. this.panel3.Location = new System.Drawing.Point(6, 48);
  509. this.panel3.Name = "panel3";
  510. this.panel3.Size = new System.Drawing.Size(164, 4);
  511. this.panel3.TabIndex = 14;
  512. // 
  513. // TvUsers
  514. // 
  515. this.TvUsers.BackColor = System.Drawing.Color.White;
  516. this.TvUsers.BorderStyle = System.Windows.Forms.BorderStyle.None;
  517. this.TvUsers.Dock = System.Windows.Forms.DockStyle.Fill;
  518. this.TvUsers.ImageIndex = 14;
  519. this.TvUsers.ImageList = this.imageList1;
  520. this.TvUsers.ItemHeight = 20;
  521. this.TvUsers.Location = new System.Drawing.Point(6, 52);
  522. this.TvUsers.Name = "TvUsers";
  523. this.TvUsers.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
  524. new System.Windows.Forms.TreeNode("部门(0/0)"),
  525. new System.Windows.Forms.TreeNode("部门(0/0)"),
  526. new System.Windows.Forms.TreeNode("部门(0/0)"),
  527. new System.Windows.Forms.TreeNode("部门(0/0)"),
  528. new System.Windows.Forms.TreeNode("部门(0/0)"),
  529. new System.Windows.Forms.TreeNode("部门(0/0)"),
  530. new System.Windows.Forms.TreeNode("部门(0/0)"),
  531. new System.Windows.Forms.TreeNode("部门(0/0)"),
  532. new System.Windows.Forms.TreeNode("部门(0/0)"),
  533. new System.Windows.Forms.TreeNode("部门(0/0)"),
  534. new System.Windows.Forms.TreeNode("未知(0/0)")});
  535. this.TvUsers.SelectedImageIndex = 15;
  536. this.TvUsers.ShowLines = false;
  537. this.TvUsers.ShowRootLines = false;
  538. this.TvUsers.Size = new System.Drawing.Size(164, 273);
  539. this.TvUsers.TabIndex = 27;
  540. this.TvUsers.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.TvUsers_AfterCheck);
  541. this.TvUsers.DoubleClick += new System.EventHandler(this.TvUsers_DoubleClick);
  542. this.TvUsers.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TvUsers_AfterSelect);
  543. this.TvUsers.MouseMove += new System.Windows.Forms.MouseEventHandler(this.TvUsers_MouseMove);
  544. // 
  545. // imageListFace
  546. // 
  547. this.imageListFace.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
  548. this.imageListFace.ImageSize = new System.Drawing.Size(20, 20);
  549. this.imageListFace.TransparentColor = System.Drawing.Color.White;
  550. // 
  551. // timerCheckOnlinState
  552. // 
  553. this.timerCheckOnlinState.Interval = 56000;
  554. this.timerCheckOnlinState.Tick += new System.EventHandler(this.timerCheckOnlinState_Tick);
  555. // 
  556. // sockUDP1
  557. // 
  558. this.sockUDP1.Server = ((System.Net.IPEndPoint)(resources.GetObject("sockUDP1.Server")));
  559. this.sockUDP1.DataArrival += new LanMsg.Controls.SockUDP.DataArrivalEventHandler(this.sockUDP1_DataArrival);
  560. // 
  561. // NotifyIcon
  562. // 
  563. this.NotifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("NotifyIcon.Icon")));
  564. this.NotifyIcon.Text = "LanMsg";
  565. this.NotifyIcon.Visible = true;
  566. this.NotifyIcon.Click += new System.EventHandler(this.NotifyIcon_Click);
  567. // 
  568. // FormMain
  569. // 
  570. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  571. this.BackColor = System.Drawing.SystemColors.Control;
  572. this.ClientSize = new System.Drawing.Size(176, 344);
  573. this.Controls.Add(this.TvUsers);
  574. this.Controls.Add(this.panel3);
  575. this.Controls.Add(this.panel2);
  576. this.Controls.Add(this.panel1);
  577. this.Controls.Add(this.ribbonControl1);
  578. this.Controls.Add(this.bar1);
  579. this.DockPadding.Bottom = 2;
  580. this.DockPadding.Left = 2;
  581. this.DockPadding.Right = 2;
  582. this.DockPadding.Top = 2;
  583. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  584. this.MinimumSize = new System.Drawing.Size(160, 344);
  585. this.Name = "FormMain";
  586. this.Opacity = 0;
  587. this.ShowInTaskbar = false;
  588. this.Text = "设计院LanMsg";
  589. this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
  590. this.Closing += new System.ComponentModel.CancelEventHandler(this.FormMain_Closing);
  591. this.SizeChanged += new System.EventHandler(this.FormMain_SizeChanged);
  592. this.Load += new System.EventHandler(this.FormMain_Load);
  593. ((System.ComponentModel.ISupportInitialize)(this.bar1)).EndInit();
  594. this.ribbonControl1.ResumeLayout(false);
  595. this.ResumeLayout(false);
  596. }
  597. #endregion
  598. private void sockUDP1_DataArrival(byte[] Data, System.Net.IPAddress Ip, int Port)
  599. {
  600. DataArrivaldelegate outdelegate = new DataArrivaldelegate( DataArrival); 
  601. this.BeginInvoke (outdelegate, new object[]{ Data,Ip,Port}); 
  602. }
  603. private delegate void DataArrivaldelegate(byte[] Data, System.Net.IPAddress Ip, int Port); 
  604. private void DataArrival(byte[] Data, System.Net.IPAddress Ip, int Port) 
  605. LanMsg.Controls.ClassMsg msg=new  ClassSerializers().DeSerializeBinary((new System.IO.MemoryStream(Data))) as LanMsg.Controls.ClassMsg;
  606. switch(msg.MsgInfoClass)
  607. {
  608. case 0://有用户离线
  609. userSingnOut(msg.ID );//处理用户离线
  610. break;
  611. case 1://服务器告诉自己已经登录,登录过程
  612. SuccessLogin(msg);
  613. break;
  614. case 2://服务器告诉用户自己目前在线
  615. updateSelfState();//更新当前用户在线状态
  616. break;
  617. case 3://服务器告诉用户有新的联系人登录
  618. NewUserLogin(new  ClassSerializers().DeSerializeBinary((new System.IO.MemoryStream(msg.MsgContent ))) as ClassUserInfo );//添加新登录的用户资料
  619. break;
  620. case 4://收到用户部分联系人的资料
  621. UsersDataArrival((new  ClassSerializers().DeSerializeBinary((new System.IO.MemoryStream(msg.MsgContent ))) as Controls.ClassUsers));//收到用户所有联系人的资料
  622. break;
  623. case 5://收到用户联系人发送来的对话消息
  624. UserChatArrival(msg,Ip,Port);//处理对话消息
  625. break;
  626. case 6://联系人返回已经收到刚才发送的对话消息
  627. returnChatArrival(msg.ID );//联系人返回已经收到刚才发送的对话消息
  628. break;
  629. case 7:
  630. //收到联系人发送来的群发通知消息
  631. noticeArrival(msg,Ip,Port);//处理联系人发送来的群发通知消息
  632. break;
  633. case 8://对方要求UDP打洞
  634.                     UDPNatTranslators(msg,Ip,Port);
  635. break;
  636. case 10://收到联系人发出发送文件请求
  637. sendFileRequest(msg,Ip,Port);
  638. break;
  639.                 case 11://收到联系人发送来的gif图片流
  640.                     UserGifArrival(msg,Ip,Port);//处理gif图片消息
  641. break;
  642.                 case 12://收到用户发送来的文本消息
  643. UserTextChatArrival(msg,Ip,Port);//处理用户发送来的文本消息
  644. break;
  645. case 13://收到视频对话请求
  646. //MessageBox.Show("视频对话请求"+ Ip.ToString() +":"+ Port.ToString());
  647. UserAVRequestArrival(msg,Ip,Port);
  648. break;
  649. case 14://对方告诉自己开始视频对话
  650. //MessageBox.Show("开始视频对话"+ Ip.ToString() +":"+ Port.ToString());
  651. UserBeginAV(msg,Ip,Port);
  652. break;
  653. case 15://对方已经取消息视频对话
  654.                     CancelAV(msg.ID );//取消视频对话
  655. break;
  656. case 16://服务器通知升级到最新版本的LanMsg
  657. update();
  658. break;
  659. }
  660. private void update()
  661. {
  662.            LanMsg.FormUpdate f=new FormUpdate();
  663.    f.ShowDialog(this);
  664. }
  665. private void CancelAV(string userID)//对方已经取消息视频对话,取消视频对话
  666. {
  667. ClassUserInfo userinfo =this.findUser(userID);
  668. if (userinfo!=null)
  669. {
  670. foreach(System.Windows.Forms.Form form in forms)
  671. if (form.Tag.ToString() == userinfo.ID )
  672. {
  673. FormSendMsg f=(form as FormSendMsg );
  674. f.CancelAV();
  675. f.Activate ();
  676. return;
  677. }
  678. }
  679. }
  680. private void UserBeginAV(LanMsg.Controls.ClassMsg msg, System.Net.IPAddress Ip, int Port)//对方要求立即进行视频对话
  681. {
  682. ClassUserInfo userinfo =this.findUser(msg.ID);
  683. if (userinfo!=null)
  684. {
  685. foreach(System.Windows.Forms.Form form in forms)
  686. if (form.Tag.ToString() == userinfo.ID )
  687. {
  688. FormSendMsg f=(form as FormSendMsg );
  689. f.BeginAV(Ip,Port);
  690. f.Activate ();
  691. return;
  692. }
  693. }
  694. }
  695.  
  696. private void UDPNatTranslators(LanMsg.Controls.ClassMsg msg, System.Net.IPAddress Ip, int Port)//对方要求UDP打洞
  697. {
  698.             LanMsg.ClassUserInfo userinfo=this.findUser(msg.ID );
  699. if(userinfo!=null)
  700. {
  701. userinfo.IP=Ip;
  702. userinfo.Port=Port;
  703. }
  704. }
  705. private void UserAVRequestArrival(LanMsg.Controls.ClassMsg msg, System.Net.IPAddress Ip, int Port)//收到视频聊天请求
  706. {
  707. ClassUserInfo userinfo =this.findUser(msg.ID);
  708. if (userinfo!=null)
  709. {
  710. string title= userinfo.UserName  +"("+ System.DateTime.Now.ToString() +")";
  711. foreach(System.Windows.Forms.Form form in forms)
  712. if (form.Tag.ToString() == userinfo.ID )
  713. {
  714. FormSendMsg f=(form as FormSendMsg );
  715. f.AVrequest(Ip,Port);
  716. f.Activate ();
  717. return;
  718. }
  719. FormSendMsg newf =new FormSendMsg();
  720. newf.Tag=msg.ID;
  721. newf.Text="与 "+ userinfo.UserName+"("+userinfo.ID+") 对话";
  722. forms.add(newf);
  723. newf.AVrequest(Ip,Port);
  724. ShowNotifyIcon(1,"","收到 "+userinfo.UserName +"("+ userinfo.ID  +") 发送给您的视频对话请求,您可以接收或取消视频对话。");
  725. newf.Show();
  726. }
  727. }
  728. private void UserTextChatArrival(LanMsg.Controls.ClassMsg msg, System.Net.IPAddress Ip, int Port)//处理用户发送来的文本消息
  729. {
  730. ClassUserInfo userinfo =this.findUser(msg.ID);
  731. if (userinfo!=null)
  732. {
  733. string title= userinfo.UserName  +"("+ System.DateTime.Now.ToString() +")";
  734. foreach(System.Windows.Forms.Form form in forms)
  735. if (form.Tag.ToString() == userinfo.ID )
  736. {
  737. FormSendMsg f=(form as FormSendMsg );
  738. f.newTextMsg(msg.MsgContent,title,new System.Drawing.Font("宋体",10), Color.Blue);
  739. f.Activate ();
  740. return;
  741. }
  742. FormSendMsg newf =new FormSendMsg();
  743. newf.Tag=msg.ID;
  744. newf.Text="与 "+ userinfo.UserName+"("+userinfo.ID+") 对话";
  745. newf.newTextMsg(msg.MsgContent,title,new System.Drawing.Font("宋体",10),Color.Blue );
  746. forms.add(newf);
  747. ShowNotifyIcon(1,"","收到 "+userinfo.UserName +"("+ userinfo.ID  +") 发送给您的新消息。");
  748. newf.Show();
  749. }
  750. }
  751. private void UserGifArrival(LanMsg.Controls.ClassMsg msg, System.Net.IPAddress Ip, int Port)//处理gif图片消息
  752. {
  753. ClassUserInfo userinfo =this.findUser(msg.ID);
  754. if (userinfo!=null)
  755. {
  756. this.sendMsgToOneUser(new LanMsg.Controls.ClassMsg(6,selfInfo.ID,null),userinfo.IP,userinfo.Port );//告诉发消息的联系人已经收到发送的消息
  757. string title= userinfo.UserName  +"("+ System.DateTime.Now.ToString() +")";
  758. //MsgAddToDB(msgRtf,msg.ID,selfInfo.ID,msg.AssemblyVersion,System.DateTime.Now.ToString(),true);//将消息添加进数据库
  759. foreach(System.Windows.Forms.Form form in forms)
  760. if (form.Tag.ToString() == userinfo.ID )
  761. {
  762. FormSendMsg f=(form as FormSendMsg );
  763. f.newMsg(msg.MsgContent,title,new System.Drawing.Font("宋体",10), Color.Blue);
  764. f.Activate ();
  765. return;
  766. }
  767. FormSendMsg newf =new FormSendMsg();
  768. newf.Tag=msg.ID;
  769. newf.Text="与 "+ userinfo.UserName+"("+userinfo.ID+") 对话";
  770. newf.newMsg(msg.MsgContent,title,new System.Drawing.Font("宋体",10),Color.Blue );
  771. forms.add(newf);
  772. ShowNotifyIcon(1,"","收到 "+userinfo.UserName +"("+ userinfo.ID  +") 发送给您的新消息。");
  773. newf.Show();
  774. }
  775. }
  776. private void sendFileRequest(LanMsg.Controls.ClassMsg msg,System.Net.IPAddress Ip, int Port) //处理联系人发送接收文件要求
  777. {
  778. ClassUserInfo userinfo =this.findUser(msg.ID);
  779. if (userinfo!=null)
  780. {
  781. string[] fileInfo= System.Text.Encoding.Unicode.GetString (msg.MsgContent).Split('|');
  782. ShowNotifyIcon(1,"",userinfo.UserName +"("+ userinfo.ID  +") 要求发送文件给您,请接收或拒绝。");
  783. foreach(System.Windows.Forms.Form form in forms)
  784. if (form.Tag.ToString() == userinfo.ID )
  785. {
  786. FormSendMsg f=(form as FormSendMsg );
  787. f.ReceiveFileRequest(fileInfo[0].ToString(),fileInfo[1].ToString(),Convert.ToInt64(fileInfo[2]),Ip,Port);
  788. f.Activate ();
  789. return;
  790. }
  791. FormSendMsg newf =new FormSendMsg();
  792. newf.Tag=msg.ID;
  793. newf.Text="与 "+ userinfo.UserName+"("+userinfo.ID+") 对话";
  794. newf.ReceiveFileRequest(fileInfo[0].ToString(),fileInfo[1].ToString(),Convert.ToInt64(fileInfo[2]),Ip,Port);
  795. forms.add(newf);
  796. newf.Show();
  797. }
  798. }
  799. private void noticeArrival(LanMsg.Controls.ClassMsg msg,System.Net.IPAddress Ip, int Port) //处理联系人发送来的群发通知消息
  800. {
  801.             ClassUserInfo userinfo =this.findUser(msg.ID);
  802. if (userinfo!=null)
  803. {
  804. string msgContent=System.Text.Encoding.Unicode.GetString(msg.MsgContent);
  805.   MsgAddToDB(msgContent,msg.ID,selfInfo.ID,msg.AssemblyVersion ,System.DateTime.Now.ToString(),"",false);//将消息添加进数据库
  806. LanMsg.FormNotice nt=new FormNotice();
  807. nt.RTBNoticeContent.AppendText(msgContent);
  808. nt.RTBNoticeContent.AppendText("n发布:"+userinfo.UserName +"("+ userinfo.ID  +")");
  809. ShowNotifyIcon(3,"通知-消息","收到 "+userinfo.UserName +"("+ userinfo.ID  +") 发布的设计院 通知-消息");
  810. nt.Show();
  811. }
  812. }
  813. private void returnChatArrival(string ID ) //联系人返回已经收到刚才发送的对话消息
  814. {
  815. ClassUserInfo userinfo =this.findUser(ID);
  816. if (userinfo!=null)
  817. userinfo.SendIsSuccess=true;//标识刚才发送的消息联系人已经成功收到
  818. }
  819. private void UserChatArrival(LanMsg.Controls.ClassMsg msg, System.Net.IPAddress Ip, int Port)//处理对话消息
  820. {
  821. ClassUserInfo userinfo =this.findUser(msg.ID);
  822. if (userinfo!=null)
  823. {
  824. this.sendMsgToOneUser(new LanMsg.Controls.ClassMsg(6,selfInfo.ID,null),userinfo.IP,userinfo.Port );//告诉发消息的联系人已经收到发送的消息
  825. string title= userinfo.UserName  +"("+ System.DateTime.Now.ToString() +")";
  826. string msgRtf=System.Text.Encoding.Unicode.GetString(msg.MsgContent);
  827. // MsgAddToDB(msgRtf,msg.ID,selfInfo.ID,msg.AssemblyVersion,System.DateTime.Now.ToString(),true);//将消息添加进数据库
  828. foreach(System.Windows.Forms.Form form in forms)
  829. if (form.Tag.ToString() == userinfo.ID )
  830. {
  831. FormSendMsg f=(form as FormSendMsg );
  832. f.newMsg(msgRtf,title,new System.Drawing.Font("宋体",10), Color.Blue);
  833. f.Activate ();
  834. return;
  835. }
  836. FormSendMsg newf =new FormSendMsg();
  837. newf.Tag=msg.ID;
  838. newf.Text="与 "+ userinfo.UserName+"("+userinfo.ID+") 对话";
  839. newf.newMsg(msgRtf,title,new System.Drawing.Font("宋体",10),Color.Blue );
  840. forms.add(newf);
  841. ShowNotifyIcon(1,"","收到 "+userinfo.UserName +"("+ userinfo.ID  +") 发送给您的新消息。");
  842. newf.Show();
  843. }
  844. }
  845. private void NewUserLogin(ClassUserInfo userinfo)//添加新登录的用户资料
  846. {
  847. // if(userinfo.ID==selfInfo.ID )
  848. // return;//如果新登录的联系人是自己则退出
  849. ClassUserInfo UserInfo;  
  850. UserInfo=findUser(userinfo.ID);
  851. if(UserInfo==null )
  852. {
  853. userinfo.Node=new TreeNode();
  854. this.TvUsers.Nodes[userinfo.Dep].Nodes.Add(userinfo.Node);
  855. this.MyUsers.add(userinfo);
  856. userinfo.State =userinfo.State ;
  857. userinfo.Dep =userinfo.Dep ;
  858. userinfo.ID=userinfo.ID;
  859. }
  860. else
  861. {
  862. UserInfo.ID=userinfo.ID;
  863. UserInfo.Dep=userinfo.Dep;
  864. UserInfo.State  =userinfo.State;
  865. UserInfo.IP=userinfo.IP ;
  866. UserInfo.Port=userinfo.Port;
  867. UserInfo.UserName =userinfo.UserName;
  868. UserInfo.AssemblyVersion=userinfo.AssemblyVersion;
  869. }
  870. updateGroupInfo();//更新部门成员上线与未上线的数据
  871. }
  872. private void updateSelfState()//更新当前用户在线状态
  873. {
  874. selfInfo.State  =OnlineState;//将自己的在线状态设置为非0表示在线
  875. this.LabselfName.Text=selfInfo.UserName  + selfInfo.StateInfo ;
  876. this.LabselfName.Refresh();
  877. }
  878. private void userSingnOut(string ID) //处理用户离线
  879. {
  880. ClassUserInfo userinfo=this.findUser(ID);
  881. if(userinfo!=null)
  882. {
  883. int GroupIndex=userinfo.Dep ;
  884. if (userinfo.Dep==10)//如果用户在未知组
  885. {
  886. userinfo.Node.Parent.Nodes.Remove(userinfo.Node);
  887. this.MyUsers.Romove(userinfo);//在用户列表中删除未知组的此离线用户
  888. }
  889. else
  890. {
  891. userinfo.State=0;//标识用户已经离线
  892. }
  893. updateGroupInfo();//更新部门成员上线与未上线的数据
  894. }
  895. }
  896.    
  897. private void UsersDataArrival(Controls.ClassUsers users)//收到用户所有联系人的资料
  898. {
  899. ClassUserInfo UserInfo;  
  900. foreach(ClassUserInfo userinfo in users)
  901. {
  902. UserInfo=findUser(userinfo.ID);
  903. if(UserInfo==null)
  904. {
  905. userinfo.Node=new TreeNode();
  906. this.TvUsers.Nodes[userinfo.Dep].Nodes.Add(userinfo.Node);
  907. this.MyUsers.add(userinfo);
  908. userinfo.ID=userinfo.ID;
  909. userinfo.State =userinfo.State ;
  910. userinfo.Dep=userinfo.Dep;
  911. //updateGroupInfo(userinfo);
  912. }
  913. }
  914. updateGroupInfo();//更新部门成员上线与未上线的数据
  915. }
  916. private void updateGroupInfo()//更新部门成员上线与未上线的数据 
  917. {
  918. int Online=0;
  919. for(int i=0;i<this.TvUsers.Nodes.Count;i++)
  920. {
  921. for(int j=0;j<this.TvUsers.Nodes[i].Nodes.Count;j++)
  922. if(this.TvUsers.Nodes[i].Nodes[j].Text.IndexOf("(脱机)")==-1)
  923. Online++;
  924. this.TvUsers.Nodes[i].Text=Convert.ToString(this.TvUsers.Nodes[i].Tag) +"("+Online.ToString() +"/"+this.TvUsers.Nodes[i].Nodes.Count.ToString() +")";
  925. Online=0;
  926. }
  927. }
  928. private void updateGroupInfo(LanMsg.ClassUserInfo userinfo)//更新部门成员上线与未上线的数据 
  929. {
  930. int Online=0;
  931. int userCount=0;
  932. foreach(ClassUserInfo TempUserinfo in this.MyUsers)
  933. if(TempUserinfo.Dep==userinfo.Dep )
  934. {
  935. userCount++;
  936. if(TempUserinfo.State!=0) Online++;
  937. }
  938.            userinfo.Node.Parent.Text=Convert.ToString(userinfo.Node.Parent.Tag)+"("+Online.ToString() +"/"+userCount.ToString()+")";
  939. }
  940. public ClassUserInfo findUser(string ID)//在我的用户列表中查找用户ID
  941. {
  942. foreach(ClassUserInfo userinfo in  this.MyUsers)
  943. if(userinfo.ID.ToLower()==ID.ToLower())
  944. return userinfo;
  945. return null;
  946. }
  947. private void SuccessLogin(LanMsg.Controls.ClassMsg msg)//服务器告诉用户已经成功登录的处理过程
  948. {
  949. //this.Text="成功登陆";
  950. ClassUserInfo self=(new  ClassSerializers().DeSerializeBinary (new System.IO.MemoryStream(msg.MsgContent ))) as ClassUserInfo;
  951.   selfInfo.UserName =self.UserName;
  952.             selfInfo.State =1;
  953. this.LabselfName.Text=selfInfo.UserName  +"(联机)";
  954. this.LabselfName.Refresh();
  955. //ShowNotifyIcon(1,"","LanMsg已经成功登录服务器。");
  956. }
  957. private void TvUsers_DoubleClick(object sender, System.EventArgs e)
  958. {
  959.              ActivateOrCreateFormSend();
  960. }
  961. private void ActivateOrCreateFormSend()//激活或创建新的消息发送窗体
  962. {
  963. if(this.TvUsers.SelectedNode.Parent!=null)
  964. {
  965. foreach(System.Windows.Forms.Form fo in forms)
  966. if (fo.Tag == this.TvUsers.SelectedNode.Tag)
  967. {
  968. fo.Activate ();return;
  969. }
  970.         FormSendMsg f =new FormSendMsg();
  971.     forms.add(f);
  972.     LanMsg.ClassUserInfo userinfo=this.findUser( this.TvUsers.SelectedNode.Tag.ToString());
  973.     if(userinfo!=null)
  974.     f.Text="与 "+ userinfo.UserName+"("+userinfo.ID+") 对话";
  975.     f.Tag=this.TvUsers.SelectedNode.Tag;
  976.                     f.Show();
  977. }
  978. }
  979.         
  980. private void FormMain_Load(object sender, System.EventArgs e)
  981. {
  982. this.Left=Screen.PrimaryScreen.WorkingArea.Width -this.Width;
  983. this.Top=200; 
  984.     BeginListen();
  985. }
  986.          
  987. private void BeginListen()//
  988. {
  989. //AssemblyName assName = Assembly.GetExecutingAssembly().GetName(); 
  990. //string version = assName.Version.ToString(); 
  991. //System.Diagnostics.FileVersionInfo fInfo=new System.Diagnostics.FileVersionInfo();
  992.    System.Random i =new Random();
  993.    int j= i.Next(2000,6000);
  994.            this.sockUDP1.Listen (j);//UDP开始侦听来自外部的消息.
  995.    selfInfo.Port=j;
  996.    selfInfo.ID=System.Net.Dns.GetHostName()+ j.ToString();// 
  997.    System.Reflection.AssemblyName assName = System.Reflection.Assembly.GetExecutingAssembly().GetName(); 
  998.    selfInfo.AssemblyVersion = assName.Version.ToString(); 
  999.    System.Threading.Thread.Sleep(3000);
  1000.            Login();//用户登录 
  1001.    this.timerCheckOnlinState.Enabled=true;
  1002. }
  1003. private void butMenuMainExit_Click(object sender, System.EventArgs e)
  1004. {
  1005.            AppExit();
  1006. }
  1007. private void FormMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  1008. {
  1009. if(!IsWindowsExit) 
  1010. {
  1011. this.WindowState=System.Windows.Forms.FormWindowState.Minimized;
  1012. this.Hide();
  1013. e.Cancel=true;
  1014. }
  1015. }
  1016. private void AppExit()//关闭Sock,退出程序
  1017. {
  1018. this.sockUDP1.CloseSock();
  1019. Application.Exit();
  1020. }
  1021. private void Login()//用户登录
  1022. {    
  1023.  this.LabselfName.Text="正在登录...";
  1024.  LanMsg.Controls.ClassMsg msg=new LanMsg.Controls.ClassMsg(1,selfInfo.ID,System.Text.Encoding.Unicode.GetBytes(selfInfo.AssemblyVersion));
  1025.  sendMsgToServer(msg);
  1026. }
  1027. private void timerCheckOnlinState_Tick(object sender, System.EventArgs e)//检测自己的在线状态
  1028. {
  1029.             CheckOnlineState();//检测自己的在线状态
  1030. foreach(LanMsg.ClassUserInfo userinfo in this.MyUsers)//向对方打洞
  1031. if(userinfo.State!=0)
  1032. this.sendMsgToOneUser(new Controls.ClassMsg(8,this.selfInfo.ID,null),userinfo.IP,userinfo.Port);//向对方打洞
  1033. }
  1034.         
  1035. private int OnlineState=1;
  1036. private void CheckOnlineState()//检测自己的在线状态
  1037. {
  1038. if(selfInfo.State ==0)//如果没有登录,则登录
  1039. {
  1040.  Login();
  1041. }
  1042. else//如果已经登录在线,则将自己设为脱机状态,然后向服务器发送消息告之自已在线状态
  1043. {
  1044.         OnlineState=selfInfo.State;
  1045. selfInfo.State=0;
  1046.                 LanMsg.Controls.ClassMsg msg=new LanMsg.Controls.ClassMsg(2,selfInfo.ID,System.Text.Encoding.Unicode.GetBytes(OnlineState.ToString()));
  1047.                 sendMsgToServer(msg);
  1048. }
  1049. }
  1050. public void sendMsgToServer(Controls.ClassMsg msg)//发送消息到服务器
  1051. {
  1052.    this.sockUDP1.Send(this.ServerIP,this.ServerPort,new  ClassSerializers().SerializeBinary(msg).ToArray());
  1053. }
  1054. public void sendMsgToOneUser(Controls.ClassMsg msg,System.Net.IPAddress Ip, int Port)//发送消息到用户的一个联系人
  1055. {   
  1056. msg.ID=selfInfo.ID;//标识本人的ID号
  1057. this.sockUDP1.Send(Ip,Port,new ClassSerializers().SerializeBinary(msg).ToArray());
  1058. }
  1059. private void TvUsers_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
  1060. {
  1061. foreach(System.Windows.Forms.TreeNode nd in e.Node.Nodes)
  1062. nd.Checked=e.Node.Checked;
  1063. }
  1064. private void butMsgSendGourp_Click(object sender, System.EventArgs e)
  1065. {
  1066. foreach(System.Windows.Forms.Form form in forms)
  1067. if( form is LanMsg.FormNotice )
  1068. {
  1069. form.Activate();
  1070. return;
  1071. }
  1072.             FormSendMsgGroup fSendMsgGroup=new FormSendMsgGroup();
  1073. fSendMsgGroup.Tag="Notice";
  1074. forms.add(fSendMsgGroup);
  1075. fSendMsgGroup.Show ();
  1076. this.TvUsers.CheckBoxes=true;
  1077. }
  1078. public void sendMsgToOneUser(Controls.ClassMsg msg,string userID)//发送消息到用户的一个联系人
  1079. {   
  1080. msg.ID=selfInfo.ID;//标识本人的ID号
  1081. ClassUserInfo userinfo=this.findUser(userID);
  1082.             if(userinfo!=null)
  1083.  this.sockUDP1.Send(userinfo.IP ,userinfo.Port ,new  ClassSerializers().SerializeBinary(msg).ToArray());
  1084. }
  1085. private void sendMsgToAllUser(Controls.ClassMsg msg)//发送通知消息(群发)
  1086. {
  1087. msg.ID=selfInfo.ID;//标识本人的ID号
  1088. foreach(ClassUserInfo userinfo in this.MyUsers )
  1089. {
  1090. this.sockUDP1.Send(userinfo.IP ,userinfo.Port ,new ClassSerializers().SerializeBinary(msg).ToArray());
  1091. }
  1092. }
  1093. public void sendNotice(Controls.ClassMsg msg)//发送通知消息(群发)
  1094. {
  1095. msg.ID=selfInfo.ID;//标识本人的ID号
  1096. foreach(ClassUserInfo userinfo in this.MyUsers )
  1097. {
  1098. if(userinfo.Node.Checked)
  1099. this.sockUDP1.Send(userinfo.IP ,userinfo.Port ,new  ClassSerializers().SerializeBinary(msg).ToArray());
  1100. }
  1101. }
  1102. private System.Drawing.Point  point=new  Point(0,0);
  1103. private void TvUsers_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
  1104. {
  1105. if(e.Node.Parent==null)
  1106. {
  1107. foreach(System.Windows.Forms.TreeNode nd in this.TvUsers.Nodes)
  1108. nd.Collapse();
  1109. e.Node.Expand();
  1110. }
  1111. else
  1112. {
  1113. this.butSendMsg.Visible=true;
  1114. this.butSendFile.Visible=true;
  1115. this.butOpenShared.Visible=true;
  1116. this.butOpenShared.Tag=e.Node.Tag;
  1117. this.butSendFile.Tag=e.Node.Tag;
  1118. butMenuMain.PopupMenu(this.Left + this.point.X+10  ,this.Top + this.point.Y+50  );
  1119. }
  1120. }
  1121. private void LabselfName_TextChanged(object sender, System.EventArgs e)
  1122. {
  1123. this.NotifyIcon.Text=this.LabselfName.Text;
  1124.     }
  1125. private void butMsgMis_Click(object sender, System.EventArgs e)
  1126. {
  1127.  OpenMsgMis("");//打开消息管理器
  1128. }
  1129.         
  1130. public  void OpenMsgMis(string OpenID)//打开消息管理器
  1131. {
  1132. foreach(System.Windows.Forms.Form form in forms)
  1133. if (form is LanMsg.FormMsgMis)
  1134. {
  1135. LanMsg.FormMsgMis f=(form as  LanMsg.FormMsgMis);
  1136. f.Activate ();
  1137. f.selectID(OpenID);
  1138. return;
  1139. }
  1140. FormMsgMis fr=new FormMsgMis();
  1141. this.forms.add(fr);
  1142. fr.Show();
  1143. fr.Activate();
  1144. fr.selectID(OpenID);
  1145. }
  1146. #region 添加记录到数据库
  1147. public void MsgAddToDB(string msgContent,string sendID,string ReceiveID,string AssemblyVersion,string msgDateTime,string ImageInfo,bool IsNotNotice)//添加用户对话消息到数据库
  1148. {
  1149. try
  1150. {  
  1151. string DBtable="Notice";
  1152. if(IsNotNotice)
  1153. {
  1154. DBtable="MsgRecord";
  1155. }
  1156. System.Data.OleDb.OleDbConnection connection=new  System.Data.OleDb.OleDbConnection(new ClassFormMain().ConStr);    
  1157.         
  1158. System.Data.OleDb.OleDbCommand command=new System.Data.OleDb.OleDbCommand("INSERT  INTO  ["+DBtable+"](msgContent,sendID,ReceiveID,AssemblyVersion,msgDateTime,ImageInfo) VALUES( @msgContent,@sendID,@ReceiveID ,@AssemblyVersion,@msgDateTime,@ImageInfo)",  connection  );    
  1159.           
  1160. System.Data.OleDb.OleDbParameter paramMsgContent =new System.Data.OleDb.OleDbParameter("@msgContent",System.Data.OleDb.OleDbType.LongVarChar);    
  1161. paramMsgContent.Value  =  msgContent;    
  1162. command.Parameters.Add(paramMsgContent);    
  1163. System.Data.OleDb.OleDbParameter paramSendID=new System.Data.OleDb.OleDbParameter("@sendID",System.Data.OleDb.OleDbType.Char);    
  1164. paramSendID.Value  =  sendID;    
  1165. command.Parameters.Add(paramSendID);    
  1166. System.Data.OleDb.OleDbParameter paramReceiveID=new System.Data.OleDb.OleDbParameter("@ReceiveID",System.Data.OleDb.OleDbType.Char);    
  1167. paramReceiveID.Value  =  ReceiveID;    
  1168. command.Parameters.Add(paramReceiveID);    
  1169. System.Data.OleDb.OleDbParameter paramAssemblyVersion=new System.Data.OleDb.OleDbParameter("@AssemblyVersion",System.Data.OleDb.OleDbType.Char);    
  1170. paramAssemblyVersion.Value  =  AssemblyVersion;    
  1171. command.Parameters.Add(paramAssemblyVersion);    
  1172. System.Data.OleDb.OleDbParameter paramMsgDateTime=new System.Data.OleDb.OleDbParameter("@msgDateTime",System.Data.OleDb.OleDbType.DBTimeStamp);    
  1173. paramMsgDateTime.Value  =msgDateTime;    
  1174. command.Parameters.Add(paramMsgDateTime);    
  1175. System.Data.OleDb.OleDbParameter paramImageInfo=new System.Data.OleDb.OleDbParameter("@ImageInfo",System.Data.OleDb.OleDbType.LongVarChar);    
  1176. paramImageInfo.Value  =ImageInfo;    
  1177. command.Parameters.Add(paramImageInfo);    
  1178. connection.Open();    
  1179.         
  1180. int  numRowsAffected  =  command.ExecuteNonQuery();    
  1181.         
  1182. connection.Close();    
  1183. }
  1184. catch//如果有错误发生
  1185. {
  1186.   
  1187. }
  1188. }
  1189. #endregion
  1190. [System.Runtime.InteropServices.DllImport("user32")] 
  1191. private static extern long AnimateWindow(long hwnd, long dwTime, long dwFlags);
  1192. [System.Runtime.InteropServices.DllImport("winmm.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)] 
  1193. private static extern int PlaySound(string lpszSoundName, int hModule, int dwFlags); 
  1194. const int SND_FILENAME = 131072; 
  1195. const int SND_ALIAS = 65536; 
  1196. const int SND_SYNC = 0; 
  1197. private void PlaySound(string fileStr) 
  1198. PlaySound(fileStr, 0, SND_FILENAME); 
  1199. }
  1200. private void buttonItemState1_Click(object sender, System.EventArgs e)
  1201. {
  1202. CheckButFalse(sender);
  1203. this.OnlineState=1;
  1204. updateSelfState();
  1205. }
  1206. private void buttonItemState2_Click(object sender, System.EventArgs e)
  1207. {
  1208. CheckButFalse(sender);
  1209. this.OnlineState=2;
  1210. updateSelfState();
  1211. }
  1212. private void buttonItemState3_Click(object sender, System.EventArgs e)
  1213. {
  1214. CheckButFalse(sender);
  1215. this.OnlineState=3;
  1216. updateSelfState();
  1217. }
  1218. private void buttonItemState4_Click(object sender, System.EventArgs e)
  1219. {
  1220. CheckButFalse(sender);
  1221. this.OnlineState=4;
  1222. updateSelfState();
  1223. }
  1224. private void buttonItemState5_Click(object sender, System.EventArgs e)
  1225. {
  1226. CheckButFalse(sender);
  1227. this.OnlineState=5;
  1228. updateSelfState();
  1229. }
  1230.         
  1231. private void CheckButFalse(object sender)
  1232. {
  1233.             buttonItemState1.Checked=false;
  1234. buttonItemState2.Checked=false;
  1235. buttonItemState3.Checked=false;
  1236. buttonItemState4.Checked=false;
  1237. buttonItemState5.Checked=false;
  1238. (sender as  DevComponents.DotNetBar.ButtonItem).Checked=true;
  1239. }
  1240.  
  1241. private void NotifyIcon_Click(object sender, System.EventArgs e)
  1242. {
  1243. this.Opacity=100;
  1244. this.ShowInTaskbar=true;
  1245. this.WindowState=System.Windows.Forms.FormWindowState.Normal;
  1246. this.Show();
  1247. this.Activate();
  1248. this.Refresh();
  1249. }
  1250. private void FormMain_SizeChanged(object sender, System.EventArgs e)
  1251. {
  1252. }
  1253.  
  1254. private void ShowNotifyIcon(int ShowClass,string title,string content)
  1255. {
  1256. if(title=="")title="新消息";
  1257. LanMsg.CustomUIControls.TaskbarNotifier  taskbarNotifier=new TaskbarNotifier();
  1258. switch(ShowClass)
  1259. {
  1260. case 1:
  1261. taskbarNotifier.SetBackgroundBitmap(new Bitmap(GetType(),"Resources.skin.bmp"),Color.FromArgb(255,0,255));
  1262. taskbarNotifier.SetCloseBitmap(new Bitmap(GetType(),"Resources.close.bmp"),Color.FromArgb(255,0,255),new Point(127,8));
  1263. taskbarNotifier.TitleRectangle=new Rectangle(40,9,70,25);
  1264. taskbarNotifier.ContentRectangle=new Rectangle(8,41,133,68);
  1265. break;
  1266. case 2:
  1267. taskbarNotifier.SetBackgroundBitmap(new Bitmap(GetType(),"Resources.skin2.bmp"),Color.FromArgb(255,0,255));
  1268. taskbarNotifier.SetCloseBitmap(new Bitmap(GetType(),"Resources.close2.bmp"),Color.FromArgb(255,0,255),new Point(300,74));
  1269. taskbarNotifier.TitleRectangle=new Rectangle(123,80,176,16);
  1270. taskbarNotifier.ContentRectangle=new Rectangle(116,97,197,22);
  1271. break;
  1272. case 3:
  1273. taskbarNotifier.SetBackgroundBitmap(new Bitmap(GetType(),"Resources.skin3.bmp"),Color.FromArgb(255,0,255));
  1274. taskbarNotifier.SetCloseBitmap(new Bitmap(GetType(),"Resources.close.bmp"),Color.FromArgb(255,0,255),new Point(280,57));
  1275. taskbarNotifier.TitleRectangle=new Rectangle(150, 57, 125, 28);
  1276. taskbarNotifier.ContentRectangle=new Rectangle(75, 92, 215, 55);
  1277. break;
  1278. }
  1279. taskbarNotifier.Show(title ,content,500,3000,500);
  1280. }
  1281. private void TvUsers_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  1282. {
  1283. this.point.X =e.X ;
  1284. this.point.Y =e.Y;
  1285. }
  1286. private void butOpenShared_Click(object sender, System.EventArgs e)
  1287. {
  1288. try
  1289. {
  1290. string sharedComputerName="\\"+ Convert.ToString(this.butOpenShared.Tag);
  1291. System.Diagnostics.Process.Start(sharedComputerName);
  1292. }
  1293. catch  
  1294. {
  1295. MessageBox.Show("无法打开对方("+ Convert.ToString(this.butOpenShared.Tag) +")的共享文件夹(原因可能是对方没有开机或没有设置共享以及其它网络故障造成的)。","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  1296. }
  1297. }
  1298. private void butMenuMain_PopupClose(object sender, System.EventArgs e)
  1299. {
  1300. this.butOpenShared.Visible=false;
  1301. this.butSendFile.Visible=false;
  1302. this.butSendMsg.Visible=false;
  1303. }
  1304. private void butSendMsg_Click(object sender, System.EventArgs e)
  1305. {
  1306. ActivateOrCreateFormSend();
  1307. }
  1308. private void butSendFile_Click(object sender, System.EventArgs e)//发送文件
  1309. {
  1310.             System.Windows.Forms.OpenFileDialog fd=new OpenFileDialog();
  1311.             fd.Title="选择要发送的文件";
  1312. fd.Filter="所有文件(*.*)|*.*";
  1313. if (fd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
  1314. {
  1315. ClassUserInfo userinfo =this.findUser(butSendFile.Tag.ToString());
  1316. if (userinfo!=null)
  1317. {
  1318. foreach(System.Windows.Forms.Form form in forms)
  1319. if (form.Tag.ToString() == userinfo.ID )
  1320. {
  1321. FormSendMsg f=(form as FormSendMsg );
  1322. f.sendFileRequest(fd.FileName );
  1323. f.Activate ();
  1324. return;
  1325. }
  1326. FormSendMsg newf =new FormSendMsg();
  1327. newf.Tag=userinfo.ID;
  1328. newf.Text="与 "+ userinfo.UserName+"("+userinfo.ID+") 对话";
  1329. newf.sendFileRequest(fd.FileName );
  1330. forms.add(newf);
  1331. newf.Show();
  1332. }
  1333. }
  1334. }
  1335. private void ButAbout_Click(object sender, System.EventArgs e)
  1336. {
  1337.                MessageBox.Show("LanMsg局域网即时通讯n作者:租李叶(25348855)");
  1338. }
  1339.  
  1340.    }
  1341. }