asp.net| Static
Batch static page generation with progress bars in asp.net
Namespace Wdfrog. Bll
... {
public delegate void Createhtmlhandler (string filename,string msg,int percent);
public class News
... {
Private Const String c_err_msg = "You have no rights!";
Private Const string c_chk_name = "Newsmanage";
private static string C_dir = configurationmanager.appsettings["newshtml"];
public event Createhtmlhandler Completeafile;
public static int Create (String Adminname,newsinfo News)
... {
Ipermissionchecker chk = Permissioncheckerfactory.getchecker (AdminName, c_chk_name);
Chk. Check (C_ERR_MSG);
News. Htmlfile =fileoperator.getrandfilename (". html");
int ret= newsdal.create (news);
Createhtmlfile (news);
return ret;
}
public static int Deletebyidlist (string adminname,string idlist)
... {
Ipermissionchecker chk = Permissioncheckerfactory.getchecker (AdminName, c_chk_name);
Chk. Check (C_ERR_MSG);
DataTable dt = selecthtmlfilebyidlist (idlist). Tables[0];
String fileName = "";
foreach (DataRow dr in Dt. Rows)
... {
if (!) ( Dr[0] is DBNull))
... {
FileName = dr[0]. ToString ();
if (string. IsNullOrEmpty (FileName))
... {
filename = Fileoperator.mappath (c_dir + filename);
File.delete (FileName);
}
}
}
return Newsdal.deletebyidlist (idlist);
}
public static int Deletebynewsid (string adminname, int NewsID)
... {
ipermissionchecker chk = Permissioncheckerfactory.getchecker (AdminName, c_chk_name);
chk. Check (C_ERR_MSG);
String fileName = Selecthtmlfile (NewsID);
if (!string. IsNullOrEmpty (fileName))
File.delete (HttpContext.Current.Server.MapPath (C_dir + fileName));
return Newsdal.deletebynewsid (NewsID);
}
public static DataSet querypage (int ClassID, string Title, int PageSize, int PageIndex)
... {
Return Newsdal.querypage (Classid,title,pagesize,pageindex);
}
public static int Querypagecount (int ClassID, string Title)
... {
Return Newsdal.querypagecount (ClassID, Title);
}
public static DataSet querytopnews (int ClassID, int Num, bool ordertype)
... {
return newsdal.querytopnews (ClassID, Num, OrderType);
}
public static string selecthtmlfile (int NewsID)
... {
Return Newsdal.selecthtmlfile (NewsID);
}
public static DataSet Selecthtmlfilebyidlist (String idlist)
... {
Return Newsdal.selecthtmlfilebyidlist (idlist);
}
public static int Update (String Adminname,newsinfo News)
... {
Ipermissionchecker chk = Permissioncheckerfactory.getchecker (AdminName, c_chk_name);
Chk. Check (C_ERR_MSG);
int ret= newsdal.update (news);
Createhtmlfile (news);
return ret;
}
public static DataSet querypagewithcontent (int ClassID, string Title, int PageSize, int PageIndex)
... {
Return Newsdal.querypagewithcontent (ClassID, Title, PageSize, PageIndex);
}
Over here
public void Createhtmlfile (int startpage, int endpage,int pagesize,int ClassID)
... {
int total = Querypagecount (ClassID, String. Empty);
Total= (total% pageSize) ==0? Total/pagesize: (total/pagesize) +1;
if (Total < endpage)
EndPage = total;
String fileName = "";
String htmlfile = "";
int rtotal = (endpage-startpage + 1) * pageSize; Total number of records
for (int i = StartPage i <= endpage; i++)
... {
DataTable dt = Querypagewithcontent (ClassID, String. Empty, PageSize, i). Tables[0];
int CurR = (i-startpage) * pageSize;
foreach (DataRow dr in Dt. Rows)
... {
if (!) ( dr["Htmlfile"] is DBNull))
... {
Htmlfile = dr["Htmlfile"]. ToString ();
if (string. IsNullOrEmpty (Htmlfile))
... {
Htmlfile = Fileoperator.getrandfilename (". html");
}
FileName = Xmldata.getfilenamebyid (templatenode.news, (int) dr["TemplateID"]);
String tempcontent = Fileoperator.loadfilewithcache (fileName);
Tempcontent = Tempcontent.replace ("{$NewsTitle $}", dr["title"]. ToString ());
Tempcontent = Tempcontent.replace ("{$NewsContent $}", dr["content"]. ToString ());
Tempcontent = Tempcontent.replace ("{$NewsAddTime $}" ((DateTime) dr["Addtime"). ToString ("Yyyy-mm-dd"));
curr++;
Fileoperator.savefile (Fileoperator.mappath (C_dir + htmlfile), tempcontent);
if (completeafile!= null)
Completeafile (Htmlfile, String. Empty, (CurR *)/rtotal);
}
}
}
}
private static void Createhtmlfile (Newsinfo News)
... {
String fileName = Xmldata.getfilenamebyid (Templatenode.news, News. TemplateID);
String tempcontent = Fileoperator.loadfilewithcache (fileName);
Tempcontent = Tempcontent.replace ("{$NewsTitle $}", news. Title);
Tempcontent = Tempcontent.replace ("{$NewsContent $}", news. Content);
Tempcontent=tempcontent.replace ("{$NewsAddTime $}", news. Addtime.tostring ("Yyyy-mm-dd"));
Fileoperator.savefile (HttpContext.Current.Server.MapPath, C_dir + news. Htmlfile), tempcontent);
}
}
} public partial class _default:system.web.ui.page
... {
protected void Page_Load (object sender, EventArgs e)
... {
}
protected void Navigatebutton1_click (object sender, EventArgs e)
... {
Wdfrog. Bll. News.deletebyidlist (Admin.adminname, "1,2,3,4,5,6");
}
protected void Button1_Click (object sender, EventArgs e)
... {
Wdfrog. Bll. News objnews = new News ();
Objnews.completeafile + = new Createhtmlhandler (createafile);
Response.Buffer = false;
Response.Write ("<div style=" width:100px; height:25px;background-color:yellow; " Id= "CP" >_</div> "+ Environment.NewLine);
Objnews.createhtmlfile (1, 100, 30,-1);
Response.Write ("<script>cp.style.visibility= ' hidden ' </script>");
}
protected void Createafile (String fileName, string msg, int percent)
... {
This. Response.Write (String. Format ("<script> cp.innerhtml= ' Complete {0}% ');" </script> ", percent));
Response.Flush ();
}
}