private void btn_ok_Click(object sender, EventArgs e) { Action <string> Dofail = (error) => { ProgramData.Table_List[0] = new Table("默认表", int.Parse(txt_maxiWeek.Text)); MessageBox.Show(error); }; System.Globalization.DateTimeFormatInfo dfi = new System.Globalization.DateTimeFormatInfo(); dfi.ShortDatePattern = "HH:mm:ss"; DateTime startTime = new DateTime(); DateTime endTime = new DateTime(); string describsion = ""; foreach (var item in groupBox1.Controls.OfType <GroupBox>()) { try { foreach (var _item in item.Controls.OfType <MaskedTextBox>()) { if (item.ForeColor == Color.Red) { Dofail("提交失败:时间格式错误"); return; } if (_item.Tag.ToString().Substring(1, 1) == "s") { startTime = Convert.ToDateTime(_item.Text, dfi); } else { endTime = Convert.ToDateTime(_item.Text, dfi); } } foreach (var _item in item.Controls.OfType <TextBox>()) { describsion = _item.Text; } if (!ProgramData.Table_List[0].AddTimeSpan_Title(startTime, endTime, describsion)) { Dofail("提交失败:时间格式错误\n" + "请检查第" + item.Text + "项"); return; } if (!TimeSpan_Title.CheckVaild(ProgramData.Table_List[0].GetTitileList(), out string error)) { Dofail("提交失败:存在冲突的时间\n" + error); return; } } catch (Exception) {} } Hide(); XMLManager x = new XMLManager(ProgramData.Table_List[0].TableName); x.WriteXmlBniary(ProgramData.Table_List[0]); ProgramData.Form_TableEdit.Show(); }
private void btn_ok_Click(object sender, EventArgs e) { Action <string> Dofail = (error) => { ProgramData.Table_List[0] = new Table("默认表", int.Parse(txt_maxiWeek.Text)); MessageBox.Show(error); return; }; foreach (var item in groupBox1.Controls.OfType <MaskedTextBox>()) { System.Globalization.DateTimeFormatInfo dfi = new System.Globalization.DateTimeFormatInfo(); dfi.ShortDatePattern = "HH:mm:ss"; try { if (item.ForeColor == Color.Red) { Dofail("提交失败:时间格式错误"); return; } DateTime startTime = Convert.ToDateTime(item.Text, dfi); DateTime endTime = startTime.AddMinutes(int.Parse(txt_class_length.Text)); ProgramData.Table_List[0].AddTimeSpan_Title(startTime, endTime, "第" + item.Tag + "节课"); if (!TimeSpan_Title.CheckVaild(ProgramData.Table_List[0].GetTitileList(), out string error)) { Dofail("提交失败:存在冲突的时间\n" + error); return; } } catch (Exception) {} } Hide(); XMLManager x = new XMLManager(ProgramData.Table_List[0].TableName); x.WriteXmlBniary(ProgramData.Table_List[0]); ProgramData.Form_TableEdit.Show(); }