工作中的新知识.doc_第1页
工作中的新知识.doc_第2页
工作中的新知识.doc_第3页
工作中的新知识.doc_第4页
工作中的新知识.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

工作中的新知识1.有的时候我们会遇到一些可能用到缓存的时候,下面的类就是缓存类,此类涉及缓存的添加、删除、赋值还有提取。 using System;using System.Collections.Generic;using System.Text;namespace RCMRS.Common / / 缓存管理类 / public class CacheManager private static readonly System.Web.Caching.Cache cache; static CacheManager() System.Web.HttpContext current = System.Web.HttpContext.Current; if (null != current) cache = current.Cache; else cache = System.Web.HttpRuntime.Cache; / / 不允许实例化本类的对象 / private CacheManager() / / 从指定的键名称中获取缓存对象 / / 缓存的键名称 / public static object Get(string key) return cachekey; / / 设置缓存 / / 缓存的键名称 / 缓存的值 public static void Set(string key, object value) Add(key, value, null); / / 添加缓存对象 / / 索引键值 / 缓存对象 / 缓存依赖项 public static void Add(string key, object value, System.Web.Caching.CacheDependency dependency) cache.Insert(key, value, dependency, DateTime.MaxValue, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.AboveNormal, null); / / 删除缓存对象 / / 索引键值 public static void Remove(string key) cache.Remove(key); / / 清空缓存 / public static void Clear() System.Collections.IDictionaryEnumerator enumerator = cache.GetEnumerator(); while (enumerator.MoveNext() cache.Remove(enumerator.Key.ToString(); 2.将 dataset(gridview)导出到excel的两种方法: A如果 没有遇到母板页的情况我们可以用以下这种方法。此方法在网上比较好查出来,但是一般不建议用此方法。 /导出成Word文件 protected void WebToWord() Response.Clear(); Response.BufferOutput = true; /设定输出的字符集 Response.Charset = GB2312; /假定导出的文件名为FileName.doc Response.AppendHeader(Content-Disposition, attachment;filename=StuSubjectiveExam.doc); Response.ContentEncoding = System.Text.Encoding.GetEncoding(GB2312); /设置导出文件的格式 Response.ContentType = application/ms-word; /关闭ViewState System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo(ZH-CN, true); System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo); System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter); GridView4.RenderControl(textWriter); / /把HTML写回浏览器 Response.Write(stringWriter.ToString(); Response.End(); 注释:此方法必须要在页面中写重写VerifyRenderingInServerForm的函数。即: public override void VerifyRenderingInServerForm(Control control) /注释掉下面的代码,否则在2.0下会报错 /base.VerifyRenderingInServerForm(control); B此种方法是用在母板页或者上上述方法出错的情况下:public bool DoExport(DataSet ds, string columns, string fileName) if (ds.Tables.Count = 0 | fileName = string.Empty) return false; Application excel = new ApplicationClass(); int rowindex = 1; int colindex = 0; Workbook work = excel.Workbooks.Add(true); /Worksheet sheet1 = (Worksheet)work.Worksheets0; System.Data.DataTable table = ds.Tables0; if (columns != null) for (int i = 0; i columns.Length; i+) colindex+; if (columnsi != null & columnsi != ) excel.Cells1, colindex = columnsi; else excel.Cells1, colindex = table.Columnsi.ColumnName; else foreach (DataColumn col in table.Columns) colindex+; excel.Cells1, colindex = col.ColumnName; foreach (DataRow row in table.Rows) rowindex+; colindex = 0; foreach (DataColumn col in table.Columns) colindex+; excel.Cellsrowindex, colindex = rowcol.ColumnName.ToString(); excel.Visible = false; excel.ActiveWorkbook.SaveAs(fileName, XlFileFormat.xlExcel9795, null, null, false, false, XlSaveAsAccessMode.xlNoChange, null, null, null, null, null); excel.Quit(); excel = null; GC.Collect(); return true; 注释:此方法必须要添加引用Microsoft.Office.Interop.Excel;3.在repeater(gridview)里添加checkbox复选框,然后得到所选的内容。 A在repeater里面添加checkbox并获值。Html页面: input id=HiddenSCCJ runat=server value= type=hidden / CS文件页面:得到的是所有的选择的内容foreach (RepeaterItem ri in RepeaterSCCJ.Items) CheckBox cb = (CheckBox)ri.FindControl(CBxLSCCJ); if (cb.Checked) string sccjStr = (System.Web.UI.HtmlControls.HtmlInputHidden)ri.FindControl(HiddenSCCJ).Value.ToString(); if (sccjStr != ) CJStr = CJStr + + sccjStr + + ,; if (CJStr != ) CJStr = CJStr.Substring(0, CJStr.Length - 1);B. 在gridview里面添加checkbox并获值。Html页面: input id=HiddenFenQu runat=server value=type=hidden / Cs文件页面:foreach (GridViewRow gvr in GVFenQu.Rows) CheckBox cb = (CheckBox)gvr.FindControl(CBxFenQu); if (cb.Checked) string FenQuName = (System.Web.UI.HtmlControls.HtmlInputHidden)gvr.FindControl(HiddenFenQu).Value.ToString(); FenQuStr = + FenQuName + + , + FenQuStr; if (FenQuStr != ) FenQuStr = FenQuStr.Substring(0, FenQuStr.Length - 1); 4.NET统计用量或者别的曲线方法:Html页面: CS页面:Chart1.DataSource = ds.Tables0; Chart1.SeriesSeries1.XValueMember = 抄表时间;Chart1.SeriesSeries1.YValueMembers = 线损;Chart1.DataBind();System.Web.UI.DataVisualization.Charting.Series series = Chart1.SeriesSeries1;series.ToolTip = 抄表时间 = #AXISLABELn线损 = #VALYD;注释:必须要引用using System.Web.UI.DataVisualization.Charting; 得到一个dataset对象,然后赋值给曲线控件,然后指定列就OK。之中学到的一个sql语句:如果数据库中存在表TABLE则删除 if( object_id(NT1) is not null ) drop table NT15.在项目中添加 cookie添加cookie: HttpCookie myCookie = new HttpCoo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论