private void Add_Arend() { DateTime New_fr = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day, dateTimePicker2.Value.Hour, dateTimePicker2.Value.Minute, 0); DateTime New_to = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day, dateTimePicker3.Value.Hour, dateTimePicker3.Value.Minute, 0); bool flag = true; for (int i = 0; i < Arend.Count; i++) { if (!(New_to < Arend[i].Time_from || New_fr > Arend[i].Time_to)) { flag = false; } } if (flag) { Sauna_Arend New_Arend = new Sauna_Arend(); New_Arend.Number = Int32.Parse(comboBox1.SelectedItem.ToString()); New_Arend.Time_from = New_fr; New_Arend.Time_to = New_to; Arend.Add(New_Arend); Arend.Sort(delegate(Sauna_Arend s1, Sauna_Arend s2) { return s1.Time_from.CompareTo(s2.Time_from); }); Refresh_grid(); Save_Arend(); MessageBox.Show("Новая запись\nуспешно добавлена", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Это время уже\nзанято!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Load_Arend() { if (File.Exists("Sauna_Arendators.bin")) { FileStream fs = new FileStream("Sauna_Arendators.bin", FileMode.Open); BinaryReader br = new BinaryReader(fs); int kol = br.ReadInt32(); for (int i = 0; i < kol; i++) { Sauna_Arend New_Arend = new Sauna_Arend(); DateTime fr = new DateTime( br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), 0); New_Arend.Time_from = fr; DateTime to = new DateTime( br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), 0); New_Arend.Time_to = to; New_Arend.Number = br.ReadInt32(); Arend.Add(New_Arend); } br.Close(); fs.Close(); Refresh_grid(); } }