public void Add(RewardsInfosInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into RewardsInfos("); strSql.Append("JiannChengId,Money,UserId,LuRuUserId,Remark,SubTime)"); strSql.Append(" values ("); strSql.Append("'" + model.JiannChengId + "','" + model.Money + "','" + model.UserId + "','" + model.LuRuUserId + "','" + model.Remark + "','" + model.SubTime + "')"); strSql.Append(";select @@IDENTITY"); SqlConnection scon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); scon.Open(); SqlCommand scmd = new SqlCommand(strSql.ToString(), scon); scmd.ExecuteNonQuery(); scmd.Dispose(); scon.Close(); Response.Write("<script language='javascript'>alert('添加成功!');</script>"); Server.Transfer("list.aspx"); }
protected void btnSave_Click(object sender, EventArgs e) { int Money = 0; if (!int.TryParse(this.txtMoney.Text, out Money)) { Response.Write("<script language='javascript'>alert('请输入正确的金额!');</script>"); } else { int JiannChengId = int.Parse(ddlJiannChengId.SelectedValue); //int Money = int.Parse(this.txtMoney.Text); int UserId = int.Parse(ddlUserInfos.SelectedValue); int LuRuUserId = int.Parse(Session["userid"].ToString()); string Remark = this.txtRemark.Text; DateTime SubTime = DateTime.Now; RewardsInfosInfo model = new RewardsInfosInfo(); model.JiannChengId = JiannChengId; if (JiannChengId == 0) { model.Money = -Money; } else { model.Money = Money; } model.UserId = UserId; model.LuRuUserId = LuRuUserId; model.Remark = Remark; model.SubTime = SubTime; Add(model); } }