|
技术资料 > .Net专区 > Asp.Net开发 : 自动生成SERVER CONTROLS在程序里的应用 |
自动生成SERVER CONTROLS在程序里的应用 March 25,2004 |
private string listFolder(EASYMAILIMAP4Lib.EasyMailIMAP4 IMAP4,string strFolder,int perpage)
{
TableRow r;
TableCell c;
int x,pages,pgnum,start,end;
string str1;
x = IMAP4.SelectMailbox(strFolder);
if(x != 0)
{
IMAP4.CreateMailbox(strFolder);
return "(Created!)";
}
else
{
r = new TableRow();
c = new TableCell();
str1 = "当前邮箱 "+strFolder+" ";
str1 = str1+"共有邮件 "+IMAP4.MessageCount+" 封";
Folder_Info.Text = str1;
if(IMAP4.MessageCount==0)
{
return "No Message";
}
if((IMAP4.MessageCount%perpage) ==0 )
{
pages=IMAP4.MessageCount/perpage;
}
else
{
pages=(int)IMAP4.MessageCount/perpage+1;
}
pgnum=1;
try
{
pgnum=Convert.ToInt32(Request.QueryString["pg"].ToString());
}
catch
{
pgnum=1;
}
if(pgnum>1)
{
end=pgnum*perpage;
start=end-perpage+1;
}
else
{
end=perpage;
start=1;
}
x = IMAP4.DownloadEnvelopes(start, end, 0);
if(x != 0)
{
return "(Error:"+x+")";
}
r = new TableRow();
c = new TableCell();
c.Controls.Add(new LiteralControl(""));
c.Width=15;
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl(""));
c.Width=15;
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("发件人"));
c.Attributes.Add("nowrap","true");
c.Attributes.Add("align","center");
c.Width=80;
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("主题"));
c.Attributes.Add("align","center");
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("日期"));
c.Attributes.Add("align","center");
c.Width=120;
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("大小"));
c.Width=40;
c.Attributes.Add("align","center");
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("附"));
c.Attributes.Add("align","center");
c.Width=10;
r.Cells.Add(c);
r.BackColor=System.Drawing.Color.FromName("#6699cc");
r.ForeColor=System.Drawing.Color.WhiteSmoke;
listTable.Rows.Add(r);
EASYMAILIMAP4Lib.IEMIMAP4Envelopes pEnvelopes;
pEnvelopes= (EASYMAILIMAP4Lib.IEMIMAP4Envelopes) IMAP4.Envelopes ;
EASYMAILIMAP4Lib.IEMIMAP4Message pMessage;
EASYMAILIMAP4Lib.IEMIMAP4Attachments pAttachments;
IEnumerator e = pEnvelopes.GetEnumerator();
CheckBox o;
foreach(EASYMAILIMAP4Lib.IEMIMAP4Envelope pEnvelope in pEnvelopes)
{
IMAP4.DownloadMessage(pEnvelope.IMAPID,1);
pMessage = (EASYMAILIMAP4Lib.IEMIMAP4Message) IMAP4.Message;
r = new TableRow();
c = new TableCell();
o = new CheckBox();
o.ID=pEnvelope.IMAPID.ToString();
//MailBoxesform.Controls.Add(o);
//str1="<input type="checkbox" name="chk" + pEnvelope.IMAPID.ToString() + "" class="in1" style="width:15px;height:15px">";
//c.Controls.Add(new LiteralControl(""));
c.Controls.Add(o);
c.Attributes.Add("align","center");
r.Cells.Add(c);
c = new TableCell();
if (pMessage.Priority.ToString()=="1")
{
str1="<font color=Red style="width:15px;height:15px">!</font>";
}
else
{
str1=" ";
}
c.Controls.Add(new LiteralControl(str1));
c.Attributes.Add("align","right");
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl(pEnvelope.From));
c.Attributes.Add("nowrap","true");
c.Width=80;
r.Cells.Add(c);
c = new TableCell();
str1 = "<a href="viewdraft.aspx?folder="+strFolder+"&imapid=" + pEnvelope.IMAPID.ToString() + "">"+pEnvelope.Subject+"</a>";
c.Controls.Add(new LiteralControl(str1));
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl(pEnvelope.Date.Substring(0,20)));
r.Cells.Add(c);
c = new TableCell();
if (pEnvelope.Size/1000<1)
{
c.Controls.Add(new LiteralControl(pEnvelope.Size.ToString()+"B"));
}
else
{
if (pEnvelope.Size/1000000<1)
{
c.Controls.Add(new LiteralControl((pEnvelope.Size/1000).ToString()+"K"));
}
else
{
c.Controls.Add(new LiteralControl((pEnvelope.Size/1000).ToString()+"M"));
}
}
c.Attributes.Add("align","right");
r.Cells.Add(c);
c = new TableCell();
pAttachments = (EASYMAILIMAP4Lib.IEMIMAP4Attachments) pMessage.Attachments;
if(pAttachments.Count>0)
{
c.Controls.Add(new LiteralControl("有"));
}
else
{
c.Controls.Add(new LiteralControl("无"));
}
c.Attributes.Add("align","center");
r.Cells.Add(c);
listTable.Rows.Add(r);
}
r = new TableRow();
c = new TableCell();
str1 = "<a style="TEXT-DECORATION: none;" href="Drafts.aspx?pg=1"> << </a> ";
if(pgnum==1)
{
str1 = str1+"< ";
}
else
{
str1 = str1+"<a style="TEXT-DECORATION: none;" href="Drafts.aspx?pg=" + (pgnum-1) + ""> < </a> ";
}
if(pgnum==pages)
{
str1 = str1+"> ";
}
else
{
str1 = str1+"<a style="TEXT-DECORATION: none;" href="Drafts.aspx?pg=" + (pgnum+1) + ""> > </a> ";
}
str1 = str1+"<a style="TEXT-DECORATION: none;" href="Drafts.aspx?pg=" + pages+ ""> >> </a> ";
c.Controls.Add(new LiteralControl(str1));
c.Attributes.Add("align","right");
c.ColumnSpan=7;
r.Cells.Add(c);
listTable.Rows.Add(r);
return "Ok";
}
}
这段生成乐一个CHECKBOX控制对象加入的列邮件的TABLE里面去
这样就通过这些CHECKBOX来选择特定邮件来进行删除,修改朝左
o = new CheckBox();
o.ID=pEnvelope.IMAPID.ToString();
c.Controls.Add(o);
|
|