Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created April 30, 2020 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/ab0fc984e1d3d585d5688be904607a84 to your computer and use it in GitHub Desktop.
Save jianminchen/ab0fc984e1d3d585d5688be904607a84 to your computer and use it in GitHub Desktop.
Coronavirus project at work - April 30, 2020 - make it simple, more readable
/// <summary>
/// code review on April 24, 2020
/// add id in html for each div element to make code readable
///
/// Code review on July 7, 2017
/// March 14, 2016
/// Cannot be extracted, because Server.MapPath(pngFile) <- check IIS server file exists or not
/// January 4, 2016
/// Add "ABS" to the list
/// </summary>
/// <param name="mainMenu"></param>
/// <param name="subMenu"></param>
/// <param name="name"></param>
/// <param name="imagePath"></param>
/// <param name="text"></param>
/// <param name="products"></param>
/// <returns></returns>
public static string prepareHtml(
string mainMenu,
string subMenu,
string name,
string imagePath,
string text,
IEnumerable<PictureSlideColumns> products)
{
string urlKey = getUrlStr(mainMenu, subMenu);
string imgUrlHelper = Image_render.getHelperString(name, urlKey, imagePath);
string cssClass = CssClassTitle.GetName(text);
string html = "";
for (int i = 0; i < products.Count(); i++)
{
var visit = products.ElementAt(i);
var mountName = visit.MountName;
var mountWebName = visit.MountOnWeb;
var subTitle = visit.SubTitle;
var fileName = imgUrlHelper + mountName;
// HOLD: if .png img file exists, then .png will be displayed; otherwise, go for .img file
string imageFile = fileName + ".jpg";
var index = i.ToString();
var prefixs = new string[] {"titleDiv" + index,"subTitleDiv" + index,"imgDiv" + index};
var list = new List<string>();
list.Add(composeOuterDiv(cssClass, prefixs[0], mountWebName));
list.Add(MainSlideShow.Html.HtmlDivSubTitle.Compose(prefixs[1], subTitle));
list.Add(getImageHtml(prefixs[2], imageFile));
// a div for each product
var htmlDiv = "";
var finishClass = getFinishClass(name, mountName);
htmlDiv += "<div class=\"slide " + finishClass + "\">";
htmlDiv += String.Join("", list.ToArray());
htmlDiv += "</div>";
html += htmlDiv;
}
return html;
}
/// <summary>
/// April 27, 2020
/// add div id for each div
/// </summary>
/// <param name="cssClass"></param>
/// <param name="divName"></param>
/// <param name="mountWebName"></param>
/// <returns></returns>
private static string composeOuterDiv(string cssClass, string divName, string mountWebName)
{
return "<div id=\"" + divName + "\" class=\"mount_id " + cssClass + "\" class=\"grid_2\">" + mountWebName + "</div>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment