/// <summary> /// 增加一条数据 /// </summary> public static bool Add(SqlConnection sqlconn, QRCodeManageModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Configuration..SE_QRCodeManageConfig("); strSql.Append("ChannelName,QRCodeType,QRCodeUrl,ValidityTime,CreateTime,IsShow,TraceId,ResponseContent)"); strSql.Append(" values ("); strSql.Append("@ChannelName,@QRCodeType,@QRCodeUrl,@ValidityTime,@CreateTime,@IsShow,@TraceId,@ResponseContent)"); SqlParameter[] parameters = { new SqlParameter("@ChannelName", SqlDbType.NVarChar), new SqlParameter("@QRCodeType", SqlDbType.Int), new SqlParameter("@QRCodeUrl", SqlDbType.NVarChar), new SqlParameter("@ValidityTime", SqlDbType.NVarChar), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@IsShow", SqlDbType.Int), new SqlParameter("@TraceId", SqlDbType.Int), new SqlParameter("@ResponseContent", SqlDbType.VarChar) }; parameters[0].Value = model.ChannelName; parameters[1].Value = model.QRCodeType; parameters[2].Value = model.QRCodeUrl; parameters[3].Value = model.ValidityTime; parameters[4].Value = model.CreateTime; parameters[5].Value = model.IsShow; parameters[6].Value = model.TraceId; parameters[7].Value = model.ResponseContent; return(SqlHelper.ExecuteNonQuery(sqlconn, CommandType.Text, strSql.ToString(), parameters) > 0); }
public ActionResult AddOrEdit(int id) { if (id != 0) { //修改 QRCodeManageModel model = _QRCodeManageConfigManager.GetModel(id) ?? new QRCodeManageModel() { Id = -1, IsShow = 1, CreateTime = DateTime.Now }; return(View(model)); } else { //新增 QRCodeManageModel model = new QRCodeManageModel() { Id = 0, IsShow = 1, QRCodeType = 0, CreateTime = DateTime.Now }; return(View(model)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(QRCodeManageModel model) { try { return(handler.Update(model)); } catch (Exception ex) { logger.Log(Level.Error, ex.ToString()); return(false); } }
public ActionResult Save(int id, QRCodeManageModel model) { bool result = false; if (id == 0) { model.QRCodeUrl = CreateQRCode(model) ?? model.QRCodeUrl; //新增 model.CreateTime = DateTime.Now; model.IsShow = 1; result = _QRCodeManageConfigManager.Add(model); } else { model.QRCodeUrl = CreateQRCode(model) ?? model.QRCodeUrl; //修改 result = _QRCodeManageConfigManager.Update(model); } return(RedirectToAction("Index")); }
/// <summary> /// 更新一条数据 /// </summary> public static bool Update(SqlConnection sqlconn, QRCodeManageModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Configuration..SE_QRCodeManageConfig set "); strSql.Append("ChannelName=@ChannelName,"); strSql.Append("QRCodeType=@QRCodeType,"); strSql.Append("QRCodeUrl=@QRCodeUrl,"); strSql.Append("ValidityTime=@ValidityTime,"); strSql.Append("CreateTime=@CreateTime,"); strSql.Append("IsShow=@IsShow,"); strSql.Append("TraceId=@TraceId,"); strSql.Append("ResponseContent=@ResponseContent"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@ChannelName", SqlDbType.NVarChar), new SqlParameter("@QRCodeType", SqlDbType.Int), new SqlParameter("@QRCodeUrl", SqlDbType.NVarChar), new SqlParameter("@ValidityTime", SqlDbType.NVarChar), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@IsShow", SqlDbType.Int), new SqlParameter("@Id", SqlDbType.Int), new SqlParameter("@TraceId", SqlDbType.Int), new SqlParameter("@ResponseContent", SqlDbType.VarChar) }; parameters[0].Value = model.ChannelName; parameters[1].Value = model.QRCodeType; parameters[2].Value = model.QRCodeUrl; parameters[3].Value = model.ValidityTime; parameters[4].Value = model.CreateTime; parameters[5].Value = model.IsShow; parameters[6].Value = model.Id; parameters[7].Value = model.TraceId; parameters[8].Value = model.ResponseContent; return(SqlHelper.ExecuteNonQuery(sqlconn, CommandType.Text, strSql.ToString(), parameters) > 0); }
/// <summary> /// 获取 二维码地址 /// </summary> /// <returns></returns> private string CreateQRCode(QRCodeManageModel model) { if (model != null && !string.IsNullOrWhiteSpace(model.appid) && !string.IsNullOrWhiteSpace(model.appsecret)) { string access_token = CreateToken(model.appid, model.appsecret).access_token ?? "", tempQRCodeUrl = string.Format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}", access_token), eikyQRCodeUrl = string.Format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}", access_token), tempQRCodeParams = "{\"expire_seconds\": " + model.ValidityTime + ", \"action_name\": \"QR_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + model.TraceId + "}}}", eikyQRCodeParams = "{\"action_name\": \"QR_LIMIT_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + model.TraceId + "}}}"; string QRCodeJson = model.QRCodeType == 0 ? webRequestPost(tempQRCodeUrl, tempQRCodeParams) : webRequestPost(eikyQRCodeUrl, eikyQRCodeParams); QRCodeTicket _QRCodeTicket = JsonConvert.DeserializeObject <QRCodeTicket>(QRCodeJson ?? ""); return((_QRCodeTicket != null && !string.IsNullOrWhiteSpace(_QRCodeTicket.ticket)) ? string.Format("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={0}", _QRCodeTicket.ticket) : "{error:'返回无效ticket'}"); } return(null); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(QRCodeManageModel model) { Func <SqlConnection, bool> action = (connection) => QRCodeManageDAL.Update(connection, model); return(dbManager.Execute(action)); }