分享
 
 
 

控件操作类文件的部分手写代码

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

控件操作类文件的部分手写代码

控件操作类文件的部分手写代码 using System;

using System.Web.Security;

using System.Text;

using System.IO;

using System.Security.Cryptography;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

using System.Collections;

using System.Web.Mail;

using System.Configuration;

using System.ComponentModel;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI.HtmlControls;

namespace MY

{

/// <summary>

/// UserClass 的摘要说明。

/// </summary>

public class UserClass:System.Web.UI.Page

{

private string[] userdata;

private string[] managerdata;

private string strOutPicName;

private DbControl db;

protected Page page = null;

//private Hashtable ht;

public UserClass()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

public UserClass(Page page)

{

db = new DbControl();

this.page = page;

strOutPicName = '';

}

#region 加密方法

/// <summary>

/// 加密

/// </summary>

/// <param name='pToEncrypt'></param>

/// <returns></returns>

public string Encrypt(string pToEncrypt)

{

string sKey='1234abcd';

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

//把字符串放到byte数组中

//原来使用的UTF8编码,我改成Unicode编码了,不行

byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);

//byte[] inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);

//建立加密对象的密钥和偏移量

//原文使用ASCIIEncoding.ASCII方法的GetBytes方法

//使得输入密码必须输入英文文本

des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);

des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);

MemoryStream ms = new MemoryStream();

CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),CryptoStreamMode.Write);

//Write the byte array into the crypto stream

//(It will end up in the memory stream)

cs.Write(inputByteArray, 0, inputByteArray.Length);

cs.FlushFinalBlock();

//Get the data back from the memory stream, and into a string

StringBuilder ret = new StringBuilder();

foreach(byte b in ms.ToArray())

{

//Format as hex

ret.AppendFormat('{0:X2}', b);

}

ret.ToString();

return ret.ToString();

}

public string Decrypt(string pToDecrypt)

{

string sKey='1234abcd';

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

//Put the input string into the byte array

byte[] inputByteArray = new byte[pToDecrypt.Length / 2];

for(int x = 0; x < pToDecrypt.Length / 2; x++)

{

int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));

inputByteArray[x] = (byte)i;

}

//建立加密对象的密钥和偏移量,此值重要,不能修改

des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);

des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);

MemoryStream ms = new MemoryStream();

CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(),CryptoStreamMode.Write);

//Flush the data through the crypto stream into the memory stream

cs.Write(inputByteArray, 0, inputByteArray.Length);

cs.FlushFinalBlock();

//Get the decrypted data back from the memory stream

//建立StringBuild对象,CreateDecrypt使用的是流对象,必须把解密后的文本变成流对象

StringBuilder ret = new StringBuilder();

return System.Text.Encoding.Default.GetString(ms.ToArray());

}

#endregion

#region 处理字段落字符串

/// <summary>

/// 处理字段落字符串

/// </summary>

/// <param name='notes'></param>

/// <returns></returns>

public string Ctrltxt(string notes)

{

StringBuilder outstr=new StringBuilder(notes);

outstr.Replace('\n','<br>');

outstr.Replace('&nbsp;',' ');

return outstr.ToString();

}

#endregion

#region 手动方法

/// <summary>

/// 从数据库里读取已经选 择的DR

/// </summary>

/// <param name='lb'></param>

/// <param name='strshow'></param>

/// <param name='intFlag'></param>

public void ShowDropDownList(DropDownList lb,string strshow,int intFlag)

{

foreach(ListItem objitem in lb.Items)

{

if (intFlag==0 && objitem.Text==strshow)

{

objitem.Selected=true;

}

else if (intFlag==1 && objitem.Value==strshow)

{

objitem.Selected=true;

}

else

{

objitem.Selected=false;

}

}

}

/// <summary>

/// 把数据里的值读到DL里面。

/// </summary>

/// <param name='dl'></param>

/// <param name='dr'></param>

/// <param name='strtext'></param>

/// <param name='strvalue'></param>

public void ShowDrData(DropDownList dl,SqlDataReader dr,string strtext,string strvalue)

{

dl.DataSource=dr;

dl.DataTextField=strtext;

dl.DataValueField=strvalue;

dl.DataBind();

}

/// <summary>

/// 把数据里的值读到DL里面并且选择某一项为选中,重载上面的!

/// </summary>

/// <param name='dl'></param>

/// <param name='dr'></param>

/// <param name='strtext'></param>

/// <param name='strvalue'></param>

/// <param name='sltvalue'></param>

public void ShowDrData(DropDownList dl,SqlDataReader dr ,string strtext,string strvalue,string sltvalue)

