您好,欢迎访问三七文档
CommonMethod(通用操作方法类一)1.///summary2.///根据列名字符串数组,创建自定义DataTable3.////summary4.///paramname=sList列名字符串数组/param5.///returnsDataTable/returns6.publicstaticDataTableCreateSelfDataTable(String[]sList)7.{8.DataTable_dtSelf=newDataTable();9.10.foreach(StringsinsList)11.{12._dtSelf.Columns.Add(s);13.}14._dtSelf.AcceptChanges();15.16.return_dtSelf;17.}18.19.///summary20.///加密一个字符串21.////summary22.///paramname=vStringToEncrypt待要去加密的字符串/param23.///returns返回一个加密后的字符串/returns24.publicstaticStringEncrypt(StringvStrToEncrypt)25.{26.byte[]key={};27.byte[]IV={10,20,30,40,50,60,70,80};28.byte[]inputByteArray;29.StringvEncryptKey=!@#$1234;30.try31.{32.key=System.Text.Encoding.UTF8.GetBytes(vEncryptKey.Substring(0,8));33.DESCryptoServiceProviderdes=newDESCryptoServiceProvider();34.inputByteArray=System.Text.Encoding.UTF8.GetBytes(vStrToEncrypt);35.System.IO.MemoryStreamms=newSystem.IO.MemoryStream();36.CryptoStreamcs=newCryptoStream(ms,des.CreateEncryptor(key,IV),CryptoStreamMode.Write);37.cs.Write(inputByteArray,0,inputByteArray.Length);38.cs.FlushFinalBlock();39.40.returnConvert.ToBase64String(ms.ToArray());41.}42.catch(System.Exceptionex)43.{44.throwex;45.}46.}47.///summary48.///对一进行加密的字符串进行解密49.////summary50.///paramname=vStringToDecrypt待要去解密的字符串/param51.///returns返回一个明文/returns52.publicstaticStringDecrypt(StringvStrToDecrypt)53.{54.vStrToDecrypt=vStrToDecrypt.Trim().Replace(,+);//processblankcharfortheencryptmethod.55.byte[]key={};56.byte[]IV={10,20,30,40,50,60,70,80};57.byte[]inputByteArray=newbyte[vStrToDecrypt.Length];58.StringvDecryptKey=!@#$1234;59.try60.{61.key=System.Text.Encoding.UTF8.GetBytes(vDecryptKey.Substring(0,8));62.DESCryptoServiceProviderdes=newDESCryptoServiceProvider();63.inputByteArray=Convert.FromBase64String(vStrToDecrypt);64.65.System.IO.MemoryStreamms=newSystem.IO.MemoryStream();66.CryptoStreamcs=newCryptoStream(ms,des.CreateDecryptor(key,IV),CryptoStreamMode.Write);67.cs.Write(inputByteArray,0,inputByteArray.Length);68.cs.FlushFinalBlock();69.70.System.Text.Encodingencoding=System.Text.Encoding.UTF8;71.returnencoding.GetString(ms.ToArray());72.}73.catch(System.Exceptionex)74.{75.throwex;76.}77.}78.79.///summary80.///WebForm弹出信息框81.////summary82.///paramname=strMsg/param83.publicstaticvoidJsAlert(stringstrMsg)84.{85.HttpResponseresponse=HttpContext.Current.Response;86.strings=string.Format(scripttype=\text/javascript\alert('{0}');/script,strMsg);87.response.Write(s);88.}89.///summary90.///弹出并关闭信息对话框91.////summary92.///paramname=strMsg/param93.publicstaticvoidJsAlertAndCloseWindow(stringstrMsg)94.{95.JsAlert(strMsg);96.JsCloseWindow();97.}98.publicstaticvoidJsCloseWindow()99.{100.HttpResponseresponse=HttpContext.Current.Response;101.response.Write(scripttype=\text/javascript\window.close();/script);102.response.End();103.}104.///summary105.///弹出信息并回到上一个页面106.////summary107.///paramname=strMsg/param108.publicstaticvoidJsAlertAndGoback(stringstrMsg)109.{110.JsAlert(strMsg);111.JsGoBack();112.}113.publicstaticvoidJsGoBack()114.{115.HttpResponseresponse=HttpContext.Current.Response;116.strings=string.Format(scripttype=\text/javascript\history.go(-1);/script,newobject[0]);117.response.Write(s);118.response.End();119.}120.121.///summary122.///弹出信息并转移到指定页面123.////summary124.///paramname=strMsg/param125.///paramname=url/param126.publicstaticvoidJsAlertAndGoUrl(stringstrMsg,stringurl)127.{128.JsAlert(strMsg);129.JsGoUrl(url);130.}131.132.publicstaticvoidJsGoUrl(stringurl)133.{134.HttpResponseresponse=HttpContext.Current.Response;135.response.Write(string.Format(scripttype=\text/javascript\window.location.href='{0}';/script,url));136.response.End();137.}138.139.///summary140.///加载所有的单位并新增一条记录全部单位到ComboBox控件141.////summary142.///paramname=cbbCompany/param143.publicstaticvoidLoadComboxPassword(System.Web.UI.WebControls.DropDownListddlPassword)144.{145.ddlPassword.DataSource=null;146.ddlPassword.DataTextField=PRODUCT_ID;147.ddlPassword.DataValueField=PASSWORD;148.BLL.PasswordobjPassword=newBLL.Password();149.DataTable_dt=objPassword.GetPasswordInfo().Tables[0];150.DataRow_drNew=_dt.NewRow();151._drNew[PASSWORD]=0;152._drNew[PRODUCT_ID]=请选择;153._dt.Rows.Add(_drNew);154._dt.AcceptChanges();155.ddlPassword.DataSource=_dt;156.ddlPassword.DataBind();157.}158.159.///summary160.///绑定数据源ComboBox控件重载方法161.////summary162.///paramname=cbbCompany/param163.publicvoidLoadValueCombox(System.Web.UI.WebControls.DropDownListddlControl,DataTabledt,stringmessageName,intmessageValue)164.{165.//if(dt!=null)166.//{167.//DataRowdr=dt.NewRow();168.//dr[0]=messageValue;169.//dr[1]=messageName;170.//dt.Rows.Add(dr);171.//dt.AcceptChanges();172.173.//ddlControl.DataTextField=dr[0];174.//}175.176.//PropertyCenter.BLL.Organizeorg=newPropertyCenter.BLL.Organize();177.//org.GetModelList();178.179.//ddlPassword.DataSource=null;180.//ddlPassword.DataTextField=PRODUCT_ID;181.//ddlPassword.DataValueField=PASSWORD;182.//BLL.PasswordobjPassword=n
本文标题:C#通用操作方法类
链接地址:https://www.777doc.com/doc-4699640 .html