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