diff --git a/HKCardManager/Form1.Designer.cs b/HKCardManager/Form1.Designer.cs index 1a0b6bb..491f367 100644 --- a/HKCardManager/Form1.Designer.cs +++ b/HKCardManager/Form1.Designer.cs @@ -72,6 +72,7 @@ this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.panel1 = new System.Windows.Forms.Panel(); this.listBox1 = new System.Windows.Forms.ListBox(); + this.label1 = new System.Windows.Forms.Label(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); @@ -583,6 +584,7 @@ // // splitContainer2.Panel2 // + this.splitContainer2.Panel2.Controls.Add(this.label1); this.splitContainer2.Panel2.Controls.Add(this.listBox1); this.splitContainer2.Size = new System.Drawing.Size(954, 664); this.splitContainer2.SplitterDistance = 500; @@ -611,6 +613,16 @@ this.listBox1.Size = new System.Drawing.Size(954, 160); this.listBox1.TabIndex = 0; // + // label1 + // + this.label1.AutoSize = true; + this.label1.BackColor = System.Drawing.SystemColors.Control; + this.label1.Location = new System.Drawing.Point(247, 61); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(43, 17); + this.label1.TabIndex = 1; + this.label1.Text = "label1"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); @@ -644,6 +656,7 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit(); this.splitContainer2.Panel1.ResumeLayout(false); this.splitContainer2.Panel2.ResumeLayout(false); + this.splitContainer2.Panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); this.splitContainer2.ResumeLayout(false); this.ResumeLayout(false); @@ -697,5 +710,6 @@ private PictureBox pictureBox4; private PictureBox pictureBox3; private PictureBox pictureBox2; + private Label label1; } } \ No newline at end of file diff --git a/HKCardManager/Form1.cs b/HKCardManager/Form1.cs index 5840b72..1b44026 100644 --- a/HKCardManager/Form1.cs +++ b/HKCardManager/Form1.cs @@ -16,18 +16,122 @@ namespace HKCardManager ShowPage(new PersonnelEntryPage()); this.SizeChanged += Form1_SizeChanged; this.button1.SizeChanged += Button1_SizeChanged; - MessageLogNotify.GetInstance.Info = new Action((s) => + MessageLogNotify.GetInstance.Info = new Action((s, br) => + { + this.Invoke(() => + { + AddListToListBox(listBox1, s, br, true); + //if (listBox1.Items.Count > 0) + // listBox1.Items.Insert(0, $"{DateTime.Now.ToString("HH:mm:ss")}:{s}"); + //else + // listBox1.Items.Add($"{DateTime.Now.ToString("HH:mm:ss")}:{s}"); + }); + }); + } + + 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) { - this.Invoke(() => + rtbox.ItemHeight = 1; + rtbox.DrawItem += ((sender, e) => //控件重绘事件 { - if (listBox1.Items.Count > 0) - listBox1.Items.Insert(0, $"{DateTime.Now.ToString("HH:mm:ss")}:{s}"); + 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 - listBox1.Items.Add($"{DateTime.Now.ToString("HH:mm:ss")}:{s}"); + { + e.Graphics.DrawString(item.Text, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault); + } }); - }); + } + + + rtbox.ItemHeight = 25;//设置单行高度 + if (rtbox.InvokeRequired) + { + rtbox.Invoke(new Action((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 temp = new List(); + + // 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; diff --git a/HKCardManager/Models/ListBoxItem.cs b/HKCardManager/Models/ListBoxItem.cs new file mode 100644 index 0000000..9fdc2b4 --- /dev/null +++ b/HKCardManager/Models/ListBoxItem.cs @@ -0,0 +1,20 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HKCardManager +{ + public class ListBoxItem + { + public string Text { set; get; } + public Brush ForeColor { set; get; } + public ListBoxItem(string text, Brush foreColor) + { + this.Text = text; + + this.ForeColor = foreColor; + } + } +} diff --git a/HKCardManager/Servers/MessageLogNotify.cs b/HKCardManager/Servers/MessageLogNotify.cs index 81a6a43..041f872 100644 --- a/HKCardManager/Servers/MessageLogNotify.cs +++ b/HKCardManager/Servers/MessageLogNotify.cs @@ -13,23 +13,47 @@ namespace HKCardManager public static MessageLogNotify GetInstance => _Instance ?? (_Instance = new MessageLogNotify()); private MessageLogNotify() { } - public Action Info { get; set; } - - public void Show(string info) + public Action Info { get; set; } + + /// + /// 甯歌鏃ュ織鏄剧ず + /// + /// 鏃ュ織娑堟伅 + /// 鏃ュ織鏄剧ず棰滆壊 + public void Show(string info, Brush brush = null) { - Info?.Invoke(info); + Info?.Invoke(info, brush == null ? Brushes.Green : brush); } - public void ShowEx(string info) + /// + /// 搴旂敤绋嬪簭寮傚父鏃ュ織鏄剧ず + /// + /// 鏃ュ織淇℃伅 + /// 鏃ュ織鏄剧ず棰滆壊 + public void ShowEx(string info, Brush brush = null) { - Info?.Invoke(info); + Info?.Invoke(info, brush == null ? Brushes.Red : brush); } - public void ShowError(string info) + /// + /// 閿欒鏃ュ織鏄剧ず + /// + /// 鏃ュ織淇℃伅 + /// 鏃ュ織鏄剧ず棰滆壊 + public void ShowError(string info, Brush brush = null) { - Info?.Invoke(info); + Info?.Invoke(info, brush == null ? Brushes.Red : brush); } + /// + /// 璀﹀憡鏃ュ織鏄剧ず + /// + /// 鏃ュ織淇℃伅 + /// 鏃ュ織鏄剧ず棰滆壊 + public void ShowWarning(string info, Brush brush = null) + { + Info?.Invoke(info, brush == null ? Brushes.Yellow : brush); + } } } diff --git a/HKCardManager/UserPages/CancellationPage.cs b/HKCardManager/UserPages/CancellationPage.cs index 1880be7..125fafe 100644 --- a/HKCardManager/UserPages/CancellationPage.cs +++ b/HKCardManager/UserPages/CancellationPage.cs @@ -32,13 +32,13 @@ namespace HKCardManager.UserPages string name = textBox1.Text.Trim(); if (string.IsNullOrEmpty(name)) { - MessageLogNotify.GetInstance.Show("璇疯緭鍏ョ敤鎴峰悕"); + MessageLogNotify.GetInstance.ShowWarning("璇疯緭鍏ョ敤鎴峰悕"); return; } string TagName = this.Tag.ToString(); if (string.IsNullOrEmpty(TagName)) { - MessageLogNotify.GetInstance.Show("鍔熻兘鍚嶇О涓虹┖锛屾搷浣滃け璐ワ紝璇烽噸璇"); + MessageLogNotify.GetInstance.ShowError("鍔熻兘鍚嶇О涓虹┖锛屾搷浣滃け璐ワ紝璇烽噸璇"); } else { @@ -54,7 +54,7 @@ namespace HKCardManager.UserPages Stutas = status }); if (res) MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 {TagName} 鎴愬姛"); - else MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 {TagName} 澶辫触锛岃閲嶈瘯"); + else MessageLogNotify.GetInstance.ShowError($"鐢ㄦ埛 {TagName} 澶辫触锛岃閲嶈瘯"); }); } } diff --git a/HKCardManager/UserPages/CarMangerPage.cs b/HKCardManager/UserPages/CarMangerPage.cs index c3ea594..5d03411 100644 --- a/HKCardManager/UserPages/CarMangerPage.cs +++ b/HKCardManager/UserPages/CarMangerPage.cs @@ -47,12 +47,12 @@ namespace HKCardManager.UserPages { if (string.IsNullOrEmpty(textBox2.Text.Trim())) { - MessageLogNotify.GetInstance.Show("璇疯緭鍏ュ鍚"); + MessageLogNotify.GetInstance.ShowWarning("璇疯緭鍏ュ鍚"); return; } if (!textBox4.Text.Trim().IsMobile()) { - MessageLogNotify.GetInstance.Show("鎵嬫満鍙锋牸寮忎笉姝g‘"); + MessageLogNotify.GetInstance.ShowWarning("鎵嬫満鍙锋牸寮忎笉姝g‘"); return; } string OrgName = comboBox1.Text; @@ -74,7 +74,7 @@ namespace HKCardManager.UserPages } else { - MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 鍐欏崱澶辫触锛屽師鍥狅細{res?.ResMes}"); + MessageLogNotify.GetInstance.ShowError($"鐢ㄦ埛 銆恵userDto.Name}銆 鍐欏崱澶辫触锛屽師鍥狅細{res?.ResMes}"); } if (HKLibHelper.AddUserAndBindCard(userDto)) @@ -82,12 +82,12 @@ namespace HKCardManager.UserPages MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 娣诲姞鎴愬姛"); } else - MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 娣诲姞澶辫触锛岃閲嶈瘯锛"); + MessageLogNotify.GetInstance.ShowError($"鐢ㄦ埛 銆恵userDto.Name}銆 娣诲姞澶辫触锛岃閲嶈瘯锛"); }); } else { - MessageLogNotify.GetInstance.Show("璁惧鏈繛鎺"); + MessageLogNotify.GetInstance.ShowError("璁惧鏈繛鎺"); } } @@ -124,7 +124,7 @@ namespace HKCardManager.UserPages } else { - MessageLogNotify.GetInstance.Show("璁惧鏈繛鎺"); + MessageLogNotify.GetInstance.ShowWarning("璁惧鏈繛鎺"); } } } diff --git a/HKCardManager/UserPages/InstitutionalEntryPage.cs b/HKCardManager/UserPages/InstitutionalEntryPage.cs index cc4cc93..bc79bf7 100644 --- a/HKCardManager/UserPages/InstitutionalEntryPage.cs +++ b/HKCardManager/UserPages/InstitutionalEntryPage.cs @@ -30,14 +30,14 @@ namespace HKCardManager.UserPages string name = this.textBox1.Text.Trim(); if (string.IsNullOrEmpty(name)) { - MessageLogNotify.GetInstance.Show("璇疯緭鍏ユ満鏋勫悕绉"); + MessageLogNotify.GetInstance.ShowWarning("璇疯緭鍏ユ満鏋勫悕绉"); } Task.Factory.StartNew(() => { if (ServiceHandler.AddOrg(name)) MessageLogNotify.GetInstance.Show($"銆恵name}銆 鏈烘瀯娣诲姞鎴愬姛"); else - MessageLogNotify.GetInstance.Show($"銆恵name}銆 鏈烘瀯娣诲姞澶辫触锛岃閲嶈瘯"); + MessageLogNotify.GetInstance.ShowError($"銆恵name}銆 鏈烘瀯娣诲姞澶辫触锛岃閲嶈瘯"); }); } diff --git a/HKCardManager/UserPages/MealSegmentSetPage.cs b/HKCardManager/UserPages/MealSegmentSetPage.cs index 2b83796..bda5380 100644 --- a/HKCardManager/UserPages/MealSegmentSetPage.cs +++ b/HKCardManager/UserPages/MealSegmentSetPage.cs @@ -45,7 +45,7 @@ namespace HKCardManager.UserPages } else { - MessageLogNotify.GetInstance.Show("璁剧疆鏃堕棿娈靛け璐ワ紝璇烽噸璇曪紒"); + MessageLogNotify.GetInstance.ShowError("璁剧疆鏃堕棿娈靛け璐ワ紝璇烽噸璇曪紒"); } }); } diff --git a/HKCardManager/UserPages/PersonnelEntryPage.cs b/HKCardManager/UserPages/PersonnelEntryPage.cs index 9555647..7b8cd43 100644 --- a/HKCardManager/UserPages/PersonnelEntryPage.cs +++ b/HKCardManager/UserPages/PersonnelEntryPage.cs @@ -23,6 +23,7 @@ namespace HKCardManager.UserPages { InitializeComponent(); //this.SizeChanged += PersonnelEntryPage_SizeChanged; + dataGridView1.AutoGenerateColumns = false; comboBox1.SelectedIndex = 0; orgTables = ServiceHandler.GetOrgList(); orgTables?.ForEach(item => @@ -81,12 +82,12 @@ namespace HKCardManager.UserPages { if (string.IsNullOrEmpty(textBox1.Text.Trim())) { - MessageLogNotify.GetInstance.Show("璇疯緭鍏ュ鍚"); + MessageLogNotify.GetInstance.ShowWarning("璇疯緭鍏ュ鍚"); return; } if (!textBox2.Text.Trim().IsMobile()) { - MessageLogNotify.GetInstance.Show("鎵嬫満鍙锋牸寮忎笉姝g‘"); + MessageLogNotify.GetInstance.ShowWarning("鎵嬫満鍙锋牸寮忎笉姝g‘"); return; } UserDto userDto = new UserDto() @@ -108,18 +109,20 @@ namespace HKCardManager.UserPages }); this.Invoke(() => { - dataGridView1.Rows.Add(); - int len = dataGridView1.Rows.Count - 1; - dataGridView1.Rows[len].Cells[0].Value = userDto.Name; - dataGridView1.Rows[len].Cells[1].Value = ""; - dataGridView1.Rows[len].Cells[2].Value = OrgName; - dataGridView1.Rows[len].Cells[3].Value = userDto.Phone; - dataGridView1.Rows[len].Cells[4].Value = ""; + dataGridView1.DataSource = null; + dataGridView1.DataSource = userListDtos; + //dataGridView1.Rows.Add(); + //int len = dataGridView1.Rows.Count - 1; + //dataGridView1.Rows[len].Cells[0].Value = userDto.Name; + //dataGridView1.Rows[len].Cells[1].Value = ""; + //dataGridView1.Rows[len].Cells[2].Value = OrgName; + //dataGridView1.Rows[len].Cells[3].Value = userDto.Phone; + //dataGridView1.Rows[len].Cells[4].Value = ""; }); MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 娣诲姞鎴愬姛"); } else - MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 娣诲姞澶辫触锛岃閲嶈瘯锛"); + MessageLogNotify.GetInstance.ShowError($"鐢ㄦ埛 銆恵userDto.Name}銆 娣诲姞澶辫触锛岃閲嶈瘯锛"); }); } diff --git a/HKCardManager/UserPages/ReportFormPage.cs b/HKCardManager/UserPages/ReportFormPage.cs index 9508c7c..fe3a541 100644 --- a/HKCardManager/UserPages/ReportFormPage.cs +++ b/HKCardManager/UserPages/ReportFormPage.cs @@ -18,6 +18,7 @@ namespace HKCardManager.UserPages public ReportFormPage() { InitializeComponent(); + dataGridView1.AutoGenerateColumns = false; } private void ExportDataToExcel(DataGridView TableName, string FileName) @@ -110,12 +111,12 @@ namespace HKCardManager.UserPages } else if (res.Count <= 0) { - MessageLogNotify.GetInstance.Show("鏈煡璇㈠埌鏁版嵁"); + MessageLogNotify.GetInstance.ShowWarning("鏈煡璇㈠埌鏁版嵁"); } } else { - MessageLogNotify.GetInstance.Show("鏌ヨ澶辫触锛岃杈撳叆姝g‘鐨勬椂闂存"); + MessageLogNotify.GetInstance.ShowError("鏌ヨ澶辫触锛岃杈撳叆姝g‘鐨勬椂闂存"); } }); }