NotifyWindow.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using ProjectBase.Data.Logs;
  12. using ProjectBase.Data.BaseDAL;
  13. using System.Runtime.InteropServices;
  14. using SIMDP.BLL;
  15. using System.Drawing.Drawing2D;
  16. using ProjectBase.Util;
  17. using SIMDP.Model;
  18. namespace SIMDP.View
  19. {
  20. public partial class NotifyWindow : DevExpress.XtraEditors.XtraForm
  21. {
  22. #region Public Variables
  23. /// <summary>
  24. /// Gets or sets the title text to be displayed in the NotifyWindow.
  25. /// </summary>
  26. public string Title;
  27. /// <summary>
  28. /// Gets or sets the Font used for the title text.
  29. /// </summary>
  30. public System.Drawing.Font TitleFont;
  31. /// <summary>
  32. /// Gets or sets the Font used when the mouse hovers over the main body of text.
  33. /// </summary>
  34. public System.Drawing.Font HoverFont;
  35. /// <summary>
  36. /// Gets or sets the Font used when the mouse hovers over the title text.
  37. /// </summary>
  38. public System.Drawing.Font TitleHoverFont;
  39. /// <summary>
  40. /// Gets or sets the style used when drawing the background of the NotifyWindow.
  41. /// </summary>
  42. public BackgroundStyles BackgroundStyle;
  43. /// <summary>
  44. /// Gets or sets the Blend used when drawing a gradient background for the NotifyWindow.
  45. /// </summary>
  46. public System.Drawing.Drawing2D.Blend Blend;
  47. /// <summary>
  48. /// Gets or sets the StringFormat used when drawing text in the NotifyWindow.
  49. /// </summary>
  50. public System.Drawing.StringFormat StringFormat;
  51. /// <summary>
  52. /// Gets or sets a value specifiying whether or not the window should continue to be displayed if the mouse cursor is inside the bounds
  53. /// of the NotifyWindow.
  54. /// </summary>
  55. public bool WaitOnMouseOver;
  56. /// <summary>
  57. /// An EventHandler called when the NotifyWindow main text is clicked.
  58. /// </summary>
  59. public event System.EventHandler TextClicked;
  60. /// <summary>
  61. /// An EventHandler called when the NotifyWindow title text is clicked.
  62. /// </summary>
  63. public event System.EventHandler TitleClicked;
  64. /// <summary>
  65. /// Gets or sets the color of the title text.
  66. /// </summary>
  67. public System.Drawing.Color TitleColor;
  68. /// <summary>
  69. /// Gets or sets the color of the NotifyWindow main text.
  70. /// </summary>
  71. public System.Drawing.Color TextColor;
  72. /// <summary>
  73. /// Gets or sets the gradient color which will be blended in drawing the background.
  74. /// </summary>
  75. public System.Drawing.Color GradientColor;
  76. /// <summary>
  77. /// Gets or sets the color of text when the user clicks on it.
  78. /// </summary>
  79. public System.Drawing.Color PressedColor;
  80. /// <summary>
  81. /// Gets or sets the amount of milliseconds to display the NotifyWindow for.
  82. /// </summary>
  83. public int WaitTime;
  84. /// <summary>
  85. /// Gets or sets the full height of the NotifyWindow, used after the opening animation has been completed.
  86. /// </summary>
  87. public int ActualHeight;
  88. /// <summary>
  89. /// Gets or sets the full width of the NotifyWindow.
  90. /// </summary>
  91. public int ActualWidth;
  92. public enum BackgroundStyles { BackwardDiagonalGradient, ForwardDiagonalGradient, HorizontalGradient, VerticalGradient, Solid };
  93. public enum ClockStates { Opening, Closing, Showing, None };
  94. public ClockStates ClockState;
  95. #endregion
  96. #region Protected Variables
  97. protected bool closePressed = false, textPressed = false, titlePressed = false, closeHot = false, textHot = false, titleHot = false;
  98. protected Rectangle rClose, rText, rTitle, rDisplay, rScreen, rGlobClose, rGlobText, rGlobTitle, rGlobDisplay;
  99. protected System.Windows.Forms.Timer viewClock;
  100. #endregion
  101. #region Constructor
  102. /// <param name="title">Title text displayed in the NotifyWindow</param>
  103. /// <param name="text">Main text displayedin the NotifyWindow</param>
  104. public NotifyWindow(string title, string text) : this() { Title = title; Text = text; }
  105. /// <param name="text">Text displayed in the NotifyWindow</param>
  106. public NotifyWindow(string text) : this() { Text = text; }
  107. public NotifyWindow()
  108. {
  109. InitializeComponent();
  110. this.gridControl1.DataSource = BLLFactory<BlSystemNotice>.Instance.Find(string.Format(" notice_sign = {0}", 0));
  111. SetStyle(ControlStyles.UserMouse, true);
  112. SetStyle(ControlStyles.UserPaint, true);
  113. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // WmPaint calls OnPaint and OnPaintBackground
  114. SetStyle(ControlStyles.DoubleBuffer, true);
  115. ShowInTaskbar = false;
  116. FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  117. StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  118. // Default values
  119. BackgroundStyle = BackgroundStyles.VerticalGradient;
  120. ClockState = ClockStates.None;
  121. BackColor = Color.SteelBlue;
  122. GradientColor = Color.WhiteSmoke;
  123. PressedColor = Color.Gray;
  124. TitleColor = SystemColors.ControlText;
  125. TextColor = SystemColors.ControlText;
  126. WaitOnMouseOver = true;
  127. ActualWidth = 130;
  128. ActualHeight = 110;
  129. WaitTime = 11000;
  130. }
  131. #endregion
  132. #region Public Methods
  133. /// <summary>
  134. /// Sets the width and height of the NotifyWindow.
  135. /// </summary>
  136. public void SetDimensions(int width, int height)
  137. {
  138. ActualWidth = width;
  139. ActualHeight = height;
  140. }
  141. /// <summary>
  142. /// Displays the NotifyWindow.
  143. /// </summary>
  144. public void Notify()
  145. {
  146. //if (Text == null || Text.Length < 1)
  147. // throw new System.Exception("You must set NotifyWindow.Text before calling Notify()");
  148. Width = ActualWidth;
  149. rScreen = Screen.GetWorkingArea(Screen.PrimaryScreen.Bounds);
  150. Height = 0;
  151. Top = rScreen.Bottom;
  152. Left = rScreen.Width - Width - 11;
  153. if (HoverFont == null)
  154. HoverFont = new Font(Font, Font.Style | FontStyle.Underline);
  155. if (TitleFont == null)
  156. TitleFont = Font;
  157. if (TitleHoverFont == null)
  158. TitleHoverFont = new Font(TitleFont, TitleFont.Style | FontStyle.Underline);
  159. if (this.StringFormat == null)
  160. {
  161. this.StringFormat = new StringFormat();
  162. this.StringFormat.Alignment = StringAlignment.Center;
  163. this.StringFormat.LineAlignment = StringAlignment.Center;
  164. this.StringFormat.Trimming = StringTrimming.EllipsisWord;
  165. }
  166. rDisplay = new Rectangle(0, 0, Width, ActualHeight);
  167. rClose = new Rectangle(Width - 21, 10, 13, 13);
  168. int offset;
  169. if (Title != null)
  170. {
  171. using (Graphics fx = CreateGraphics())
  172. {
  173. SizeF sz = fx.MeasureString(Title, TitleFont, ActualWidth - rClose.Width - 22, this.StringFormat);
  174. rTitle = new Rectangle(11, 12, (int)Math.Ceiling(sz.Width), (int)Math.Ceiling(sz.Height));
  175. offset = (int)Math.Max(Math.Ceiling(sz.Height + rTitle.Top + 2), rClose.Bottom + 5);
  176. }
  177. }
  178. else
  179. {
  180. offset = rClose.Bottom + 1;
  181. rTitle = new Rectangle(-1, -1, 1, 1);
  182. }
  183. rText = new Rectangle(11, offset, ActualWidth - 22, ActualHeight - (int)(offset * 1.5));
  184. // rGlob* are Rectangle's Offset'ed to their actual position on the screen, for use with Cursor.Position.
  185. rGlobClose = rClose;
  186. rGlobClose.Offset(Left, rScreen.Bottom - ActualHeight);
  187. rGlobText = rText;
  188. rGlobText.Offset(Left, rScreen.Bottom - ActualHeight);
  189. rGlobTitle = rTitle;
  190. if (Title != null)
  191. rGlobTitle.Offset(Left, rScreen.Bottom - ActualHeight);
  192. rGlobDisplay = rDisplay;
  193. rGlobDisplay.Offset(Left, rScreen.Bottom - ActualHeight);
  194. rGlobClose = rClose;
  195. rGlobClose.Offset(Left, rScreen.Bottom - ActualHeight);
  196. rGlobDisplay = rDisplay;
  197. rGlobDisplay.Offset(Left, rScreen.Bottom - ActualHeight);
  198. // Use unmanaged ShowWindow() and SetWindowPos() instead of the managed Show() to display the window - this method will display
  199. // the window TopMost, but without stealing focus (namely the SW_SHOWNOACTIVATE and SWP_NOACTIVATE flags)
  200. ShowWindow(Handle, SW_SHOWNOACTIVATE);
  201. SetWindowPos(Handle, HWND_TOPMOST, rScreen.Width - ActualWidth - 11, rScreen.Bottom, ActualWidth, 0, SWP_NOACTIVATE);
  202. viewClock = new System.Windows.Forms.Timer();
  203. viewClock.Tick += new System.EventHandler(viewTimer);
  204. viewClock.Interval = 1;
  205. viewClock.Start();
  206. ClockState = ClockStates.Opening;
  207. }
  208. #endregion
  209. #region Drawing
  210. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  211. {
  212. // Draw the close button and text.
  213. drawCloseButton(e.Graphics);
  214. Font useFont; Color useColor;
  215. if (Title != null)
  216. {
  217. if (titleHot)
  218. useFont = TitleHoverFont;
  219. else
  220. useFont = TitleFont;
  221. if (titlePressed)
  222. useColor = PressedColor;
  223. else
  224. useColor = TitleColor;
  225. using (SolidBrush sb = new SolidBrush(useColor))
  226. e.Graphics.DrawString(Title, useFont, sb, rTitle, this.StringFormat);
  227. }
  228. if (textHot)
  229. useFont = HoverFont;
  230. else
  231. useFont = Font;
  232. if (textPressed)
  233. useColor = PressedColor;
  234. else
  235. useColor = TextColor;
  236. using (SolidBrush sb = new SolidBrush(useColor))
  237. e.Graphics.DrawString(Text, useFont, sb, rText, this.StringFormat);
  238. }
  239. protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
  240. {
  241. // First paint the background
  242. if (BackgroundStyle == BackgroundStyles.Solid)
  243. {
  244. using (SolidBrush sb = new SolidBrush(BackColor))
  245. e.Graphics.FillRectangle(sb, rDisplay);
  246. }
  247. else
  248. {
  249. LinearGradientMode lgm;
  250. switch (BackgroundStyle)
  251. {
  252. case BackgroundStyles.BackwardDiagonalGradient:
  253. lgm = LinearGradientMode.BackwardDiagonal;
  254. break;
  255. case BackgroundStyles.ForwardDiagonalGradient:
  256. lgm = LinearGradientMode.ForwardDiagonal;
  257. break;
  258. case BackgroundStyles.HorizontalGradient:
  259. lgm = LinearGradientMode.Horizontal;
  260. break;
  261. default:
  262. case BackgroundStyles.VerticalGradient:
  263. lgm = LinearGradientMode.Vertical;
  264. break;
  265. }
  266. using (LinearGradientBrush lgb = new LinearGradientBrush(rDisplay, GradientColor, BackColor, lgm))
  267. {
  268. if (this.Blend != null)
  269. lgb.Blend = this.Blend;
  270. e.Graphics.FillRectangle(lgb, rDisplay);
  271. }
  272. }
  273. // Next draw borders...
  274. drawBorder(e.Graphics);
  275. }
  276. protected virtual void drawBorder(Graphics fx)
  277. {
  278. fx.DrawRectangle(Pens.Silver, 2, 2, Width - 4, ActualHeight - 4);
  279. // Top border
  280. fx.DrawLine(Pens.Silver, 0, 0, Width, 0);
  281. fx.DrawLine(Pens.White, 0, 1, Width, 1);
  282. fx.DrawLine(Pens.DarkGray, 3, 3, Width - 4, 3);
  283. fx.DrawLine(Pens.DimGray, 4, 4, Width - 5, 4);
  284. // Left border
  285. fx.DrawLine(Pens.Silver, 0, 0, 0, ActualHeight);
  286. fx.DrawLine(Pens.White, 1, 1, 1, ActualHeight);
  287. fx.DrawLine(Pens.DarkGray, 3, 3, 3, ActualHeight - 4);
  288. fx.DrawLine(Pens.DimGray, 4, 4, 4, ActualHeight - 5);
  289. // Bottom border
  290. fx.DrawLine(Pens.DarkGray, 1, ActualHeight - 1, Width - 1, ActualHeight - 1);
  291. fx.DrawLine(Pens.White, 3, ActualHeight - 3, Width - 3, ActualHeight - 3);
  292. fx.DrawLine(Pens.Silver, 4, ActualHeight - 4, Width - 4, ActualHeight - 4);
  293. // Right border
  294. fx.DrawLine(Pens.DarkGray, Width - 1, 1, Width - 1, ActualHeight - 1);
  295. fx.DrawLine(Pens.White, Width - 3, 3, Width - 3, ActualHeight - 3);
  296. fx.DrawLine(Pens.Silver, Width - 4, 4, Width - 4, ActualHeight - 4);
  297. }
  298. protected virtual void drawCloseButton(Graphics fx)
  299. {
  300. if (visualStylesEnabled())
  301. drawThemeCloseButton(fx);
  302. else
  303. drawLegacyCloseButton(fx);
  304. }
  305. /// <summary>
  306. /// Draw a Windows XP style close button.
  307. /// </summary>
  308. protected void drawThemeCloseButton(Graphics fx)
  309. {
  310. IntPtr hTheme = OpenThemeData(Handle, "Window");
  311. if (hTheme == IntPtr.Zero)
  312. {
  313. drawLegacyCloseButton(fx);
  314. return;
  315. }
  316. int stateId;
  317. if (closePressed)
  318. stateId = CBS_PUSHED;
  319. else if (closeHot)
  320. stateId = CBS_HOT;
  321. else
  322. stateId = CBS_NORMAL;
  323. RECT reClose = new RECT(rClose);
  324. RECT reClip = reClose; // should fx.VisibleClipBounds be used here?
  325. IntPtr hDC = fx.GetHdc();
  326. DrawThemeBackground(hTheme, hDC, WP_CLOSEBUTTON, stateId, ref reClose, ref reClip);
  327. fx.ReleaseHdc(hDC);
  328. CloseThemeData(hTheme);
  329. }
  330. /// <summary>
  331. /// Draw a Windows 95 style close button.
  332. /// </summary>
  333. protected void drawLegacyCloseButton(Graphics fx)
  334. {
  335. ButtonState bState;
  336. if (closePressed)
  337. bState = ButtonState.Pushed;
  338. else // the Windows 95 theme doesn't have a "hot" button
  339. bState = ButtonState.Normal;
  340. ControlPaint.DrawCaptionButton(fx, rClose, CaptionButton.Close, bState);
  341. }
  342. /// <summary>
  343. /// Determine whether or not XP Visual Styles are active. Compatible with pre-UxTheme.dll versions of Windows.
  344. /// </summary>
  345. protected bool visualStylesEnabled()
  346. {
  347. try
  348. {
  349. if (IsThemeActive() == 1)
  350. return true;
  351. else
  352. return false;
  353. }
  354. catch (System.DllNotFoundException) // pre-XP systems which don't have UxTheme.dll
  355. {
  356. return false;
  357. }
  358. }
  359. #endregion
  360. #region Timers and EventHandlers
  361. protected void viewTimer(object sender, System.EventArgs e)
  362. {
  363. switch (ClockState)
  364. {
  365. case ClockStates.Opening:
  366. if (Top - 2 <= rScreen.Height - ActualHeight)
  367. {
  368. Top = rScreen.Height - ActualHeight;
  369. Height = ActualHeight;
  370. ClockState = ClockStates.Showing;
  371. viewClock.Interval = WaitTime;
  372. }
  373. else
  374. {
  375. Top -= 2;
  376. Height += 2;
  377. }
  378. break;
  379. case ClockStates.Showing:
  380. if (!WaitOnMouseOver || !rGlobDisplay.Contains(Cursor.Position))
  381. {
  382. viewClock.Interval = 1;
  383. //ClockState = ClockStates.Closing;
  384. }
  385. break;
  386. case ClockStates.Closing:
  387. Top += 2;
  388. Height -= 2;
  389. if (Top >= rScreen.Height)
  390. {
  391. ClockState = ClockStates.None;
  392. viewClock.Stop();
  393. viewClock.Dispose();
  394. Close();
  395. }
  396. break;
  397. }
  398. }
  399. protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
  400. {
  401. if (Title != null && rGlobTitle.Contains(Cursor.Position) && !textPressed && !closePressed)
  402. {
  403. Cursor = Cursors.Hand;
  404. titleHot = true;
  405. textHot = false; closeHot = false;
  406. Invalidate();
  407. }
  408. else if (rGlobText.Contains(Cursor.Position) && !titlePressed && !closePressed)
  409. {
  410. Cursor = Cursors.Hand;
  411. textHot = true;
  412. titleHot = false; closeHot = false;
  413. Invalidate();
  414. }
  415. else if (rGlobClose.Contains(Cursor.Position) && !titlePressed && !textPressed)
  416. {
  417. Cursor = Cursors.Hand;
  418. closeHot = true;
  419. titleHot = false; textHot = false;
  420. Invalidate();
  421. }
  422. else if ((textHot || titleHot || closeHot) && (!titlePressed && !textPressed && !closePressed))
  423. {
  424. Cursor = Cursors.Default;
  425. titleHot = false; textHot = false; closeHot = false;
  426. Invalidate();
  427. }
  428. base.OnMouseMove(e);
  429. }
  430. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  431. {
  432. if (e.Button == MouseButtons.Left)
  433. {
  434. if (rGlobClose.Contains(Cursor.Position))
  435. {
  436. closePressed = true;
  437. closeHot = false;
  438. Invalidate();
  439. }
  440. else if (rGlobText.Contains(Cursor.Position))
  441. {
  442. textPressed = true;
  443. Invalidate();
  444. }
  445. else if (Title != null && rGlobTitle.Contains(Cursor.Position))
  446. {
  447. titlePressed = true;
  448. Invalidate();
  449. }
  450. }
  451. base.OnMouseDown(e);
  452. }
  453. protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
  454. {
  455. if (e.Button == MouseButtons.Left)
  456. {
  457. if (closePressed)
  458. {
  459. Cursor = Cursors.Default;
  460. closePressed = false;
  461. closeHot = false;
  462. Invalidate();
  463. if (rGlobClose.Contains(Cursor.Position))
  464. Close();
  465. }
  466. else if (textPressed)
  467. {
  468. Cursor = Cursors.Default;
  469. textPressed = false;
  470. textHot = false;
  471. Invalidate();
  472. if (rGlobText.Contains(Cursor.Position))
  473. {
  474. Close();
  475. if (TextClicked != null)
  476. TextClicked(this, new System.EventArgs());
  477. }
  478. }
  479. else if (titlePressed)
  480. {
  481. Cursor = Cursors.Default;
  482. titlePressed = false;
  483. titleHot = false;
  484. Invalidate();
  485. if (rGlobTitle.Contains(Cursor.Position))
  486. {
  487. Close();
  488. if (TitleClicked != null)
  489. TitleClicked(this, new System.EventArgs());
  490. }
  491. }
  492. }
  493. base.OnMouseUp(e);
  494. }
  495. #endregion
  496. #region P/Invoke
  497. // DrawThemeBackground()
  498. protected const Int32 WP_CLOSEBUTTON = 18;
  499. protected const Int32 CBS_NORMAL = 1;
  500. protected const Int32 CBS_HOT = 2;
  501. protected const Int32 CBS_PUSHED = 3;
  502. [StructLayout(LayoutKind.Explicit)]
  503. protected struct RECT
  504. {
  505. [FieldOffset(0)] public Int32 Left;
  506. [FieldOffset(4)] public Int32 Top;
  507. [FieldOffset(8)] public Int32 Right;
  508. [FieldOffset(12)] public Int32 Bottom;
  509. public RECT(System.Drawing.Rectangle bounds)
  510. {
  511. Left = bounds.Left;
  512. Top = bounds.Top;
  513. Right = bounds.Right;
  514. Bottom = bounds.Bottom;
  515. }
  516. }
  517. // SetWindowPos()
  518. protected const Int32 HWND_TOPMOST = -1;
  519. protected const Int32 SWP_NOACTIVATE = 0x0010;
  520. // ShowWindow()
  521. protected const Int32 SW_SHOWNOACTIVATE = 4;
  522. // UxTheme.dll
  523. [DllImport("UxTheme.dll")]
  524. protected static extern Int32 IsThemeActive();
  525. [DllImport("UxTheme.dll")]
  526. protected static extern IntPtr OpenThemeData(IntPtr hWnd, [MarshalAs(UnmanagedType.LPTStr)] string classList);
  527. [DllImport("UxTheme.dll")]
  528. protected static extern void CloseThemeData(IntPtr hTheme);
  529. [DllImport("UxTheme.dll")]
  530. protected static extern void DrawThemeBackground(IntPtr hTheme, IntPtr hDC, Int32 partId, Int32 stateId, ref RECT rect, ref RECT clipRect);
  531. // user32.dll
  532. [DllImport("user32.dll")]
  533. protected static extern bool ShowWindow(IntPtr hWnd, Int32 flags);
  534. [DllImport("user32.dll")]
  535. protected static extern bool SetWindowPos(IntPtr hWnd, Int32 hWndInsertAfter, Int32 X, Int32 Y, Int32 cx, Int32 cy, uint uFlags);
  536. #endregion
  537. /// <summary>
  538. /// 表格显示
  539. /// </summary>
  540. /// <param name="sender"></param>
  541. /// <param name="e"></param>
  542. private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
  543. {
  544. if (e.Column.ColumnType == typeof(DateTime))
  545. {
  546. string columnName = e.Column.FieldName;
  547. if (e.Value != null)
  548. {
  549. if (Convert.ToDateTime(e.Value) <= Convert.ToDateTime("1900-1-1"))
  550. {
  551. e.DisplayText = "";
  552. }
  553. else
  554. {
  555. e.DisplayText = Convert.ToDateTime(e.Value).ToString("yyyy-MM-dd HH:mm:ss");//yyyy-MM-dd
  556. }
  557. }
  558. }
  559. if (e.Column.FieldName == "NoticeType")
  560. {
  561. e.DisplayText = SysEnvironment.dirSystemNoticType.FirstOrDefault(p => p.Key == Convert.ToInt32(e.Value)).Value;
  562. }
  563. }
  564. /// <summary>
  565. /// 表格超链接点击事件
  566. /// </summary>
  567. /// <param name="sender"></param>
  568. /// <param name="e"></param>
  569. private void repositoryItemHyperLinkEdit1_Click(object sender, EventArgs e)
  570. {
  571. MoSystemNotice selectRow = this.gridView1.GetFocusedRow() as MoSystemNotice;
  572. try
  573. {
  574. selectRow.NoticeOperator = SysEnvironment.CurrentLoginID;
  575. selectRow.NoticeSign = true;
  576. bool flag = BLLFactory<BlSystemNotice>.Instance.Update(selectRow, selectRow.ID);
  577. if (flag)
  578. {
  579. RefreshWindow();
  580. }
  581. }
  582. catch (Exception ex)
  583. {
  584. DevExpress.XtraEditors.XtraMessageBox.Show("确认失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  585. LogHelper.log.Error(string.Format("修改数据库system_notice出现错误:{0}", ex));
  586. }
  587. }
  588. /// <summary>
  589. /// 刷新窗口
  590. /// </summary>
  591. public void RefreshWindow()
  592. {
  593. this.gridControl1.DataSource = BLLFactory<BlSystemNotice>.Instance.Find(string.Format(" notice_sign = {0}", 0));
  594. this.gridControl1.RefreshDataSource();
  595. }
  596. }
  597. }