{

dl.DataSource=dr;

dl.DataTextField=strtext;

dl.DataValueField=strvalue;

dl.DataBind();

dl.Items.Add(sltvalue);

foreach(ListItem objitem in dl.Items)

{

if (objitem.Text==sltvalue)

{

objitem.Selected=true;

}

else

{

objitem.Selected=false;

}

}

}

/// <summary>

/// 重载上面的函数将Reader参数换成Array

/// </summary>

/// <param name='dl'></param>

/// <param name='al'></param>

public void ShowDrData(DropDownList dl,ArrayList al)

{

dl.DataSource=al;

//dl.DataTextField=strtext;

//dl.DataValueField=strvalue;

dl.DataBind();

}

/// <summary>

/// 把数据库里的数据读到LB里面去.

/// </summary>

/// <param name='lb'></param>

/// <param name='dr'></param>

/// <param name='strtext'></param>

/// <param name='strvalue'></param>

public void ShowDrData(ListBox lb,SqlDataReader dr,string strtext,string strvalue)

{

lb.DataSource=dr;

lb.DataTextField=strtext;

lb.DataValueField=strvalue;

lb.DataBind();

}

/// <summary>

/// 将数据读到Array数组//

/// </summary>

/// <param name='dr'></param>

/// <param name='strslt'></param>

/// <param name='strfield'></param>

/// <returns></returns>

public ArrayList ReturnArray(SqlDataReader dr,string strslt,string strfield)

{

ArrayList objarr;

objarr=new ArrayList();

if (dr.HasRows)

{

while (dr.Read())

{

objarr.Add(dr[strfield].ToString());

}

dr.Close();

}

objarr.Insert(0,strslt);

return objarr;

}

public void Close()

{

db.Close();

userdata=null;

}

/// <summary>

/// 读取Check组的值;

/// </summary>

/// <param name='lb'></param>

/// <returns></returns>

public string ReadCheckBoxList(CheckBoxList lb)

{

string returnvalue='0';

for (int i=0; i<lb.Items.Count; i++)

{

if (lb.Items[i].Selected)

returnvalue=returnvalue +','+ lb.Items[i].Value;

}

return returnvalue;

}

/// <summary>

/// 显示Check组的值

/// </summary>

/// <param name='cbl'></param>

/// <param name='strCheckValue'></param>

public void ShowCheckBoxList(CheckBoxList cbl,string strCheckValue)

{

for (int i=0;i<cbl.Items.Count;i++)

{

if (strCheckValue.IndexOf(cbl.Items[i].Value)>0)

{

cbl.Items[i].Selected=true;

}

}

}

/// <summary>

/// DateDiff功能实现函数

/// </summary>

/// <param name='howtocompare'></param>

/// <param name='startDate'></param>

/// <param name='endDate'></param>

/// <returns></returns>

public double DateDiff(string howtocompare, System.DateTime startDate, System.DateTime endDate)

{

double diff=0;

System.TimeSpan TS = new System.TimeSpan(startDate.Ticks-endDate.Ticks);

switch (howtocompare.ToLower())

{

case 'm':

diff = Convert.ToDouble(TS.TotalMinutes);

break;

case 's':

diff = Convert.ToDouble(TS.TotalSeconds);

break;

case 't':

diff = Convert.ToDouble(TS.Ticks);

break;

case 'mm':

diff = Convert.ToDouble(TS.TotalMilliseconds);

break;

case 'yyyy':

diff = Convert.ToDouble(TS.TotalDays/365);

break;

case 'q':

diff = Convert.ToDouble((TS.TotalDays/365)/4);

break;

default:

//d

diff = Convert.ToDouble(TS.TotalDays);

break;

}

return diff;

}

/// <summary>

/// 以送Email过程.

/// </summary>

/// <param name='strMailTo'></param>

/// <param name='strMailSubject'></param>

/// <param name='strMailBody'></param>

/// <returns></returns>

public bool sendMail(string strMailTo,string strMailSubject,string strMailBody )

