.NET 4.x Сохранение данных через бинарную сериализацию - C#
Формулировка задачи:
[Serializable()] public class DataModel { public bool Active { get; set; } public int ElementType { get; set; } public int ElementDimensionType { get; set; } public string Quantity { get; set; } public string WeightFor { get; set; } public string Weight { get; set; } public string Rate { get; set; } public string Area { get; set; } } [Serializable()] public class GeneralDataModel { public string Code { get; set; } public string Pool { get; set; } public string ObjectName { get; set; } public string Position { get; set; } public string Construction { get; set; } }
protected void SetGeneralData(GeneralDataModel model) { Code_number_info.Text = model.Code; Object_name_info.Text = model.ObjectName; Pool_info.Text = model.Pool; Position_info.Text = model.Position; Construction_info.Text = model.Construction; } protected void SetIndexData(DataModel model, Panel modelPanel) { try { (modelPanel.Controls[0] as System.Windows.Forms.CheckBox).Checked = model.Active; (modelPanel.Controls[1] as ComboBox).SelectedIndex = model.ElementType; (modelPanel.Controls[2] as ComboBox).SelectedIndex = model.ElementDimensionType; (modelPanel.Controls[3] as TextBox).Text = model.Quantity; (modelPanel.Controls[4] as TextBox).Text = model.WeightFor; (modelPanel.Controls[5] as TextBox).Text = model.Weight; (modelPanel.Controls[6] as TextBox).Text = model.Rate; (modelPanel.Controls[7] as TextBox).Text = model.Area; } catch { } } protected void SetAllData(List<DataModel> models, Panel GeneralPanel,GeneralDataModel gModel) { int index = 0; foreach (var p in GeneralPanel.Controls) { if (p is Panel) { SetIndexData(models[index], (Panel)p); index++; } } SetGeneralData(gModel); } protected DataModel GetIndexData(Panel modelPanel) { int c = modelPanel.Controls.Count; DataModel d = new DataModel(); try { d.Active = (modelPanel.Controls[0] as System.Windows.Forms.CheckBox).Checked; d.ElementType = (modelPanel.Controls[1] as ComboBox).SelectedIndex; d.ElementDimensionType = (modelPanel.Controls[2] as ComboBox).SelectedIndex; d.Quantity = (modelPanel.Controls[3] as TextBox).Text; d.WeightFor = (modelPanel.Controls[4] as TextBox).Text; d.Weight = (modelPanel.Controls[5] as TextBox).Text; d.Rate = (modelPanel.Controls[6] as TextBox).Text; d.Area = (modelPanel.Controls[7] as TextBox).Text; } catch { } return d; } protected void GetAllData(ref List<DataModel> models, ref GeneralDataModel gModel, Panel GeneralPanel) { foreach (var p in GeneralPanel.Controls) { if (p is Panel) { models.Add(GetIndexData((Panel)p)); } } gModel.Code = Code_number_info.Text; gModel.ObjectName = Object_name_info.Text; gModel.Pool = Pool_info.Text; gModel.Position = Position_info.Text; gModel.Construction = Construction_info.Text; }
Решение задачи: «.NET 4.x Сохранение данных через бинарную сериализацию»
textual
Листинг программы
var ob = deserializer.Deserialize(FileStream);
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д