/// <summary> /// 注册验证码 /// </summary> /// <returns></returns> public FileResult RegisterCode() { //生成验证码 string num = RandomTo.NumCode(4); HttpContext.Session.SetString("RegisterCode", num); byte[] bytes = ImageTo.CreateImg(num); return(File(bytes, "image/jpeg")); }
private static SharedResultVM UploadCheck(IFormFile file, byte[] content, string ext, string subdir) { var vm = new SharedResultVM(); if (file != null) { ext = Path.GetExtension(file.FileName); } if (string.IsNullOrWhiteSpace(ext) || !ext.Contains('.') || ext.EndsWith("exe")) { vm.Set(SharedEnum.RTag.refuse); vm.Msg = "Invalid extension"; } else { var now = DateTime.Now; string filename = now.ToString("HHmmss") + RandomTo.NumCode() + ext; if (!string.IsNullOrWhiteSpace(subdir) && !ParsingTo.IsLinkPath(subdir)) { vm.Set(SharedEnum.RTag.invalid); vm.Msg = "subdir 仅为字母、数字"; } else { //虚拟路径 var vpath = PathTo.Combine(subdir, now.ToString("yyyy'/'MM'/'dd")); //物理根路径 var prp = GlobalTo.GetValue("StaticResource:PhysicalRootPath").Replace("~", GlobalTo.ContentRootPath); //物理路径 var ppath = PathTo.Combine(prp, vpath); //创建物理目录 if (!Directory.Exists(ppath)) { Directory.CreateDirectory(ppath); } using var fs = new FileStream(PathTo.Combine(ppath, filename), FileMode.CreateNew); if (file != null) { file.CopyTo(fs); } else { fs.Write(content, 0, content.Length); } fs.Flush(); fs.Close(); //输出 vm.Data = new { server = GlobalTo.GetValue("StaticResource:Server"), path = PathTo.Combine(vpath, filename) }; vm.Set(SharedEnum.RTag.success); } } return(vm); }
public async Task <SharedResultVM> Upload(IFormFileCollection files, int?temp, string subdir) { var vm = new SharedResultVM(); try { if (files.Count > 0) { var now = DateTime.Now; //虚拟路径 var vpath = GlobalTo.GetValue("StaticResource:RootDir"); if (temp == 1) { vpath = GlobalTo.GetValue("StaticResource:TmpDir"); } else { vpath = PathTo.Combine(vpath, subdir, now.ToString("yyyy'/'MM'/'dd")); } //物理路径 var ppath = PathTo.Combine(GlobalTo.WebRootPath, vpath); if (!Directory.Exists(ppath)) { Directory.CreateDirectory(ppath); } var listPath = new List <string>(); for (int i = 0; i < files.Count; i++) { var file = files[i]; var ext = Path.GetExtension(file.FileName); var filename = now.ToString("HHmmss") + RandomTo.NumCode() + ext; using (var stream = new FileStream(PathTo.Combine(ppath, filename), FileMode.Create)) { await file.CopyToAsync(stream); } listPath.Add(PathTo.Combine(vpath, filename)); } if (listPath.Count == 1) { vm.Data = listPath.FirstOrDefault(); } else { vm.Data = listPath; } vm.Set(SharedEnum.RTag.success); } } catch (Exception ex) { vm.Set(ex); } return(vm); }
/// <summary> /// 数据实体映射 /// </summary> public static DataTable ModelsMapping(QueryDataInputVM ivm, QueryDataOutputVM ovm) { //转表(类型为字符串) DataTable dt = ovm.Table; //更改列长度 foreach (DataColumn col in dt.Columns) { col.MaxLength = short.MaxValue * 9; } var listColumns = ovm.Columns as List <SysTableConfig>; //调整列排序 var colorder = listColumns.Where(x => dt.Columns.Contains(x.ColField)).OrderBy(x => x.ColOrder).ToList(); for (int i = 0; i < colorder.Count; i++) { var ci = colorder[i]; if (dt.Columns.Contains(ci.ColField)) { dt.Columns[ci.ColField].SetOrdinal(i); } } #region 单元格转换 foreach (DataRow dr in dt.Rows) { for (int i = 0; i < dt.Columns.Count; i++) { string field = dt.Columns[i].ColumnName; dr[i] = CellFormat(ivm.TableName, field, dr[i].ToString(), dr); } } #endregion //剔除不导出的列 List <SysTableConfig> removeCol = listColumns.Where(x => x.ColExport != 1).ToList(); foreach (SysTableConfig col in removeCol) { if (dt.Columns.Contains(col.ColField)) { dt.Columns.Remove(dt.Columns[col.ColField]); } } //剔除没在表配置的列 List <string> removeColNotExists = new(); foreach (DataColumn dc in dt.Columns) { if (!listColumns.Where(x => x.ColField == dc.ColumnName).Any()) { removeColNotExists.Add(dc.ColumnName); } } foreach (string col in removeColNotExists) { dt.Columns.Remove(dt.Columns[col]); } //更改列名为中文(重复的列,后面追加4位随机数) foreach (SysTableConfig col in listColumns) { if (dt.Columns.Contains(col.ColField)) { try { dt.Columns[col.ColField].ColumnName = col.ColTitle; } catch (Exception) { dt.Columns[col.ColField].ColumnName = col.ColTitle + "-" + RandomTo.NumCode(); } } } return(dt); }