StationRadio.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using log4net;
  11. using IntelligentControlForsx.Service;
  12. namespace IntelligentControlForsx.MyControls
  13. {
  14. public partial class StationRadio : UserControl
  15. {
  16. private ILog logger = LogManager.GetLogger("AppInfoLog");
  17. public StationRadio()
  18. {
  19. InitializeComponent();
  20. }
  21. private string stationId = "";
  22. public string StationId
  23. {
  24. get
  25. {
  26. return stationId;
  27. }
  28. set
  29. {
  30. if (stationId.Equals(value) == false)
  31. {
  32. stationId = value;
  33. UpdateUI();
  34. StationIdChanged(this, null);
  35. }
  36. }
  37. }
  38. public event EventHandler StationIdChanged;
  39. private void StationRadio_Load(object sender, EventArgs e)
  40. {
  41. try
  42. {
  43. var lstStation = CacheService.Instance.GetFDCList();
  44. foreach(var st in lstStation)
  45. {
  46. Button btnSt = new ImageButton();
  47. this.Controls.Add(btnSt);
  48. //this.SuspendLayout();
  49. btnSt.Text = st.NAME;
  50. btnSt.Tag = st.ID;
  51. btnSt.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.btn_station1;
  52. btnSt.Dock = System.Windows.Forms.DockStyle.Left;
  53. btnSt.Click += new System.EventHandler(this.btnStation_Click);
  54. //this.ResumeLayout(false);
  55. }
  56. StationId = lstStation.Last().ID;
  57. } catch(Exception ex)
  58. {
  59. logger.Error(ex);
  60. }
  61. }
  62. private void btnStation_Click(object sender, EventArgs e)
  63. {
  64. ImageButton btn = sender as ImageButton;
  65. if (btn != null)
  66. StationId = btn.Tag.ToString();
  67. //MessageBox.Show(btn.Tag.ToString());
  68. }
  69. private void UpdateUI()
  70. {
  71. foreach(var control in this.Controls)
  72. {
  73. ImageButton btn = control as ImageButton;
  74. if (btn != null)
  75. {
  76. if (StationId.Equals(btn.Tag.ToString()))
  77. {
  78. btn.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.btn_station2;
  79. } else
  80. {
  81. btn.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.btn_station1;
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }