| | |
| | | public List<Printer> Printers { get; set; } = new List<Printer>(); |
| | | |
| | | |
| | | |
| | | [Category("产品显示界面配置")] |
| | | [Description("字体大小")] |
| | | [DisplayName("字体大小")] |
| | | public int FontSize_p { get; set; } = 15; |
| | | |
| | | |
| | | [Category("产品显示界面配置")] |
| | | [Description("每行列数")] |
| | |
| | | [Editor(typeof(ComplexCollectionEditor<PLCAlarmDetails>), typeof(UITypeEditor))] |
| | | public List<PLCAlarmDetails> AlarmDetails { get; set; } = new List<PLCAlarmDetails>(); |
| | | |
| | | |
| | | |
| | | |
| | | public string GetDisplayText() |
| | | { |
| | | return plcname + (isused ? "启用" : "禁用"); |
| | | } |
| | | } |
| | | |
| | | public class PLCAlarmDetails : IComplexDisplay |
| | | public class PLCAlarmDetails : IComplexDisplay, IImportFromFileInEditor |
| | | { |
| | | [Category("配置")] |
| | | [DisplayName("首地址")] |
| | |
| | | { |
| | | return alarmname; |
| | | } |
| | | |
| | | |
| | | |
| | | public IImportFromFileInEditor GetImportObject(string data, out string msg) |
| | | { |
| | | msg = ""; |
| | | PLCAlarmDetails ret = new PLCAlarmDetails(); |
| | | try |
| | | { |
| | | var temchar = data.Split(','); |
| | | ret.alarmname = temchar[0]; |
| | | ret.address =Convert.ToInt32(temchar[1]); |
| | | ret.address2 = Convert.ToInt32(temchar[2]); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | } |
| | | |
| | | return ret; |
| | | |
| | | } |
| | | |
| | | public bool ICSVOutput(object o) |
| | | { |
| | | try |
| | | { |
| | | if (o is List<PLCAlarmDetails> Pl) |
| | | { |
| | | SaveFileDialog saveFileDialog = new SaveFileDialog(); |
| | | saveFileDialog.Filter = "CSV files (*.csv)|*.csv"; // 设置文件过滤器,只显示CSV文件 |
| | | saveFileDialog.Title = "Save CSV File"; // 设置对话框标题 |
| | | saveFileDialog.FileName = "PLCAlarms"; // 默认文件名 |
| | | saveFileDialog.DefaultExt = "csv"; // 默认文件扩展名 |
| | | string filePath = ""; |
| | | if (saveFileDialog.ShowDialog() == DialogResult.OK) |
| | | { |
| | | filePath = saveFileDialog.FileName; // 获取用户选择的文件路径 |
| | | } |
| | | else |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | using (StreamWriter writer = new StreamWriter(filePath)) |
| | | { |
| | | // 写入标题行 |
| | | writer.WriteLine("报警名称,首地址,子地址"); |
| | | // 写入数据行 |
| | | foreach (var row in Pl) |
| | | { |
| | | writer.WriteLine($"{row.alarmname},{row.address},{row.address2}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch |
| | | { |
| | | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |