Заглавная страница Избранные статьи Случайная статья Познавательные статьи Новые добавления Обратная связь FAQ Написать работу КАТЕГОРИИ: ТОП 10 на сайте Приготовление дезинфицирующих растворов различной концентрацииТехника нижней прямой подачи мяча. Франко-прусская война (причины и последствия) Организация работы процедурного кабинета Смысловое и механическое запоминание, их место и роль в усвоении знаний Коммуникативные барьеры и пути их преодоления Обработка изделий медицинского назначения многократного применения Образцы текста публицистического стиля Четыре типа изменения баланса Задачи с ответами для Всероссийской олимпиады по праву
Мы поможем в написании ваших работ! ЗНАЕТЕ ЛИ ВЫ?
Влияние общества на человека
Приготовление дезинфицирующих растворов различной концентрации Практические работы по географии для 6 класса Организация работы процедурного кабинета Изменения в неживой природе осенью Уборка процедурного кабинета Сольфеджио. Все правила по сольфеджио Балочные системы. Определение реакций опор и моментов защемления |
Пространство имён ExamineExamolesViewСодержание книги
Поиск на нашем сайте
ExamineExamplesDataGridItem.cs using System; using System.Collections.Generic; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using CN2.Core.DataStructures; using CN2.UC.LearningExamplesView; using Brush = System.Drawing.Brush; using Brushes = System.Drawing.Brushes;
namespace CN2.UC.ExamineExamolesView { public class ExamineExamplesDataGridItem: IValidatable { public bool IsUse { get; set; } public List<string> PredictiveAttributeValues { get; set; } public string DecisiveAttributeValue { get; set; } public string ExaminedAttributeValue { get; set; } public string ProductionRule { get; set; }
public SolidColorBrush ExaminedAttributeValueColor { get { return DecisiveAttributeValue == null || ExaminedAttributeValue == null ? new SolidColorBrush(Colors.Black) : DecisiveAttributeValue.Equals(ExaminedAttributeValue)? new SolidColorBrush(Colors.Green): new SolidColorBrush(Colors.Red); } set { } }
public ExamineExamplesDataGridItem() { IsUse = true; PredictiveAttributeValues = new List<string>(); }
public bool IsValid { get { return PredictiveAttributeValues.Count > 0 &&!DecisiveAttributeValue.Equals(string.Empty) &&!ExaminedAttributeValue.Equals(string.Empty); } }
public ExamineExamplesDataGridItem(ExaminableExample examinedExample): this() { // todo цикл должен быть по Attributes, а установка Result должна производиться отдельно foreach (var attributeValue in examinedExample.AllAttributes) { PredictiveAttributeValues.Add(attributeValue.Value); } DecisiveAttributeValue = examinedExample.DecisiveAttribute.Value; ExaminedAttributeValue = examinedExample.ExaminedAttribute.Value; ProductionRule = string.Empty; //ArguedExample = string.Empty; }
//public ExamineExamplesDataGridItem(ExaminableExample examinedExample, ProductionRule productionRule, ArguedLearnableExample arguedExample): this() public ExamineExamplesDataGridItem(ExaminableExample examinedExample, ProductionRule productionRule): this() { foreach (var attributeValue in examinedExample.AllAttributes) { PredictiveAttributeValues.Add(attributeValue.Value); } DecisiveAttributeValue = examinedExample.DecisiveAttribute.Value; ExaminedAttributeValue = examinedExample.ExaminedAttribute.Value; ProductionRule = productionRule.GetStringValue(); //ArguedExample = arguedExample.BecauseExpression.GetValueString(); } } } ExamineExamplesView.xaml <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CN2.UC.ExamineExamolesView" xmlns:NumericUpDown="clr-namespace:CN2.UC.NumericUpDown" x:Class="CN2.UC.ExamineExamolesView.ExamineExamplesView" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <UserControl.Resources> <Image x:Key="SaveImage" Source="../../Images/Save_16x.png"/> <Image x:Key="OpenImage" Source="../../Images/Open_16x.png"/> <Image x:Key="ExamineImage" Source="../../Images/Examine_16x.png"/> </UserControl.Resources> <Grid> <Menu x:Name="menu" Height="22" VerticalAlignment="Top"> <Button x:Name="buttonLoadExamples" Content="{StaticResource OpenImage}" Height="16" Width="20" Click="buttonLoadExamples_Click" ToolTip="Загрузить примеры из файла"/> <Button x:Name="buttonSaveExamples" Content="{StaticResource SaveImage}" Height="16" Width="20" Click="buttonSaveExamples_Click" ToolTip="Сохранить примеры в файл"/> <Label x:Name="labelCoverIndex" Content="# набора:" Padding="0"/> <NumericUpDown:NumericUpDown x:Name="numericUpDownCoverIndex" MaxValue="0"/> <Button x:Name="buttonExamine" Content="{StaticResource ExamineImage}" Height="16" Width="20" Click="buttonExamine_Click" ToolTip="Провести экзамен"/> </Menu> <DataGrid x:Name="dataGrid" Margin="0,22,0,0" ItemsSource="{Binding items}" AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserAddRows="True" CanUserDeleteRows="True" CanUserResizeRows="False" RowHeight="24" HeadersVisibility="Column" InitializingNewItem="dataGrid_InitializingNewItem" MouseDown="dataGrid_MouseDown" CellEditEnding="dataGrid_CellEditEnding" GotFocus="dataGrid_GotFocus" CanUserSortColumns="True">
</DataGrid>
</Grid> </UserControl> ExamineExamplesView.xaml.sc using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Xml.Linq; using CN2.Core.DataStructures; using Microsoft.Win32;
namespace CN2.UC.ExamineExamolesView { /// <summary> /// Interaction logic for ExamineExamplesView.xaml /// </summary> public partial class ExamineExamplesView: UserControl { /// <summary> /// Список типов атрибутов. /// </summary> private AttributeTypeSet _attributeTypeSet; /// <summary> /// <summary> /// Индекс типа решающего атрибута в списке типов атрибутов. /// </summary> private int _decisiveAttributeIndex;
public int CoverId { get { return numericUpDownCoverIndex.Value - 1; } }
public ExamineExamplesView() { InitializeComponent(); }
public void SetAttributeTypes(AttributeTypeSet attributeTypeSet) { List<ExamineExamplesDataGridItem> items = new List<ExamineExamplesDataGridItem>(); _attributeTypeSet = attributeTypeSet;
dataGrid.Columns.Clear();
DataGridCheckBoxColumn isUseColumn = new DataGridCheckBoxColumn() { Header = "Использовать", Width = 30, Binding = new Binding("IsUse") }; dataGrid.Columns.Add(isUseColumn);
for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i++) { DataGridComboBoxColumn attributeTypeColumn = new DataGridComboBoxColumn() { Header = _attributeTypeSet.PredictiveAttributeTypes[i].Name, Width = 100, ItemsSource = _attributeTypeSet.PredictiveAttributeTypes[i].Values, TextBinding = new Binding("PredictiveAttributeValues[" + i + "]") }; dataGrid.Columns.Add(attributeTypeColumn); }
DataGridComboBoxColumn decisiveComboBoxColumn = new DataGridComboBoxColumn() { Header = _attributeTypeSet.DecisiveAttributeType.Name, Width = 100, ItemsSource = _attributeTypeSet.DecisiveAttributeType.Values, TextBinding = new Binding("DecisiveAttributeValue"), CellStyle = new Style(typeof (DataGridCell)) {Setters = {new Setter() {Property = ForegroundProperty, Value = Brushes.Blue}}} }; dataGrid.Columns.Add(decisiveComboBoxColumn);
DataGridTextColumn examinedColumn = new DataGridTextColumn() { Header = "Экзамен", Width = 100, Binding = new Binding("ExaminedAttributeValue"), IsReadOnly = true, CellStyle = new Style() { TargetType = typeof(DataGridCell), Setters = { new Setter(DataGridCell.ForegroundProperty, new Binding("ExaminedAttributeValueColor")) } } }; dataGrid.Columns.Add(examinedColumn);
dataGrid.ItemsSource = items; //dataGrid.DataContext = items; dataGrid.Items.Refresh(); }
public void SetArguedAttributeTypes(AttributeTypeSet attributeTypeSet) { SetAttributeTypes(attributeTypeSet);
DataGridTextColumn productionRuleColumn = new DataGridTextColumn() { Header = "Причина", Width = 300, Binding = new Binding("ProductionRule"), IsReadOnly = true }; dataGrid.Columns.Add(productionRuleColumn); }
public void SetExaminedExamples(IEnumerable<ExaminableExample> examinedExamples) { List<ExamineExamplesDataGridItem> items = new List<ExamineExamplesDataGridItem>(); foreach (var examinedExample in examinedExamples) { items.Add(new ExamineExamplesDataGridItem(examinedExample)); } dataGrid.ItemsSource = items; //dataGrid.Items.Refresh(); }
public void SetExaminedExamples(IEnumerable<Tuple<ExaminableExample, ProductionRule>> examinedExamples) { List<ExamineExamplesDataGridItem> items = new List<ExamineExamplesDataGridItem>(); foreach (var examinedExample in examinedExamples) { items.Add(new ExamineExamplesDataGridItem(examinedExample.Item1, examinedExample.Item2)); } dataGrid.ItemsSource = items; }
public void SetCoversCount(int coversCount) { numericUpDownCoverIndex.MinValue = 1; numericUpDownCoverIndex.MaxValue = coversCount; numericUpDownCoverIndex.Value = 1; }
public void ResetCoversCount() { numericUpDownCoverIndex.MinValue = 0; numericUpDownCoverIndex.MaxValue = 0; }
private void dataGrid_InitializingNewItem(object sender, InitializingNewItemEventArgs e) { List<ExamineExamplesDataGridItem> items = new List<ExamineExamplesDataGridItem>(dataGrid.ItemsSource.Cast<ExamineExamplesDataGridItem>()); items.Last().PredictiveAttributeValues = new List<string>(); for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i++) { items.Last().PredictiveAttributeValues.Insert(i, string.Empty); } items.Last().DecisiveAttributeValue = string.Empty; items.Last().ExaminedAttributeValue = string.Empty; }
#region средства для сериализации и десериализации списка примеров
private void buttonLoadExamples_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog ofd = new OpenFileDialog() { Filter = SerializationData.FileDialogFilter, Title = SerializationData.LoadExamplesFileDialogTitle };
Nullable<bool> ofdResult = ofd.ShowDialog();
if (ofdResult == true) { List<ExamineExamplesDataGridItem> items = new List<ExamineExamplesDataGridItem>();
XDocument examplesXDocument = XDocument.Load(ofd.FileName); foreach (var examplesXElement in examplesXDocument.Elements()) { if (examplesXElement.Name.ToString().Equals(SerializationData.ExamplesNode)) { foreach (var exampleXElement in examplesXElement.Elements()) { if (exampleXElement.Name.ToString().Equals(SerializationData.ExampleNode)) { ExamineExamplesDataGridItem item = new ExamineExamplesDataGridItem();
string[] predictiveValues = new string[_attributeTypeSet.PredictiveAttributeTypes.Count]; string decisiveValue = string.Empty;
// признак того, что следует перейти к следующзему примеру bool isNeedContinue = false;
foreach (var exampleXAttribute in exampleXElement.Attributes()) { if (exampleXAttribute.Name.ToString().Equals(SerializationData.IsUse)) { bool isUse; if (Boolean.TryParse(exampleXAttribute.Value, out isUse)) { item.IsUse = isUse; } else { if (OnErrorOccured!= null) { OnErrorOccured(this, @"Недопустимое значение атрибута ""Использовать""."); isNeedContinue = true; break; } } } }
if (isNeedContinue) { continue; }
foreach (var exampleAttributeXElement in exampleXElement.Elements()) { int j = -2; string value = string.Empty;
foreach (var exampleAttributeXAttribute in exampleAttributeXElement.Attributes()) { switch (exampleAttributeXAttribute.Name.ToString()) { case SerializationData.ExampleAttributeTypeName: { if (_attributeTypeSet.DecisiveAttributeType.Name.Equals(exampleAttributeXAttribute.Value)) { j = -1; } else { for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i++) { if (_attributeTypeSet.PredictiveAttributeTypes[i].Name.Equals(exampleAttributeXAttribute.Value)) { j = i; break; } } }
if (j == -2) { OnErrorOccured(this, @"Тип атрибута """ + exampleAttributeXAttribute.Value + @""" не определён в текущем наборе типов атрибутов."); isNeedContinue = true; break; } } break;
case SerializationData.ExampleAttrinuteValue: { value = exampleAttributeXAttribute.Value; } break; }
if (isNeedContinue) { break; } }
//todo проверить наличие значения у типа данных и если всё хорошо
if (j == -1) { decisiveValue = value; } else { predictiveValues[j] = value; }
if (isNeedContinue) { break; } }
if (isNeedContinue) { continue; }
for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i++) { item.PredictiveAttributeValues.Insert(i, predictiveValues[i]); } item.DecisiveAttributeValue = decisiveValue; item.ExaminedAttributeValue = string.Empty; items.Add(item); } } } }
dataGrid.ItemsSource = items;
if (OnFileLoaded!= null) { OnFileLoaded(sender, "Примеры загружены из файла " + ofd.FileName + "."); } } } catch (Exception ex) { if (OnErrorOccured!= null) { OnErrorOccured(this, ex.Message); } } }
private void buttonSaveExamples_Click(object sender, RoutedEventArgs e) { try { SaveFileDialog sfd = new SaveFileDialog() { Title = SerializationData.SaveExamplesFileDialogTitle, Filter = SerializationData.FileDialogFilter, FileName = "examples" };
Nullable<bool> sfdResult = sfd.ShowDialog();
if (sfdResult == true) { XElement examplesXElement = new XElement(SerializationData.ExamplesNode); foreach (var example in dataGrid.ItemsSource.Cast<ExamineExamplesDataGridItem>()) { XElement exampleXElement = new XElement(SerializationData.ExampleNode, new XAttribute(SerializationData.IsUse, example.IsUse)); for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i++) { exampleXElement.Add(new XElement(SerializationData.ExampleAttributeNode, new XAttribute(SerializationData.ExampleAttributeTypeName, _attributeTypeSet.PredictiveAttributeTypes[i].Name), new XAttribute(SerializationData.ExampleAttrinuteValue, example.PredictiveAttributeValues[i]))); } exampleXElement.Add(new XElement(SerializationData.ExampleAttributeNode, new XAttribute(SerializationData.ExampleAttributeTypeName, _attributeTypeSet.DecisiveAttributeType.Name), new XAttribute(SerializationData.ExampleAttrinuteValue, example.DecisiveAttributeValue))); examplesXElement.Add(exampleXElement); }
new XDocument(examplesXElement).Save(sfd.FileName);
if (OnFileSaved!= null) { OnFileSaved(sender, "Примеры сохранены в файл " + sfd.FileName + "."); } } } catch (Exception ex) { if (OnErrorOccured!= null) { OnErrorOccured(this, ex.Message); } } }
#endregion средства для сериализации и десериализации списка примеров
public List<ExaminableExample> GetExamples() { List<ExaminableExample> examples = new List<ExaminableExample>();
foreach (var item in dataGrid.ItemsSource.Cast<ExamineExamplesDataGridItem>()) { if (!item.IsUse) { continue; }
List<AttributeValue> attributes = new List<AttributeValue>(); for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i++) { attributes.Add(new AttributeValue(_attributeTypeSet.PredictiveAttributeTypes[i], item.PredictiveAttributeValues[i])); } examples.Add(new ExaminableExample(attributes, new AttributeValue(_attributeTypeSet.DecisiveAttributeType, item.DecisiveAttributeValue))); }
return examples; }
#region обработчики событий элемента управления dataGrid
private void dataGrid_GotFocus(object sender, RoutedEventArgs e) { if (e.OriginalSource.GetType() == typeof(DataGridCell)) { dataGrid.BeginEdit(e); } }
private void dataGrid_MouseDown(object sender, MouseButtonEventArgs e) { dataGrid.CommitEdit(); }
private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { ExamineExamplesDataGridItem item = (ExamineExamplesDataGridItem)e.Row.Item; if (item.IsValid) { e.Row.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)); } else { e.Row.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } }
private void buttonExamine_Click(object sender, RoutedEventArgs e) { if (OnExamine!= null) { OnExamine(this, null); } }
#endregion обработчики событий элемента управления dataGrid
#region события
public delegate void ErrorOccuredHandler(object sender, string message); public event ErrorOccuredHandler OnErrorOccured;
public delegate void FileSavedHandler(object sender, string message); public event FileSavedHandler OnFileSaved;
public delegate void FileLoadedHandler(object sender, string message); public event FileLoadedHandler OnFileLoaded;
public delegate void ExamineHandler(object sender, EventArgs e); public event ExamineHandler OnExamine;
#endregion события } } Пространство имён Log Log.xaml <UserControl x:Class="CN2.UC.Log.Log" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CN2.UC.Log" mc:Ignorable="d"> <UserControl.Resources> <Image x:Key="SaveImage" Source="../../Images/Save_16x.png"/> </UserControl.Resources> <Grid> <Menu x:Name="menu" Height="22" VerticalAlignment="Top"> <Label Content="Журнал" Padding="0"/> <Button x:Name="buttonSaveLog" Margin="0,2,0,0" Content="{StaticResource SaveImage}" Height="16" Width="20" Click="buttonSaveLog_Click" ToolTip="Сохранить журнал в файл"/> </Menu> <ScrollViewer x:Name="scrollViewer" Margin="0,22,0,0"> <TextBlock x:Name="logTextBlock" TextWrapping="Wrap" Text="" Background="White"/> </ScrollViewer> </Grid> </UserControl> Log.xaml.sc using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Microsoft.Win32;
namespace CN2.UC.Log { /// <summary> /// Interaction logic for Log.xaml /// </summary> public partial class Log: UserControl { public Log() { InitializeComponent(); }
/// <summary> /// Очищает содержимое журнала. /// </summary> public void Clear() { logTextBlock.Text = string.Empty; }
public string CorrectMessage(string message) { return message.EndsWith(Environment.NewLine)? message: message + Environment.NewLine; }
private void WriteColor(string message, Brush brush) { logTextBlock.Dispatcher.Invoke( new Action( () => logTextBlock.Inlines.Add(new Run(/*DateTime.Now + ": " + */CorrectMessage(message)) {Foreground = brush}))); scrollViewer.Dispatcher.Invoke(new Action(() => scrollViewer.ScrollToBottom())); }
public void Write(string message) { WriteColor(message, Brushes.Black); }
public void WriteOfftop(string message) { WriteColor(message, Brushes.Gray); }
public void WriteError(string message) { WriteColor(message, Brushes.Red); }
public void WriteSuccess(string message) { WriteColor(message, Brushes.Green); }
public void WriteWarning(string message) { WriteColor(message, Brushes.YellowGreen); }
public void WriteSection(string message) { WriteColor(message, Brushes.Blue); }
public void WriteSubSection1(string message) { WriteColor(message, Brushes.CornflowerBlue); }
public void WriteSubSection2(string message) { WriteColor(message, Brushes.DeepSkyBlue); }
private void buttonSaveLog_Click(object sender, RoutedEventArgs e) { try { SaveFileDialog sfd = new SaveFileDialog() { Title = SerializationData.SaveLogFileDialogTitle, Filter = SerializationData.LogFileDialogFilter, FileName = "log" + DateTime.Now.ToFileTime() };
Nullable<bool> sfdResult = sfd.ShowDialog();
if (sfdResult!= null && sfdResult == true) { using (StreamWriter logFile = new StreamWriter(sfd.FileName)) { logFile.Write(logTextBlock.Text); } } } catch (Exception ex) { WriteError(ex.Message); } } } }
|
||||
|
Последнее изменение этой страницы: 2016-08-10; просмотров: 255; Нарушение авторского права страницы; Мы поможем в написании вашей работы! infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 216.73.216.20 (0.009 с.) |