/// <summary> /// 修改出版社字典 /// </summary> /// <param name="publishingHouse"></param> /// <returns></returns> public bool UpdatePublishingHouse(DictionaryPublishingHouse publishingHouse) { string sqlStr = "UPDATE tb_DictionaryPublishingHouse SET " + " PublishingHouse=@PublishingHouse, " + " Location=@Location, " + " PublishingLocation=@PublishingLocation, " + " CallNumber=@CallNumber, " + " Postcodes=@Postcodes, " + " BankName=@BankName, " + " Remark=@Remark " + " where Id=@Id;"; //储存Datatable MySqlParameter[] para = new MySqlParameter[]//存储相应参数的容器 { new MySqlParameter("@Id", publishingHouse.Id), new MySqlParameter("@PublishingHouse", publishingHouse.PublishingHouse), new MySqlParameter("@Location", publishingHouse.Location), new MySqlParameter("@PublishingLocation", publishingHouse.PublishingLocation), new MySqlParameter("@CallNumber", publishingHouse.CallNumber), new MySqlParameter("@Postcodes", publishingHouse.PostCodes), new MySqlParameter("@BankName", publishingHouse.BankName), new MySqlParameter("@Remark", publishingHouse.Remark), }; int count = helper.ExecuteNonQuery(sqlStr, para, CommandType.Text); if (count > 0) { return(true); } else { return(false); } }
/// <summary> /// 获取出版社 /// </summary> /// <param name="error"></param> /// <returns></returns> private DictionaryPublishingHouse GetDictionaryPublishingHouse(ref List <string> error) { List <string> errorList = new List <string>();//错误列表 //规则判断 //生成对象 DictionaryPublishingHouse publishingHouse = new DictionaryPublishingHouse() { //出版社编号 Id = currentID, //出版社名称 PublishingHouse = textBox_Name.Text.Trim(), //地址 Location = textBox_Adress.Text.Trim(), //出版地 PublishingLocation = textBox_CorPL.Text.Trim(), //电话 CallNumber = textBox_Call.Text.Trim(), //邮编 PostCodes = int.Parse(textBox_Postcodes.Text.Trim()), //开户行 BankName = textBox_BankName.Text.Trim(), //备注 Remark = textBox_Remark.Text.Trim(), }; error = errorList; return(publishingHouse); }
private void btn_addCase_Click(object sender, EventArgs e) { try { List <string> errorList = new List <string>();//创建一个错误列表 //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中) var list = new DictionaryPublishingHouse[] { GetDictionaryPublishingHouse(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(); }
public void TestUpdatePublishingHouse() { Tools.UserCaseHandle userCaseHandle = new Tools.UserCaseHandle(@"C:\Users\73473\Desktop\软件工程\用例\Update_DictionaryPublishingHouse.xls"); IEnumerable updatePublishingHouse = userCaseHandle.GetUserCases(); List <string> errorList = new List <string>(); foreach (var i in updatePublishingHouse) { Assert.AreEqual(false, maintainaceBll.UpdateDicPublishingHouse((DictionaryPublishingHouse)i, ref errorList)); } int maxId = -1; foreach (DictionaryPublishingHouse i in maintainaceBll.getAllDicPublishingHouseArray()) { if (i.Id > maxId) { maxId = i.Id; } } DictionaryPublishingHouse publishingHouse = new DictionaryPublishingHouse() { Id = maxId, PublishingHouse = "华电出版社", Location = "华电路", PublishingLocation = "华北电力大学", CallNumber = "1234567890", PostCodes = 12345, BankName = "建设银行", Remark = "" }; Assert.AreEqual(true, maintainaceBll.UpdateDicPublishingHouse(publishingHouse, ref errorList)); }
public void TestAddPublishingHouse() { Tools.UserCaseHandle userCaseHandle = new Tools.UserCaseHandle(@"C:\Users\73473\Desktop\软件工程\用例\Add_DictionaryPublishingHouse.xls"); IEnumerable addPublishingHouse = userCaseHandle.GetUserCases(); List <string> errorList = new List <string>(); foreach (var i in addPublishingHouse) { Assert.AreEqual(false, maintainaceBll.AddDicPublishingHouse((DictionaryPublishingHouse)i, ref errorList)); } //int maxId = -1; //foreach (DictionaryBookSeller i in maintainaceBll.getAllDicBookSellerArry()) //{ // if (i.Id > maxId) // { // maxId = i.Id; // } //} DictionaryPublishingHouse publishingHouse = new DictionaryPublishingHouse() { Id = -1, PublishingHouse = "华电出版社", Location = "华电路", PublishingLocation = "华北电力大学", CallNumber = "1234567890", PostCodes = 12345, BankName = "建设银行", Remark = "" }; Assert.AreEqual(true, maintainaceBll.AddDicPublishingHouse(publishingHouse, ref errorList)); }
public IEnumerable getDicPublishingHouseArray(int index, int size) { List <DictionaryPublishingHouse> result = new List <DictionaryPublishingHouse>(); try { DataTable datatable = maintainaceDal.getDicPublishingHouse(index, size); foreach (DataRow dr in datatable.Rows) { DictionaryPublishingHouse publishingHouse = new DictionaryPublishingHouse() { Id = (int)dr["编号"], PublishingHouse = dr["出版社名字"].ToString(), Location = dr["地址"].ToString(), PublishingLocation = dr["出版地"].ToString(), CallNumber = dr["电话"].ToString(), PostCodes = (int)dr["邮编"], BankName = dr["开户行"].ToString(), Remark = dr["备注"].ToString() }; result.Add(publishingHouse); } return(result); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }
private void Addlog_click(object sender, System.EventArgs e) { try { List <string> errorList = new List <string>();//创建一个错误列表 //获取根据当前页面内容生成的订单(若有错误会被添加到错误列表中) if (comboBox_Dictionary.SelectedIndex == 0) { DictionaryBookSeller bookSeller = GetDictionaryBookSeller(ref errorList); //判断是否添加订单成功 if (maintainaceBll.AddDicBookSeller(bookSeller, ref errorList)) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); foreach (var i in errorList) { MessageBox.Show(i);//逐条显示错误信息 } } } else if (comboBox_Dictionary.SelectedIndex == 1) { DictionaryPublishingHouse publishingHouse = GetDictionaryPublishingHouse(ref errorList); //判断是否添加订单成功 if (maintainaceBll.AddDicPublishingHouse(publishingHouse, ref errorList)) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); foreach (var i in errorList) { MessageBox.Show(i);//逐条显示错误信息 } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } //textWritableChange(); DataBind(); }
/// <summary> /// 增添出版社数据操作 /// </summary> /// <param name="publishingHouse">出版社项</param> /// <returns>返回成功与否</returns> public bool AddDicPublishingHouse(DictionaryPublishingHouse publishingHouse) { string sqlStr = "INSERT INTO tb_DictionaryPublishingHouse ( " + "PublishingHouse," + "Location," + " PublishingLocation," + " CallNumber," + " Postcodes," + " BankName," + " Remark " + ")" + "VALUES(" + "@PublishingHouse," + "@Location," + "@PublishingLocation," + "@CallNumber," + "@Postcodes," + "@BankName," + "@Remark " + ");"; //储存DB MySqlParameter[] para = new MySqlParameter[] { new MySqlParameter("@PublishingHouse", publishingHouse.PublishingHouse), new MySqlParameter("@Location", publishingHouse.Location), new MySqlParameter("@PublishingLocation", publishingHouse.PublishingLocation), new MySqlParameter("@CallNumber", publishingHouse.CallNumber), new MySqlParameter("@Postcodes", publishingHouse.PostCodes), new MySqlParameter("@BankName", publishingHouse.BankName), new MySqlParameter("@Remark", publishingHouse.Remark), }; int count = helper.ExecuteNonQuery(sqlStr, para, CommandType.Text); if (count > 0) { return(true); } else { return(false); } }
/// <summary> /// 通过名字获取出版社信息 /// </summary> /// <param name="publishingHouse"></param> /// <returns></returns> public DataTable getPublishingHouserByName(DictionaryPublishingHouse publishingHouse) { string sqlStr = "Select " + " tb_DictionaryPublishingHouse.Id as 编号," + " tb_DictionaryPublishingHouse.PublishingHouse as 出版社名字," + " tb_DictionaryPublishingHouse.Location as 地址," + " tb_DictionaryPublishingHouse.PublishingLocation as 出版地," + " tb_DictionaryPublishingHouse.CallNumber as 电话," + " tb_DictionaryPublishingHouse.Postcodes as 邮编," + " tb_DictionaryPublishingHouse.BankName as 开户行," + " tb_DictionaryPublishingHouse.Remark as 备注 " + " from tb_DictionaryPublishingHouse" + " Where PublishingHouse =@PublishingHouse ;"; MySqlParameter[] para = new MySqlParameter[] { new MySqlParameter("@PublishingHouse", publishingHouse.PublishingHouse), }; DataTable dataTable = helper.ExecuteQuery(sqlStr, para, CommandType.Text); return(dataTable); }
/// <summary> /// 更新出版社信息名字查重 /// </summary> /// <param name="publishingHouse"></param> /// <returns></returns> public bool UpdateCaseNameCheckPH(DictionaryPublishingHouse publishingHouse) { DataTable result = null; try { result = maintainaceDal.getPublishingHouserByName(publishingHouse); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } if (result.Rows.Count <= 1) { return(true); } else { return(false); } }
/// <summary> /// 更新出版社信息 /// </summary> /// <param name="bookSeller"></param> /// <param name="errorMsg"></param> /// <returns></returns> public bool UpdateDicPublishingHouse(DictionaryPublishingHouse publishingHouse, ref List <string> errorMsg) { bool result = false; try { if (!DictionaryPublishingHouse.isNull(publishingHouse)) { if (!DictionaryPublishingHouse.isNormative(publishingHouse, ref errorMsg)) { if (this.UpdateCaseNameCheckPH(publishingHouse)) { result = maintainaceDal.UpdatePublishingHouse(publishingHouse); } } } } catch (Exception e) { Console.WriteLine(e.Message); throw e; } return(result); }