[关闭]
@ys930126 2017-07-06T10:36:51.000000Z 字数 3123 阅读 104

常用

常用代码


代码


JavaScript


Jq.Ajax请求

  1. $.ajaxjson(actionUrl + "?action=Delete", "moduleId=" + row.Id, function (obj) {
  2. if (obj.Success) {
  3. msg.ok("删除成功!");
  4. grid.reload();
  5. } else {
  6. msg.error(obj.Message);
  7. }
  8. });

UTF-8 转码

  1. HttpUtility.UrlEncode(frameName, System.Text.Encoding.UTF8)

浏览器乱码

  1. 使用 escape(value) 方法

INPUT 只能输入汉字

  1. onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

通过ajax 直接调用返回参数

  1. $.ajax({ url: actionUrl + "?Action=RemarkNum", timeout: 3000, cache: false, async: false }).responseText;

上传Excel

  1. function UploadExcel() {
  2. $.ajaxFileUpload({
  3. url: actionUrl+"?Action=Upload",//服务器端程序
  4. secureuri: false,
  5. fileElementId: 'uploadFile',//input框的ID
  6. dataType: 'json',//返回数据类型
  7. success: function (data,statu) {//上传成功
  8. if (data.Success == true) {
  9. alert("更新成功"+data.Message);
  10. } else {
  11. alert("更新失败",data.Message);
  12. }
  13. }
  14. });

51通知回复模块调用方法

  1. //页面需要引入下方资源
  2. <link href="/Reply/css/replycss.css" rel="stylesheet" />
  3. <script type="text/javascript" src="/Reply/js/lodingreply.js"></script>
  4. //html文件需要嵌入下方div
  5. <div id="replyContent" style=" border: solid 1px #95B8E7;"></div>
  6. <div id="yc">
  7. <input id="ReplyId" type="hidden" />
  8. <input type="hidden" id="ModuleName" />
  9. <input type="hidden" id="ForeignerId" />
  10. </div>
  11. //js 需要加入以下代码
  12. $("#ForeignerId").val(worksPointId);
  13. $("#ModuleName").val("Design");
  14. moduleReply(1);

Sql

游标

  1. DECLARE name CURSOR FOR
  2. select 语句
  3. OPEN name
  4. fetch next from name into @Paras
  5. while @@fetch_status<>-1
  6. begin
  7. --xxx 这里输入循环体语句
  8. fetch next from name into @Paras
  9. end
  10. close name
  11. deallocate name

比较时间

  1. DATEDIFF(day,'2014-10-10',createtime)<=0

CSharp

JsonMessage Try代码段

  1. var msg = new JsonMessage() {Success = true};
  2. try
  3. {
  4. }
  5. catch (DbEntityValidationException dex)
  6. {
  7. msg.Message = dex.Message;
  8. msg.Success = false;
  9. foreach (var error in dex.EntityValidationErrors)
  10. {
  11. msg.Message = string.Format("{0}\r\n:{1}", msg.Message, string.Join(";", error.ValidationErrors.Select(v => v.ErrorMessage)));
  12. }
  13. }
  14. catch (Exception ex)
  15. {
  16. msg.Success = false;
  17. var sbMsg = new StringBuilder(ex.Message);
  18. while (ex.InnerException != null)
  19. {
  20. sbMsg.AppendFormat(">>{0}", ex.InnerException.Message);
  21. ex = ex.InnerException;
  22. }
  23. msg.Message = sbMsg.ToString();
  24. }
  25. return msg;

判断排序字段是否为空

  1. if (string.IsNullOrEmpty(pg.Order?.OrderFields))
  2. {
  3. pg.Order = new Pagination.OrderBy()
  4. {
  5. OrderFields = "CreateTime",
  6. OrderType = Pagination.EOrderType.DESC
  7. };
  8. }

解决映射冲突

  1. AutoMapper.Mapper.DynamicMap

获取配置文件

  1. System.Configuration.ConfigurationManager.AppSettings

获取数据库刚插入的ID

  1. DbHelperSQL.GetSingleToString("SELECT IDENT_CURRENT('Report_TableName')");

LINQ 去除缓存

  1. .AsNoTracking() //该字段为了去缓存

附件批量上传

  1. for (int i = 0; i < context.Request.Files.Count; i++)
  2. {
  3. HttpPostedFile aFile = context.Request.Files[i];
  4. if (aFile.ContentLength == 0 || String.IsNullOrEmpty(aFile.FileName))
  5. continue;
  6. string uploadPath = "";
  7. fileName = aFile.FileName;
  8. string realFileName = "";
  9. //上传图片
  10. {
  11. uploadPath = Const.getConstructionDataUploadPath(timePath);
  12. realFileName = uploadPath + fileName;
  13. aFile.SaveAs(realFileName);
  14. //Warterfontmark.AddTextWatermark(realFileName, realFileName, markStr);
  15. }
  16. }

规范

系统规定

搜索条件标志

  1. case "eq": return " 等于 ";
  2. case "gt": return " 大于 ";
  3. case "ge": return " 大于等于 ";
  4. case "nu": return " 为空 ";
  5. case "nn": return " 不为空 ";
  6. case "lt": return " 小于 ";
  7. case "le": return " 小于等于 ";
  8. case "cn": return " 包含 ";
  9. case "ncn": return " 不包含 ";
  10. case "bw": return " 包含 ";
  11. case "ew": return " 包含 ";
  12. case "ne": return " 不等于 ";
  13. case "in": return " 包含于 ";
  14. case "ni": return " 不包含于 ";
  15. default: return " 等于 ";

其他规定

系统主色

  1. #3CB9F8

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注