Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Form1.cs 11 KiB

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