public returnR machineUserDel(JObject passObj) { returnR rr = new returnR(); string idList = passObj["idList"].ToString(); string sql = "delete tb_Machine_user where userid in(" + idList + ")"; sqlHelper sh = new sqlHelper(); int iLen = 0; try { iLen = sh.dbClient().Ado.ExecuteCommand(sql); if (iLen > 0) { rr.code = 100; rr.msg = "删除成功!"; } else { rr.code = 0; rr.msg = "删除失败!"; } } catch (Exception ex) { rr.code = -5; rr.msg = ex.Message; } return(rr); }
public returnR companyInfoUpload() { returnR reseultR = new returnR(); return(reseultR); }
public returnR getNowLoginObejct() { sysLoginInCls si = public_method.getLoginInObject(); returnR r = new returnR(); r.code = (int)sysEnum.操作成功; r.data = si; r.msg = "成功"; return(r); }
public returnR checkAction() { returnR rr = new returnR(); sysLoginInCls si = public_method.getLoginInObject(); if (si == null) { rr.code = -1;//掉线了 } else { rr.code = 1;//有效 } return(rr); }
public returnR machineUserModify(JObject passObj) { returnR rr = new returnR(); string userId = passObj["userId"].ToString(); string belongsId = passObj["belongsId"].ToString(); string cpuId = passObj["cpuId"].ToString(); string userName = passObj["userName"].ToString(); string sex = passObj["sex"].ToString(); string psw = passObj["psw"].ToString(); string machineName = passObj["machineName"].ToString(); string account = passObj["account"].ToString(); string remarks = ""; if (passObj["remarks"] != null) { remarks = passObj["remarks"].ToString(); } psw = DES_En_De.UserMd5(psw); string sql = "update tb_Machine_user set account='" + account + "',cpuId='" + cpuId + "',machineName='" + machineName + "',userName='******',sex='" + sex + "',belongsId='" + belongsId + "',remarks='" + remarks + "',updateDate=GETDATE() where userId='" + userId + "'"; sqlHelper sh = new sqlHelper(); int iLen = 0; try { iLen = sh.dbClient().Ado.ExecuteCommand(sql); if (iLen > 0) { rr.code = 100; rr.msg = "修改成功!"; } else { rr.code = 0; rr.msg = "修改失败!"; } } catch (Exception ex) { rr.code = -5; rr.msg = ex.Message; } return(rr); }
public HttpResponseMessage publicExport(JObject jObject) { HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); returnR rr = ExcelStreamObject(jObject); String fileName = jObject["fileName"].ToString(); if (rr.code == (int)sysEnum.操作成功) { result.StatusCode = HttpStatusCode.OK; result.Content = new StreamContent((Stream)rr.data); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = fileName + "[" + public_method.getCurrDateTime() + "]" + ".xls"; } else { result.StatusCode = HttpStatusCode.OK; result.Content = new StringContent("下载失败:" + rr.msg); } return(result); }
public returnR getSystemMenu(string role_id) { returnR r = new returnR(); r.code = (int)sysEnum.还没有执行; if (string.IsNullOrEmpty(role_id)) { r.code = (int)sysEnum.参数必填; return(r); } //这里执行 try { sqlHelper sh = new sqlHelper(); } catch (Exception ex) { r.code = (int)sysEnum.发生异常; r.msg = ex.Message; } return(r); }
public returnR submitUserInfo(JObject passObj) { returnR rr = new returnR(); rr.code = 0; string cpuId = passObj["cpuId"].ToString(); string userName = passObj["userName"].ToString(); string belongsId = passObj["belongsId"].ToString(); sqlHelper sh = new sqlHelper(); string sql = "select * from tb_Machine_user with(nolock) where flag=1 and cpuId='" + cpuId + "'"; try { SqlSugarClient db = sh.dbClient(); DataTable dt = db.Ado.GetDataTable(sql); if (dt.Rows.Count > 0) { sql = "update tb_Machine_user set userName='******' ,belongsId='" + belongsId + "',updateDate=GETDATE() where flag=1 and cpuId='" + cpuId + "'"; } else { sql = "insert into tb_Machine_user(cpuId,userName,belongsId,createDate) values('" + cpuId + "','" + userName + "','" + belongsId + "',getdate())"; } int iReturn = db.Ado.ExecuteCommand(sql); if (iReturn > 0) { rr.code = 100; } else { rr.code = 0; } } catch { } return(rr); }
/// <summary> /// 得到execl流 /// </summary> /// <returns></returns> private returnR ExcelStreamObject(JObject jObject) { returnR r = new returnR(); r.code = (int)sysEnum.还没有执行; try { string fileName = "导出文件"; HSSFWorkbook hssfworkbook = new HSSFWorkbook(); ISheet sheet1 = hssfworkbook.CreateSheet(fileName); IRow rowHeader = sheet1.CreateRow(0);//生成标题 JArray jColumnArray = JArray.Parse(jObject["columnArray"].ToString()); for (var i = 0; i < jColumnArray.Count; i++) { //写标题 string fileTitle = jColumnArray[i]["title"].ToString(); rowHeader.CreateCell(i).SetCellValue(fileTitle); } //开始写内容 string keyName = jObject["keyName"].ToString(); string ip = public_method.GetIPAddress(); string sql = "";//从内存中过去对应的信息 for (var i = 0; i < MvcApplication.l_sysSearchSql.Count; i++) { if (MvcApplication.l_sysSearchSql[i].loginInIp == ip && MvcApplication.l_sysSearchSql[i].gridkey == keyName) { sql = MvcApplication.l_sysSearchSql[i].sql; break; } } if (string.IsNullOrEmpty(sql)) { r.code = (int)sysEnum.参数必填; r.msg = "sql没有获取到"; return(r); } sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); DataTable dt = db.SqlQueryable <object>(sql).ToDataTable(); if (dt == null) { r.code = (int)sysEnum.执行数据库失败; r.msg = "dt数据库失败"; return(r); } #region 写入内容 for (int i = 0; i < dt.Rows.Count; i++) { IRow row = sheet1.CreateRow(i + 1); for (int j = 0; j < jColumnArray.Count; j++) { string columnName = jColumnArray[j]["field"].ToString().Trim();//获取列名 if (checkColumnIndt(columnName, dt)) { string str = dt.Rows[i][columnName].ToString();//获取到值 if (string.IsNullOrEmpty(str)) { str = " "; } row.CreateCell(j).SetCellValue(str);//把值写进去 } } } #endregion #region 写入内存中 MemoryStream file = new MemoryStream(); hssfworkbook.Write(file); file.Seek(0, SeekOrigin.Begin); r.code = (int)sysEnum.操作成功; r.data = file; //return file; #endregion } catch (Exception ex) { r.code = (int)sysEnum.发生异常; r.msg = ex.Message; } return(r); }
public returnR machineUserAdd(JObject passObj) { returnR rr = new returnR(); string belongsId = passObj["belongsId"].ToString(); string cpuId = passObj["cpuId"].ToString(); string userName = passObj["userName"].ToString(); string sex = passObj["sex"].ToString(); string psw = passObj["psw"].ToString(); psw = DES_En_De.UserMd5(psw); string machineName = passObj["machineName"].ToString(); string account = passObj["account"].ToString(); string remarks = ""; if (passObj["remarks"] != null) { remarks = passObj["remarks"].ToString(); } sqlHelper sh = new sqlHelper(); string sql = "select * from tb_Machine_user where flag=1 and cpuId='" + cpuId + "'"; DataTable dt = new DataTable(); dt = sh.dbClient().Ado.GetDataTable(sql); if (dt != null && dt.Rows.Count > 0) { rr.code = 10; rr.msg = "该系统key【" + cpuId + "】已存在!"; } else { sql = "insert into tb_Machine_user(account,psw,cpuId,userName,sex,machineName,belongsId,remarks,managerFlag,flag,createDate)"; sql += " values('" + account + "','" + psw + "','" + cpuId + "','" + userName + "','" + sex + "','" + machineName + "','" + belongsId + "','" + remarks + "',0,1,getdate())"; int iLen = 0; try { iLen = sh.dbClient().Ado.ExecuteCommand(sql); if (iLen > 0) { rr.code = 100; rr.msg = "添加成功!"; } else { rr.code = 0; rr.msg = "添加失败!"; } } catch (Exception ex) { rr.code = -5; rr.msg = ex.Message; } } return(rr); }
public returnR resetPsw(JObject userObj) { returnR r = new returnR(); r.code = (int)sysEnum.还没有执行; if (userObj == null) { r.code = (int)sysEnum.参数必填; return(r); } //这里执行 try { #region 判断用户 string userId = userObj["userId"].ToString(); if (string.IsNullOrEmpty(userId)) { r.code = (int)sysEnum.参数必填; r.msg = "userId必填"; return(r); } string pwd = userObj["psw"].ToString(); if (string.IsNullOrEmpty(pwd)) { r.code = (int)sysEnum.参数必填; r.msg = "用户密码必填"; return(r); } sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); #endregion sysLoginInCls si = public_method.getLoginInObject(); pwd = DES_En_De.UserMd5(pwd);//这里进行加密 int iReturn = db.Updateable <sys_user>() .SetColumns(it => new sys_user() { pwd = pwd , updateUserId = si.loginUserId , updateDate = DateTime.Now }) .Where(it => it.userId.ToString() == userId).ExecuteCommand(); if (iReturn > 0) { r.code = (int)sysEnum.操作成功; r.msg = "重置密码成功"; #region //写日志 sys_log sys_log = new sys_log(); sys_log.logType = "重置"; sys_log.logText = "重置用户id[" + userId + "]密码成功"; sys_log.createUserId = si.loginUserId; public_method.saveLog(sys_log); #endregion return(r); } else { r.code = (int)sysEnum.执行数据库失败; r.msg = "重置密码失败"; return(r); } } catch (Exception ex) { r.code = (int)sysEnum.发生异常; r.msg = ex.Message; } return(r); }
public returnR login(JObject passJson) { returnR r = new returnR(); r.code = (int)sysEnum.还没有执行; try { string userName = passJson["userName"].ToString(); if (string.IsNullOrEmpty(userName)) { r.code = (int)sysEnum.参数必填; return(r); } string psw = passJson["psw"].ToString(); if (string.IsNullOrEmpty(psw)) { r.code = (int)sysEnum.参数必填; return(r); } psw = DES_En_De.UserMd5(psw); string isAdmin = passJson["isAdmin"].ToString(); if (string.IsNullOrEmpty(isAdmin)) { isAdmin = "false"; } sqlHelper sh = new sqlHelper(); if (isAdmin.ToLower() == "true") { #region DataTable loginTable = sh.dbClient().Queryable <sys_user>() .Where(it => it.userName == userName && it.pwd == psw).ToDataTable(); if (loginTable == null || loginTable.Rows.Count <= 0) { r.code = (int)sysEnum.数据不存在; r.msg = "账号或密码错误"; return(r); } //这里是成成功的 string ip = public_method.GetIPAddress(); sysLoginInCls si = new sysLoginInCls(); si.loginInIp = ip; si.loginUserId = int.Parse(loginTable.Rows[0]["userId"].ToString()); si.userName = loginTable.Rows[0]["userName"].ToString(); si.roleId = loginTable.Rows[0]["roleId"].ToString(); si.dataRoleId = loginTable.Rows[0]["dataRoleId"].ToString(); si.loginIsAdmin = true; si.mySubordinateList = ""; MvcApplication.setLoginInCls(si); r.code = (int)sysEnum.操作成功; r.data = si; r.msg = "登录成功!"; #endregion } else { DataTable loginTable = sh.dbClient().Queryable <tb_Machine_user>() .Where(it => it.account == userName && it.psw == psw).ToDataTable(); if (loginTable == null || loginTable.Rows.Count <= 0) { r.code = (int)sysEnum.数据不存在; r.msg = "账号或密码错误"; return(r); } //这里是成成功的 string ip = public_method.GetIPAddress(); sysLoginInCls si = new sysLoginInCls(); si.loginInIp = ip; si.loginIsAdmin = false; si.loginUserId = int.Parse(loginTable.Rows[0]["userId"].ToString()); si.userName = loginTable.Rows[0]["userName"].ToString(); si.roleId = "15"; si.dataRoleId = loginTable.Rows[0]["belongsId"].ToString();; si.managerFlag = loginTable.Rows[0]["managerFlag"].ToString(); si.mySubordinateList = ""; MvcApplication.setLoginInCls(si); r.code = (int)sysEnum.操作成功; r.data = si; r.msg = "登录成功!"; } } catch (Exception ex) { r.code = (int)sysEnum.发生异常; r.msg = "发生异常" + ex.Message; return(r); } return(r); }
public returnR userDel(JObject passJson) { returnR r = new returnR(); r.code = (int)sysEnum.还没有执行; if (passJson == null) { r.code = (int)sysEnum.参数必填; return(r); } //这里执行 try { sysLoginInCls si = public_method.getLoginInObject(); string userIdList = passJson["userIdList"].ToString(); sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); string[] useridArray = userIdList.Split(','); List <string> list = new List <string>(); for (int i = 0; i < useridArray.Length; i++) { list.Add(useridArray[i]); } int iReturn = db.Updateable <sys_user>() .SetColumns(it => new sys_user() { flag = (int)sysEnum.数据被删除 , updateUserId = si.loginUserId , updateDate = DateTime.Now }) .Where(it => list.Contains(it.userId.ToString())).ExecuteCommand(); if (iReturn > 0) { r.code = (int)sysEnum.操作成功; r.msg = "成功删除用户"; #region //写日志 sys_log sys_log = new sys_log(); sys_log.logType = "删除"; sys_log.logText = "删除用户id[" + userIdList + "]"; sys_log.createUserId = si.loginUserId; public_method.saveLog(sys_log); #endregion return(r); } else { r.code = (int)sysEnum.执行数据库失败; r.msg = "删除用户失败"; return(r); } } catch (Exception ex) { r.code = (int)sysEnum.发生异常; r.msg = ex.Message; } return(r); }
public returnR userUpdate(JObject userObj) { returnR r = new returnR(); r.code = (int)sysEnum.还没有执行; if (userObj == null) { r.code = (int)sysEnum.参数必填; return(r); } //这里执行 try { #region 判断用户 string userId = userObj["userId"].ToString(); if (string.IsNullOrEmpty(userId)) { r.code = (int)sysEnum.参数必填; r.msg = "userId必填"; return(r); } string username = userObj["userName"].ToString(); if (string.IsNullOrEmpty(username)) { r.code = (int)sysEnum.参数必填; r.msg = "用户名称必填"; return(r); } sqlHelper sh = new sqlHelper(); ISqlSugarClient db = sh.dbClient(); var dataList = db.Queryable <sys_user>() .Where(it => it.userName == username && it.flag == 1 && it.userId.ToString() != userId).ToList(); if (dataList.Count > 0) { r.code = (int)sysEnum.数据库中已经存在; r.msg = "数据库中已存在[" + username + "]"; return(r); } #endregion sysLoginInCls si = public_method.getLoginInObject(); string realName = userObj["realName"].ToString(); sys_user sys_user = new sys_user(); sys_user.userId = int.Parse(userId); sys_user.userName = username; sys_user.realName = realName; sys_user.roleId = int.Parse(userObj["roleId"].ToString()); sys_user.dataRoleId = int.Parse(userObj["dataRoleId"].ToString()); sys_user.phone = userObj["phone"].ToString(); sys_user.email = userObj["email"].ToString(); sys_user.remarks = userObj["remarks"].ToString(); sys_user.updateUserId = si.loginUserId; //更新人 sys_user.updateDate = System.DateTime.Now; //更新时间 sys_user.flag = 1; //默认开启 //这里转换一下 int iReturn = db.Updateable(sys_user) .IgnoreColumns(it => new { it.createDate, it.createUserId, it.pwd }).ExecuteCommand(); if (iReturn > 0) { r.code = (int)sysEnum.操作成功; r.msg = "更新[" + username + "]成功"; #region //写日志 sys_log sys_log = new sys_log(); sys_log.logType = "更新"; sys_log.logText = Newtonsoft.Json.JsonConvert.SerializeObject(sys_user); sys_log.createUserId = si.loginUserId; public_method.saveLog(sys_log); #endregion return(r); } else { r.code = (int)sysEnum.执行数据库失败; r.msg = "更新[" + username + "]失败"; return(r); } } catch (Exception ex) { r.code = (int)sysEnum.发生异常; r.msg = ex.Message; } return(r); }
public returnR login_employee(JObject passJson) { returnR r = new returnR(); r.code = (int)sysEnum.还没有执行; try { string account = passJson["account"].ToString(); if (string.IsNullOrEmpty(account)) { r.code = (int)sysEnum.参数必填; return(r); } string psw = passJson["psw"].ToString(); if (string.IsNullOrEmpty(psw)) { r.code = (int)sysEnum.参数必填; return(r); } psw = DES_En_De.UserMd5(psw); sqlHelper sh = new sqlHelper(); DataTable loginTable = sh.dbClient().Queryable <tb_Machine_user>() .Where(it => it.account == account && it.psw == psw).ToDataTable(); if (loginTable == null || loginTable.Rows.Count <= 0) { r.code = (int)sysEnum.数据不存在; r.msg = "账号或密码错误"; return(r); } //这里是成成功的 string ip = public_method.GetIPAddress(); sysLoginInCls si = new sysLoginInCls(); si.loginInIp = ip; si.loginUserId = int.Parse(loginTable.Rows[0]["userId"].ToString()); si.userName = loginTable.Rows[0]["userName"].ToString(); si.belongsId = loginTable.Rows[0]["belongsId"].ToString(); si.managerFlag = loginTable.Rows[0]["managerFlag"].ToString(); if (si.managerFlag == "1") { DataTable subList = getMySubordinateList(si.belongsId);//递归求得所有下级的userId string mySubordinateList = ""; for (int i = 0; i < subList.Rows.Count; i++) { if (i > 0) { mySubordinateList += ","; } mySubordinateList += subList.Rows[i][0].ToString(); } si.mySubordinateList = mySubordinateList; } else { si.mySubordinateList = si.loginUserId.ToString(); } MvcApplication.setLoginInCls(si); r.code = (int)sysEnum.操作成功; r.data = si; r.msg = "登录成功!"; } catch (Exception ex) { r.code = (int)sysEnum.发生异常; r.msg = "发生异常" + ex.Message; return(r); } return(r); }
public returnR uploadImagesWithBase64() { var request = HttpContext.Current.Request; Stream resStream = request.InputStream; int len = (int)resStream.Length;//post数据长度 string base64Data = string.Empty; byte[] inputByts = new byte[len]; //字节数据,用于存储post数据 resStream.Read(inputByts, 0, len); //将post数据写入byte数组中s resStream.Close(); base64Data = Encoding.UTF8.GetString(inputByts); //转为UTF8编码 returnR rr = new returnR(); string uploadpath = HttpContext.Current.Server.MapPath("image\\upload\\"); try { if (!Directory.Exists(uploadpath)) { Directory.CreateDirectory(uploadpath); } String base64 = base64Data.Substring(base64Data.IndexOf(",") + 1); //将‘,’以前的多余字符串删除 base64 = base64.Replace(" ", "+"); //string base64 = base64Data; base64 = base64.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+"); if (base64.Length % 4 > 0) { base64 = base64.PadRight(base64.Length + 4 - base64.Length % 4, '='); } System.Drawing.Bitmap bitmap = null; //定义一个Bitmap对象,接收转换完成的图片 byte[] arr = Convert.FromBase64String(base64); //将纯净资源Base64转换成等效的8位无符号整形数组 System.IO.MemoryStream ms = new System.IO.MemoryStream(arr); //转换成无法调整大小的MemoryStream对象 bitmap = new System.Drawing.Bitmap(ms); //将MemoryStream对象转换成Bitmap对象 Random r = new Random(); int i = r.Next(); string strSuiji = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + r.Next(9999999); //随机数//实际的名称 string filename = "H5_" + strSuiji + ".jpg"; //所要保存的相对路径及名字 string imagesurl2 = uploadpath + filename; //转换成绝对路径 bitmap.Save(imagesurl2, System.Drawing.Imaging.ImageFormat.Jpeg); //保存到服务器路径 ms.Close(); //关闭当前流,并释放所有与之关联的资源 bitmap.Dispose(); string httpUrl = HttpContext.Current.Request.Url.Authority; rr.code = 100; rr.msg = httpUrl + "/api/imageUpload/image/upload/" + filename; } catch (Exception ex) { rr.code = -20; rr.msg = ex.Message; } return(rr); }