Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

310 rindas
10 KiB

  1. using HKLib.DB;
  2. using HKCardManager.UserPages;
  3. namespace HKCardManager
  4. {
  5. public partial class Form1 : Form
  6. {
  7. public Form1()
  8. {
  9. InitializeComponent();
  10. splitContainer1.SplitterDistance = 240;
  11. Task.Factory.StartNew(() =>
  12. {
  13. DbContext.InitTable();
  14. });
  15. ShowPage(new PersonnelEntryPage());
  16. this.SizeChanged += Form1_SizeChanged;
  17. this.button1.SizeChanged += Button1_SizeChanged;
  18. MessageLogNotify.GetInstance.Info = new Action<string, Brush>((s, br) =>
  19. {
  20. this.Invoke(() => { AddListToListBox(listBox1, s, br, true); });
  21. });
  22. }
  23. private void Write(string msg)
  24. {
  25. //bool条件默认为配置文件里面定义,可以自定义任何保存数据条件
  26. //bool temp = Convert.ToBoolean(iniFile.IniReadValue("设置", "保存运行信息", AppDomain.CurrentDomain.BaseDirectory + "设置.ini"));
  27. //if (temp)
  28. //{
  29. // string logPath = Path.GetDirectoryName(Application.ExecutablePath);
  30. // // System.IO.StreamWriter sw = System.IO.File.AppendText(logPath + "/" + DateTime.Now.ToString("yyMMdd") + ".txt");
  31. // System.IO.StreamWriter sw = System.IO.File.AppendText(logPath + "\\log\\" + DateTime.Now.ToString("yyMMdd") + ".txt");
  32. // sw.WriteLine(DateTime.Now.ToString("HH:mm:ss ") + msg);
  33. // sw.Close();
  34. // sw.Dispose();
  35. //}
  36. }
  37. private void AddListToListBox(ListBox rtbox, string text, Brush foreColor, bool addTime = true)
  38. {
  39. rtbox.DrawMode = DrawMode.OwnerDrawVariable;
  40. rtbox.Font = new Font("楷体", 12);
  41. if (rtbox.ItemHeight != 24)
  42. {
  43. rtbox.ItemHeight = 1;
  44. rtbox.DrawItem += ((sender, e) => //控件重绘事件
  45. {
  46. if (e.Index == -1) return;
  47. e.DrawBackground();
  48. ListBoxItem item = (ListBoxItem)rtbox.Items[e.Index];
  49. if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
  50. {
  51. e.DrawFocusRectangle();
  52. Brush b = Brushes.Khaki;//设置选中项颜色
  53. e.Graphics.FillRectangle(b, e.Bounds);
  54. }
  55. if (item != null)
  56. {
  57. Brush brush = item.ForeColor;
  58. Rectangle r = e.Bounds;
  59. r.Height = e.Bounds.Height;
  60. r.Width = e.Bounds.Width + 100;
  61. e.Graphics.DrawString(item.Text, e.Font, brush, r, StringFormat.GenericDefault);
  62. }
  63. else
  64. {
  65. e.Graphics.DrawString(item.Text, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
  66. }
  67. });
  68. }
  69. rtbox.ItemHeight = 25;//设置单行高度
  70. if (rtbox.InvokeRequired)
  71. {
  72. rtbox.Invoke(new Action<ListBox, string, Brush, bool>((rtb, str, color, addtime) => AddListToListBox(rtb, str, color, addtime)), rtbox, text, foreColor, addTime);
  73. return;
  74. }
  75. //text = string.Format("{0}-{1}", rtbox.Items.Count.ToString("000"), text);
  76. if (addTime)
  77. {
  78. //text = string.Format("[{0}]:{1}", DateTime.Now.ToString("HH:mm:ss"), text);
  79. text = $"{DateTime.Now.ToString("HH:mm:ss")}:{text}";
  80. }
  81. if (rtbox.Items.Count > 0)
  82. rtbox.Items.Insert(0, new ListBoxItem(text, foreColor));
  83. else
  84. rtbox.Items.Add(new ListBoxItem(text, foreColor));
  85. try
  86. {
  87. Write(text);
  88. }
  89. catch { }
  90. //清除过多的数据
  91. //if (rtbox.Items.Count > 100)
  92. //{
  93. // int count = rtbox.Items.Count - 100;
  94. // List<object> temp = new List<object>();
  95. // for (int i = 0; i < count; i++)
  96. // {
  97. // temp.Add(rtbox.Items[i]);
  98. // }
  99. // foreach (object obj in temp)
  100. // {
  101. // rtbox.Items.Remove(obj);
  102. // }
  103. //}
  104. //rtbox.SelectedIndex = rtbox.Items.Count - 1;
  105. }
  106. private void Button1_SizeChanged(object? sender, EventArgs e)
  107. {
  108. groupBox1.Width = button1.Width;
  109. groupBox2.Width = button1.Width;
  110. groupBox3.Width = button1.Width;
  111. groupBox4.Width = button1.Width;
  112. button2.Left = 10;
  113. button2.Width = (groupBox1.Width - 20);
  114. button3.Left = 10;
  115. button3.Width = (groupBox1.Width - 20);
  116. button4.Left = 10;
  117. button4.Width = (groupBox2.Width - 20);
  118. button5.Left = 10;
  119. button5.Width = (groupBox2.Width - 20);
  120. button6.Left = 10;
  121. button6.Width = (groupBox2.Width - 20);
  122. button7.Left = 10;
  123. button7.Width = (groupBox2.Width - 20);
  124. button9.Left = 10;
  125. button9.Width = (groupBox3.Width - 20);
  126. button10.Left = 10;
  127. button10.Width = (groupBox3.Width - 20);
  128. button11.Left = 10;
  129. button11.Width = (groupBox3.Width - 20);
  130. button12.Left = 10;
  131. button12.Width = (groupBox4.Width - 20);
  132. }
  133. UserControl tempUserControl;
  134. private void Form1_SizeChanged(object? sender, EventArgs e)
  135. {
  136. if (tempUserControl != null)
  137. {
  138. tempUserControl.Width = this.panel1.Width;
  139. tempUserControl.Height = this.panel1.Height;
  140. }
  141. splitContainer1.SplitterDistance = 240;
  142. if (this.WindowState == FormWindowState.Maximized || this.WindowState == FormWindowState.Normal)
  143. {
  144. Task.Factory.StartNew(() =>
  145. {
  146. Thread.Sleep(100);
  147. this.Invoke(() =>
  148. {
  149. if (tempUserControl != null)
  150. {
  151. tempUserControl.Width = this.panel1.Width;
  152. tempUserControl.Height = this.panel1.Height;
  153. }
  154. splitContainer1.SplitterDistance = 240;
  155. });
  156. });
  157. }
  158. }
  159. //private void 人员录入ToolStripMenuItem_Click(object sender, EventArgs e)
  160. //{
  161. // new PersonnelEntry().ShowDialog();
  162. //}
  163. //private void 机构录入ToolStripMenuItem_Click(object sender, EventArgs e)
  164. //{
  165. // new InstitutionalEntry().ShowDialog();
  166. //}
  167. //private void 发卡ToolStripMenuItem_Click(object sender, EventArgs e)
  168. //{
  169. // new Hairpin().ShowDialog();
  170. //}
  171. //private void 销户ToolStripMenuItem_Click(object sender, EventArgs e)
  172. //{
  173. // Cancellation cancellation = new Cancellation();
  174. // cancellation.Text = "销户";
  175. // cancellation.ShowDialog();
  176. //}
  177. //private void 挂失ToolStripMenuItem_Click(object sender, EventArgs e)
  178. //{
  179. // Cancellation cancellation = new Cancellation();
  180. // cancellation.Text = "挂失";
  181. // cancellation.ShowDialog();
  182. //}
  183. //private void 解挂ToolStripMenuItem_Click(object sender, EventArgs e)
  184. //{
  185. // Cancellation cancellation = new Cancellation();
  186. // cancellation.Text = "解挂";
  187. // cancellation.ShowDialog();
  188. //}
  189. //private void 月餐段汇总表ToolStripMenuItem_Click(object sender, EventArgs e)
  190. //{
  191. // DailyConsumptionTable dailyConsumptionTable = new DailyConsumptionTable();
  192. // dailyConsumptionTable.Text = "月餐段汇总表";
  193. // dailyConsumptionTable.ShowDialog();
  194. //}
  195. //private void 计次就餐天消费表ToolStripMenuItem_Click(object sender, EventArgs e)
  196. //{
  197. // DailyConsumptionTable dailyConsumptionTable = new DailyConsumptionTable();
  198. // dailyConsumptionTable.Text = "计次就餐天消费表";
  199. // dailyConsumptionTable.ShowDialog();
  200. //}
  201. //private void 计次就餐消费明细表ToolStripMenuItem_Click(object sender, EventArgs e)
  202. //{
  203. // DailyConsumptionTable dailyConsumptionTable = new DailyConsumptionTable();
  204. // dailyConsumptionTable.Text = "计次就餐消费明细表";
  205. // dailyConsumptionTable.ShowDialog();
  206. //}
  207. //private void 餐段设置ToolStripMenuItem_Click(object sender, EventArgs e)
  208. //{
  209. // new MealSegmentSet().ShowDialog();
  210. //}
  211. //人员录入
  212. private void button2_Click(object sender, EventArgs e)
  213. {
  214. ShowPage(new PersonnelEntryPage());
  215. }
  216. //机构录入
  217. private void button3_Click(object sender, EventArgs e)
  218. {
  219. ShowPage(new InstitutionalEntryPage());
  220. }
  221. //发卡
  222. private void button5_Click(object sender, EventArgs e)
  223. {
  224. ShowPage(new CarMangerPage());
  225. }
  226. //销户,挂失,解挂
  227. private void button4_Click(object sender, EventArgs e)
  228. {
  229. ShowPage(new CancellationPage(), ((Button)sender)?.Tag.ToString());
  230. }
  231. //月餐段汇总表
  232. private void button11_Click(object sender, EventArgs e)
  233. {
  234. ShowPage(new ReportFormPage(), ((Button)sender)?.Tag.ToString());
  235. }
  236. //餐段设置
  237. private void button12_Click(object sender, EventArgs e)
  238. {
  239. ShowPage(new MealSegmentSetPage());
  240. }
  241. private void ShowPage(UserControl userControl, string? name = "")
  242. {
  243. panel1.Controls.Clear();
  244. userControl.Width = panel1.Width;
  245. userControl.Height = panel1.Height;
  246. tempUserControl = userControl;
  247. userControl.Tag = name;
  248. userControl.Show();
  249. panel1.Controls.Add(userControl);
  250. }
  251. private void button8_Click(object sender, EventArgs e)
  252. {
  253. ShowPage(new AdvertisingSetPage());
  254. }
  255. }
  256. }