protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { YouFu_Type YouFuType = new YouFu_Type(); try { int id = Convert.ToInt32(Request.QueryString["Id"]); YouFuType = Ctrl_YouFuType.FindYouFu_TypeById(id); if (YouFuType != null) { lWarning.Text = YouFuType.Type; hdId.Value = YouFuType.Id.ToString(); txtTypeValue.Text = YouFuType.Value; } else { MessageBox.Show(this, "加载优抚信息失败!请刷新,或者重新进入。"); } } catch (Exception) { MessageBox.Show(this, "加载优抚信息失败!请刷新,或者重新进入。"); } } }
/// <summary> /// 提交修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSub_Click(object sender, EventArgs e) { YouFu_Type YouFu_Type = new YouFu_Type(); try { int id = Convert.ToInt32(hdId.Value); string value = txtTypeValue.Text; YouFu_Type.Id = id; YouFu_Type.Tname = "AnFu_Info"; YouFu_Type.Type = lWarning.Text; YouFu_Type.Value = value; int result= Ctrl_YouFuType.UpdateYouFu_Type(YouFu_Type); if (result > 0) { MessageBox.Show(this, "修改成功!"); Response.Redirect("CareTypeManage.aspx"); } else MessageBox.Show(this, "修改失败!"); } catch (Exception) { MessageBox.Show(this, "修改失败!"); } }
/// <summary> /// 触发爆出类型的按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSaveTyppe_Click(object sender, EventArgs e) { try { string type = ddlType.SelectedValue.Trim(); string typeName = txtTypeName.Text; YouFu_Type YouFuType = new YouFu_Type(); YouFuType.Tname = "AnFu_Info"; YouFuType.Type = type; YouFuType.Value = typeName.Trim(); if (Ctrl_YouFuType.AddYouFu_Type(YouFuType) > 0) { MessageBox.Show(this, "增加成功!"); Response.AddHeader("Refresh", "0"); //刷新当前页面 } else { MessageBox.Show(this, "增加失败!"); Response.AddHeader("Refresh", "0"); //刷新当前页面 } } catch (Exception ec) { Log4Net.LogWrite("err", "jgq.Care.CareOperation\\btnSaveTyppe_Click" + ec.Message); } }
/// <summary> /// 增加优抚类型 /// </summary> /// <param name="YouFuType"></param> /// <returns></returns> public static int AddYouFu_Type(YouFu_Type YouFuType) { int iExecute = 0; try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into AnFu_Type ("); strSql.Append("TName,Type,Value"); strSql.Append(") values("); strSql.Append("@TName,@Type,@Value"); strSql.Append(");select @@IDENTITY"); SqlParameter[] para = new SqlParameter[] { new SqlParameter("@TName",SqlDbType.NVarChar,50), new SqlParameter("@Type",SqlDbType.NVarChar,50), new SqlParameter("@Value",SqlDbType.NVarChar), }; para[0].Value = YouFuType.Tname; para[1].Value = YouFuType.Type; para[2].Value = YouFuType.Value; object obj = DbHelperSQL.GetSingle(strSql.ToString(), para); if (obj != null) { iExecute = Convert.ToInt32(obj); } } catch (Exception e) { Log4Net.LogWrite("err", "Controler\\AddYouFu_Type" + e.Message); } return iExecute; }
/// <summary> /// 根据id查找优抚类型 /// </summary> /// <param name="id"></param> /// <returns></returns> public static YouFu_Type FindYouFu_TypeById(int id) { YouFu_Type YouFuType = new YouFu_Type(); string sql = null; try { sql = "SELECT * FROM AnFu_Type WHERE Id=@Id"; SqlParameter para = new SqlParameter("@Id", SqlDbType.Int); para.Value = id; DataSet ds = null; ds = DbHelperSQL.Query(sql, para); if (ds != null) { DataTable dt = ds.Tables[0]; DataRow dr = dt.Rows[0]; YouFuType.Id = id; YouFuType.Tname = "AnFu_Info"; YouFuType.Type = dr["Type"].ToString(); YouFuType.Value = dr["Value"].ToString(); } } catch (Exception e) { Log4Net.LogWrite("err", "Controler\\FindYouFu_TypeById" + e.Message); } return YouFuType; }
/// <summary> /// 修改优抚类型信息 /// </summary> /// <param name="YouFuType"></param> /// <returns></returns> public static int UpdateYouFu_Type(YouFu_Type YouFuType) { int iExcute = 0; string sql = null; sql = "UPDATE AnFu_Type SET Type=@Type,Value=@Value WHERE Id=@Id"; try { SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@Type", SqlDbType.NVarChar, 50), new SqlParameter("@Value", SqlDbType.NVarChar, 50), new SqlParameter("@Id",SqlDbType.Int), }; paras[0].Value = YouFuType.Type; paras[1].Value = YouFuType.Value; paras[2].Value = YouFuType.Id; iExcute = DbHelperSQL.ExecuteSql(sql, paras); } catch (Exception e) { Log4Net.LogWrite("err", "Controler\\FindYouFu_TypeById" + e.Message); } return iExcute; }