首页
归档
留言
友链
广告合作
壁纸
更多
美女主播
Search
1
博瑞GE车机升级/降级
5,610 阅读
2
Mac打印机设置黑白打印
4,950 阅读
3
修改elementUI中el-table树形结构图标
4,895 阅读
4
Mac客户端添加腾讯企业邮箱方法
4,674 阅读
5
intelliJ Idea 2022.2.X破解
4,357 阅读
后端开发
HarmonyOS Next
Web前端
微信开发
开发辅助
App开发
数据库
随笔日记
登录
/
注册
Search
标签搜索
Spring Boot
Java
Vue
Spring Cloud
Mac
MyBatis
WordPress
MacOS
asp.net
Element UI
Nacos
.Net
Spring Cloud Alibaba
MySQL
Mybatis-Plus
Typecho
jQuery
Java Script
IntelliJ IDEA
微信小程序
Laughing
累计撰写
627
篇文章
累计收到
1,421
条评论
首页
栏目
后端开发
HarmonyOS Next
Web前端
微信开发
开发辅助
App开发
数据库
随笔日记
页面
归档
留言
友链
广告合作
壁纸
美女主播
搜索到
224
篇与
的结果
2017-07-24
VS2017使用MVC提示no-executables-found-matching-command-dotnet-aspnet-codegenerator
╮(╯▽╰)╭,发现自己是越来越使用不了VS了,最近想拿.NetCore练练手,结果添加控制器也好,添加视图也好,都是提示命令找不到。度娘也不太给力,最后还是在Stack Overflow找到了原因问题原因主要是因为我在VS2017中还是使用的csproj,现在都是使用project.json了,所以我们需要在csproj的ItemGroup节点,添加一下信息<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
2017年07月24日
1,135 阅读
0 评论
0 点赞
2017-07-21
NPOI读取、写入Excel
简介使用 NPOI 你就可以在没有安装 Office 或者相应环境的机器上对 WORD/EXCEL 文档进行读写。NPOI是构建在POI 3.x版本之上的,它可以在没有安装Office的情况下对Word/Excel文档进行读写操作。代码封装using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; namespace Genersoft.GS.ZDB.Development.Controller.RO { public class NPOIHelper : IDisposable { private string fileName = null; //文件名 private IWorkbook workbook = null; private FileStream fs = null; private bool disposed; public NPOIHelper(string fileName) { this.fileName = fileName; disposed = false; } #region 导出Excel 根据datatable的格式导出对应的格式 /// <summary> /// 导出Excel 根据datatable的格式导出对应的格式 /// </summary> /// <param name="fileName">保存路径</param> /// <param name="dtSource">导出的数据源</param> /// <param name="sheetName">创建的sheet表名称</param> /// <param name="isColumnWritten">是否写入列名作为Excel头</param> /// <returns></returns> public int DataTableToExcel( DataTable dtSource, string sheetName, bool isColumnWritten) { FileStream fs = null; int i = 0; int j = 0; int count = 0; IWorkbook workbook = null; ISheet sheet = null; try { using (fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { if (fileName.IndexOf(".xlsx") > 0) // 2007版本 workbook = new XSSFWorkbook(); else if (fileName.IndexOf(".xls") > 0) // 2003版本 workbook = new HSSFWorkbook(); if (workbook != null) { sheet = workbook.CreateSheet(sheetName); } else { return -1; } ICellStyle dateStyle = workbook.CreateCellStyle(); IDataFormat format = workbook.CreateDataFormat(); dateStyle.DataFormat = format.GetFormat("yyyy/mm/dd"); ICellStyle dateStyleStr = workbook.CreateCellStyle(); IDataFormat formatStr = workbook.CreateDataFormat(); dateStyleStr.DataFormat = formatStr.GetFormat("@"); if (isColumnWritten == true) //写入DataTable的列名 { IRow row = sheet.CreateRow(0); for (j = 0; j < dtSource.Columns.Count; ++j) { row.CreateCell(j).SetCellValue(dtSource.Columns[j].ColumnName); } count = 1; } else { count = 0; } foreach (DataRow dr in dtSource.Rows) { IRow row = sheet.CreateRow(count); foreach (DataColumn column in dtSource.Columns) { ICell newCell = row.CreateCell(column.Ordinal); string drValue = dr[column].ToString(); switch (column.DataType.ToString()) { case "System.String"://字符串类型 newCell.SetCellValue(drValue); newCell.SetCellType(CellType.String); newCell.CellStyle = dateStyleStr; break; case "System.DateTime"://日期类型 DateTime dateV; if (!string.IsNullOrEmpty(drValue)) { DateTime.TryParse(drValue, out dateV); newCell.SetCellValue(dateV); } newCell.CellStyle = dateStyle;//格式化显示 break; case "System.Boolean"://布尔型 bool boolV = false; bool.TryParse(drValue, out boolV); newCell.SetCellValue(boolV); newCell.SetCellType(CellType.Boolean); break; case "System.Int16"://整型 case "System.Int32": case "System.Int64": case "System.Byte": if (!string.IsNullOrEmpty(drValue)) { int intV = 0; int.TryParse(drValue, out intV); newCell.SetCellValue(intV); newCell.SetCellType(CellType.Numeric); } break; case "System.Decimal"://浮点型 case "System.Double": if (!string.IsNullOrEmpty(drValue)) { double doubV = 0; double.TryParse(drValue, out doubV); newCell.SetCellValue(doubV); newCell.SetCellType(CellType.Numeric); } break; case "System.DBNull"://空值处理 newCell.SetCellValue(""); break; default: newCell.SetCellValue(""); break; } } ++count; } for ( i = 0; i <= sheet.LastRowNum; i++) { sheet.AutoSizeColumn(i,true); } sheet.SetColumnWidth(4, 10 * 256); sheet.SetColumnWidth(5, 10 * 256); if (dtSource.Columns.Count >= 13) { sheet.SetColumnWidth(13, 10 * 256); } workbook.Write(fs); //写入到excel} return count; } } catch (Exception ex) { fs.Dispose(); fs.Close(); throw; } } #endregion #region 导出Excel 根据datatable的格式导出对应的格式 /// <summary> /// 导出Excel 根据datatable的格式导出对应的格式 /// </summary> /// <param name="fileName">保存路径</param> /// <param name="dtSource">导出的数据源</param> /// <param name="sheetName">创建的sheet表名称</param> /// <param name="isColumnWritten">是否写入列名作为Excel头</param> /// <returns></returns> public int DataTableToExcelString(DataTable dtSource, string sheetName, bool isColumnWritten) { FileStream fs = null; int i = 0; int j = 0; int count = 0; IWorkbook workbook = null; ISheet sheet = null; try { using (fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { if (fileName.IndexOf(".xlsx") > 0) // 2007版本 workbook = new XSSFWorkbook(); else if (fileName.IndexOf(".xls") > 0) // 2003版本 workbook = new HSSFWorkbook(); if (workbook != null) { sheet = workbook.CreateSheet(sheetName); } else { return -1; } ICellStyle dateStyle = workbook.CreateCellStyle(); IDataFormat format = workbook.CreateDataFormat(); dateStyle.DataFormat = format.GetFormat("yyyy/mm/dd hh:mm:ss"); ICellStyle dateStyleStr = workbook.CreateCellStyle(); IDataFormat formatStr = workbook.CreateDataFormat(); dateStyleStr.DataFormat = formatStr.GetFormat("@"); if (isColumnWritten == true) //写入DataTable的列名 { IRow row = sheet.CreateRow(0); for (j = 0; j < dtSource.Columns.Count; ++j) { row.CreateCell(j).SetCellValue(dtSource.Columns[j].ColumnName); } count = 1; } else { count = 0; } foreach (DataRow dr in dtSource.Rows) { IRow row = sheet.CreateRow(count); foreach (DataColumn column in dtSource.Columns) { ICell newCell = row.CreateCell(column.Ordinal); string drValue = dr[column].ToString(); switch (column.DataType.ToString()) { case "System.String"://字符串类型 newCell.SetCellValue(drValue); newCell.CellStyle = dateStyleStr; break; case "System.DateTime"://日期类型 DateTime dateV; if (!string.IsNullOrEmpty(drValue)) { DateTime.TryParse(drValue, out dateV); newCell.SetCellValue(dateV); } newCell.CellStyle = dateStyle;//格式化显示 break; case "System.Boolean"://布尔型 bool boolV = false; bool.TryParse(drValue, out boolV); newCell.SetCellValue(boolV); break; case "System.Int16"://整型 case "System.Int32": case "System.Int64": case "System.Byte": if (!string.IsNullOrEmpty(drValue)) { int intV = 0; int.TryParse(drValue, out intV); newCell.SetCellValue(intV); newCell.SetCellType(CellType.Numeric); } break; case "System.Decimal"://浮点型 case "System.Double": if (!string.IsNullOrEmpty(drValue)) { double doubV = 0; double.TryParse(drValue, out doubV); newCell.SetCellValue(doubV); newCell.SetCellType(CellType.Numeric); } break; case "System.DBNull"://空值处理 newCell.SetCellValue(""); break; default: newCell.SetCellValue(""); break; } } ++count; } for (i = 0; i < sheet.LastRowNum; i++) { sheet.AutoSizeColumn(i, true); } workbook.Write(fs); //写入到excel} return count; } } catch (Exception ex) { fs.Dispose(); fs.Close(); throw; } } #endregion #region 将excel中的数据导入到DataTable中 /// <summary> /// 将excel中的数据导入到DataTable中 /// </summary> /// <param name="sheetName">excel工作薄sheet的名称</param> /// <param name="isFirstRowColumn">第一行是否是DataTable的列名</param> /// <returns>返回的DataTable</returns> public DataTable ExcelToDataTable(string sheetName, bool isFirstRowColumn) { ISheet sheet = null; DataTable data = new DataTable(); int startRow = 0; try { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); if (fileName.IndexOf(".xlsx") > 0) // 2007版本 workbook = new XSSFWorkbook(fs); else if (fileName.IndexOf(".xls") > 0) // 2003版本 workbook = new HSSFWorkbook(fs); if (sheetName != null) { sheet = workbook.GetSheet(sheetName); if (sheet == null) //如果没有找到指定的sheetName对应的sheet,则尝试获取第一个sheet { sheet = workbook.GetSheetAt(0); } } else { sheet = workbook.GetSheetAt(0); } if (sheet != null) { IRow firstRow = sheet.GetRow(0); int cellCount = firstRow.LastCellNum; //一行最后一个cell的编号 即总的列数 if (isFirstRowColumn) { for (int i = firstRow.FirstCellNum; i < cellCount; ++i) { ICell cell = firstRow.GetCell(i); if (cell != null) { string cellValue = cell.StringCellValue; if (cellValue != null) { DataColumn column = new DataColumn(cellValue); data.Columns.Add(column); } } } startRow = sheet.FirstRowNum + 1; } else { startRow = sheet.FirstRowNum; } //最后一列的标号 int rowCount = sheet.LastRowNum; for (int i = startRow; i <= rowCount; ++i) { IRow row = sheet.GetRow(i); if (row == null) continue; //没有数据的行默认是null DataRow dataRow = data.NewRow(); for (int j = row.FirstCellNum; j < cellCount; ++j) { if (row.GetCell(j) != null) //同理,没有数据的单元格都默认是null dataRow[j] = row.GetCell(j).ToString(); } data.Rows.Add(dataRow); } } return data; } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); throw; } } #endregion public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (fs != null) fs.Close(); } fs = null; disposed = true; } } } }
2017年07月21日
1,489 阅读
2 评论
0 点赞
2017-07-18
使用Linq判断DataTable数据是否重复
我们一般系统在导入数据的时候,一般都是通过NPOI将excel数据转换成DataTable,然后将DataTable导入到数据库。在数据导入的过程中,其实很重要的一部就是检查DataTable中的数据是否有重复的,如果存在重复的,我们需要识别出重复的数据。在.net中,我们通过Rows属性的cast()方法,可以很方便的过滤出重复的数据,下面的代码即可实现var query = from e in dt.Rows.Cast<DataRow>() group e by new { sapCode = e.Field<string>("SAPComCode"), sapsupplierCode = e.Field<string>("SapSupplierCode") } into g select new { sapComCode = g.Key, count = g.Count() }; var items = query.Where(A => A.count > 1); if (items.Count() > 0)//存在重复数据 { string SameSapComCode = string.Empty; foreach (var item in items) { SameSapComCode += item.sapComCode + ";"; } SameSapComCode = SameSapComCode.TrimEnd(';'); result.Data = "以下SAP公司编号的数据存在重复,请检查后重新导入<br/>" + SameSapComCode; return result; }
2017年07月18日
1,285 阅读
0 评论
0 点赞
2017-06-30
C#操作AD域之测试域连接
C#操作域的第一步便是测试程序是否能成功连接到域,通过LDAP协议,可以非常简单的测试域连接的情况。代码如下/// </summary> /// <param name="domainName">域名或IP</param> /// <param name="userName">用户名</param> /// <param name="userPwd">密码</param> /// <param name="entry">域</param> /// <returns></returns> public string IsConnect(string domainName, string userName, string userPwd, out DirectoryEntry domain) { domain = new DirectoryEntry(); try { domain.Path = string.Format("LDAP://{0}", domainName);//LDAP是轻量目录访问协议 domain.Username = userName; domain.Password = userPwd; domain.AuthenticationType = AuthenticationTypes.Secure;//身份验证的类型 domain.RefreshCache();//将此DirectoryEntry 对象的属性值加载到属性缓存中 return "测试连接成功!"; } catch (Exception ex) { return "[IsConnected方法]错误信息:" + ex.Message; } }
2017年06月30日
1,598 阅读
1 评论
1 点赞
2017-06-30
WebForms UnobtrusiveValidationMode 需要“jquery”ScriptResourceMapping
症状WebForms UnobtrusiveValidationMode 需要“jquery”ScriptResourceMapping。请添加一个名为 jquery (区分大小写)的 ScriptResourceMapping。解决办法在webconfig中找到<appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms" /> </appSettings> 删除即可。在网站根目录下新建一scripts文件夹,向里边添加jquery-1.7.2.min.js和jquery-1.7.2.js(可根据自己需要使用不同的版本)在根目录下添加全局应用程序类Global.asax文件,在Application_Start事件中添加如下代码:ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition { Path = "~/scripts/jquery-1.7.2.min.js", DebugPath = "~/scripts/jquery-1.7.2.js", CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.min.js", CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.7.2.js" });
2017年06月30日
1,278 阅读
0 评论
0 点赞
2017-06-30
meta标签属性
meta标签meta是html语言head区的一个辅助性标签。几乎所有的网页里,我们可以看到类似下面这段的html代码:<head> <meta http-equiv="content-Type" content="text/html; charset=gb2312"> </head>也许你认为这些代码可有可无。其实如果你能够用好meta标签,会给你带来意想不到的效果,例如加入关键字会自动被大型搜索网站自动搜集;可以设定页面格式及刷新等等。meta标签的组成meta标签共有两个属性,它们分别是http-equiv属性和name属性,不同的属性又有不同的参数值,这些不同的参数值就实现了不同的网页功能。name属性 name属性主要用于描述网页,与之对应的属性值为content,content中的内容主要是便于搜索引擎机器人查找信息和分类信息用的。meta标签的name属性语法格式是:<meta name="参数" content="具体的参数值"> 其中name属性主要有以下几种参数:A、Keywords(关键字)说明:keywords用来告诉搜索引擎你网页的关键字是什么。举例:<meta name ="keywords" content="science, education,culture,politics,ecnomics,relationships, entertaiment, human"> B、description(网站内容描述)说明:description用来告诉搜索引擎你的网站主要内容。举例:<meta name="description" content="This page is about the meaning of science, education,culture.">C、robots(机器人向导)说明:robots用来告诉搜索机器人哪些页面需要索引,哪些页面不需要索引。content的参数有all,none,index,noindex,follow,nofollow。默认是all。举例:<meta name="robots" content="none">D、author(作者)说明:标注网页的作者举例:<meta name="author" content="root,root@21cn.com">http-equiv属性http-equiv顾名思义,相当于http的文件头作用,它可以向浏览器传回一些有用的信息,以帮助正确和精确地显示网页内容,与之对应的属性值为content,content中的内容其实就是各个参数的变量值。meta标签的http-equiv属性语法格式是:<meta http-equiv="参数" content="参数变量值">其中http-equiv属性主要有以下几种参数:A、Expires(期限)说明:可以用于设定网页的到期时间。一旦网页过期,必须到服务器上重新传输。用法:<meta http-equiv="expires" content="Fri, 12 Jan 2001 18:18:18 GMT">注意:必须使用GMT的时间格式。B、Pragma(cache模式)说明:禁止浏览器从本地计算机的缓存中访问页面内容。用法:<meta http-equiv="Pragma" content="no-cache">注意:这样设定,访问者将无法脱机浏览。C、Refresh(刷新)说明:自动刷新并指向新页面。用法:<meta http-equiv="Refresh" content="2;URL=http://www.root.net">(注意后面的引号,分别在秒数的前面和网址的后面)注意:其中的2是指停留2秒钟后自动刷新到URL网址。D、Set-Cookie(cookie设定)说明:如果网页过期,那么存盘的cookie将被删除。用法:<meta http-equiv="Set-Cookie" content="cookievalue=xxx; expires=Friday, 12-Jan-2001 18:18:18 GMT; path=/">注意:必须使用GMT的时间格式。E、Window-target(显示窗口的设定)说明:强制页面在当前窗口以独立页面显示。用法:<meta http-equiv="Window-target" content="_top">注意:用来防止别人在框架里调用自己的页面。F、content-Type(显示字符集的设定)说明:设定页面使用的字符集。用法:<meta http-equiv="content-Type" content="text/html; charset=gb2312">G、content-Language(显示语言的设定)用法:<meta http-equiv="Content-Language" content="zh-cn" />meta标签的功能帮助主页被各大搜索引擎登录;定义页面的使用语言自动刷新并指向新的页面实现网页转换时的动画效果控制页面缓冲控制网页显示的窗口
2017年06月30日
1,384 阅读
0 评论
1 点赞
2017-06-30
GUID转换成16位字符串或19位数字并确保唯一
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string str = GuidTo16String(); Console.WriteLine(str); Console.WriteLine(str.Length); Console.Read(); } public static string GuidTo16String() { long i = 1; foreach (byte b in Guid.NewGuid().ToByteArray()) i *= ((int)b + 1); return string.Format("{0:x}", i - DateTime.Now.Ticks); } /// <summary> /// 根据GUID获取19位的唯一数字序列 /// </summary> /// <returns></returns> public static long GuidToLongID() { byte[] buffer = Guid.NewGuid().ToByteArray(); return BitConverter.ToInt64(buffer, 0); } } }
2017年06月30日
1,394 阅读
0 评论
0 点赞
2017-06-30
SoapUI测试webservice接口中文乱码
在SoapUI的启动批处理soapui.bat文件中,在set JAVA_OPTS=-Xms128m -Xmx384m -Dsoapui.properties=soapui.properties "-Dsoapui.home=%SOAPUI_HOME%\" 这句话后面加上一句:-Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8 然后重启soapUI。
2017年06月30日
1,437 阅读
0 评论
0 点赞
1
...
18
19