public ActionResult UploadFile() { int iTotal = Request.Files.Count; if (iTotal == 0) { return(Json(ResultData.CreateError("没有数据"))); } else { for (int i = 0; i < iTotal; i++) { HttpPostedFileBase file = Request.Files[i]; if (file.ContentType != "text/csv" && file.ContentType != "application/vnd.ms-excel" && file.ContentType != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")//excel版本不同类型也不同2014-10-11 ysh { return(Json(ResultData.CreateError("文件类型错误,只能导入.csv或者.xlsx文件"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } if (file.ContentLength > 0 || !string.IsNullOrEmpty(file.FileName)) { //保存文件 string filePath = string.Format(HttpRuntime.AppDomainAppPath.ToString() + @"Upload"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string filename = Path.GetFileName(file.FileName); string savepath = string.Format("{0}\\{1}", filePath, filename); file.SaveAs(savepath); var json = ImportToDb(savepath); return(json); } } } return(null); }
public ActionResult Import(FormCollection form) { //string JCID = form["JCID"]; ReceivablesHelpers th = new ReceivablesHelpers(); HttpRequest request = System.Web.HttpContext.Current.Request; HttpFileCollection FileCollect = request.Files; if (FileCollect.Count > 0) { foreach (string str in FileCollect) { HttpPostedFile FileSave = FileCollect[str]; //用key获取单个文件对象HttpPostedFile string fileName = FileSave.FileName.Substring(FileSave.FileName.LastIndexOf("\\") + 1); string filePath = string.Format(HttpRuntime.AppDomainAppPath.ToString() + @"Upload"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string Path = string.Format("{0}\\{1}_{2}", filePath, DateTime.Now.ToString("yyyyMMddHHmmss"), fileName); FileSave.SaveAs(Path); //将上传的文件保存 //return Json(ResultData.CreateError("维护中,暂不能用!")); ResultData result = th.ImportResult(Path); if (result.HasError) { return(Json(ResultData.CreateError("导入失败!错误信息:" + result.ErrorMessage), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } return(Json(ResultData.CreateError("导入成功!"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } } return(View(form)); }
public ActionResult Update() { try { string RoleID = Request["RoleID"]; string Name = Request["Name"]; string Description = Request["Description"]; string CompanyIDs = Request["CompanyIDs"]; string DeptIDs = Request["DeptIDs"]; string BankIDs = Request["BankIDs"]; SysService.UpdateRole(RoleID, Name, Description); var pageValues = Request.Params.AllKeys .Where(k => k.StartsWith("P") && k.Length == 6) .Select((r) => new RolePage { RoleID = RoleID, PageID = r, DataFilter = (r == "P01001") ? CompanyIDs : (r == "P01002") ? DeptIDs : (r == "P01017") ? BankIDs : "", ActionValue = Convert.ToInt32(Request.Params[r]) }).ToList(); SysService.UpdateRolePages(RoleID, pageValues); Role role = new Role { RoleID = RoleID, Name = Name, Description = Description }; return(Json(ResultData.Create(role), "text/html")); } catch (Exception ex) { return(Json(ResultData.CreateError(ex.Message), "text/html")); } }
/// <summary> /// 导入数据库成功或失败都需要记录 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="FileName"></param> /// <returns></returns> public ActionResult ImportToDb(string fileName) { if (FileIsUsed(fileName)) { return(Json(ResultData.CreateError("文件正在使用中!"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } //调用通用导入 ExcelImportResult result = ExcelImportCommand.OnExecute(fileName); return(Json(ResultData.Create(result), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); }
public ActionResult Update(UserModel model) { try { var user = SysService.UpdateUser(model); return(Json(ResultData.Create(user), "text/html")); } catch (Exception ex) { return(Json(ResultData.CreateError(ex.Message), "text/html")); } }
public ActionResult Add(UserCreateModel model) { try { var user = Sys.SysService.CreateUser(model.UserName, model.Email, model.FullName, Sys.SystemConsts.DefaultPassword); return(Json(ResultData.Create(user))); } catch (Exception ex) { return(Json(ResultData.CreateError(ex.Message), "text/html")); } }
public ActionResult Delete(string keys) { if (string.IsNullOrEmpty(keys)) { return(Json(ResultData.CreateError("主键为空,删除取消"))); } if (keys.Contains(',')) { SysService.DeleteUsers(keys); } else { SysService.DeleteUser(keys); } return(Json(ResultData.Create(true), "text/html")); }
public ActionResult UpdateUserRole() { try { var userID = Request["UserID"]; string[] roles = Request["Roles[]"].Split(','); SysService.SaveUserRole(userID, roles); return(Json(ResultData.Create(SysService.GetUserModel(userID)), "text/html")); } catch (Exception ex) { return(Json(ResultData.CreateError(ex.Message), "text/html")); } }
public ActionResult UploadFile(FormCollection form) { HttpRequestBase request = Request; string fileNewName = form["CustomerID"] + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); //新文件名 string document = @"\Upload\CustomerAtt"; //上传文件夹 string[] fileTypes = new[] { "jpg", "jpeg", "png", "gif", "bmp" }; //文件格式设定 int iTotal = request.Files.Count; if (iTotal == 0) { return(Json(ResultData.CreateError("没有数据"))); } else { for (int i = 0; i < iTotal; i++) { HttpPostedFileBase file = Request.Files[i]; string fileType = System.IO.Path.GetExtension(file.FileName).Substring(1).ToLower(); //扩展名(包含‘.’) if (!fileTypes.Contains(fileType)) { return(Json(ResultData.CreateError("文件类型错误"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } else if (file.ContentLength > 1024 * 1024 * 2) { return(Json(ResultData.CreateError("文件大小不得超过2M"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } else { string fileName = file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1); //原文件名(包含扩展名) fileNewName = fileNewName + "." + fileType; //新文件名(包含扩展名) string filePath = string.Format(HttpRuntime.AppDomainAppPath.ToString() + document); //绝对路径文件夹 if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string relativePath = string.Format("{0}\\{1}", document, fileNewName); //相对路径 string Path = string.Format("{0}\\{1}", filePath, fileNewName); //绝对路径 file.SaveAs(Path); //保存文件到绝对路径 object data = (object)relativePath.Replace("\\", "/"); return(Json(ResultData.Create(data), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); //返回相对路径 } } } return(null); }
// // GET: /Order/ public ActionResult UploadAttach() { int iTotal = Request.Files.Count; ResultData r = new ResultData(); if (iTotal == 0) { r = ResultData.CreateError("没有数据"); } else { string orderID = Request.Form["OrderID"]; var supportedTypes = new[] { "jpg", "jpeg", "png", "gif", "bmp" }; HttpPostedFileBase file = Request.Files[0]; string fileExt = System.IO.Path.GetExtension(file.FileName).Substring(1); string fileName = Guid.NewGuid().ToString("N") + "." + fileExt; if (!supportedTypes.Contains(fileExt.ToLower())) { r = ResultData.CreateError("文件类型错误"); } if (file.ContentLength > 0 || !string.IsNullOrEmpty(file.FileName)) { //保存文件 string filePath = Server.MapPath(string.Format("~/Upload/OrderAttachment/{0}/", orderID)); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string savepath = string.Format(@"{0}\{1}", filePath, fileName); file.SaveAs(savepath); r = ResultData.Create(fileName); string originFileUrl = Request.Form.AllKeys.Contains("OriginAttFileUrl") ? Request.Form["OriginAttFileUrl"] : ""; if (originFileUrl != "") { string originFilePath = Server.MapPath(string.Format("~/Upload/OrderAttachment/{0}/{1}", orderID, originFileUrl)); if (System.IO.File.Exists(originFilePath)) { System.IO.File.Delete(originFilePath); } } } } return(Json(r, JsonRequestBehavior.AllowGet));; }
public ActionResult UploadImageFile() { int iTotal = Request.Files.Count; if (iTotal == 0) { return(Json(ResultData.CreateError("没有数据"))); } else { var supportedTypes = new[] { "jpg", "jpeg", "png", "gif", "bmp" }; for (int i = 0; i < iTotal; i++) { HttpPostedFileBase file = Request.Files[i]; var fileExt = System.IO.Path.GetExtension(file.FileName).Substring(1); Random r = new Random(); string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + r.Next(10000) + "." + fileExt; if (!supportedTypes.Contains(fileExt)) { return(Json(ResultData.CreateError("文件类型错误"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } if (file.ContentLength > 0 || !string.IsNullOrEmpty(file.FileName)) { //保存文件 string filePath = string.Format(HttpRuntime.AppDomainAppPath.ToString() + @"/EmployeeImg/Temp"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string filename = Path.GetFileName(fileName); string savepath = string.Format("{0}\\{1}", filePath, filename); file.SaveAs(savepath); //var json = ImportToDb(savepath); return(Json(fileName, "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } } } return(null); }
public ActionResult UpdateAuth() { try { var roleID = Request["RoleID"]; var pageValues = Request.Params.AllKeys .Where(k => k.StartsWith("P") && k.Length == 6) .Select((r) => new RolePage { RoleID = roleID, PageID = r, ActionValue = Convert.ToInt32(Request.Params[r]) }).ToList(); SysService.UpdateRolePages(roleID, pageValues); return(Json(ResultData.Create(true), "textml")); } catch (Exception ex) { return(Json(ResultData.CreateError(ex.Message), "text/html")); } }
public ActionResult Delete(string keys) { if (string.IsNullOrEmpty(keys)) { return(Json(ResultData.CreateError("主键为空,删除取消"))); } if (keys.Contains(',')) { //throw new Exception("角色不支持批量删除"); return(Json(ResultData.CreateError("角色不支持批量删除"))); } else { try { SysService.DeleteRole(keys); return(Json(ResultData.Create(true), "text/html")); } catch (Exception ex) { return(Json(ResultData.CreateError(ex.Message))); } } }
public ActionResult Upload(FormCollection form) { HttpRequestBase request = Request; //上传文件夹 string[] fileTypes = new[] { "txt" }; //文件格式设定 int iTotal = request.Files.Count; if (iTotal <= 1) { return(Json(ResultData.CreateError("缺少对比文档"))); } else { HttpPostedFileBase fileys = Request.Files[0]; HttpPostedFileBase filepd = Request.Files[1]; string fileTypeys = System.IO.Path.GetExtension(fileys.FileName).Substring(1).ToLower(); //扩展名(包含‘.’) string fileTypepd = System.IO.Path.GetExtension(filepd.FileName).Substring(1).ToLower(); //扩展名(包含‘.’) if (!fileTypes.Contains(fileTypeys)) { return(Json(ResultData.CreateError("原始文档类型错误"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } else if (fileys.ContentLength > 1024 * 1024 * 2) { return(Json(ResultData.CreateError("原始文档大小不得超过2M"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } else if (!fileTypes.Contains(fileTypepd)) { return(Json(ResultData.CreateError("盘点文档类型错误"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } else if (filepd.ContentLength > 1024 * 1024 * 2) { return(Json(ResultData.CreateError("盘点文档大小不得超过2M"), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } else { string filepathys = saveFilePath(fileys); string filepathpd = saveFilePath(filepd); string ysIDs = getIDfromTXT(filepathys); string pdIDs = getIDfromTXT(filepathpd); string pkcountstr = @"select count(y.Value) from [dbo].[fSplitString]('{0}',',',1)y left join [dbo].[fSplitString]('{1}',',',1)p on y.Value=p.Value "; string sqlstr = @"SELECT distinct p.Value ,a.[AssetID] ,a.[AssetName] ,a.[CategoryID] ,a.[SpecificationsModel] ,case a.[AddType] when 10 then '购买' when 20 then '借用' when 90 then '其它' end as [AddType] ,a.[WhCd] ,a.[LOCNO] ,a.[UnitID] ,a.[BarCard] ,a.[SupplierID] ,a.[BuyDate] ,a.[UseYear] ,(case a.UseCondition when 'RK'then'入库' when 'LY'then'领用'when 'JY'then'借用'when 'GH'then'归还'when 'DB'then'调拨'when 'BX'then'报修'when 'BF'then'报废'when 'QL'then'清理'when 'QT'then'其他' end)as UseCondition ,a.[CompanyID] ,a.[DeptID] ,a.[EmployeeID] ,a.[QualityDescription] ,convert(varchar, a.[Price],1) as [Price] ,a.[Remark] ,a.[Status] ,ca.[Category] ,wh.[WHName] ,u.[UnitName] ,s.[SupplierName] ,ass.[Area]+'('+ass.[AreaCode]+')' as [CName] ,d.[Name]as [DName] ,e.[Name]as [EName] from [dbo].[fSplitString]('{0}',',',1)y left join [dbo].[fSplitString]('{1}',',',1)p on y.Value=p.Value left join [dbo].[zc_Asset]a on y.Value=a.BarCard left join [zc_Category]ca on a.[CategoryID]=ca.[CategoryID] left join [zc_INVWarehouse]wh on a.[WhCd]=wh.[WHCd] left join [zc_Unit]u on a.[UnitID]=u.[UnitID] left join [zc_Supplier]s on a.[SupplierID]=s.[SupplierID] left join [zc_Area]ass on a.[CompanyID]=ass.[CompanyID] left join [hr_Department]d on a.[DeptID]=d.[DeptID] left join [hr_Employee]e on a.[EmployeeID]=e.[EmployeeID] order by p.Value"; PanDianData = SqlHelpers.SelectReturnDataSet(string.Format(sqlstr, ysIDs, pdIDs)).Tables[0]; string countAll = SqlHelpers.SelectReturnStr(string.Format(pkcountstr, ysIDs, pdIDs), 0, 0); string countPanKui = SqlHelpers.SelectReturnStr(string.Format(pkcountstr + " where p.Id is null", ysIDs, pdIDs), 0, 0); int[] count = new int[2]; count[0] = string.IsNullOrEmpty(countAll) ? 0 : int.Parse(countAll); count[1] = string.IsNullOrEmpty(countPanKui) ? 0 : int.Parse(countPanKui); return(Json(ResultData.Create(count), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet));//返回相对路径 } } }