private void btn_addCase_Click(object sender, EventArgs e) { try { List <string> errorList = new List <string>();//创建一个错误列表 //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中) var list = new DisHonestyLog[] { GetDishonestyLog(ref errorList) }; if (errorList.Count == 0) { if (userCaseHandle.AddUserCases(list.ToList())) { MessageBox.Show("添加成功"); } } else { MessageBox.Show("添加失败"); foreach (var i in errorList) { MessageBox.Show(i);//逐条显示错误信息 } } } catch (Exception ex) { MessageBox.Show(ex.Message); } DataBind(); }
private DisHonestyLog GetDishonestyLog(ref List <string> error) { List <string> errorList = new List <string>();//错误列表 string bookId = textBox_bookId.Text; if (string.IsNullOrEmpty(bookId)) { errorList.Add("BookId Error"); } string readerId = readerIdTextBox.Text; if (string.IsNullOrEmpty(readerId)) { errorList.Add("ReaderId Error"); } string price = textBox_PenaltyMultiple.Text; if (string.IsNullOrEmpty(price)) { errorList.Add("PenaltyMultiple Error"); } DisHonestyLog bookBorrowLog = new DisHonestyLog() { BookId = int.Parse(bookId), ReaderId = int.Parse(readerId), State = comboBox_state.Text, DishonestyTime = DateTime.Now, PenaltyMultiple = double.Parse(price) }; error = errorList; return(bookBorrowLog); }