/// <summary> /// 添加数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ibtnAdd_Click(object sender, ImageClickEventArgs e) { AusItemInfo ausItemInfo = new AusItemInfo(); ausItemInfo.itemname = this.txtTypeName.Text.ToString(); AusItemInfo ausItemInfocount = AusItemInfoManager.GetModelByName(this.txtTypeName.Text); if (ausItemInfocount == null) { bool count = AusItemInfoManager.Add(ausItemInfo); if (count == true) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('添加成功');window.location='AusItemList.aspx'</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('添加失败')</script>", false); } } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "alert('类型名称不能重复!');", true); } }
/// <summary> /// 更新数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ibtnAdd_Click(object sender, ImageClickEventArgs e) { AusItemInfo ausItemInfo = new AusItemInfo(); ausItemInfo.id = Convert.ToInt32(Request.QueryString["id"]); ausItemInfo.itemname = this.txtTypeName.Text.ToString(); AusItemInfo ausItemInfocount = AusItemInfoManager.GetModelByName(this.txtTypeName.Text); if (ausItemInfocount == null) { bool count = AusItemInfoManager.Update(ausItemInfo); if (count == true) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('更新成功');window.location='AusItemList.aspx'</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('更新失败')</script>", false); } } else { if (ausItemInfocount.id == ausItemInfo.id) //判断其与所需要更新的类别的ID是否一样,如果一样可以更新。如果不一样就不能更新 { bool count = AusItemInfoManager.Update(ausItemInfo); if (count == true) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('更新成功');window.location='AusItemList.aspx'</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('更新失败')</script>", false); } } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "alert('类型名称不能重复!');", true); } } }