*****************************************************************************
ascx.cs文件代码
public class FriendUploadPic:UserControl
{
mysuoyu.Fun Fun=new mysuoyu.Fun();
mysuoyu.sqlconn conn=new mysuoyu.sqlconn();
mysuoyu.LoginCk Ck=new mysuoyu.LoginCk();
mysuoyu.CheckFriend CF=new mysuoyu.CheckFriend();
protected Button UpLoadButton;
protected Button DelPic;
protected DataList MyList;
protected Label lblCurrentPage;
protected Label lblRecordCount;
protected Label lblPageCount;
protected Label lblPageSize;
protected Label NoList;
protected LinkButton lbtFirst;
protected LinkButton lbtLast;
protected LinkButton lbtNext;
protected LinkButton lbtPre;
int pagesize=6;//设置每页记录数
public string Rinfo,Error_Msg,Uname,BigName,SmallName,BigUrl,SmallUrl,PicContent,ImgWidth,ImgHeight,ImgSize,Oper;
public int Par_Pro,Par_Pic,Fid,Uid,Grade;
private string sql;
private SqlCommand cmd;
private SqlDataReader dr;
private void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ListPhoto();
}
}
public void ListPhoto()
{
ViewState["pageindex"]=1;
myBind((int)ViewState["pageindex"]);
cmdState((int)ViewState["pageindex"]);
lblCurrentPage.Text=ViewState["pageindex"].ToString();
lblPageCount.Text=PgCount().ToString();
lblRecordCount.Text=RsCount().ToString();
lblPageSize.Text=pagesize.ToString();
}
//计算记录数
public int RsCount()
{
int intCount=0;
conn.open();
//判断有否图片存在
sql="select count(Fpid) from User_FriendPhoto where Fp_Fid="+Fid;
cmd=new SqlCommand(sql,conn.link);
dr=cmd.ExecuteReader();
if (dr.Read())
{
intCount = Convert.ToInt32(dr[0].ToString());
}
if (intCount==0)
{
NoList.Text="<center>很抱歉,您现在还没有上传任何图片。</center>";
}
dr.Close();
cmd.Dispose();
conn.close();
return intCount;
}
public int PgCount()//计算页数
{
if (RsCount()%pagesize==0)
return RsCount()/pagesize;
else
return RsCount()/pagesize+1;
}
ascx.cs文件代码
public class FriendUploadPic:UserControl
{
mysuoyu.Fun Fun=new mysuoyu.Fun();
mysuoyu.sqlconn conn=new mysuoyu.sqlconn();
mysuoyu.LoginCk Ck=new mysuoyu.LoginCk();
mysuoyu.CheckFriend CF=new mysuoyu.CheckFriend();
protected Button UpLoadButton;
protected Button DelPic;
protected DataList MyList;
protected Label lblCurrentPage;
protected Label lblRecordCount;
protected Label lblPageCount;
protected Label lblPageSize;
protected Label NoList;
protected LinkButton lbtFirst;
protected LinkButton lbtLast;
protected LinkButton lbtNext;
protected LinkButton lbtPre;
int pagesize=6;//设置每页记录数
public string Rinfo,Error_Msg,Uname,BigName,SmallName,BigUrl,SmallUrl,PicContent,ImgWidth,ImgHeight,ImgSize,Oper;
public int Par_Pro,Par_Pic,Fid,Uid,Grade;
private string sql;
private SqlCommand cmd;
private SqlDataReader dr;
private void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ListPhoto();
}
}
public void ListPhoto()
{
ViewState["pageindex"]=1;
myBind((int)ViewState["pageindex"]);
cmdState((int)ViewState["pageindex"]);
lblCurrentPage.Text=ViewState["pageindex"].ToString();
lblPageCount.Text=PgCount().ToString();
lblRecordCount.Text=RsCount().ToString();
lblPageSize.Text=pagesize.ToString();
}
//计算记录数
public int RsCount()
{
int intCount=0;
conn.open();
//判断有否图片存在
sql="select count(Fpid) from User_FriendPhoto where Fp_Fid="+Fid;
cmd=new SqlCommand(sql,conn.link);
dr=cmd.ExecuteReader();
if (dr.Read())
{
intCount = Convert.ToInt32(dr[0].ToString());
}
if (intCount==0)
{
NoList.Text="<center>很抱歉,您现在还没有上传任何图片。</center>";
}
dr.Close();
cmd.Dispose();
conn.close();
return intCount;
}
public int PgCount()//计算页数
{
if (RsCount()%pagesize==0)
return RsCount()/pagesize;
else
return RsCount()/pagesize+1;
}
解决方案 »
- 请问各位达人,VS2010有PHP的开发插件吗?
- 求帮忙解答多态性相关问题
- c#中如何得到一个数组的五倍
- 求SQL:如何选出某时间段内的记录条数?
- C# 關閉UDP時如何處理?
- 下面的程序结果是多少啊?在线等,谁手头有VS2005,麻烦帮我试一下
- ==新手请教如何在C#中把数据导入到excell中==
- 在VS.NET 2005 中如何获取CPU系列号
- API函数ReadFile调用后,用GetLastWin32Error捕获错误提示为“函数不正确”,请问是什么原因?
- 怎样在Panel上显示浮动提示?
- 晕,我都快被datagrid(winform)搞死了,选中整行的问题?????
- 关于 无法绑定到新的显示成员
{
try
{
//读出图片记录
int rsBegin,rsEnd,n;
string[] rsPage=new string[7];
rsEnd=PgNo*pagesize-1;
rsBegin=(PgNo-1)*pagesize;
if(rsEnd>=RsCount())
rsEnd=RsCount()-1;
SqlDataAdapter da;
sql="select * from User_FriendPhoto where Fp_Fid="+Fid;
conn.open();
da=new SqlDataAdapter(sql,conn.link);
DataSet ds = new DataSet();
da.Fill(ds,"User_FriendPhoto");
da.Dispose();
//生成临时表
ds.Tables.Add("page");
ds.Tables["page"].Columns.Add("Pic_ID");
ds.Tables["page"].Columns.Add("Pic_Content");
ds.Tables["page"].Columns.Add("Pic_FNameBig");
ds.Tables["page"].Columns.Add("Pic_FNameSmall");
ds.Tables["page"].Columns.Add("Pic_Width");
ds.Tables["page"].Columns.Add("Pic_Height");
ds.Tables["page"].Columns.Add("Pic_Lenght");
for(n=rsBegin;n<=rsEnd;n++)//填充临时表
{
rsPage[0]=ds.Tables[0].Rows[n]["Fpid"].ToString();
//取指定数目的字符
string title=ds.Tables[0].Rows[n]["Fp_PicTitle"].ToString().Trim();
string content=title;
int len=title.Length;
if (len>8)
{
title=title.Substring(0,8)+"...";
}
rsPage[1]=title;
string Path="User/"+Uname+"/Friend/";
rsPage[2]=ds.Tables[0].Rows[n]["Fp_BigName"].ToString().Trim();
string big=Path+rsPage[2];
rsPage[3]=ds.Tables[0].Rows[n]["Fp_SmallName"].ToString().Trim();
rsPage[3]=Path+rsPage[3];
//读取图片的像素及字节
string path = Server.MapPath(big);
if (File.Exists(path) == true)
{
Bitmap img = new Bitmap(path);
rsPage[4]=img.Width.ToString();
rsPage[5]=img.Height.ToString();
img.Dispose();
FileInfo fi=new FileInfo(path);
double Size=((double)fi.Length)/1024;
string s=Convert.ToString(Size);
rsPage[6]=s.Substring(0,s.IndexOf(".")+3);
}
else
{
rsPage[4]="0";
rsPage[5]="0";
rsPage[6]="0";
}
rsPage[3]="<a href='"+big+"' target='_blank'><img src='"+rsPage[3]+"' alt='"+content+"' border='0'></a>";
ds.Tables[1].Rows.Add(rsPage);
}
this.MyList.DataSource = ds.Tables["page"].DefaultView;
this.MyList.DataBind();
conn.close();
Par_Pro=2;
}
catch(System.Exception e1)
{
//系统错误处理
Par_Pro=1;
Rinfo=e1.Message;
Response.Write ("dd"+Rinfo);
Response.End();
Error_Msg=Fun.ErrorMsg("0");
}
}
public void cmdState(int curPage)
{
if (curPage==1)
{
lbtFirst.Enabled=false;
lbtPre.Enabled=false;
}
else
{
lbtFirst.Enabled=true;
lbtPre.Enabled=true;
}
if (PgCount()>curPage)
{
lbtNext.Enabled=true;
lbtLast.Enabled=true;
}
else
{
lbtNext.Enabled=false;
lbtLast.Enabled=false;
}
}
public void Page_OnClick(Object sender,CommandEventArgs e)
{
string arg = e.CommandName;
//判断cmd,以判定翻页方向
switch(arg)
{
case "first":
ViewState["pageindex"]=1;
break;
case "Pre":
ViewState["pageindex"]=(int)ViewState["pageindex"]-1;
if ((int)ViewState["pageindex"]==0)
{
ViewState["pageindex"]=1;
}
break;
case "next":
ViewState["pageindex"]=(int)ViewState["pageindex"]+1;
break;
case "last":
ViewState["pageindex"]=PgCount();
break;
}
myBind((int)ViewState["pageindex"]);
cmdState((int)ViewState["pageindex"]);
lblCurrentPage.Text=ViewState["pageindex"].ToString();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.UpLoadButton.Click += new System.EventHandler(this.UpLoad);
this.DelPic.Click += new System.EventHandler(this.del_selectid);
}
#endregion