using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; using YTSoft.BaseCallCenter.Model; using YTSoft.BaseCallCenter.MVCWeb.Models; using YTSoft.Common; namespace YTSoft.BaseCallCenter.MVCWeb.Controllers { public class DefaultController : Controller { // // GET: /Default/ public ActionResult Login() { T_Sys_UserAccount userInfo = new T_Sys_UserAccount(); HttpCookie cookies = Request.Cookies["platform"]; //判断是否有cookie值,有的话就读取出来 if (cookies != null && cookies.HasKeys) { userInfo.F_UserName = cookies["Name"]; } return View(userInfo); } [AcceptVerbs(HttpVerbs.Post)] public string LoginIn(string username, string extensionphone, string password) { string res = "未知错误,请重新登录"; DataTable dt = new DataTable(); try { dt = new BaseCallCenter.BLL.T_Sys_UserAccount().GetList(username, password).Tables[0]; if (dt != null) { if (dt.Rows.Count > 0) { if (dt.Rows[0]["F_UserCode"].ToString() == dt.Rows[0]["F_PassWord"].ToString()) { res = "firstlogin" + dt.Rows[0]["F_UserId"].ToString(); } else { //记住用户名每3个月更换一次 HttpCookie cookie = new HttpCookie("platform"); cookie.Values.Add("Name", username); cookie.Expires = System.DateTime.Now.AddMonths(3); Response.Cookies.Add(cookie); Dictionary Dic = new Dictionary(); Dic.Add("F_UserID", dt.Rows[0]["F_UserId"].ToString()); Dic.Add("F_UserCode", dt.Rows[0]["F_UserCode"].ToString()); Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToString()); Dic.Add("F_UserName", HttpUtility.UrlEncode(dt.Rows[0]["F_UserName"].ToString(), Encoding.UTF8)); Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToString()); Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToString()); Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToString()); Dic.Add("F_PId", dt.Rows[0]["F_PId"].ToString()); if (dt.Rows[0]["F_GroupId"].ToString() != null) { Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToString()); } if (dt.Rows[0]["F_SeatRight"].ToString() != null) { Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToString()); } if (!string.IsNullOrEmpty(extensionphone)) { Dic.Add("F_ExtensionNumber", extensionphone); } else { Dic.Add("F_ExtensionNumber", ""); } Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToString()); CookieUtil.SetCookie("BaseCallCenter_T_User", Dic); //HttpCookie UserCookie = new HttpCookie("BaseCallCenter_T_User"); //UserCookie["F_UserId"] = dt.Rows[0]["F_UserId"].ToString(); //UserCookie["F_UserCode"] = dt.Rows[0]["F_UserCode"].ToString(); //UserCookie["F_DeptId"] = dt.Rows[0]["F_DeptId"].ToString(); //UserCookie["F_UserName"] = dt.Rows[0]["F_UserName"].ToString(); //UserCookie["F_Telephone"] = dt.Rows[0]["F_Telephone"].ToString(); //UserCookie["F_RoleID"] = dt.Rows[0]["F_RoleID"].ToString(); //UserCookie["F_SeatFlag"] = dt.Rows[0]["F_SeatFlag"].ToString(); //if (dt.Rows[0]["F_GroupId"].ToString() != null) //{ // UserCookie["F_GroupId"] = dt.Rows[0]["F_GroupId"].ToString(); //} //if (dt.Rows[0]["F_SeatRight"].ToString() != null) //{ // UserCookie["F_SeatRight"] = dt.Rows[0]["F_SeatRight"].ToString(); //} //if (!string.IsNullOrEmpty(extensionphone)) //{ // UserCookie["F_ExtensionNumber"] =extensionphone; //} //else //{ // UserCookie["F_ExtensionNumber"] = ""; //} //UserCookie["F_WorkNumber"] = dt.Rows[0]["F_WorkNumber"].ToString(); //Response.Cookies.Add(UserCookie); //写入登录日志 new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs() { F_LoginName = dt.Rows[0]["F_UserName"].ToString(), F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()), F_Result = "登录成功", F_LoginIP = Common.DTRequest.GetIP(), F_Hostname = Common.DTRequest.GetIP(), F_LoginDate = DateTime.Now, F_Remark = "", F_State = 0 }); Common.CommonRequest.dtUserId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()); Common.CommonRequest.dtUserCode = dt.Rows[0]["F_UserCode"].ToString();//Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()); res = "success"; //绑定登录用户分机号 BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount(); bll.UpdateWXId("ExtensionCode",Convert.ToInt32(extensionphone), Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString())); } } else { //写入登录日志 DataTable dt1 = new BaseCallCenter.BLL.T_Sys_UserAccount().GetList("F_UserCode='" + username + "'").Tables[0]; if (dt1.Rows.Count > 0) { int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs() { F_LoginName = dt1.Rows[0]["F_UserName"].ToString(), F_LoginId = Convert.ToInt32(dt1.Rows[0]["F_UserId"].ToString()), F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone, F_LoginIP = Common.DTRequest.GetIP(), F_Hostname = Common.DTRequest.GetIP(), F_LoginDate = DateTime.Now, F_Remark = "", F_State = 0 }); } else { int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs() { F_LoginName = username, F_LoginId = -1, F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone, F_LoginIP = Common.DTRequest.GetIP(), F_Hostname = Common.DTRequest.GetIP(), F_LoginDate = DateTime.Now, F_Remark = "", F_State = 0 }); } res = "账号或密码错误,请重新登录"; } } else { res = "账号或密码错误,请重新登录"; } } catch (Exception ex) { res = "错误:" + ex.ToString(); SysLog.WriteLog(ex); } finally { dt.Clear(); dt.Dispose(); } return res; } //退出系统 [AcceptVerbs(HttpVerbs.Post)] public string LoginOut(string username) { string res = "未知错误,请重新登录"; DataTable dt = new DataTable(); try { string userid = Request.Cookies["BaseCallCenter_T_User"]["F_UserId"]; dt = new BaseCallCenter.BLL.T_Sys_UserAccount().GetList("F_UserId='" + userid + "'").Tables[0]; //写入登录日志 new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs() { F_LoginName = dt.Rows[0]["F_UserName"].ToString(), F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()), F_Result = "退出系统成功", F_LoginIP = Common.DTRequest.GetIP(), F_Hostname = Common.DTRequest.GetIP(), F_LoginDate = DateTime.Now, F_Remark = "", F_State = 0 }); res = "success"; //绑定登录用户分机号 BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount(); bll.UpdateWXId("ExtensionCode", 0, Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString())); } catch(Exception){ } return res; } } }