{

try

{

string MailSmtp=ConfigurationSettings.AppSettings['MailSmtp'];

string MailUser=ConfigurationSettings.AppSettings['MailUser'];

string MailPassword=ConfigurationSettings.AppSettings['MailPassword'];

string MailFrom=ConfigurationSettings.AppSettings['MailFrom'];

MailMessage mailMessage = new MailMessage();

mailMessage.To = 'zxqd2008@163.com';

mailMessage.From = MailFrom;

mailMessage.Subject = strMailSubject;

mailMessage.Body = strMailBody;

mailMessage.BodyFormat = MailFormat.Html;//邮件的格式

//如果带有附件...如:attachFile =''C:\file.rar''

//if (attachFile != '')

//{

//mailMessage.Attachments.Add(new MailAttachment(attachFile));

//}

//以下三句用在SMTP需要身份验证时。Framework1.1才有支持。

mailMessage.Fields.Add('http://schemas.microsoft.com/cdo/configuration/smtpauthenticate', '1');//基本验证

mailMessage.Fields.Add('http://schemas.microsoft.com/cdo/configuration/sendusername', MailUser); //设定用户名

mailMessage.Fields.Add('http://schemas.microsoft.com/cdo/configuration/sendpassword', MailPassword);//设定密码

SmtpMail.SmtpServer = MailSmtp;//设定SMTP服务器

SmtpMail.Send(mailMessage);

return true;

}

catch

{

//邮件发送失败处理

return false;

//throw ex;

}

}

//============================================================

/// <summary>

/// 将一特定的值绑定到Panel中的CheckBox里(根据CheckBox里的Value值判断此项是否选中)

/// </summary>

/// <param name='strValue'></param>

/// <param name='objPanel'></param>

public void showPanelCheckBox(string strValue,Panel objPanel)

{

for (int i=0;i<=objPanel.Controls.Count-1;i++)

{

if (objPanel.Controls[i] is CheckBox)

{

//if (this.Panel1.Controls[i])

CheckBox cb=(CheckBox)objPanel.Controls[i];

if (strValue.IndexOf(cb.ID.Substring(1,cb.ID.Length-1))>0)

{

cb.Checked=true;

}

else

{

cb.Checked=false;

}

}

}

}

//============================================================

//上传图片时取得图片的名字

/// <summary>

/// 缺点多等待处理

/// </summary>

/// <param name='uploadPic'></param>

/// <param name='strFileSavePath'></param>

/// <returns></returns>

public bool outPutPicName(System.Web.UI.HtmlControls.HtmlInputFile uploadPic,string strFileSavePath)

{

//string strPicName = uploadPic.Value.Length.ToString();

strOutPicName = '';

SqlDataReader sdr = db.SqlGetReader('Select * From Data_Counter Where isBy = '1'');

sdr.Read();

string picFileName = sdr['iSum'].ToString();

sdr.Close();

int piclen = uploadPic.Value.Length;

int picwei = uploadPic.Value.LastIndexOf('.');

string picname = uploadPic.Value.Substring(picwei+1,piclen-picwei-1);

picname = picname.ToLower();

if (picname!='jpg'&&picname!='jpeg'&&picname!='gif'&&picname!='bmp')

{

strOutPicName = db.RetrunScript('what you uploaded can only be GIF , JPEG or JPG format...',2);

return false;

}

else

{

strOutPicName = picFileName+'.'+picname;

//更新计数器 执行sql语句

return true;

}

}

public string OutPicName

{

get

{

return strOutPicName;

}

}

/// <summary>

/// 选中有值的选项

/// </summary>

/// <param name='objrbl'></param>

/// <param name='strValue'></param>

public void ShowRadioList(RadioButtonList objrbl, string strValue)

{

for(int i = 0;i<=objrbl.Items.Count-1;i++)

{

if (strValue.IndexOf(objrbl.Items[i].Value)!=-1)

{

objrbl.Items[i].Selected = true;

}

else

{

objrbl.Items[i].Selected = false;

}

}

}

#endregion

/// <summary>

/// 图像缩小处理

/// </summary>

/// <param name='strBigImg'>存储原图像路径及文件名</param>

/// <param name='strSmallImg'>存储缩小后图像路径及文件名</param>

/// <param name='intW'>存储图像缩小宽度</param>

/// <param name='intH'>存储图像缩小高度</param>

/// <param name='objPage'>当前页</param>

/// <returns>缩小后图像路么及文件名</returns>

public string imgControl(Page objPage,string strBigImg,string strSmallImg,int intW,int intH)

{

if (File.Exists(strSmallImg))

{

//检验图像是否已经缩小

return strSmallImg;

}

else

{

//图像没有缩小时处理

Bitmap oldImg;//原图对象

Bitmap newImg;//新图对象

try

{

oldImg = new Bitmap(objPage.MapPath(strBigImg));

newImg = new Bitmap(oldImg,intW,intH);

newImg.Save(objPage.MapPath(strSmallImg));

oldImg.Dispose();

newImg.Dispose();

//strSmallImg = '系统默认出错图片的路径与名称';

}

catch

{

}

finally

{

oldImg = null;

newImg = null;

}

strSmallImg = strSmallImg.Trim();

return strSmallImg;

}

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有