You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

329 lines
11 KiB

  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. }