industry.aspx.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Web;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. namespace LYFZ.WeixinServers.LoginApi
  12. {
  13. public partial class industry : System.Web.UI.Page
  14. {
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. if (Request.HttpMethod.ToUpper() == "GET")
  18. return;
  19. #if ff
  20. Stream s = Request.InputStream;
  21. byte[] b = new byte[s.Length];
  22. s.Read(b, 0, (int)s.Length);
  23. string post = Encoding.UTF8.GetString(b);
  24. string xmlData = "";
  25. try
  26. {
  27. Request.InputStream.Seek(0, SeekOrigin.Begin);//强制调整指针位置
  28. using (var streamReader = new StreamReader(Request.InputStream))
  29. {
  30. var decryptMsg = string.Empty;
  31. xmlData = streamReader.ReadToEnd();
  32. System.Diagnostics.Debug.Write(xmlData, "加密的微信消息:");
  33. }
  34. }
  35. catch (Exception ex)
  36. {
  37. }
  38. #endif
  39. if (Request.QueryString["type"] != null)
  40. {
  41. string strOptType = Request.QueryString["type"];
  42. if (!string.IsNullOrEmpty(strOptType))
  43. {
  44. if (strOptType.StartsWith("sys-"))
  45. {
  46. string strUser, strUserPsw;
  47. if (VerifySysParam(out strUser, out strUserPsw))
  48. {
  49. // 获取系统账号信息,是否有权限操作行业信息;
  50. LoginModel.user model = GlobalCache.GetUserInfo(strUser, strUserPsw);
  51. if (model == null)
  52. {
  53. Response.Write("{\"code\":201, \"msg\":\"账号或密码不对\"}");
  54. return;
  55. }
  56. if (model.user_type != 0)
  57. {
  58. Response.Write("{\"code\":201, \"msg\":\"账号操作权限不足\"}");
  59. return;
  60. }
  61. switch (strOptType)
  62. {
  63. case "sys-add":
  64. {
  65. OptSysAdd();
  66. }
  67. break;
  68. case "sys-delete":
  69. {
  70. OptSysDelete();
  71. }
  72. break;
  73. case "sys-modify":
  74. {
  75. OptSysModify();
  76. }
  77. break;
  78. case "sys-query":
  79. {
  80. OptSysQuery();
  81. }
  82. break;
  83. default:
  84. break;
  85. }
  86. }
  87. else
  88. {
  89. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  90. }
  91. }
  92. else
  93. {
  94. }
  95. }
  96. else
  97. {
  98. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  99. }
  100. }
  101. else
  102. {
  103. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  104. }
  105. }
  106. // 获取POST返回来的数据
  107. private string PostInput()
  108. {
  109. try
  110. {
  111. System.IO.Stream s = Request.InputStream;
  112. int count = 0;
  113. byte[] buffer = new byte[1024];
  114. StringBuilder builder = new StringBuilder();
  115. while ((count = s.Read(buffer, 0, 1024)) > 0)
  116. {
  117. builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
  118. }
  119. s.Flush();
  120. s.Close();
  121. s.Dispose();
  122. return builder.ToString();
  123. }
  124. catch (Exception ex)
  125. {
  126. throw ex;
  127. }
  128. }
  129. /// <summary>
  130. /// 参数校验
  131. /// </summary>
  132. /// <param name="strEntId">企业id</param>
  133. /// <param name="strAppId">app对象id</param>
  134. /// <param name="strAppType">app对象类型</param>
  135. /// <param name="strAppWxId">app对象的微信号</param>
  136. /// <returns>若参数有效返回true,参数无效或空返回false</returns>
  137. public bool VerifySysParam(out string strUser, out string strUserPsw)
  138. {
  139. strUser = strUserPsw = "";
  140. if (this.Request.Form["user"] != null && this.Request.Form["user_psw"] != null )
  141. {
  142. strUser = Request.Form["user"];
  143. strUserPsw = Request.Form["user_psw"];
  144. if (string.IsNullOrEmpty(strUser) || string.IsNullOrEmpty(strUserPsw) )
  145. return false;
  146. return true;
  147. }
  148. return false;
  149. }
  150. /// <summary>
  151. /// 添加行业的操作
  152. /// </summary>
  153. public void OptSysAdd()
  154. {
  155. if ( Request.Form["ind_name"] != null && Request.Form["ind_note"] != null )
  156. {
  157. LoginModel.industry model = new LoginModel.industry();
  158. model.ind_id = GlobalCache.GuidString();
  159. model.ind_name = Request.Form["ind_name"];
  160. model.ind_note = Request.Form["ind_note"];
  161. if ( !string.IsNullOrEmpty(model.ind_name) && !string.IsNullOrEmpty(model.ind_note) )
  162. {// 参数有效;
  163. try
  164. {
  165. LoginDal.industry dal = new LoginDal.industry();
  166. dal.Add(model, "id");
  167. Response.Write("{\"code\":200, \"msg\":\"添加行业成功\"}");
  168. }
  169. catch
  170. {
  171. Response.Write("{\"code\":201, \"msg\":\"添加行业失败\"}");
  172. }
  173. }
  174. else
  175. {// 参数无效;
  176. Response.Write("{\"code\":201, \"msg\":\"行业参数无效\"}");
  177. }
  178. }
  179. }
  180. /// <summary>
  181. /// 删除行业的操作
  182. /// </summary>
  183. public void OptSysDelete()
  184. {
  185. if (Request.Form["ind_name"] != null )
  186. {
  187. string strIndName = Request.Form["ind_name"];
  188. if (!string.IsNullOrEmpty(strIndName))
  189. {
  190. try
  191. {
  192. LoginDal.industry dal = new LoginDal.industry();
  193. LoginModel.industry model = new LoginModel.industry();
  194. DataSet ds = dal.GetList("ind_name = '" + strIndName + "'", "id");
  195. if ( ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 )
  196. {
  197. model = dal.DataRowToModel(ds.Tables[0].Rows[0]);
  198. dal.Delete(model.id);
  199. Response.Write("{\"code\":200, \"msg\":\"删除行业成功\"}");
  200. }
  201. else
  202. {
  203. Response.Write("{\"code\":201, \"msg\":\"未找到该行业信息,可能已被删除\"}");
  204. }
  205. }
  206. catch
  207. {
  208. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败\"}");
  209. }
  210. }
  211. else
  212. {
  213. Response.Write("{\"code\":201, \"msg\":\"行业名称未填\"}");
  214. return;
  215. }
  216. }
  217. }
  218. /// <summary>
  219. /// 修改行业的操作(不必做)
  220. /// </summary>
  221. public void OptSysModify()
  222. {
  223. }
  224. /// <summary>
  225. /// 查询行业的操作
  226. /// </summary>
  227. public void OptSysQuery()
  228. {
  229. LoginDal.industry dal = new LoginDal.industry();
  230. LoginModel.industry model = new LoginModel.industry();
  231. List<LoginModel.industry> ListModel = new List<LoginModel.industry>();
  232. if (Request.Form["ind_name"] != null)
  233. {// 查询某一个;
  234. string strIndName = Request.Form["ind_name"];
  235. try
  236. {
  237. DataSet ds = dal.GetList("ind_name = '" + strIndName + "'", "id");
  238. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  239. {
  240. model = dal.DataRowToModel(ds.Tables[0].Rows[0]);
  241. ListModel.Add(model);
  242. string strJson = JsonConvert.SerializeObject(ListModel);
  243. Response.Write(strJson);
  244. }
  245. else
  246. {
  247. Response.Write("{\"code\":201, \"msg\":\"没有该行业信息\"}");
  248. }
  249. }
  250. catch
  251. {
  252. Response.Write("{\"code\":201, \"msg\":\"数据操作失败\"}");
  253. }
  254. }
  255. else
  256. {// 查询所有;
  257. try
  258. {
  259. DataSet ds = dal.GetAllList("id");
  260. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  261. {
  262. foreach ( DataRow dr in ds.Tables[0].Rows )
  263. {
  264. model = dal.DataRowToModel(dr);
  265. ListModel.Add(model);
  266. }
  267. string strJson = JsonConvert.SerializeObject(ListModel);
  268. Response.Write(strJson);
  269. }
  270. else
  271. {
  272. Response.Write("{\"code\":201, \"msg\":\"没有该行业信息\"}");
  273. }
  274. }
  275. catch
  276. {
  277. Response.Write("{\"code\":201, \"msg\":\"数据操作失败\"}");
  278. }
  279. }
  280. }
  281. }
  282. }