地铁二期项目正式开始

DefaultController.cs 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using YTSoft.BaseCallCenter.Model;
  9. using YTSoft.BaseCallCenter.MVCWeb.Models;
  10. using YTSoft.Common;
  11. namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
  12. {
  13. public class DefaultController : Controller
  14. {
  15. //
  16. // GET: /Default/
  17. public ActionResult Login()
  18. {
  19. T_Sys_UserAccount userInfo = new T_Sys_UserAccount();
  20. HttpCookie cookies = Request.Cookies["platform"];
  21. //判断是否有cookie值,有的话就读取出来
  22. if (cookies != null && cookies.HasKeys)
  23. {
  24. userInfo.F_UserName = cookies["Name"];
  25. }
  26. return View(userInfo);
  27. }
  28. [AcceptVerbs(HttpVerbs.Post)]
  29. public string LoginIn(string username, string extensionphone, string password)
  30. {
  31. string res = "未知错误,请重新登录";
  32. DataTable dt = new DataTable();
  33. try
  34. {
  35. dt = new BaseCallCenter.BLL.T_Sys_UserAccount().GetList(username, password).Tables[0];
  36. if (dt != null)
  37. {
  38. if (dt.Rows.Count > 0)
  39. {
  40. if (dt.Rows[0]["F_UserCode"].ToString() == dt.Rows[0]["F_PassWord"].ToString())
  41. {
  42. res = "firstlogin" + dt.Rows[0]["F_UserId"].ToString();
  43. }
  44. else
  45. {
  46. //记住用户名每3个月更换一次
  47. HttpCookie cookie = new HttpCookie("platform");
  48. cookie.Values.Add("Name", username);
  49. cookie.Expires = System.DateTime.Now.AddMonths(3);
  50. Response.Cookies.Add(cookie);
  51. Dictionary<string, string> Dic = new Dictionary<string, string>();
  52. Dic.Add("F_UserID", dt.Rows[0]["F_UserId"].ToString());
  53. Dic.Add("F_UserCode", dt.Rows[0]["F_UserCode"].ToString());
  54. Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToString());
  55. Dic.Add("F_UserName", HttpUtility.UrlEncode(dt.Rows[0]["F_UserName"].ToString(), Encoding.UTF8));
  56. Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToString());
  57. Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToString());
  58. Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToString());
  59. Dic.Add("F_PId", dt.Rows[0]["F_PId"].ToString());
  60. if (dt.Rows[0]["F_GroupId"].ToString() != null)
  61. {
  62. Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToString());
  63. }
  64. if (dt.Rows[0]["F_SeatRight"].ToString() != null)
  65. {
  66. Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToString());
  67. }
  68. if (!string.IsNullOrEmpty(extensionphone))
  69. {
  70. Dic.Add("F_ExtensionNumber", extensionphone);
  71. }
  72. else
  73. {
  74. Dic.Add("F_ExtensionNumber", "");
  75. }
  76. Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToString());
  77. CookieUtil.SetCookie("BaseCallCenter_T_User", Dic);
  78. //HttpCookie UserCookie = new HttpCookie("BaseCallCenter_T_User");
  79. //UserCookie["F_UserId"] = dt.Rows[0]["F_UserId"].ToString();
  80. //UserCookie["F_UserCode"] = dt.Rows[0]["F_UserCode"].ToString();
  81. //UserCookie["F_DeptId"] = dt.Rows[0]["F_DeptId"].ToString();
  82. //UserCookie["F_UserName"] = dt.Rows[0]["F_UserName"].ToString();
  83. //UserCookie["F_Telephone"] = dt.Rows[0]["F_Telephone"].ToString();
  84. //UserCookie["F_RoleID"] = dt.Rows[0]["F_RoleID"].ToString();
  85. //UserCookie["F_SeatFlag"] = dt.Rows[0]["F_SeatFlag"].ToString();
  86. //if (dt.Rows[0]["F_GroupId"].ToString() != null)
  87. //{
  88. // UserCookie["F_GroupId"] = dt.Rows[0]["F_GroupId"].ToString();
  89. //}
  90. //if (dt.Rows[0]["F_SeatRight"].ToString() != null)
  91. //{
  92. // UserCookie["F_SeatRight"] = dt.Rows[0]["F_SeatRight"].ToString();
  93. //}
  94. //if (!string.IsNullOrEmpty(extensionphone))
  95. //{
  96. // UserCookie["F_ExtensionNumber"] =extensionphone;
  97. //}
  98. //else
  99. //{
  100. // UserCookie["F_ExtensionNumber"] = "";
  101. //}
  102. //UserCookie["F_WorkNumber"] = dt.Rows[0]["F_WorkNumber"].ToString();
  103. //Response.Cookies.Add(UserCookie);
  104. //写入登录日志
  105. new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  106. {
  107. F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
  108. F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()),
  109. F_Result = "登录成功",
  110. F_LoginIP = Common.DTRequest.GetIP(),
  111. F_Hostname = Common.DTRequest.GetIP(),
  112. F_LoginDate = DateTime.Now,
  113. F_Remark = "",
  114. F_State = 0
  115. });
  116. Common.CommonRequest.dtUserId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
  117. Common.CommonRequest.dtUserCode = dt.Rows[0]["F_UserCode"].ToString();//Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
  118. res = "success";
  119. //绑定登录用户分机号
  120. BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
  121. bll.UpdateWXId("ExtensionCode",Convert.ToInt32(extensionphone), Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString())); }
  122. }
  123. else
  124. {
  125. //写入登录日志
  126. DataTable dt1 = new BaseCallCenter.BLL.T_Sys_UserAccount().GetList("F_UserCode='" + username + "'").Tables[0];
  127. if (dt1.Rows.Count > 0)
  128. {
  129. int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  130. {
  131. F_LoginName = dt1.Rows[0]["F_UserName"].ToString(),
  132. F_LoginId = Convert.ToInt32(dt1.Rows[0]["F_UserId"].ToString()),
  133. F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone,
  134. F_LoginIP = Common.DTRequest.GetIP(),
  135. F_Hostname = Common.DTRequest.GetIP(),
  136. F_LoginDate = DateTime.Now,
  137. F_Remark = "",
  138. F_State = 0
  139. });
  140. }
  141. else
  142. {
  143. int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  144. {
  145. F_LoginName = username,
  146. F_LoginId = -1,
  147. F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone,
  148. F_LoginIP = Common.DTRequest.GetIP(),
  149. F_Hostname = Common.DTRequest.GetIP(),
  150. F_LoginDate = DateTime.Now,
  151. F_Remark = "",
  152. F_State = 0
  153. });
  154. }
  155. res = "账号或密码错误,请重新登录";
  156. }
  157. }
  158. else
  159. {
  160. res = "账号或密码错误,请重新登录";
  161. }
  162. }
  163. catch (Exception ex)
  164. {
  165. res = "错误:" + ex.ToString();
  166. SysLog.WriteLog(ex);
  167. }
  168. finally
  169. {
  170. dt.Clear();
  171. dt.Dispose();
  172. }
  173. return res;
  174. }
  175. //退出系统
  176. [AcceptVerbs(HttpVerbs.Post)]
  177. public string LoginOut(string username)
  178. {
  179. string res = "未知错误,请重新登录";
  180. DataTable dt = new DataTable();
  181. try {
  182. string userid = Request.Cookies["BaseCallCenter_T_User"]["F_UserId"];
  183. dt = new BaseCallCenter.BLL.T_Sys_UserAccount().GetList("F_UserId='" + userid + "'").Tables[0];
  184. //写入登录日志
  185. new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
  186. {
  187. F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
  188. F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()),
  189. F_Result = "退出系统成功",
  190. F_LoginIP = Common.DTRequest.GetIP(),
  191. F_Hostname = Common.DTRequest.GetIP(),
  192. F_LoginDate = DateTime.Now,
  193. F_Remark = "",
  194. F_State = 0
  195. });
  196. res = "success";
  197. //绑定登录用户分机号
  198. BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
  199. bll.UpdateWXId("ExtensionCode", 0, Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()));
  200. }
  201. catch(Exception){ }
  202. return res;
  203. }
  204. }
  205. }