/// <summary> /// 修改客户 /// </summary> /// <param name="customer">修改信息</param> /// <param name="ProfessionaId"></param> /// <param name="AccountId"></param> /// <param name="UserStatusID"></param> /// <param name="SourceID"></param> /// <param name="SchoolId"></param> /// <returns></returns> public ActionResult EditCustomer(CustomerInfo customer, string ProfessionaId, string AccountId, string UserStatusID, string SourceID, string SchoolId) { customer.Id = Convert.ToInt32(CusId); customer.Lock = 1; try { if (AccountId != null && ProfessionaId != null && UserStatusID != null && SourceID != null && SchoolId != null) { int actId = Convert.ToInt32(AccountId); int proId = Convert.ToInt32(ProfessionaId); int ustId = Convert.ToInt32(UserStatusID); int souId = Convert.ToInt32(SourceID); int schId = Convert.ToInt32(SchoolId); UserInfo user = unit.UserInfo.GetAll(m => m.Id == actId).FirstOrDefault(); Professiona professiona = unit.Professiona.GetAll(m => m.Id == proId).FirstOrDefault(); UserStatus status = unit.UserStatus.GetAll(m => m.Id == ustId).FirstOrDefault(); SourceInfo source = unit.SourceInfo.GetAll(m => m.Id == souId).FirstOrDefault(); SchoolInfo school = unit.SchoolInfo.GetAll(m => m.Id == schId).FirstOrDefault(); customer.AccountId = user; customer.ProfessionaId = professiona; customer.UserStatusID = status; customer.SourceID = source; customer.SchoolId = school; unit.CustomerInfo.Update(customer); unit.Save(); return(Json(new { suses = true })); } return(Json(new { suses = false })); } catch (Exception ex) { return(RedirectToAction("CustomerEditPage", "Customer")); throw ex; } }
public ActionResult CustomerUploading() { #region + 变量 //文件大小(字节数) long fileSize = 0; //重命名的文件名称 string tempName = ""; //物理路径+重命名的文件名称 string fileName = ""; //文件扩展名 string extname = ""; //虚拟路径 string virtualPath = "/Uploads/Advs/Carousels/"; //上传固定路径 string path = Server.MapPath(virtualPath); //上传文件夹名称 string dir = ""; //获取提交的文件 var file = Request.Files[0]; #endregion #region 务器本地文件上传处理 try { if (file != null && !string.IsNullOrEmpty(file.FileName)) { dir = DateTime.Now.ToString("yyyy-MM-dd"); if (!Directory.Exists(path + dir)) { Directory.CreateDirectory(path + dir); } extname = file.FileName.Substring(file.FileName.LastIndexOf('.'), (file.FileName.Length - file.FileName.LastIndexOf('.'))); tempName = Guid.NewGuid().ToString().Substring(0, 6) + extname; fileName = path + dir + @"\" + tempName; fileSize += file.ContentLength; using (FileStream fs = System.IO.File.Create(fileName)) { file.InputStream.CopyTo(fs); fs.Flush(); fs.Close(); DataTable table = ExcelHelper.ExcelToDataTable(fileName); string aa = table.Rows.Count.ToString(); foreach (DataRow item in table.Rows) { CustomerInfo stu = new CustomerInfo(); stu.CusName = item[1].ToString(); string age = item[2].ToString(); stu.Age = int.Parse(age); stu.Lock = 1; stu.Gender = item[3].ToString(); stu.Tel = item[4].ToString(); stu.WeChat = item[5].ToString(); stu.Address = item[6].ToString(); stu.Record = item[7].ToString(); stu.CounselingTime = DateTime.Now; string sourceStr = item[10].ToString(); string statusStr = item[11].ToString(); string userStr = item[9].ToString(); string proStr = item[13].ToString(); string schoolStr = item[12].ToString(); SourceInfo source = unit.SourceInfo.Where(m => m.Source == sourceStr).FirstOrDefault(); UserStatus status = unit.UserStatus.Where(m => m.UserStatusName == statusStr).FirstOrDefault(); UserInfo user = unit.UserInfo.Where(m => m.Account == userStr).FirstOrDefault(); Professiona pro = unit.Professiona.Where(m => m.ProName == proStr).FirstOrDefault(); SchoolInfo school = unit.SchoolInfo.Where(m => m.SchoolName == schoolStr).FirstOrDefault(); stu.AccountId = user; stu.ProfessionaId = pro; stu.UserStatusID = status; stu.SourceID = source; stu.SchoolId = school; unit.CustomerInfo.Insert(stu); unit.Save(); } } } } catch (Exception ex) { return(Json(new { suses = false })); throw ex; } return(Json(new { suses = false })); #endregion }