SetParamsController.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using LeaRun.Application.Web.Common;
  8. namespace LeaRun.Application.Web.Areas.WeChatManage.Controllers
  9. {
  10. public class SetParamsController : MvcControllerBase
  11. {
  12. //
  13. // GET: /WeChatManage/SetParams/
  14. /// <summary>
  15. /// 设置系统参数
  16. /// </summary>
  17. /// <returns></returns>
  18. #region 视图功能
  19. public ActionResult Index()
  20. {
  21. //定义变量
  22. String AppId = "";
  23. String Secret = "";
  24. String Token = "";
  25. String sql = "SELECT AppId,[Secret],Token FROM BCS_WxAccessToken";
  26. //从数据库中获取数据
  27. DataTable dt = SqlHelper.ExecuteDataTable(sql, CommandType.Text, null);
  28. if (dt.Rows.Count > 0)
  29. {
  30. AppId = dt.Rows[0]["AppId"].ToString();
  31. Secret = dt.Rows[0]["Secret"].ToString();
  32. Token = dt.Rows[0]["Token"].ToString();
  33. }
  34. ViewBag.AppId = AppId;
  35. ViewBag.Secret = Secret;
  36. ViewBag.Token = Token;
  37. return View();
  38. }
  39. #endregion
  40. #region 提交数据
  41. /// <summary>
  42. /// 保存
  43. /// </summary>
  44. /// <param name="CorpId">AppID</param>
  45. /// <param name="CorpSecret">Secret</param>
  46. /// <param name="Token">Token</param>
  47. /// <returns></returns>
  48. [HttpPost]
  49. [ValidateAntiForgeryToken]
  50. [AjaxOnly]
  51. public ActionResult SaveForm(string CorpId, string CorpSecret, String Token)
  52. {
  53. //定义变量
  54. String Sql = "UPDATE BCS_WxAccessToken SET AppId = '" + CorpId + "',[Secret] = '" + CorpSecret + "',Token = '" + Token +"'";
  55. int num = SqlHelper.ExecuteNonQuery(Sql, CommandType.Text, null);
  56. if (num > 0)
  57. {
  58. return Success("操作成功。");
  59. }
  60. else
  61. {
  62. return Error("保存失败.");
  63. }
  64. }
  65. #endregion
  66. }
  67. }