Skip to content

Instantly share code, notes, and snippets.

View songzheng45's full-sized avatar

Robin Song songzheng45

  • Beijing
View GitHub Profile
@songzheng45
songzheng45 / DownloadRemoteImageAsync.cs
Last active December 21, 2016 00:42
C#下载远程图片
private static async void DownloadRemoteImageFile(string url, string fileName)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response;
try
{
WebResponse webResponse = await webRequest.GetResponseAsync();
response = webResponse as HttpWebResponse;
}
catch (Exception ex)
@songzheng45
songzheng45 / jQuery-FormaterNumber.js
Last active December 21, 2016 00:46
jquery-将数值框的值限制为指定的精度
/**
* 将jQuery对象数组中的每个元素的数值,限定为指定精度
* 该方法假设文本框是<input type="number" /> ,利用数值文本框的一些特性辅助校验
*/
var formatNumber = function (arrJqueryObjects, precision) {
for (var idx = 0; idx < arrJqueryObjects.length; idx++) {
var $elem = arrJqueryObjects[idx];
$elem.on("keyup", function () {
var numString = $(this).val().toString();
@songzheng45
songzheng45 / BuildSqlWhereCaseDynamic.cs
Created December 23, 2016 00:42
C#-ADO.NET动态构建Where条件
public class SqlWhereBuilder
{
private readonly IList<string> whereList = new List<string>();
private void AddInner(string name, object value, SearchType searchType)
{
//if (value is string || value is DateTime)
// whereList.Add($"{name}='{value}'");
//else
// whereList.Add($"{name}={value}");
@songzheng45
songzheng45 / TruncateNumber.cs
Created December 23, 2016 02:47
C#-截取数字并保留指定小数位(不四舍五入)
/// <summary>
/// 截取数字并保留指定小数位
/// </summary>
/// <param name="number">数字</param>
/// <param name="precision">要保留的小数位数</param>
/// <returns>截取后的数字</returns>
public static decimal TruncateNumber(decimal number, int precision)
{
if (precision <= 0) return number;
@songzheng45
songzheng45 / ValidIsEmptyObject.js
Created December 24, 2016 06:23
jQuery-判断对象是否是空对象
$.isEmptyObject(someObject)
@songzheng45
songzheng45 / table-noborder.html
Created December 27, 2016 08:04
CSS-去掉 table 边框
<style type="text/css">
.noborder, .noborder tr, .noborder th, .noborder td {
border: none;
}
</style>
<table class="noborder">
<tr><th>Somethingr</th></tr>
<tr><td>Something</td></tr>
</table>
@songzheng45
songzheng45 / jQuery-tooltip-demo.js
Created December 30, 2016 01:05
jQuery插件:tooltip 的用法
$("#div").tooltip({html: "111", isFocus : true})
@songzheng45
songzheng45 / EnterTriggerEvent.js
Created December 30, 2016 01:09
jQuery:回车触发某些事件
$("#username").on("keydown", function (e) {
if (e.keyCode == 13) {
// 回车提交表单
$("fooForm").trigger("submit");
}
});
@songzheng45
songzheng45 / SendEmailFailedException.txt
Last active December 30, 2016 10:06
C#-使用 SmtpClient 类发送邮件遇到的问题
1. System.Net.Mail.SmtpException: 发送邮件失败。 ---> System.IO.IOException: 无法从传输连接中读取数据: net_io_connectionclosed。
(System.Net.Mail.SmtpException: Failure sending mail. Unable to read data from the transport connection)
2. System.Net.Mail.SmtpException: SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为:5.5.1 Authentication Required.
 该异常是在使用 gmail 时抛出的。
3. 异常信息:"5.5.2 helo command rejected need fully-qualified hostname"
错误代码:504 5.5.2 Helo command rejected: need fully-qualified hostname
  错误原因:对方服务器的HELO信息不是完整的域名
  处理方式:请对方检查其HELO命令提供的域名信息,且保证其符合RFC1035国际标准的规定。
@songzheng45
songzheng45 / JavascriptNavigateToUrl.js
Created December 30, 2016 10:07
JavaScript: 跳转到指定URL
window.location.href = '...';