Skip to content

Commit 5ff23f2

Browse files
committed
增加一个运行时日志,修复一些其他的小BUG,调整文件删除确认
1 parent 5188163 commit 5ff23f2

File tree

8 files changed

+88
-18
lines changed

8 files changed

+88
-18
lines changed

CommonLibrary/AccountSupport/ServerAccount.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public void UpdatePassword(string name, string password)
4747
if (name == all_list_accounts[i].UserName)
4848
{
4949
all_list_accounts[i].Password = password;
50+
LogHelper?.LogSave(Resource.StringResouce.AccountModifyPassword + name);
5051
break;
5152
}
5253
}
@@ -144,6 +145,7 @@ public bool AddNewAccount(T account)
144145
}
145146
}
146147
all_list_accounts.Add(account);
148+
LogHelper?.LogSave(Resource.StringResouce.AccountAddSuccess + account.UserName);
147149
}
148150
return true;
149151
}
@@ -161,6 +163,7 @@ public void DeleteAccount(string name)
161163
if (name == all_list_accounts[i].UserName)
162164
{
163165
all_list_accounts.RemoveAt(i);
166+
LogHelper?.LogSave(Resource.StringResouce.AccountDeleteSuccess + name);
164167
break;
165168
}
166169
}
@@ -208,7 +211,7 @@ public void LoadAllAccountsJson(string json)
208211
}
209212
catch(Exception ex)
210213
{
211-
LogHelper.LogSave(Resource.StringResouce.AccountLoadFailed, ex);
214+
LogHelper?.LogSave(Resource.StringResouce.AccountLoadFailed, ex);
212215
}
213216
}
214217
}

CommonLibrary/HeadCode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class SimplifyHeadCode
4343
public static string 同步日志清空 { get; } = "B004";
4444
public static string 更新日志查看 { get; } = "B005";
4545
public static string 更新日志清空 { get; } = "B006";
46+
public static string 运行日志查看 { get; } = "B007";
47+
public static string 运行日志清空 { get; } = "B008";
4648

4749
/**************************************************************************************
4850
*

CommonLibrary/Resource.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public class StringResouce
2020

2121

2222

23-
public const string AccountLoadFailed = "新增账户失败";
23+
public const string AccountLoadFailed = "新增账户失败";
24+
public const string AccountDeleteSuccess = "账户删除:";
25+
public const string AccountAddSuccess = "账户新增:";
26+
public const string AccountModifyPassword = "账户更改密码:";
2427
}
2528
}
2629
}

软件系统客户端模版/FormLog.Designer.cs

Lines changed: 46 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

软件系统客户端模版/FormLog.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,15 @@ private void userButton5_Click(object sender, EventArgs e)
7171
{
7272
ClearFromServer(CommonHeadCode.SimplifyHeadCode.更新日志清空);
7373
}
74+
75+
private void userButton7_Click(object sender, EventArgs e)
76+
{
77+
ReadFromServer(CommonHeadCode.SimplifyHeadCode.运行日志查看);
78+
}
79+
80+
private void userButton6_Click(object sender, EventArgs e)
81+
{
82+
ClearFromServer(CommonHeadCode.SimplifyHeadCode.运行日志清空);
83+
}
7484
}
7585
}

软件系统客户端模版/FormRegisterAccount.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ private void userButton_login_Click(object sender, EventArgs e)
4040
UserAccount account = new UserAccount();
4141
account.UserName = textBox1.Text;
4242
account.Password = textBox2.Text;
43+
account.Factory = textBox3.Text;
4344
switch (comboBox1.SelectedIndex)
4445
{
4546
case 0: account.Grade = AccountGrade.SuperAdministrator; break;

软件系统客户端模版/UIControls/ShareFilesRender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void SetFilesShow(List<File_Save> files)
7777
}
7878
else
7979
{
80-
return true;
80+
return MessageBox.Show("请确认是否真的删除?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes;
8181
}
8282
});
8383
panel2.Controls.Add(item);

软件系统服务端模版/Form1.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public Form1()
6565
private void Form1_Load(object sender, EventArgs e)
6666
{
6767
//初始化日志工具
68-
LogHelper = new SoftLogHelper()
68+
RuntimeLogHelper = new SoftLogHelper()
6969
{
7070
LogSaveFileName = Application.StartupPath + @"\log.txt",
7171
};
@@ -78,7 +78,7 @@ private void Form1_Load(object sender, EventArgs e)
7878
//加载账户信息
7979
UserServer.ServerAccounts.FileSavePath = Application.StartupPath + @"\accounts.txt";
8080
UserServer.ServerAccounts.LoadByFile();
81-
UserServer.ServerAccounts.LogHelper = LogHelper;
81+
UserServer.ServerAccounts.LogHelper = RuntimeLogHelper;
8282
}
8383
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
8484
{
@@ -449,6 +449,15 @@ private void DataProcessingWithStartB(AsyncStateBase object1, string object2)
449449
net_soft_update_Server.LogHelper.ClearLogText();
450450
net_simplify_server.SendMessage(object1, "成功");
451451
}
452+
else if (headCode == CommonHeadCode.SimplifyHeadCode.运行日志查看)
453+
{
454+
net_simplify_server.SendMessage(object1, RuntimeLogHelper.GetLogText());
455+
}
456+
else if (headCode == CommonHeadCode.SimplifyHeadCode.运行日志清空)
457+
{
458+
RuntimeLogHelper.ClearLogText();
459+
net_simplify_server.SendMessage(object1, "成功");
460+
}
452461
else
453462
{
454463
net_simplify_server.SendMessage(object1, object2);
@@ -680,9 +689,9 @@ private void MelsecNetMultiInnitialization()
680689
IpEndPoints.Add(new System.Net.IPEndPoint(System.Net.IPAddress.Parse("192.168.10." + i), 6000));
681690
}
682691

683-
//每隔1000秒钟访问一次
692+
//每隔1秒钟访问一次
684693
MelsecMulti = new HslCommunication.Profinet.MelsecNetMultiAsync(0, 0, HslCommunication.Profinet.MelsecDataType.D, 6000, 20, 700, 1000, IpEndPoints.ToArray());
685-
MelsecMulti.OnReceivedData += MelsecMulti_OnReceivedData;
694+
MelsecMulti.OnReceivedData += MelsecMulti_OnReceivedData;//所有机台的数据都返回时触发
686695
}
687696

688697
private void MelsecMulti_OnReceivedData(byte[] object1)
@@ -696,7 +705,13 @@ private void MelsecMulti_OnReceivedData(byte[] object1)
696705
* 每台设备的前两个字节都为0才说明本次数据访问正常,为0x00,0x01说明连接失败,其他说明说明三菱本身的异常
697706
*
698707
********************************************************************************************/
708+
for (int i = 0; i < 100; i++)
709+
{
710+
int startIndex = i * 42;
711+
ushort netState = BitConverter.ToUInt16(object1, startIndex);//为0,说明数据正常,不为0说明网络访问失败或是指令出错
699712

713+
714+
}
700715
}
701716

702717

@@ -711,6 +726,6 @@ private void MelsecMulti_OnReceivedData(byte[] object1)
711726
/// <summary>
712727
/// 用来记录一般的事物日志
713728
/// </summary>
714-
private SoftLogHelper LogHelper { get; set; }
729+
private SoftLogHelper RuntimeLogHelper { get; set; }
715730
}
716731
}

0 commit comments

Comments
 (0)