Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. using HKLib.DB;
  2. using HKCardManager.UserPages;
  3. using UHFHelper;
  4. namespace HKCardManager
  5. {
  6. public partial class Form1 : Form
  7. {
  8. public Form1()
  9. {
  10. InitializeComponent();
  11. splitContainer1.SplitterDistance = 240;
  12. DataGridViewInit();
  13. Task.Factory.StartNew(() =>
  14. {
  15. DbContext.InitTable();
  16. var res = UHFCardHelper.GetInstance().OpenPort();
  17. if (res != null && res.Res)
  18. MessageLogNotify.GetInstance.ShowError("ƿ豸ӣ");
  19. else MessageLogNotify.GetInstance.ShowError($"ƿ豸ʧܣ{res?.ResMes}");
  20. });
  21. ShowPage(new PersonnelEntryPage());
  22. this.SizeChanged += Form1_SizeChanged;
  23. this.button1.SizeChanged += Button1_SizeChanged;
  24. MessageLogNotify.GetInstance.Info = new Action<string, Color>((s, br) =>
  25. {
  26. this.Invoke(() =>
  27. {
  28. dataGridView1.Rows.Insert(0, new string[] { "", $"{DateTime.Now.ToString("HH:mm:ss")} {s}" });
  29. dataGridView1.Rows[0].DefaultCellStyle.ForeColor = br;
  30. dataGridView1.Rows[0].DefaultCellStyle.Padding = new Padding(0, 0, 0, 10);
  31. });
  32. });
  33. }
  34. private void DataGridViewInit()
  35. {
  36. dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
  37. dataGridView1.AutoGenerateColumns = false;//ֹԶ
  38. dataGridView1.AllowUserToResizeColumns = false;//ǷԵеĴС
  39. dataGridView1.AllowUserToResizeRows = false;//ǷԵеĴС
  40. dataGridView1.BorderStyle = BorderStyle.None;//DataGridView߿ʽ
  41. dataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
  42. dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
  43. dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
  44. dataGridView1.SelectionChanged += DataGridView1_SelectionChanged;
  45. }
  46. private void DataGridView1_SelectionChanged(object? sender, EventArgs e)
  47. {
  48. dataGridView1.ClearSelection();//ֹѡ
  49. }
  50. private void Write(string msg)
  51. {
  52. //boolĬΪļ涨,Զκα
  53. //bool temp = Convert.ToBoolean(iniFile.IniReadValue("", "Ϣ", AppDomain.CurrentDomain.BaseDirectory + ".ini"));
  54. //if (temp)
  55. //{
  56. // string logPath = Path.GetDirectoryName(Application.ExecutablePath);
  57. // // System.IO.StreamWriter sw = System.IO.File.AppendText(logPath + "/" + DateTime.Now.ToString("yyMMdd") + ".txt");
  58. // System.IO.StreamWriter sw = System.IO.File.AppendText(logPath + "\\log\\" + DateTime.Now.ToString("yyMMdd") + ".txt");
  59. // sw.WriteLine(DateTime.Now.ToString("HH:mm:ss ") + msg);
  60. // sw.Close();
  61. // sw.Dispose();
  62. //}
  63. }
  64. private void AddListToListBox(ListBox rtbox, string text, Brush foreColor, bool addTime = true)
  65. {
  66. rtbox.DrawMode = DrawMode.OwnerDrawVariable;
  67. rtbox.Font = new Font("", 12);
  68. if (rtbox.ItemHeight != 24)
  69. {
  70. rtbox.ItemHeight = 1;
  71. rtbox.DrawItem += ((sender, e) => //ؼػ¼
  72. {
  73. if (e.Index == -1) return;
  74. e.DrawBackground();
  75. ListBoxItem item = (ListBoxItem)rtbox.Items[e.Index];
  76. if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
  77. {
  78. e.DrawFocusRectangle();
  79. Brush b = Brushes.Khaki;//ѡɫ
  80. e.Graphics.FillRectangle(b, e.Bounds);
  81. }
  82. if (item != null)
  83. {
  84. Brush brush = item.ForeColor;
  85. Rectangle r = e.Bounds;
  86. r.Height = e.Bounds.Height;
  87. r.Width = e.Bounds.Width + 100;
  88. e.Graphics.DrawString(item.Text, e.Font, brush, r, StringFormat.GenericDefault);
  89. }
  90. else
  91. {
  92. e.Graphics.DrawString(item.Text, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
  93. }
  94. });
  95. }
  96. rtbox.ItemHeight = 25;//õи߶
  97. if (rtbox.InvokeRequired)
  98. {
  99. rtbox.Invoke(new Action<ListBox, string, Brush, bool>((rtb, str, color, addtime) => AddListToListBox(rtb, str, color, addtime)), rtbox, text, foreColor, addTime);
  100. return;
  101. }
  102. //text = string.Format("{0}-{1}", rtbox.Items.Count.ToString("000"), text);
  103. if (addTime)
  104. {
  105. //text = string.Format("[{0}]:{1}", DateTime.Now.ToString("HH:mm:ss"), text);
  106. text = $"{DateTime.Now.ToString("HH:mm:ss")}{text}";
  107. }
  108. if (rtbox.Items.Count > 0)
  109. rtbox.Items.Insert(0, new ListBoxItem(text, foreColor));
  110. else
  111. rtbox.Items.Add(new ListBoxItem(text, foreColor));
  112. try
  113. {
  114. Write(text);
  115. }
  116. catch { }
  117. //
  118. if (rtbox.Items.Count > 100)
  119. {
  120. int count = rtbox.Items.Count - 100;
  121. List<object> temp = new List<object>();
  122. for (int i = 100; i < rtbox.Items.Count; i++)
  123. {
  124. if (rtbox.Items.Count >= i - 1) temp.Add(rtbox.Items[i]);
  125. }
  126. foreach (object obj in temp)
  127. {
  128. rtbox.Items.Remove(obj);
  129. }
  130. }
  131. //rtbox.SelectedIndex = rtbox.Items.Count - 1;
  132. //if (rtbox.Items.Count > 100)
  133. //{
  134. // int count = rtbox.Items.Count - 100;
  135. // List<object> temp = new List<object>();
  136. // for (int i = 0; i < count; i++)
  137. // {
  138. // temp.Add(rtbox.Items[i]);
  139. // }
  140. // foreach (object obj in temp)
  141. // {
  142. // rtbox.Items.Remove(obj);
  143. // }
  144. //}
  145. //rtbox.SelectedIndex = rtbox.Items.Count - 1;
  146. }
  147. private void Button1_SizeChanged(object? sender, EventArgs e)
  148. {
  149. groupBox1.Width = button1.Width;
  150. groupBox2.Width = button1.Width;
  151. groupBox3.Width = button1.Width;
  152. groupBox4.Width = button1.Width;
  153. button2.Left = 10;
  154. button2.Width = (groupBox1.Width - 20);
  155. button3.Left = 10;
  156. button3.Width = (groupBox1.Width - 20);
  157. button4.Left = 10;
  158. button4.Width = (groupBox2.Width - 20);
  159. button5.Left = 10;
  160. button5.Width = (groupBox2.Width - 20);
  161. button6.Left = 10;
  162. button6.Width = (groupBox2.Width - 20);
  163. button7.Left = 10;
  164. button7.Width = (groupBox2.Width - 20);
  165. button9.Left = 10;
  166. button9.Width = (groupBox3.Width - 20);
  167. button10.Left = 10;
  168. button10.Width = (groupBox3.Width - 20);
  169. button11.Left = 10;
  170. button11.Width = (groupBox3.Width - 20);
  171. button12.Left = 10;
  172. button12.Width = (groupBox4.Width - 20);
  173. }
  174. UserControl tempUserControl;
  175. private void Form1_SizeChanged(object? sender, EventArgs e)
  176. {
  177. if (tempUserControl != null)
  178. {
  179. tempUserControl.Width = this.panel1.Width;
  180. tempUserControl.Height = this.panel1.Height;
  181. }
  182. splitContainer1.SplitterDistance = 240;
  183. if (this.WindowState == FormWindowState.Maximized || this.WindowState == FormWindowState.Normal)
  184. {
  185. Task.Factory.StartNew(() =>
  186. {
  187. Thread.Sleep(100);
  188. this.Invoke(() =>
  189. {
  190. if (tempUserControl != null)
  191. {
  192. tempUserControl.Width = this.panel1.Width;
  193. tempUserControl.Height = this.panel1.Height;
  194. }
  195. splitContainer1.SplitterDistance = 240;
  196. });
  197. });
  198. }
  199. }
  200. //Ա¼
  201. private void button2_Click(object sender, EventArgs e)
  202. {
  203. ShowPage(new PersonnelEntryPage());
  204. }
  205. //¼
  206. private void button3_Click(object sender, EventArgs e)
  207. {
  208. ShowPage(new InstitutionalEntryPage());
  209. }
  210. //
  211. private void button5_Click(object sender, EventArgs e)
  212. {
  213. ShowPage(new CarMangerPage());
  214. }
  215. //ʧ
  216. private void button4_Click(object sender, EventArgs e)
  217. {
  218. ShowPage(new CancellationPage(), ((Button)sender)?.Tag.ToString());
  219. }
  220. //²Ͷλܱ
  221. private void button11_Click(object sender, EventArgs e)
  222. {
  223. ShowPage(new ReportFormPage(), ((Button)sender)?.Tag.ToString());
  224. }
  225. //Ͷ
  226. private void button12_Click(object sender, EventArgs e)
  227. {
  228. ShowPage(new MealSegmentSetPage());
  229. }
  230. private void ShowPage(UserControl userControl, string? name = "")
  231. {
  232. panel1.Controls.Clear();
  233. userControl.Width = panel1.Width;
  234. userControl.Height = panel1.Height;
  235. tempUserControl = userControl;
  236. userControl.Tag = name;
  237. userControl.Show();
  238. panel1.Controls.Add(userControl);
  239. }
  240. private void button8_Click(object sender, EventArgs e)
  241. {
  242. ShowPage(new AdvertisingSetPage());
  243. }
  244. }
  245. }