/// <summary> /// 获取全部订单 /// </summary> /// <returns>全部订单</returns> public IEnumerable GetAllInterviewCatalogArray() { List <InterviewCatalog> result = new List <InterviewCatalog>(); try { DataTable datatable = createDal.GetAllInterviewCatalog(); foreach (DataRow dr in datatable.Rows) { InterviewCatalog interviewCatalog = new InterviewCatalog() { Id = (int)dr["编号"], InterviewId = (int)dr["采访验收编号"], State = dr["状态"].ToString(), }; result.Add(interviewCatalog); } return(result); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }
/// <summary> /// 更改一条采访编目记录 /// </summary> /// <param name="list">采访编目记录</param> /// <returns>更改成功与否</returns> public bool UpdateInterviewCatalog(InterviewCatalog list) { string sqlStr = "UPDATE tb_InterviewCatalog SET " + "InterviewId=@interviewId, " + "State=@state " + "where Id=@id;"; //储存Datatable MySqlParameter[] para = new MySqlParameter[]//存储相应参数的容器 { new MySqlParameter("@state", list.State), new MySqlParameter("@interviewId", list.InterviewId), new MySqlParameter("@id", list.Id), }; int count = helper.ExecuteNonQuery(sqlStr, para, CommandType.Text); if (count > 0) { return(true); } else { return(false); } }
/// <summary> /// 更改一条编目记录 /// </summary> /// <param name="list">编目记录</param> /// <returns>更改成功与否</returns> public bool UpdateInterviewCatalog(InterviewCatalog list, ref List <string> errorMsg) { bool result = false; try { if (list.Id == 0) { errorMsg.Add("Id Error"); return(false); } if (!InterviewCatalog.isNull(list)) //是否有空项 { if (InterviewCatalog.isNormative(list, ref errorMsg)) //是否符合规范 { result = createDal.UpdateInterviewCatalog(list); } } } catch (Exception e) { Console.WriteLine(e.Message); throw e; } return(result); }
/// <summary> /// 增加一条采访编目记录 /// </summary> /// <param name="list">采访编目记录</param> /// <returns>增加成功与否</returns> public bool AddInterviewCatalog(InterviewCatalog list) { string sqlStr = "INSERT INTO tb_InterviewCatalog (" + "InterviewId," + "State" + ") " + "VALUES(" + "@interviewId," + "@state" + ");"; //储存Datatable MySqlParameter[] para = new MySqlParameter[]//存储相应参数的容器 { new MySqlParameter("@interviewId", list.InterviewId), new MySqlParameter("@state", list.State), }; int count = helper.ExecuteNonQuery(sqlStr, para, CommandType.Text); if (count > 0) { return(true); } else { return(false); } }
/// <summary> /// 修改状态按钮点击 /// </summary> private void changeStateBtn_Click(object sender, EventArgs e) { try { List <string> errorList = new List <string>();//创建一个错误列表 //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中) int id; if (!int.TryParse(idTextBox.Text, out id))//将其转换为数字失败 { MessageBox.Show("采访验收编号错误"); return; } InterviewCatalog list = GetAllCatalogList(ref errorList); list.Id = id;//设置编目ID //判断是否修改状态成功 if (createCatalogBll.UpdateInterviewCatalog(list, ref errorList)) { MessageBox.Show("修改成功"); } else { MessageBox.Show("修改失败"); foreach (var i in errorList) { MessageBox.Show(i);//逐条显示错误信息 } } } catch (Exception ex) { MessageBox.Show(ex.Message); } DataBind();//数据绑定 }
/// <summary> /// 编目按钮点击 /// </summary> private void catalogBtn_Click(object sender, EventArgs e) { try { List <string> errorList = new List <string>();//创建一个错误列表 //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中) InterviewCatalog list = GetAllCatalogList(ref errorList); //判断是否添加订单成功 if (createCatalogBll.AddInterviewCatalog(list, ref errorList)) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); foreach (var i in errorList) { MessageBox.Show(i);//逐条显示错误信息 } } } catch (Exception ex) { MessageBox.Show(ex.Message); } DataBind();//数据绑定 }
public void AddInterviewCatalogTest() { //Tools.UserCaseHandle userCaseHandle = new Tools.UserCaseHandle(@"E:\大三课程文档汇总\软件工程\FunctionTest\Add_CatalogFormList.xls"); //IEnumerable interviewCatalog = userCaseHandle.GetUserCases(); List <string> errorList = new List <string>(); InterviewCatalog interview1 = new InterviewCatalog() { Id = 1, InterviewId = 1, State = "", }; Assert.AreEqual(false, createCatalogBll.AddInterviewCatalog(interview1, ref errorList)); int maxId = -1; foreach (AcceptanceList i in interviewBll.GetAllAcceptanceListArray()) { if (i.Id > maxId) { maxId = i.Id; } } InterviewCatalog list = new InterviewCatalog() { Id = 1, InterviewId = maxId, State = "可编目", }; Assert.AreEqual(true, createCatalogBll.AddInterviewCatalog(list, ref errorList)); }
/// <summary> /// 获取当前窗体所表示的编目记录 /// </summary> /// <param name="error">错误列表</param> /// <returns>采访编目记录</returns> private InterviewCatalog GetAllCatalogList(ref List <string> error) { List <string> errorList = new List <string>();//错误列表 int interviewId; //判断采访验收编号是否能被转换为浮点型 if (!int.TryParse(interviewIdTextBox.Text, out interviewId)) { errorList.Add("InterviewId Error"); } //根据页面内容构造登到记录 InterviewCatalog list = new InterviewCatalog() { InterviewId = interviewId, State = stateComboBox.Text, }; error = errorList; //返回错误列表 return(list); //返回编目 }