public ActionResult Create(MemCards mc) { try { MemCardsBLL bll = new MemCardsBLL(); MemCards refererMc = new MemCards(); Users user = Session["user"] as Users; mc.S_ID = user.S_ID; mc.MC_Password = mc.MC_Password ?? "123456"; mc.MC_IsPast = Request.Form["MC_IsPast"] == "on" ? true : false; mc.MC_IsPointAuto = Request.Form["MC_IsPointAuto"] == "on" ? true : false; //积分兑换等级 if (mc.MC_IsPointAuto == true) { var level = bll.MenCardLevel(mc); mc.CL_ID = level.CL_ID; } if (mc.MC_RefererName != null) { mc.MC_RefererID = bll.GetExchange(mc.MC_RefererCard).MC_ID; //被推荐人增加积分 mc.MC_Point = mc.MC_Point + 100; //推荐人增加积分 refererMc.MC_Point = bll.GetExchange(mc.MC_RefererCard).MC_Point + 100; refererMc.MC_ID = bll.GetExchange(mc.MC_RefererCard).MC_ID; bll.Edit(refererMc, "MC_Point"); } mc.MC_TotalCount = 0; mc.MC_TotalMoney = 0; mc.MC_CreateTime = DateTime.Now; bll.Add(mc); bll.SaveChanges(); return Json(new { result = "ok" }); } catch { return Json(new { result = "error" }); } }
public ActionResult UpExcel() { HttpPostedFileBase upfile = Request.Files[0]; if (upfile.ContentLength > 0) { string fileName = Path.GetFileName(upfile.FileName); string fileExt = Path.GetExtension(fileName); if (fileExt.Equals(".xls") || fileExt.Equals(".xlsx")) { string path = Request.MapPath("/Filters/" + fileName); upfile.SaveAs(path); using (FileStream file = System.IO.File.OpenRead(path)) { try { // 根据文件名后缀加载IWorkbook IWorkbook workbook = fileExt == ".xls" ? new HSSFWorkbook(file) : workbook = new XSSFWorkbook(file); ISheet sheet = workbook.GetSheetAt(0); List<MemCards> mcList = new List<MemCards>(); for (int i = sheet.FirstRowNum + 1; i <= sheet.LastRowNum; i++) { IRow row = sheet.GetRow(i); MemCards mc = new MemCards(); mc.MC_CardID = row.Cells[0].ToString(); mc.MC_Name = row.Cells[1].ToString(); mc.MC_Sex = row.Cells[2].ToString() == "男" ? 1 : 0; mc.MC_Mobile = row.Cells[3].ToString(); mc.MC_Point = (int)row.Cells[4].NumericCellValue; mc.MC_TotalMoney = (float)row.Cells[5].NumericCellValue; mc.MC_TotalCount = (int)row.Cells[6].NumericCellValue; int state = 1; if (row.Cells[7].ToString() == "挂失") state = 2; else if (row.Cells[7].ToString() == "锁定") state = 3; mc.MC_State = state; mc.CL_ID = (int)row.Cells[8].NumericCellValue; mc.MC_CreateTime = Convert.ToDateTime(row.Cells[9].ToString()); mc.S_ID = (Session["user"] as Users).S_ID; mc.MC_Password = "******"; mcList.Add(mc); } MemCardsBLL bll = new MemCardsBLL(); foreach (MemCards mc in mcList) { bll.Add(mc); } bll.SaveChanges(); return Content("ok"); } catch { return Content("error"); } } } return Content("no"); } return Content("none"); }