@@ -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; | |||
} | |||
} |
@@ -16,18 +16,122 @@ namespace HKCardManager | |||
ShowPage(new PersonnelEntryPage()); | |||
this.SizeChanged += Form1_SizeChanged; | |||
this.button1.SizeChanged += Button1_SizeChanged; | |||
MessageLogNotify.GetInstance.Info = new Action<string>((s) => | |||
MessageLogNotify.GetInstance.Info = new Action<string, Brush>((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<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 = 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; | |||
@@ -0,0 +1,20 @@ | |||
using 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; | |||
} | |||
} | |||
} |
@@ -13,23 +13,47 @@ namespace HKCardManager | |||
public static MessageLogNotify GetInstance => _Instance ?? (_Instance = new MessageLogNotify()); | |||
private MessageLogNotify() { } | |||
public Action<string> Info { get; set; } | |||
public void Show(string info) | |||
public Action<string, Brush> Info { get; set; } | |||
/// <summary> | |||
/// 常规日志显示 | |||
/// </summary> | |||
/// <param name="info">日志消息</param> | |||
/// <param name="brush">日志显示颜色</param> | |||
public void Show(string info, Brush brush = null) | |||
{ | |||
Info?.Invoke(info); | |||
Info?.Invoke(info, brush == null ? Brushes.Green : brush); | |||
} | |||
public void ShowEx(string info) | |||
/// <summary> | |||
/// 应用程序异常日志显示 | |||
/// </summary> | |||
/// <param name="info">日志信息</param> | |||
/// <param name="brush">日志显示颜色</param> | |||
public void ShowEx(string info, Brush brush = null) | |||
{ | |||
Info?.Invoke(info); | |||
Info?.Invoke(info, brush == null ? Brushes.Red : brush); | |||
} | |||
public void ShowError(string info) | |||
/// <summary> | |||
/// 错误日志显示 | |||
/// </summary> | |||
/// <param name="info">日志信息</param> | |||
/// <param name="brush">日志显示颜色</param> | |||
public void ShowError(string info, Brush brush = null) | |||
{ | |||
Info?.Invoke(info); | |||
Info?.Invoke(info, brush == null ? Brushes.Red : brush); | |||
} | |||
/// <summary> | |||
/// 警告日志显示 | |||
/// </summary> | |||
/// <param name="info">日志信息</param> | |||
/// <param name="brush">日志显示颜色</param> | |||
public void ShowWarning(string info, Brush brush = null) | |||
{ | |||
Info?.Invoke(info, brush == null ? Brushes.Yellow : brush); | |||
} | |||
} | |||
} |
@@ -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} 失败,请重试"); | |||
}); | |||
} | |||
} | |||
@@ -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("手机号格式不正确"); | |||
MessageLogNotify.GetInstance.ShowWarning("手机号格式不正确"); | |||
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("设备未连接"); | |||
} | |||
} | |||
} | |||
@@ -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}】 机构添加失败,请重试"); | |||
}); | |||
} | |||
@@ -45,7 +45,7 @@ namespace HKCardManager.UserPages | |||
} | |||
else | |||
{ | |||
MessageLogNotify.GetInstance.Show("设置时间段失败,请重试!"); | |||
MessageLogNotify.GetInstance.ShowError("设置时间段失败,请重试!"); | |||
} | |||
}); | |||
} | |||
@@ -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("手机号格式不正确"); | |||
MessageLogNotify.GetInstance.ShowWarning("手机号格式不正确"); | |||
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}】 添加失败,请重试!"); | |||
}); | |||
} | |||
@@ -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("查询失败,请输入正确的时间段"); | |||
MessageLogNotify.GetInstance.ShowError("查询失败,请输入正确的时间段"); | |||
} | |||
}); | |||
} | |||