/// <summary> /// generate a file containing model info /// </summary> /// <param name="index"></param> /// <param name="color"></param> /// <param name="model_id"></param> /// <returns></returns> private HtmlGenericControl GenerateFile(int index, string color, int model_id) { HtmlGenericControl file = new HtmlGenericControl("div"); file.Attributes["class"] = "asset-file-color"; file.Attributes["style"] = "background-color:" + color; file.Attributes["onclick"] = "putInfront(" + index + ");"; HtmlGenericControl thumbnail = new HtmlGenericControl("img"); thumbnail.Attributes["src"] = ws.GetModelThumbnail(model_id); thumbnail.Attributes["class"] = "thumbnail-profile"; Button edit_btn = GenerateButton("VIEW", "view-btn", model_id); Button delete_btn = GenerateButton("DELETE", "delete-btn", model_id); HtmlGenericControl rating = new HtmlGenericControl("p"); rating.Attributes["id"] = "asset-rate-" + index; rating.Attributes["class"] = "asset-rate Report1942Font"; rating.InnerHtml = (Math.Floor(ws.GetRate(model_id) * 100) / 100).ToString() + "/5"; Label[] labelX, labelY; HtmlGenericControl graph = GenerateAssetGraph(index, model_id, out labelX, out labelY); file.Controls.Add(thumbnail); file.Controls.Add(edit_btn); file.Controls.Add(delete_btn); file.Controls.Add(rating); file.Controls.Add(graph); foreach (Label lbl in labelX) { file.Controls.Add(lbl); } foreach (Label lbl in labelY) { file.Controls.Add(lbl); } return(file); }
/// <summary> /// updates model rating on rating changes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void UpdateRating(object sender, EventArgs e) { string senderId = ((ImageButton)sender).ID; int rate = int.Parse(senderId.Substring(senderId.IndexOf('n') + 1)) + 1; ws.InsertRating((int)Session["user-id"], model_id, rate); Rating.Text = ws.GetRate(model_id).ToString(); int userRate = ws.GetModelUserRate(model_id, (int)Session["user-id"]); selectedImg0.CssClass = "shownImg"; selectedImg1.CssClass = "shownImg"; selectedImg2.CssClass = "shownImg"; selectedImg3.CssClass = "shownImg"; selectedImg4.CssClass = "shownImg"; if (userRate < 5) { selectedImg4.CssClass = "hiddenImg"; } if (userRate < 4) { selectedImg3.CssClass = "hiddenImg"; } if (userRate < 3) { selectedImg2.CssClass = "hiddenImg"; } if (userRate < 2) { selectedImg1.CssClass = "hiddenImg"; } if (userRate < 1) { selectedImg0.CssClass = "hiddenImg"; } ws.CloseConnection(); }
/// <summary> /// gets model information from data base by model id in the url /// clear TempModels file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { DirectoryInfo temp = new DirectoryInfo(Server.MapPath("/Resources/TempModels/")); foreach (FileInfo f in temp.GetFiles()) { f.Delete(); } string url = Request.Url.AbsoluteUri;// /Pages/AssetPage.aspx?item_id=200134 try { model_id = int.Parse(url.Substring(url.IndexOf('?') + 1)); ws = new maker_service.WebService(); CreatorsName.Text = GetUserName(model_id); CreatorsName.ToolTip = CreatorsName.Text; AssetName.Text = ws.GetModelName(model_id); AssetName.ToolTip = AssetName.Text; AssetDescription.Text = ws.GetModelDescription(model_id); Rating.Text = (Math.Floor(ws.GetRate(model_id) * 100) / 100).ToString(); int userRate = ws.GetModelUserRate(model_id, (int)Session["user-id"]); string[] info = ws.GetModelInfo(model_id); camPos.Text = info[0]; camLookAt.Text = info[1]; positions.Text = info[2]; colors.Text = info[3]; normals.Text = info[4]; selectedImg0.CssClass = "shownImg"; selectedImg1.CssClass = "shownImg"; selectedImg2.CssClass = "shownImg"; selectedImg3.CssClass = "shownImg"; selectedImg4.CssClass = "shownImg"; if (userRate < 5) { selectedImg4.CssClass = "hiddenImg"; } if (userRate < 4) { selectedImg3.CssClass = "hiddenImg"; } if (userRate < 3) { selectedImg2.CssClass = "hiddenImg"; } if (userRate < 2) { selectedImg1.CssClass = "hiddenImg"; } if (userRate < 1) { selectedImg0.CssClass = "hiddenImg"; } ws.CloseConnection(); } catch//if anything failed print Error 404 { HtmlGenericControl errorCover = new HtmlGenericControl("div"); errorCover.Attributes["style"] = "position:absolute; left:0%; top:0%; width:100%; height:100%; background-color:rgba(0,0,0,0.75);"; HtmlGenericControl errorDiv = new HtmlGenericControl("div"); errorDiv.Attributes["class"] = "errorPos panelColor"; HtmlGenericControl errorMessage = new HtmlGenericControl("p"); errorMessage.InnerHtml = "Error 404: it seems like this asset does not exist anymore!"; errorDiv.Controls.Add(errorMessage); ErrorMessage.Controls.Add(errorCover); ErrorMessage.Controls.Add(errorDiv); ErrorMessage.CssClass = "ErrorMessage"; } }