public JsonResult SendCheckCode(string username, string operationtype) { //operationtype0,注册;1修改密码 StatusData myStatusData = new StatusData(); //返回状态 // #region 手机号错误 if (!FunctionClass.isMobilePhone(username)) {//手机号规则判断 myStatusData.operateStatus = 400; myStatusData.operateMsg = "手机号错误"; return(Json(myStatusData)); } #endregion // DateTime myNowDate = DateTime.Now; DateTime myExpiredDate = DateTime.Now; //验证码有效期---调试屏蔽 myExpiredDate = DateTime.Now.AddSeconds(int.Parse(StaticVarClass.CheckCodeExpiredDate)); // string myMsg = FunctionClass.RandomCode(); // try { bool allowSend = false; using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities())//数据库操作 { if (String.IsNullOrWhiteSpace(operationtype)) { operationtype = ""; } #region 发送验证码的类型判断 int isExist = 0;// switch (operationtype) { case "0": //注册 isExist = myOperating.User_UserName.Count(p => p.MobilePhone == username); if (isExist > 0) { allowSend = false; myStatusData.operateStatus = 7; } else { allowSend = true; } //allowSend = true; break; case "1": //修改密码 isExist = myOperating.User_UserName.Count(p => p.MobilePhone == username); if (isExist > 0) { allowSend = true; } else { myStatusData.operateStatus = 400; myStatusData.operateMsg = "该号码不存在"; allowSend = false; } break; default: myStatusData.operateStatus = 400; myStatusData.operateMsg = "参数错误"; allowSend = false; break; } #endregion // if (allowSend) { #region 发送验证码 bool IsSendOk = true; // int deleteNum = myOperating.User_CheckCode.Where(p => p.ExpiredDate < myNowDate).Delete(); if (deleteNum > 0) { EFCachClear.ClearTable("User_CheckCode"); } // User_CheckCode myCheckCode = new User_CheckCode(); myCheckCode = myOperating.User_CheckCode.FirstOrDefault(p => p.MobilePhone == username); if (myCheckCode != null) { if (myCheckCode.AddDate > myNowDate.AddMinutes(-1)) { myStatusData.operateStatus = 0; myStatusData.operateMsg = "不能频繁操作,稍后重试"; } else { SmsClass mySmsClass = new SmsClass(); IsSendOk = mySmsClass.sendSmsMsg(username, 0, myMsg); // if (IsSendOk) { myCheckCode.CheckCode = myMsg; myCheckCode.ExpiredDate = myExpiredDate; myCheckCode.AddDate = myNowDate; myCheckCode.AlreadCheck = false; myOperating.SaveChanges(); // myStatusData.operateStatus = 200; myStatusData.operateMsg = "完成"; } else { myStatusData.operateStatus = 0; myStatusData.operateMsg = "发送失败!请重试"; } } } else { //调试暂时屏蔽 SmsClass mySmsClass = new SmsClass(); IsSendOk = mySmsClass.sendSmsMsg(username, 0, myMsg); // if (IsSendOk) { User_CheckCode newCheckCode = new User_CheckCode(); newCheckCode.MobilePhone = username; newCheckCode.CheckCode = myMsg; newCheckCode.ExpiredDate = myExpiredDate; newCheckCode.AddDate = myNowDate; newCheckCode.AlreadCheck = false; myOperating.User_CheckCode.Add(newCheckCode); myOperating.SaveChanges(); // myStatusData.operateStatus = 200; myStatusData.operateMsg = "完成"; } else { myStatusData.operateStatus = 0; myStatusData.operateMsg = "发送失败!请重试"; } } #endregion } } } catch { myStatusData.operateStatus = -1; throw; } return(Json(myStatusData)); }
// #region 根据批次和书号导出excel public void ExportExcel(int batchNum, long bookid) { // int rowNum = 0; string saveFileName = batchNum.ToString() + "_" + bookid.ToString(); string xlsSheetName = ""; /// using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities())//数据库操作 { #region 要开通那本图书 Child_Book_Study myChild_Book_Study = new Child_Book_Study(); myChild_Book_Study = myOperating.Child_Book_Study.FirstOrDefault(p => p.BookID == bookid); if (myChild_Book_Study != null) { xlsSheetName = myChild_Book_Study.BookName; saveFileName = myChild_Book_Study.BookName; } #endregion // if (!String.IsNullOrWhiteSpace(saveFileName)) { NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); NPOI.SS.UserModel.ISheet sheet = book.CreateSheet(xlsSheetName); // 添加数据 IQueryable <Sys_BookStudy_QRCode> myDataTable = myOperating.Sys_BookStudy_QRCode.Where(p => p.BatchNum == batchNum && p.BookStudyID == bookid); NPOI.SS.UserModel.IRow row = null; foreach (Sys_BookStudy_QRCode item in myDataTable) { row = sheet.CreateRow(rowNum); NPOI.SS.UserModel.ICell cell = row.CreateCell(0); cell.SetCellType(NPOI.SS.UserModel.CellType.String); cell.SetCellValue(StaticVarClass.QRCodeUrl + "1/" + item.QRCode); sheet.SetColumnWidth(0, 20000); rowNum++; } #region 导出文件 if (rowNum > 0) { // 写入 System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); book = null; // int updateCount = myOperating.Sys_BookStudy_QRCode.Where(p => p.BatchNum == batchNum && p.BookStudyID == bookid && p.PrintStatus == false).Update(q => new Sys_BookStudy_QRCode() { PrintStatus = true }); if (updateCount > 0) { EFCachClear.ClearTable("Sys_BookStudy_QRCode"); } // Response.ClearHeaders(); Response.Clear(); Response.Expires = 0; Response.Buffer = true; Response.AddHeader("Accept-Language", "zh-tw"); // saveFileName = saveFileName + "_" + batchNum.ToString() + "_" + rowNum + ".xls"; // Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(saveFileName, System.Text.Encoding.UTF8)); Response.ContentType = "application/octet-stream;charset=gbk"; Response.BinaryWrite(ms.ToArray()); ms.Close(); ms.Dispose(); Response.End(); } else { Response.AddHeader("Accept-Language", "zh-tw"); Response.Write("没有任何数据导出,请选择图书和批次。"); Response.End(); } #endregion } } }