|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- using HKCardManager.UserPages;
- using HKLib.Dto;
- using HKLib.Interfaces;
- using HKLib.SQLHelper;
- using System.Text.RegularExpressions;
- using HKHelper;
- using UHFHelper;
-
- namespace HKCardManager
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- DbContext.InitTable();
- splitContainer1.SplitterDistance = 240;
- DataGridViewInit();
- ShowPage(new PersonnelEntryPage());
- Task.Factory.StartNew(() =>
- {
- var res = UHFCardHelper.GetInstance().OpenPort();
- if (res != null && res.Res)
- MessageLogNotify.GetInstance.Show("ƿ豸ӣ");
- else MessageLogNotify.GetInstance.ShowError($"ƿ豸δӣ");
- });
- this.SizeChanged += Form1_SizeChanged;
- this.button1.SizeChanged += Button1_SizeChanged;
- this.splitContainer2.SplitterMoved += SplitContainer1_SizeChanged;
- MessageLogNotify.GetInstance.Info = new Action<string, Color>((s, br) =>
- {
- this.Invoke(() =>
- {
- dataGridView1.Rows.Insert(0, new string[] { "", $"{DateTime.Now.ToString("HH:mm:ss")} {s}" });
- dataGridView1.Rows[0].DefaultCellStyle.ForeColor = br;
- dataGridView1.Rows[0].DefaultCellStyle.Padding = new Padding(0, 0, 0, 10);
- });
- });
- }
-
- private void SplitContainer1_SizeChanged(object? sender, EventArgs e)
- {
- if (tempUserControl != null)
- {
- tempUserControl.Width = this.panel1.Width;
- tempUserControl.Height = this.panel1.Height;
- }
- }
-
- private void DataGridViewInit()
- {
- dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
- dataGridView1.AutoGenerateColumns = false;//ֹԶ
- dataGridView1.AllowUserToResizeColumns = false;//ǷԵеĴС
- dataGridView1.AllowUserToResizeRows = false;//ǷԵеĴС
- dataGridView1.BorderStyle = BorderStyle.None;//DataGridView߿ʽ
- dataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
- dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
- dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
- dataGridView1.SelectionChanged += DataGridView1_SelectionChanged;
-
- }
-
- private void DataGridView1_SelectionChanged(object? sender, EventArgs e)
- {
- dataGridView1.ClearSelection();//ֹѡ
- }
-
- private void Write(string msg)
- {
- //boolĬΪļ涨,Զκα
- //bool temp = Convert.ToBoolean(iniFile.IniReadValue("", "Ϣ", AppDomain.CurrentDomain.BaseDirectory + ".ini"));
- //if (temp)
- //{
- // string logPath = Path.GetDirectoryName(Application.ExecutablePath);
- // // System.IO.StreamWriter sw = System.IO.File.AppendText(logPath + "/" + DateTime.Now.ToString("yyMMdd") + ".txt");
- // System.IO.StreamWriter sw = System.IO.File.AppendText(logPath + "\\log\\" + DateTime.Now.ToString("yyMMdd") + ".txt");
-
- // sw.WriteLine(DateTime.Now.ToString("HH:mm:ss ") + msg);
- // sw.Close();
- // sw.Dispose();
- //}
- }
-
- private void AddListToListBox(ListBox rtbox, string text, Brush foreColor, bool addTime = true)
- {
- rtbox.DrawMode = DrawMode.OwnerDrawVariable;
- rtbox.Font = new Font("", 12);
- if (rtbox.ItemHeight != 24)
- {
- rtbox.ItemHeight = 1;
- rtbox.DrawItem += ((sender, e) => //ؼػ¼
- {
- if (e.Index == -1) return;
- e.DrawBackground();
- ListBoxItem item = (ListBoxItem)rtbox.Items[e.Index];
- if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
- {
- e.DrawFocusRectangle();
- Brush b = Brushes.Khaki;//ѡɫ
- e.Graphics.FillRectangle(b, e.Bounds);
- }
- if (item != null)
- {
- Brush brush = item.ForeColor;
- Rectangle r = e.Bounds;
- r.Height = e.Bounds.Height;
- r.Width = e.Bounds.Width + 100;
-
- e.Graphics.DrawString(item.Text, e.Font, brush, r, StringFormat.GenericDefault);
- }
- else
- {
- e.Graphics.DrawString(item.Text, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
- }
- });
- }
-
-
- rtbox.ItemHeight = 25;//õи߶
- if (rtbox.InvokeRequired)
- {
- rtbox.Invoke(new Action<ListBox, string, Brush, bool>((rtb, str, color, addtime) => AddListToListBox(rtb, str, color, addtime)), rtbox, text, foreColor, addTime);
- return;
- }
-
- //text = string.Format("{0}-{1}", rtbox.Items.Count.ToString("000"), text);
-
- if (addTime)
- {
- //text = string.Format("[{0}]:{1}", DateTime.Now.ToString("HH:mm:ss"), text);
- text = $"{DateTime.Now.ToString("HH:mm:ss")}{text}";
- }
-
- if (rtbox.Items.Count > 0)
- rtbox.Items.Insert(0, new ListBoxItem(text, foreColor));
- else
- rtbox.Items.Add(new ListBoxItem(text, foreColor));
-
- try
- {
- Write(text);
-
- }
- catch { }
-
- //
- if (rtbox.Items.Count > 100)
- {
- int count = rtbox.Items.Count - 100;
- List<object> temp = new List<object>();
- for (int i = 100; i < rtbox.Items.Count; i++)
- {
- if (rtbox.Items.Count >= i - 1) temp.Add(rtbox.Items[i]);
- }
- foreach (object obj in temp)
- {
- rtbox.Items.Remove(obj);
- }
- }
- //rtbox.SelectedIndex = rtbox.Items.Count - 1;
- //if (rtbox.Items.Count > 100)
- //{
- // int count = rtbox.Items.Count - 100;
-
- // List<object> temp = new List<object>();
-
- // for (int i = 0; i < count; i++)
- // {
- // temp.Add(rtbox.Items[i]);
- // }
-
- // foreach (object obj in temp)
- // {
- // rtbox.Items.Remove(obj);
- // }
- //}
- //rtbox.SelectedIndex = rtbox.Items.Count - 1;
- }
-
- private void Button1_SizeChanged(object? sender, EventArgs e)
- {
- groupBox1.Width = button1.Width;
- groupBox2.Width = button1.Width;
- groupBox3.Width = button1.Width;
- groupBox4.Width = button1.Width;
-
- button2.Left = 10;
- button2.Width = (groupBox1.Width - 20);
-
- button3.Left = 10;
- button3.Width = (groupBox1.Width - 20);
-
- button4.Left = 10;
- button4.Width = (groupBox2.Width - 20);
-
- button5.Left = 10;
- button5.Width = (groupBox2.Width - 20);
-
- button6.Left = 10;
- button6.Width = (groupBox2.Width - 20);
-
- button7.Left = 10;
- button7.Width = (groupBox2.Width - 20);
-
- button9.Left = 10;
- button9.Width = (groupBox3.Width - 20);
-
- button10.Left = 10;
- button10.Width = (groupBox3.Width - 20);
-
- button11.Left = 10;
- button11.Width = (groupBox3.Width - 20);
-
- button12.Left = 10;
- button12.Width = (groupBox4.Width - 20);
- }
-
- UserControl tempUserControl;
- private void Form1_SizeChanged(object? sender, EventArgs e)
- {
- if (tempUserControl != null)
- {
- tempUserControl.Width = this.panel1.Width;
- tempUserControl.Height = this.panel1.Height;
- }
- splitContainer1.SplitterDistance = 240;
-
- if (this.WindowState == FormWindowState.Maximized || this.WindowState == FormWindowState.Normal)
- {
- Task.Factory.StartNew(() =>
- {
- Thread.Sleep(100);
- this.Invoke(() =>
- {
- if (tempUserControl != null)
- {
- tempUserControl.Width = this.panel1.Width;
- tempUserControl.Height = this.panel1.Height;
- }
- splitContainer1.SplitterDistance = 240;
- });
- });
- }
- }
-
- //Ա¼
- private void button2_Click(object sender, EventArgs e)
- {
- ShowPage(new PersonnelEntryPage());
- }
-
- //¼
- private void button3_Click(object sender, EventArgs e)
- {
- ShowPage(new InstitutionalEntryPage());
- }
-
- //
- private void button5_Click(object sender, EventArgs e)
- {
- ShowPage(new CarMangerPage());
- }
-
- //ʧ
- private void button4_Click(object sender, EventArgs e)
- {
- ShowPage(new CancellationPage(), ((Button)sender)?.Tag.ToString());
- }
-
- //²Ͷλܱ
- private void button11_Click(object sender, EventArgs e)
- {
- ShowPage(new ReportFormPage(), ((Button)sender)?.Tag.ToString());
- }
-
- //Ͷ
- private void button12_Click(object sender, EventArgs e)
- {
- ShowPage(new MealSegmentSetPage());
- }
-
- private void ShowPage(UserControl userControl, string? name = "")
- {
- panel1.Controls.Clear();
- userControl.Width = panel1.Width;
- userControl.Height = panel1.Height;
- tempUserControl = userControl;
- userControl.Tag = name;
- userControl.Show();
- panel1.Controls.Add(userControl);
- }
-
- private void button8_Click(object sender, EventArgs e)
- {
- ShowPage(new AdvertisingSetPage());
- }
-
- private async void button13_Click(object sender, EventArgs e)
- {
-
- if (UHFCardHelper.GetInstance().ComOpen)
- {
- try
- {
-
- var res = UHFCardHelper.GetInstance().ReadCard();
-
- if (string.IsNullOrEmpty(res))
- {
- MessageBox.Show("ʾ\n 뿨Ƭѡ...");
- MessageLogNotify.GetInstance.Show("뿨Ƭ");
- return;
- }
-
- if (res.Equals("666") || res.Equals("888") || res.Equals("999"))
- {
- MessageBox.Show("ܱע");
- return;
- }
-
- var result = await HKLibHelper.GetUserList("");
- UserListDto users = null;
- result.ForEach(item =>
- {
- if (item.Cards.FirstOrDefault(t => t.CardNum.Equals(res)) != null)
- {
- users = item;
- return;
- }
- });
-
- if (users != null)
- {
- await HKLibHelper.CardStutasChange(new CardStutasDto()
- {
- keywrod = users.Name,
- Stutas = 3,
- });
- }
- var resz = MessageBox.Show($"ʾ\n ǰ{res}ȷ?", "ʾ", MessageBoxButtons.YesNo);
- if (resz == DialogResult.Yes)
- {
- var res1 = UHFCardHelper.GetInstance().WriteCard("000");
- MessageBox.Show(res1.Res ? "000ΪĬ¿ţɹ" : "ʧ");
- }
- }
- catch (Exception)
- {
- MessageBox.Show("ɹ");
- }
-
- }
- else
- {
- MessageBox.Show("ʾ\n 豸δ...");
- MessageLogNotify.GetInstance.ShowWarning("豸δ");
- }
- }
- }
-
-
- }
|