/// <summary> /// 取回用戶密碼 /// </summary> public void GetPassword(Newtonsoft.Json.Linq.JObject requestValue, Newtonsoft.Json.Linq.JObject Data, MESStationReturn StationReturn) { OleExec sfcdb = null; T_c_user GetPassword; string EMP_NO = Data["EMP_NO"].ToString(); Dictionary <string, string> dic = new Dictionary <string, string>(); try { sfcdb = this.DBPools["SFCDB"].Borrow(); GetPassword = new T_c_user(sfcdb, DBTYPE); Row_c_user row = (Row_c_user)GetPassword.NewRow(); row = GetPassword.getC_Userbyempno(EMP_NO, sfcdb, this.DBTYPE); if (row != null) { ///缺發送EMAIL 或者短信功能 dic.Add("EMP_PASSWORD", row.EMP_PASSWORD.ToString()); StationReturn.MessageCode = "MES00000015"; StationReturn.Data = dic; } StationReturn.Status = StationReturnStatusValue.Pass; this.DBPools["SFCDB"].Return(sfcdb); } catch (Exception e) { this.DBPools["SFCDB"].Return(sfcdb); throw e; } }
/// <summary> /// 登錄API /// </summary> /// <param name="requestValue"></param> /// <param name="Data"></param> /// <param name="StationReturn"></param> public void Login(Newtonsoft.Json.Linq.JObject requestValue, Newtonsoft.Json.Linq.JObject Data, MESStationReturn StationReturn) { string EMP_NO = Data["EMP_NO"].ToString(); string PWD = Data["Password"].ToString(); string BU_NAME = Data["BU_NAME"].ToString(); DataSet res = new DataSet(); Language = Data["Language"].ToString(); MESReturnMessage.Language = Language; LoginReturn lr = new LoginReturn(); OleExec SFCDB = _DBPools["SFCDB"].Borrow(); T_c_user GetLoginUser = new T_c_user(SFCDB, this.DBTYPE); Row_c_user rcu = (Row_c_user)GetLoginUser.NewRow(); rcu = GetLoginUser.getC_Userbyempno(EMP_NO, SFCDB, this.DBTYPE); if (rcu == null) { StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.MessageCode = "MES00000010"; _DBPools["SFCDB"].Return(SFCDB); return; } c_user_info user_info = new c_user_info(); user_info = GetLoginUser.GetLoginUser(EMP_NO, SFCDB); MESPubLab.MESStation.LogicObject.User lu = new MESPubLab.MESStation.LogicObject.User(); if (PWD == rcu.EMP_PASSWORD) { lu.ID = user_info.ID; lu.FACTORY = user_info.FACTORY; lu.BU = user_info.BU_NAME; lu.EMP_NO = user_info.EMP_NO; lu.EMP_LEVEL = user_info.EMP_LEVEL; lu.DPT_NAME = user_info.DPT_NAME; string token1 = DateTime.Now.ToString("yyyyMMddHHmmss"); string token2 = rand.Next(100, 999).ToString(); char[] TokenChars = (token1 + token2).ToArray(); byte[] TokenBytes = Encoding.Default.GetBytes(TokenChars); string TokenBas64 = Convert.ToBase64String(TokenBytes); StationReturn.Status = StationReturnStatusValue.Pass; StationReturn.MessageCode = "MES00000009"; LoginUser = lu; lr = new LoginReturn() { Token = TokenBas64, User_ID = LoginUser.EMP_NO, UserInfo = user_info }; } else { StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.MessageCode = "MES00000010"; } StationReturn.Data = lr; _DBPools["SFCDB"].Return(SFCDB); }
/// <summary> /// 創建新用戶 /// </summary> /// <param name="requestValue"></param> /// <param name="Data"></param> /// <param name="StationReturn"></param> public void RegisterNewUser(Newtonsoft.Json.Linq.JObject requestValue, Newtonsoft.Json.Linq.JObject Data, MESStationReturn StationReturn) { OleExec sfcdb = null; T_c_user USER; try { sfcdb = this.DBPools["SFCDB"].Borrow(); USER = new T_c_user(sfcdb, DBTYPE); Row_c_user UserRow = (Row_c_user)USER.NewRow(); UserRow.ID = USER.GetNewID(BU, sfcdb); UserRow.FACTORY = Data["FACTORY"].ToString(); UserRow.BU_NAME = Data["BU_NAME"].ToString(); UserRow.EMP_NO = Data["EMP_NO"].ToString(); UserRow.EMP_PASSWORD = Data["EMP_PASSWORD"].ToString(); UserRow.EMP_NAME = Data["EMP_NAME"].ToString(); UserRow.EMP_LEVEL = "0";//Data["EMP_LEVEL"].ToString();///創建用戶默認全部為普通用戶 0表示普通用戶,1表示可編輯本部門角色權限的用戶,9表示後台管理,能操作權限相關的任何動作 UserRow.DPT_NAME = Data["DPT_NAME"].ToString(); UserRow.POSITION_NAME = Data["POSITION_NAME"].ToString(); UserRow.MAIL_ADDRESS = Data["MAIL_ADDRESS"].ToString().ToLower(); UserRow.PHONE_NUMBER = Data["PHONE_NUMBER"].ToString(); UserRow.LOCATION = Data["LOCATION"].ToString(); UserRow.LOCK_FLAG = "N"; UserRow.AGENT_EMP_NO = Data["AGENT_EMP_NO"].ToString(); UserRow.CHANGE_PASSWORD_TIME = GetDBDateTime(); UserRow.EMP_DESC = Data["EMP_DESC"].ToString(); UserRow.EDIT_TIME = GetDBDateTime(); UserRow.EDIT_EMP = Data["EMP_NO"].ToString(); UserRow.EMP_EN_NAME = Data["EMP_EN_NAME"].ToString(); if (Data["FACTORY"].ToString() == null) { this.DBPools["SFCDB"].Return(sfcdb); StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = ""; return; } if (Data["BU_NAME"].ToString() == null) { this.DBPools["SFCDB"].Return(sfcdb); StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = "廠別為空"; return; } if (Data["EMP_NO"].ToString() == null) { this.DBPools["SFCDB"].Return(sfcdb); StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = "工號為空"; return; } if (Data["DPT_NAME"].ToString() == null) { this.DBPools["SFCDB"].Return(sfcdb); StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = "所屬部門"; return; } if (Data["EMP_NAME"].ToString() == null) { this.DBPools["SFCDB"].Return(sfcdb); StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = "員工姓名為空"; return; } ///CHECK 用戶密碼 string STRPWD = USER.CheckPWD(Data["EMP_PASSWORD"].ToString(), sfcdb); if (STRPWD != "Pass") { this.DBPools["SFCDB"].Return(sfcdb); StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = STRPWD; return; } /// CHECK EMAIL地址 string STRMAIL = USER.CheckMail(Data["MAIL_ADDRESS"].ToString().ToLower(), sfcdb); if (STRMAIL != "Pass") { this.DBPools["SFCDB"].Return(sfcdb); StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = STRMAIL; return; } ///CHECK 電話號碼 if (!USER.CheckPhone(Data["PHONE_NUMBER"].ToString(), sfcdb)) { this.DBPools["SFCDB"].Return(sfcdb); StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.Message = "电话号码填寫格式不正確"; return; } DataTable userstr = new DataTable(); userstr = USER.SelectC_Userbyempno(UserRow.EMP_NO, sfcdb, this.DBTYPE); if (userstr.Rows.Count != 0) { this.DBPools["SFCDB"].Return(sfcdb); StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.MessageCode = "MES00000012"; this.DBPools["SFCDB"].Return(sfcdb); } else { string strRet = sfcdb.ExecSQL(UserRow.GetInsertString(this.DBTYPE)); if (strRet == "1") { StationReturn.Status = StationReturnStatusValue.Pass; StationReturn.MessageCode = "MES00000013"; this.DBPools["SFCDB"].Return(sfcdb); } else { StationReturn.Status = StationReturnStatusValue.Fail; StationReturn.MessageCode = "MES00000014"; this.DBPools["SFCDB"].Return(sfcdb); } } } catch (Exception e) { this.DBPools["SFCDB"].Return(sfcdb); throw e; } }