1、repeater控件绑定时间非空判断
<%#Convert.IsDBNull(Eval("Time_Ok")) ? "--" : Eval("Time_Ok")%>
2、aspx页面通过jquery选中设定值的下拉框
var key=<%=locked %>;
$("#sellcokId option[value='"+key+"']").attr("selected","selected");
3、jquery获取下拉框选中的值
var id = $('#select_id option:selected').val();
4、页面跳转时页面嵌套重叠问题解决方法
if (window != window.top.window) {
window.top.window.location.href = '/admin/login.aspx';
}
5、修改sql server 自增主键ID初始值
1 | DBCC CHECKIDENT ('Person',RESEED,100000000) |
6、vs使用快捷键小集
1 | Ctrl+j 智能提示、Ctrl+e+d 对齐、 F6 生成解决方案、 Ctrl+shift+空格 显示方法参数 |
7、sql 根据时间查询
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | Sql Server中查询今天、昨天、本周、上周、本月、上月数据
在做Sql Server开发的时候有时需要获取表中今天、昨天、本周、上周、本月、上月等数据,这时候就需要使用DATEDIFF()函数及GetDate()函数了。 DATEDIFF ( datepart , startdate , enddate ) 释义:计算时间差 datepare值:year | quarter | month | week | day | hour | minute | second | millisecond startdate:开始日期 enddate :结束日期 GetDate() 释义:获取当前的系统日期
下面例子中表名为tablename,条件字段名为inputdate
查询今天
SELECT * FROM tablename where DATEDIFF(day,inputdate,GETDATE())=0
查询昨天
SELECT * FROM tablename where DATEDIFF(day,inputdate,GETDATE())=1
查询本周
SELECT * FROM tablename where datediff(week,inputdate,getdate())=0
查询上周
SELECT * FROM tablename where datediff(week,inputdate,getdate())=1
查询本月
SELECT * FROM tablename where DATEDIFF(month,inputdate,GETDATE())=0
查询上月
SELECT * FROM tablename where DATEDIFF(month,inputdate,GETDATE())=1
查询本季度的
select * from T_InterViewInfo where datediff(QQ,inputdate,getdate())=0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | sqlserver中如何实现时间按月,日,小时分组查询 --按照月份统计 select count(id) cnt,datepart(mm,time) [Month] from [table] where [time] between '2007/09/08 09:10:43' and '2007/10/09 04:32:37' group by datepart(mm,time) --按照日统计 select count(id) cnt,datepart(dd,time) [Day] from [table] where time between '2007/09/08 09:10:43' and '2007/10/09 04:32:37' group by datepart(dd,time) --按照小时统计 select count(id) cnt,datepart(hh,time) [Hour] from [table] where [time] between '2007/09/08 09:10:43' and '2007/10/09 04:32:37'
group by datepart(hh,time)
==========================================================================
1、每年 select year(ordertime) AS '年', sum(Total) '销售合计' from order_list group by year(ordertime)
2、每月 select year(ordertime) '年', month(ordertime) '月', sum(Total) '销售合计' from order_list group by year(ordertime), month(ordertime)
3、每日 select year(ordertime) '年', month(ordertime) '月', day(ordertime) '日', sum(Total) '销售合计' from order_list group by year(ordertime), month(ordertime), day(ordertime)
另外每日也可以这样: select convert(char(8),ordertime,112) dt, sum(Total) '销售合计' from order_list group by convert(char(8),ordertime,112)
另外,每月(年、日)的记录条数 select year(ordertime) '年', month(ordertime) '月', count(*) '销售记录' from order_list group by year(ordertime),
month(ordertime) |
8、执行webapi项目命令
在cmd命令行窗口中,切换到webapi项目文件下面,输入 dotnet watch run 命令就可以将程序执行起来,就不用每一次修改完api接口,都要去重新启动项目
如(目录需要指定到具体的api项目根目录):D:\project\rr\xx\xx\ww\api dotnet watch run
9、sql server maanger studio下载地址
https://docs.microsoft.com/zh-cn/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-2017
10、visual studio 老版本下载地址
https://visualstudio.microsoft.com/zh-hans/vs/older-downloads/
11、使项目脱离svn管理
建一个记事本文件,然后吧这句话复制进去
for /r . %%a in (.) do @if exist "%%a\.svn" rd /s /q "%%a\.svn"
然后保存,在吧记事本文件从命名 叫 删除SVN信息.bat ,这时候要注意后缀名不是txt而是bat 了,然后双击这个批处理文件就可以解决
要在那个项目的根目录
12、在安装是vs目录:D:\install\vs2017\Common7\IDE 里面有一个WcfTestClient.exe可执行文件,该程序可测试wcf测试客户端
13、vscode快捷键
![](https://i-blog.csdnimg.cn/blog_migrate/0061addba7239980e2d3271eef55f636.gif)
代码行向左或向右缩进: Ctrl+[ 、 Ctrl+]
复制或剪切当前行/当前选中内容: Ctrl+C 、 Ctrl+V
代码格式化: Shift+Alt+F
向上或向下移动一行: Alt+Up 或 Alt+Down
向上或向下复制一行: Shift+Alt+Up 或 Shift+Alt+Down
在当前行下方插入一行: Ctrl+Enter
在当前行上方插入一行: Ctrl+Shift+Enter
![](https://i-blog.csdnimg.cn/blog_migrate/00b94a4c070e731cc13135aa37febaba.gif)
14、webstorm快捷键
ctrl + / : 单行注释
ctrl + shift + / : 块注释
ctrl+alt+L 格式化代码
Ctrl+Shift+Up/Down 代码向上/下移动。
ctrl + d: 行复制
15、.NET CORE项目部署
案例:https://www.cnblogs.com/w5942066/p/13411646.html
16、根据地址还原文件(图片)
![](https://i-blog.csdnimg.cn/blog_migrate/f95b8e7316c2b10d3143cf84d54c2dcd.gif)
staticpublicbyte[] GetBytesFromUrl(string url)
{
byte[] b;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
WebResponse myResp = myReq.GetResponse();
Stream stream = myResp.GetResponseStream();
//int i;using (BinaryReader br = new BinaryReader(stream))
{
//i = (int)(stream.Length);
b = br.ReadBytes(500000);
br.Close();
}
myResp.Close();
return b;
}
staticpublicvoid WriteBytesToFile(string fileName, byte[] content)
{
FileStream fs = new FileStream(fileName, FileMode.Create);
BinaryWriter w = new BinaryWriter(fs);
try
{
w.Write(content);
}
finally
{
fs.Close();
w.Close();
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/736f767381951dcc6d573b30d0a16245.gif)
17、解决webapi项目新建的map.json文件中文乱码问题
可通过Notepad++将其打开,然后编码方式选择utf-8编码方式
![](https://i-blog.csdnimg.cn/blog_migrate/7ea170161083ba2900d5479c77e44c25.png)
18、SQLite分页
![](https://i-blog.csdnimg.cn/blog_migrate/3cba9ed4364bb950b2900efd20a148a0.gif)
降序分页
Select * From CodeUsed Where CodeUsedId <=(
Select CodeUsedId From CodeUsed Order By CodeUsedId desc limit 6,1
) Order By CodeUsedId desc limit 3
升序分页
Select * From CodeUsed Where CodeUsedId >=(
Select CodeUsedId From CodeUsed Order By CodeUsedId limit 6,1
) Order By CodeUsedId limit 3
//升序
Select * From 表 Where 主键ID>=(
Select 主键ID From 表 Order By 主键ID limit (pageIndex -1) * pagesize,1
) Order By 主键ID limit pagesize
//降序
Select * From 表 Where 主键ID<=(
Select 主键ID From 表 Order By 主键ID desc limit (pageIndex -1) * pagesize,1
) Order By 主键ID desc limit pagesize
![](https://i-blog.csdnimg.cn/blog_migrate/4ee1561c7dc1855323d073ebc1b21f54.gif)
通过关键字limit进行分页,limit n,m 表示跳过n行查询m条数据
或者使用 limit m offset n 同上,表示跳过n行查询m条数据
int pagesize = m = 3
int pageIndex = 1
n = (pageIndex - 1) * pagesize
19、操作不同服务器数据库数据
https://www.cnblogs.com/zhaoyl9/p/11527090.html
20、读取文件转为byte
![](https://i-blog.csdnimg.cn/blog_migrate/e39d39885cccd70c28119e9715645cdd.gif)
//将一个file文件转化为byte[]publicstaticbyte[] GetBytesFromUrl1(string url)
{
byte[] b;
FileWebRequest myReq = (FileWebRequest)WebRequest.Create(url);
WebResponse myResp = myReq.GetResponse();
Stream stream = myResp.GetResponseStream();
//int i;using (BinaryReader br = new BinaryReader(stream))
{
b = br.ReadBytes(500000);
br.Close();
}
myResp.Close();
return b;
}
![](https://i-blog.csdnimg.cn/blog_migrate/912db5391bc35895a39b769700ef1741.gif)
21,加密解密操作
22、后台系统跳转页面时,主页出现了嵌套解决方法
if (window != window.top.window) {
window.top.window.location.href = '/login.aspx';
}
23、使用TransactionScope进行事务回滚,只需要将代码放入到里面就行了,Complete()方法表示事务完成
![](https://i-blog.csdnimg.cn/blog_migrate/52a369e2c6794900a921c3fda6ec5848.gif)
try
{
using (TransactionScope ts = new TransactionScope())
{
OP_UserInfo info1 = OP_UserInfoBLL.GetModel(100);
info1.Remark = "测试事务";
OP_UserInfoBz.Update(info1);
int m = 0;
int n = 11;
int c = n / m;
Console.WriteLine(c);
ts.Complete();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
![](https://i-blog.csdnimg.cn/blog_migrate/1de20a7d1c3ee0d03bb998e9fd1147e1.gif)
24、asp.net导出word
![](https://i-blog.csdnimg.cn/blog_migrate/a6b62e9d41b96cbaaf67cd5e59c1b64a.gif)
publicvoid Download()
{
Random rd = new Random();
string fileName = DateTime.Now.ToString("yyyyMMddhhmm") + rd.Next() + ".doc";
//存储路径string path = Server.MapPath(fileName);
//创建字符输出流
StreamWriter sw = new StreamWriter(path, true, System.Text.UnicodeEncoding.UTF8);
//需要导出的内容
// string str = "<html><head><title>无标题文档</title></head><body>这里放从数据库导出的word文档内容</body></html>";string str = "";
str += "<html><head><title>无标题文档</title></head><body>";
str += "<div>阅读报表</div>";
str += "<table border='1'><tr>";
str += "<td>20000</td>";
str += "<td>10000</td></tr><tr>";
str += "<td>30000</td>";
str += "<td>30000</td><tr>";
str += "</table></body></html>";
//写入 sw.Write(str);
sw.Close();
Response.Clear();
Response.Buffer = true;
this.EnableViewState = false;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "application/octet-stream";
Response.WriteFile(path);
Response.Flush();
Response.Close();
Response.End();
}
![](https://i-blog.csdnimg.cn/blog_migrate/23997f5f98de646351a9b8f61a469c53.gif)
25、asp.net导出pdf
![](https://i-blog.csdnimg.cn/blog_migrate/647947942ad6ebc7247a1cad7a48ecee.gif)
string fileurl = Server.MapPath("/file/" + model.DailyId +"-"+ DateTime.Now.ToString("yyyyMMddHHmmss")+ ".pdf");
string filename = model.DailyId + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
PDFHelper pdf = new PDFHelper();
pdf.Open(new FileStream(fileurl, FileMode.Create));
pdf.SetBaseFont(@"C:\Windows\Fonts\SIMHEI.TTF");
pdf.AddImage("/images/a.jpg", 0, 200, 50);
///<summary>/// 添加段落
///</summary>///<param name="content">内容</param>///<param name="fontsize">字体大小</param>///<param name="Alignment">对齐方式(1为居中,0为居左,2为居右)</param>///<param name="SpacingAfter">段后空行数(0为默认值)</param>///<param name="SpacingBefore">段前空行数(0为默认值)</param>///<param name="MultipliedLeading">行间距(0为默认值)</param>
pdf.AddParagraph(model.DailyContent, 15, 1, 10, 0, 0);
pdf.AddParagraph(model.Remark + " 时间:" +model.PostTime.ToString("yyyy/MM/dd HH:mm:ss"), 25, 2, 20, 0, 0);
pdf.Close();
//取文件大小 FileStream MyFileStream;
uint FileSize1;
MyFileStream = new FileStream(fileurl, FileMode.Open, FileAccess.Read, FileShare.None);
int iConverTemp = Convert.ToInt32(MyFileStream.Length);
FileSize1 = (uint)(iConverTemp);
MyFileStream.Close();
Response.ContentType = "APPLICATION/OCTET-STREAM";
Response.AddHeader("Content-length", FileSize1.ToString());//下载文件长度
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
Response.WriteFile(fileurl);
Response.Flush();
Response.End();
![](https://i-blog.csdnimg.cn/blog_migrate/cab79760ddc9452592fd6a4ebfc84c91.gif)
26、获取ip地址
![](https://i-blog.csdnimg.cn/blog_migrate/d177cc8278ee5ee84f58560b3781cedc.gif)
publicstatic IPAddress GetIP()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
foreach (var uni in adapter.GetIPProperties().UnicastAddresses)
{
if (uni.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
return uni.Address;
}
}
}
returnnull;
}
27、去掉序列化为json字符串中携带的反斜杠
string responsedata = JsonConvert.SerializeObject(obj);
var json = new JsonSerializer().Deserialize(new JsonTextReader(new StringReader(responsedata)));
string res = "{\"code\":0,\"messgae\":\"xxxx\",\"data\":" + json + "}";
这样最终的res 字符串就不带反斜杠了