курсовая дерево принятия решений. курсач123ДПР. Первая. Анализ прикладной области. Требования к системе 4 Глава вторая. Постановка задачи
Скачать 0.95 Mb.
|
transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } } public void DelElement(int id) { PK element = context.PKs.FirstOrDefault(rec => rec.Id == id); if (element != null) { context.PKs.Remove(element); context.SaveChanges(); } else { throw new Exception("Элемент не найден"); } } public PKBM GetElement(int id) { PK element = context.PKs.FirstOrDefault(rec => rec.Id == id); if (element != null) { return new PKBM { Id = element.Id, Name = element.Name, Date = element.Date, PKParams = element.PKParams }; } throw new Exception("Элемент не найден"); } public List GetList() { List result = context.PKs .Select(rec => new PKBM { Id = rec.Id, Name = rec.Name, Date = rec.Date, PKParams = rec.PKParams }) .ToList(); return result; } public List GetSortList() { List result = new List (); PKComparer pkComparer = new PKComparer(); List list = context.PKs .Select(rec => new PK { Id = rec.Id, Name = rec.Name, Date = rec.Date }) .ToList(); list.Sort(pkComparer); foreach (var l in list) { result.Add(GetElement(l.Id)); } return result; } public void UpdElement(PKBM model) { } } } using PK_Analysis; using System; using System.Collections.Generic; namespace SPPR_Services.ImplementationBD { public class Sevices { } public class ParamMark { public int Id { get; set; } public string par { get; set; } public Marks Mark { get; set; } } public class PK1 { public int Id { get; set; } public string Name { get; set; } public DateTime Date { get; set; } public List PKParams { get; internal set; } } public class PKComparer : IComparer { public int Compare(PK t1, PK t2) { if (t1.Date > t2.Date) { return 1; } else { return -1; } } } } using PK_Analysis_Services.BindingModels; namespace PK_Analysis_Services.Interfaces { public interface IAnalizeService { PKBM GetAnalize(PKBM idialPK); PKBM GetPredict(PKBM futurePK); } } using PK_Analysis; using PK_Analysis_Services.BindingModels; using System.Collections.Generic; namespace PK_Analysis_Services.Interfaces { public interface IMarkParamService { void CreateElement(MarkParametrBM model); void UpdElement(MarkParametrBM model); void DelElement(MarkParametrBM model); List List MarkParametrBM GetElement(int id); MarkParametrBM GetElement(int idParam, Marks mark); } } using PK_Analysis_Services.BindingModels; using System.Collections.Generic; namespace PK_Analysis_Services.Interfaces { public interface IParametrService { void CreateElement(ParametrBM model); void UpdElement(ParametrBM model); void DelElement(int id); List GetList(); ParametrBM GetElement(int id); } } using PK_Analysis_Services.BindingModels; using System.Collections.Generic; namespace PK_Analysis_Services.Interfaces { public interface IPKParamService { void CreateElement(PKParamBM model); void UpdElement(PKParamBM model); void DelElement(PKParamBM model); List GetList(); PKParamBM GetElement(int id); PKParamBM GetElement(int paramId, int pkId); } } using PK_Analysis_Services.BindingModels; using System.Collections.Generic; namespace PK_Analysis_Services.Interfaces { public interface IPKService { void CreateElement(PKBM model); void UpdElement(PKBM model); void DelElement(int id); List GetList(); List GetSortList(); PKBM GetElement(int id); } } using PK_Analysis; using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity; namespace PK_Analysis_Services { [Table("PK_AnalysisDatabase3")] public class PK_AnalysisDbContext3 : DbContext { public PK_AnalysisDbContext3() { //настройки конфигурации для entity Configuration.ProxyCreationEnabled = false; Configuration.LazyLoadingEnabled = false; var ensureDLLIsCopied = System.Data.Entity.SqlServer.SqlProviderServices.Instance; } public virtual DbSet public virtual DbSet Parametrs { get; set; } public virtual DbSet PKs { get; set; } public virtual DbSet PKParams { get; set; } } } using PK_Analysis; using PK_Analysis_Services.Interfaces; using System; using System.Windows.Forms; using Unity; namespace PK_Analysis_Forms { public partial class Form_Start : Form { [Dependency] public new IUnityContainer Container { get; set; } public Form_Start() { InitializeComponent(); } private void добавитьКомпьютерToolStripMenuItem_Click(object sender, EventArgs e) { var form = Container.Resolve form.Show(); } private void списокКомпьютеровToolStripMenuItem_Click(object sender, EventArgs e) { var form = Container.Resolve form.Show(); } private void добавитьПараметрToolStripMenuItem_Click(object sender, EventArgs e) { var form = Container.Resolve form.Show(); } private void списокПараметровToolStripMenuItem_Click(object sender, EventArgs e) { var form = Container.Resolve form.Show(); } private void выборToolStripMenuItem_Click(object sender, EventArgs e) { var form = Container.Resolve form.Show(); } private void Form_Start_Load(object sender, EventArgs e) { } private void заполнитьОценкиToolStripMenuItem_Click(object sender, EventArgs e) { var form = Container.Resolve form.Show(); } } } using PK_Analysis_Services.BindingModels; using System; using System.Collections.Generic; using System.Windows.Forms; using Unity; namespace PK_Analysis_Forms { public partial class Form_Res : Form { [Dependency] public new IUnityContainer Container { get; set; } public List list; BindingSource sourse; public Form_Res() { list = new List (); InitializeComponent(); } private void Form_Res_Load(object sender, EventArgs e) { sourse = new BindingSource(); sourse.DataSource = list; dataGridView1.DataSource = sourse; } } } using PK_Analysis; using PK_Analysis_Services.BindingModels; using PK_Analysis_Services.Interfaces; using System; using System.Collections.Generic; using System.Windows.Forms; using Unity; namespace PK_Analysis_Forms { public partial class Form_PKs : Form { [Dependency] public new IUnityContainer Container { get; set; } private readonly IPKService _serviceT; public Form_PKs(IPKService serviceT) { _serviceT = serviceT; InitializeComponent(); } private void Form_PKs_Load(object sender, EventArgs e) { LoadData(); } private void LoadData() { try { List list = _serviceT.GetList(); if (list != null) { dataGridView_PKs.DataSource = list; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void button_Add_Click(object sender, EventArgs e) { var form = Container.Resolve form.Show(); LoadData(); } private void button_Del_Click(object sender, EventArgs e) { if (dataGridView_PKs.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView_PKs.SelectedRows[0].Cells[0].Value); try { _serviceT.DelElement(id); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } } } private void dataGridView_PKs_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { if (dataGridView_PKs.SelectedRows.Count == 1) { var form = Container.Resolve form.Id = Convert.ToInt32(dataGridView_PKs.SelectedRows[0].Cells[0].Value); if (form.ShowDialog() == DialogResult.OK) { LoadData(); } } } private void button1_Click(object sender, EventArgs e) { LoadData(); } } } using PK_Analysis; using PK_Analysis_Services.BindingModels; using PK_Analysis_Services.Interfaces; using System; using System.Collections.Generic; using System.Windows.Forms; using Unity; namespace PK_Analysis_Forms { public partial class Form_ParamTreb : Form { [Dependency] public new IUnityContainer Container { get; set; } private readonly IParametrService _serviceP; public TrebParam model { set; get; } public Form_ParamTreb(IParametrService serviceP) { _serviceP = serviceP; InitializeComponent(); } private void button_Ok_Click(object sender, EventArgs e) { try { model = new TrebParam { ParametrId = Convert.ToInt32(comboBox_Param.SelectedValue), Mark = (Marks)comboBox_Mark.SelectedValue }; MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void Form_ParamTreb_Load(object sender, EventArgs e) { try { List list = _serviceP.GetList(); if (list != null) { comboBox_Param.DisplayMember = "Name"; comboBox_Param.ValueMember = "Id"; comboBox_Param.DataSource = list; comboBox_Param.SelectedItem = null; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } comboBox_Mark.DataSource = Enum.GetValues(typeof(Marks)); } } } using PK_Analysis; using PK_Analysis_Services.BindingModels; using PK_Analysis_Services.Interfaces; using System; using System.Collections.Generic; using System.Windows.Forms; using Unity; namespace PK_Analysis_Forms { public partial class Form_Params : Form { [Dependency] public new IUnityContainer Container { get; set; } private readonly IParametrService _serviceP; public Form_Params(IParametrService serviceP) { _serviceP = serviceP; InitializeComponent(); } private void Form_Params_Load(object sender, EventArgs e) { LoadData(); } private void LoadData() { try { List list = _serviceP.GetList(); if (list != null) { dataGridView_Params.DataSource = list; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void button_Add_Click(object sender, EventArgs e) { var form = Container.Resolve if (form.ShowDialog() == DialogResult.OK) { LoadData(); } } private void button_Del_Click(object sender, EventArgs e) { if (dataGridView_Params.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView_Params.SelectedRows[0].Cells[0].Value); try { _serviceP.DelElement(id); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } } } private void dataGridView_Params_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { if (dataGridView_Params.SelectedRows.Count == 1) { var form = Container.Resolve form.Id = Convert.ToInt32(dataGridView_Params.SelectedRows[0].Cells[0].Value); if (form.ShowDialog() == DialogResult.OK) { LoadData(); } } } } } using PK_Analysis_Services.BindingModels; using PK_Analysis_Services.Interfaces; using System; using System.Collections.Generic; using System.Windows.Forms; using Unity; namespace PK_Analysis_Forms { public partial class Form_MarksParam : Form { [Dependency] public new IUnityContainer Container { get; set; } public int paramId { get; set; } private readonly IParametrService _serviceP; private readonly IMarkParamService _serviceMP; List public Form_MarksParam(IParametrService serviceP, IMarkParamService serviceMP) { _serviceP = serviceP; _serviceMP = serviceMP; InitializeComponent(); } private void LoadData() { ParametrBM parametr = _serviceP.GetElement(paramId); textBox_Name.Text = parametr.Name; markParametrs = new List markParametrs = _serviceMP.GetList(parametr); dataGridView_MarkParams.DataSource = markParametrs; for (int i=0; i < dataGridView_MarkParams.RowCount; i++) { if ((int)dataGridView_MarkParams.Rows[i].Cells[0].Value == 0) { dataGridView_MarkParams.Rows[i].Cells[0].ReadOnly = false; } } } private void Form_MarksParam_Load(object sender, EventArgs e) { LoadData(); } private void button_Add_Click(object sender, EventArgs e) { var form = Container.Resolve form.paramId = paramId; if (form.ShowDialog() == DialogResult.OK) { markParametrs.Add(form.model); } dataGridView_MarkParams.DataSource = null; dataGridView_MarkParams.DataSource = markParametrs; } private void button_Del_Click(object sender, EventArgs e) { if (dataGridView_MarkParams.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { MarkParametrBM marks = _serviceMP.GetElement((int)dataGridView_MarkParams.SelectedRows[0].Cells[0].Value); // markParametrs.RemoveAt(dataGridView_MarkParams.SelectedRows[0].Cells[0].RowIndex); _serviceMP.DelElement(marks); LoadData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } private void button_OK_Click(object sender, EventArgs e) |