private void simpleButtonLoadTemplate_Click(object sender, EventArgs e) { var openDialog = new OpenFileDialog { DefaultExt = ".template", Filter = @"Template Files (.template)|*.template" }; if (openDialog.ShowDialog() == DialogResult.OK) { Template = JsonConvert.DeserializeObject <CalculationTemplate>( System.IO.File.ReadAllText(openDialog.FileName)); using (var context = new ConstructionDataContext()) { context.Database.Log = _print.PrintLog; comboBoxEditBusinessFeature.EditValue = FindFile(context, Template.BusinessFeature.Id); comboBoxEditConstructionValue.EditValue = FindFile(context, Template.ConstructionValue.Id); comboBoxEditRiskLevel.EditValue = FindFile(context, Template.RiskLevel.Id); comboBoxEditCellMapping.EditValue = FindFile(context, Template.CellMapping.Id); foreach (var construction in Template.Constructions) { var item = cmbListConstructions.Properties.Items .FirstOrDefault(w => ((File)w.Value).Id == construction.Id); if (item != null) { item.CheckState = CheckState.Checked; } } } } }
private void SetTempate() { Template = new CalculationTemplate { BusinessFeature = GetTemplate(comboBoxEditBusinessFeature), ConstructionValue = GetTemplate(comboBoxEditConstructionValue), RiskLevel = GetTemplate(comboBoxEditRiskLevel), CellMapping = GetTemplate(comboBoxEditCellMapping), Constructions = new List <Table>() }; foreach (CheckedListBoxItem item in cmbListConstructions.Properties.Items) { if (item.CheckState == CheckState.Checked) { if (item.Value is File file) { Template.Constructions.Add(new Table { Id = file.Id, Name = file.FileName }); } } } }