enterprise.aspx.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. namespace LYFZ.WeixinServers.LoginApi
  11. {
  12. public partial class enterprise : System.Web.UI.Page
  13. {
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. if (Request.HttpMethod.ToUpper() == "GET")
  17. return;
  18. if (Request.QueryString["type"] != null)
  19. {
  20. string strOptType = Request.QueryString["type"];
  21. if (!string.IsNullOrEmpty(strOptType))
  22. {
  23. if (strOptType.StartsWith("sys-"))
  24. {
  25. string strUser, strUserPsw;
  26. if (VerifySysParam(out strUser, out strUserPsw))
  27. {
  28. LoginModel.user model = GlobalCache.GetUserInfo(strUser, strUserPsw);
  29. if (model == null)
  30. {
  31. Response.Write("{\"code\":201, \"msg\":\"账号或密码不对\"}");
  32. return;
  33. }
  34. if (model.user_type != 0)
  35. {
  36. Response.Write("{\"code\":201, \"msg\":\"账号操作权限不足\"}");
  37. return;
  38. }
  39. switch (strOptType)
  40. {
  41. case "sys-add":
  42. {
  43. OptSysAdd();
  44. }
  45. break;
  46. case "sys-delete":
  47. {
  48. OptSysDelete();
  49. }
  50. break;
  51. case "sys-modify":
  52. {
  53. OptSysModify();
  54. }
  55. break;
  56. case "sys-query":
  57. {
  58. OptSysQuery();
  59. }
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. else
  66. {
  67. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  68. }
  69. }
  70. else
  71. {
  72. }
  73. }
  74. else
  75. {
  76. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  77. }
  78. }
  79. else
  80. {
  81. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  82. }
  83. }
  84. public bool VerifySysParam(out string strUser, out string strUserPsw)
  85. {
  86. strUser = strUserPsw = "";
  87. if (this.Request.Form["user"] != null &&
  88. this.Request.Form["user_psw"] != null )
  89. {
  90. strUser = this.Request.Form["user"];
  91. strUserPsw = this.Request.Form["user_psw"];
  92. if (string.IsNullOrEmpty(strUser) || string.IsNullOrEmpty(strUserPsw) )
  93. return false;
  94. return true;
  95. }
  96. return false;
  97. }
  98. public void OptSysAdd()
  99. {
  100. bool hasnull = false;
  101. Dictionary<string, string> PostParam = new Dictionary<string, string>();
  102. string[] not_null_field = { "ind_name", "ent_name", "ent_leal_persion", "ent_phone", "ent_web_site", "ent_address", "ent_kf_count", "ent_kf_usage_days", "server_id", "ent_note" };
  103. foreach (string str in not_null_field )
  104. {
  105. if (Request.Form[str] == null) {
  106. hasnull = true;
  107. break;
  108. }
  109. PostParam.Add(str, Request.Form[str]);
  110. }
  111. if ( hasnull )
  112. {
  113. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  114. }
  115. else
  116. {
  117. string ind_name = PostParam["ind_name"];
  118. if ( string.IsNullOrEmpty( PostParam["ent_name"]) || string.IsNullOrEmpty(ind_name) )
  119. {
  120. Response.Write("{\"code\":201, \"msg\":\"行业名或企业名不能为空\"}");
  121. return;
  122. }
  123. try
  124. {
  125. LoginModel.enterprise model = new LoginModel.enterprise();
  126. LoginModel.industry model_ind = new LoginModel.industry();
  127. DataSet ds = GlobalCache.DalIndustry.GetList("ind_name = '" + ind_name + "'", "id");
  128. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  129. {
  130. model_ind = GlobalCache.DalIndustry.DataRowToModel(ds.Tables[0].Rows[0]);
  131. model.ind_id = model_ind.ind_id;
  132. model.ent_id = GlobalCache.GuidString();
  133. model.ent_name = PostParam["ent_name"];
  134. model.ent_leal_persion = PostParam["ent_leal_persion"];
  135. model.ent_phone = PostParam["ent_phone"];
  136. model.ent_web_site = PostParam["ent_web_site"];
  137. model.ent_address = PostParam["ent_address"];
  138. model.ent_kf_count = Convert.ToInt32(PostParam["ent_kf_count"].ToString());
  139. model.ent_kf_usage_days = Convert.ToInt32(PostParam["ent_kf_usage_days"].ToString());
  140. model.server_id = PostParam["server_id"];
  141. model.ent_note = PostParam["ent_note"];
  142. GlobalCache.DalEnterprise.Add(model);
  143. Response.Write("{\"code\":200, \"msg\":\"添加企业成功\"}");
  144. }
  145. }
  146. catch (Exception ex)
  147. {
  148. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  149. }
  150. }
  151. }
  152. public void OptSysDelete()
  153. {
  154. if ( Request.Form["ent_id"] != null )
  155. {
  156. string strEntId = Request.Form["ent_id"];
  157. try
  158. {
  159. LoginModel.enterprise model = new LoginModel.enterprise();
  160. DataSet ds = GlobalCache.DalEnterprise.GetList("ent_id = '" + strEntId + "'", "id");
  161. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  162. {
  163. model = GlobalCache.DalEnterprise.DataRowToModel(ds.Tables[0].Rows[0]);
  164. GlobalCache.DalEnterprise.Delete(model.id);
  165. Response.Write("{\"code\":200, \"msg\":\"删除成功\"}");
  166. }
  167. else
  168. {
  169. Response.Write("{\"code\":201, \"msg\":\"没有该企业信息\"}");
  170. }
  171. }
  172. catch (Exception ex)
  173. {
  174. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  175. }
  176. }
  177. else
  178. {
  179. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  180. }
  181. }
  182. public void OptSysModify()
  183. {
  184. bool hasnull = false;
  185. Dictionary<string, string> PostParam = new Dictionary<string, string>();
  186. string[] not_null_field = { "ent_id", "ent_name", "ent_leal_persion", "ent_phone", "ent_web_site", "ent_address", "ent_kf_count", "ent_kf_usage_days", "server_id", "ent_note" };
  187. foreach (string str in not_null_field)
  188. {
  189. if (Request.Form[str] == null)
  190. {
  191. hasnull = true;
  192. break;
  193. }
  194. PostParam.Add(str, Request.Form[str]);
  195. }
  196. if (hasnull)
  197. {
  198. Response.Write("{\"code\":201, \"msg\":\"参数名不对或参数缺少\"}");
  199. }
  200. else
  201. {
  202. LoginModel.enterprise model = new LoginModel.enterprise();
  203. model.ent_id = PostParam["ent_id"];
  204. model.ent_name = PostParam["ent_name"];
  205. if (string.IsNullOrEmpty(model.ent_id) || string.IsNullOrEmpty(model.ent_name))
  206. {
  207. Response.Write("{\"code\":201, \"msg\":\"企业id或企业名不能为空\"}");
  208. return;
  209. }
  210. try
  211. {
  212. model.ent_leal_persion = PostParam["ent_leal_persion"];
  213. model.ent_phone = PostParam["ent_phone"];
  214. model.ent_web_site = PostParam["ent_web_site"];
  215. model.ent_address = PostParam["ent_address"];
  216. model.ent_kf_count = Convert.ToInt32(PostParam["ent_kf_count"].ToString());
  217. model.ent_kf_usage_days = Convert.ToInt32(PostParam["ent_kf_usage_days"].ToString());
  218. model.server_id = PostParam["server_id"];
  219. model.ent_note = PostParam["ent_note"];
  220. if ( GlobalCache.DalEnterprise.UpdateEx(model) )
  221. Response.Write("{\"code\":200, \"msg\":\"修改企业成功\"}");
  222. else
  223. Response.Write("{\"code\":200, \"msg\":\"修改企业失败,该企业可能不存在\"}");
  224. }
  225. catch (Exception ex)
  226. {
  227. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  228. }
  229. }
  230. }
  231. public void OptSysQuery()
  232. {
  233. List<LoginModel.enterprise> listModel = new List<LoginModel.enterprise>();
  234. if (Request.Form["ent_id"] != null)
  235. {// 查询单个;
  236. string strEntId = Request.Form["ent_id"];
  237. try
  238. {
  239. LoginModel.enterprise model = new LoginModel.enterprise();
  240. DataSet ds = GlobalCache.DalEnterprise.GetList("ent_id = '" + strEntId + "'", "id");
  241. if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  242. {
  243. model = GlobalCache.DalEnterprise.DataRowToModel(ds.Tables[0].Rows[0]);
  244. listModel.Add(model);
  245. string strJson = JsonConvert.SerializeObject(listModel);
  246. Response.Write(strJson);
  247. }
  248. else
  249. {
  250. Response.Write("{\"code\":201, \"msg\":\"没有该企业信息\"}");
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  256. }
  257. }
  258. else
  259. {// 查询全部;
  260. try
  261. {
  262. LoginModel.enterprise model = new LoginModel.enterprise();
  263. DataSet ds = GlobalCache.DalEnterprise.GetAllList("id");
  264. if (ds != null && ds.Tables.Count > 0)
  265. {
  266. foreach (DataRow dr in ds.Tables[0].Rows)
  267. {
  268. model = GlobalCache.DalEnterprise.DataRowToModel(ds.Tables[0].Rows[0]);
  269. listModel.Add(model);
  270. }
  271. string strJson = JsonConvert.SerializeObject(listModel);
  272. Response.Write(strJson);
  273. }
  274. else
  275. {
  276. Response.Write("{\"code\":200, \"msg\":\"没有业信息\"}");
  277. }
  278. }
  279. catch (Exception ex)
  280. {
  281. Response.Write("{\"code\":201, \"msg\":\"数据库操作失败:" + ex.Message + "\"}");
  282. }
  283. }
  284. }
  285. }
  286. }