Вывод сообщений

This commit is contained in:
kotcheshir73 2021-03-28 00:23:01 +04:00
parent 1e1896c68d
commit 74549aa18d
5 changed files with 215 additions and 2 deletions

View File

@ -0,0 +1,30 @@
using DesktopTools.Forms;
using System.Collections.Generic;
using System.Windows.Forms;
namespace DesktopTools.BusinessLogics
{
/// <summary>
/// Класс, отвечающий за вывод сообщения с ошибками
/// </summary>
public static class ErrorMessanger
{
/// <summary>
/// Вывод сообщения
/// </summary>
/// <param name="text"></param>
/// <param name="result"></param>
public static void PrintErrorMessage(string text, List<KeyValuePair<string, string>> result)
{
if (result.Count == 1)
{
MessageBox.Show(result[0].Value, result[0].Key, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
FormDisplayErrors form = new FormDisplayErrors();
form.LoadData(text, result);
}
}
}
}

View File

@ -0,0 +1,92 @@

namespace DesktopTools.Forms
{
partial class FormDisplayErrors
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridViewErrors = new System.Windows.Forms.DataGridView();
this.ColumnKey = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnMessage = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridViewErrors)).BeginInit();
this.SuspendLayout();
//
// dataGridViewErrors
//
this.dataGridViewErrors.AllowUserToAddRows = false;
this.dataGridViewErrors.AllowUserToDeleteRows = false;
this.dataGridViewErrors.AllowUserToResizeRows = false;
this.dataGridViewErrors.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridViewErrors.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridViewErrors.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ColumnKey,
this.ColumnMessage});
this.dataGridViewErrors.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridViewErrors.Location = new System.Drawing.Point(0, 0);
this.dataGridViewErrors.MultiSelect = false;
this.dataGridViewErrors.Name = "dataGridViewErrors";
this.dataGridViewErrors.ReadOnly = true;
this.dataGridViewErrors.RowHeadersVisible = false;
this.dataGridViewErrors.RowTemplate.Height = 25;
this.dataGridViewErrors.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridViewErrors.Size = new System.Drawing.Size(588, 450);
this.dataGridViewErrors.TabIndex = 0;
//
// ColumnKey
//
this.ColumnKey.HeaderText = "Тип ошибки";
this.ColumnKey.Name = "ColumnKey";
this.ColumnKey.ReadOnly = true;
this.ColumnKey.Width = 200;
//
// ColumnMessage
//
this.ColumnMessage.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ColumnMessage.HeaderText = "Сообщение";
this.ColumnMessage.Name = "ColumnMessage";
this.ColumnMessage.ReadOnly = true;
//
// FormDisplayErrors
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(588, 450);
this.Controls.Add(this.dataGridViewErrors);
this.Name = "FormDisplayErrors";
this.Text = "Ошибки";
((System.ComponentModel.ISupportInitialize)(this.dataGridViewErrors)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridViewErrors;
private System.Windows.Forms.DataGridViewTextBoxColumn ColumnKey;
private System.Windows.Forms.DataGridViewTextBoxColumn ColumnMessage;
}
}

View File

@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Windows.Forms;
namespace DesktopTools.Forms
{
public partial class FormDisplayErrors : Form
{
public FormDisplayErrors()
{
InitializeComponent();
}
public void LoadData(string text, List<KeyValuePair<string, string>> result)
{
Text = text;
foreach (var err in result)
{
dataGridViewErrors.Rows.Add(new object[] { err.Key, err.Value });
}
ShowDialog();
}
}
}

View File

@ -0,0 +1,66 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ColumnKey.UserAddedColumn" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
<metadata name="ColumnMessage.UserAddedColumn" type="System.Boolean, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
<value>True</value>
</metadata>
</root>

View File

@ -1,5 +1,7 @@
using SecurityBusinessLogic.BusinessLogics;
using DesktopTools.BusinessLogics;
using SecurityBusinessLogic.BusinessLogics;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -25,7 +27,7 @@ namespace DepartmentPortalDesctop
}
catch (Exception ex)
{
//ErrorMessanger.PrintErrorMessage("При аутентфикации возникла ошибка: ", new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Аутентфикация", ex.Message) });
ErrorMessanger.PrintErrorMessage("При аутентфикации возникла ошибка: ", new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Аутентфикация", ex.Message) });
}
}
}