protected void Page_Load(object sender, EventArgs e) { for (int i = 1; i <= 12; i++) { ratingDetailsTable.Rows[i].Cells[1].InnerHtml = "<img src=\"Images/arrow.gif\" />"; ratingDetailsTable.Rows[i].Cells[1].Attributes["class"] = "left"; } if (!this.IsPostBack) { if (Request.QueryString["id"] != null) { int companyID = int.Parse(Request.QueryString["id"]); DatabaseManager db = new DatabaseManager(); DataSet ratDS = db.GetDataSet("SELECT * FROM MainTable,CompanyRatings WHERE MainTable.CompanyId=" + companyID + " AND CompanyRatings.CompanyRId=" + companyID); DataSet revDS = db.GetDataSet("SELECT * FROM Reviews WHERE Reviews.CompanyIDRev=" + companyID); string company = (string)ratDS.Tables[0].Rows[0]["CompanyName"]; int[] ratingInfo = new int[2] { (int)ratDS.Tables[0].Rows[0]["AverageRating"], (int)ratDS.Tables[0].Rows[0]["NumReviews"] }; int[] indvRating = new int[12] { (int)ratDS.Tables[0].Rows[0]["InterviewAtmosphere"], (int)ratDS.Tables[0].Rows[0]["Recruitment"], (int)ratDS.Tables[0].Rows[0]["LevelOfStress"], (int)ratDS.Tables[0].Rows[0]["PhysicalCondition"], (int)ratDS.Tables[0].Rows[0]["HRPractices"], (int)ratDS.Tables[0].Rows[0]["SalaryBenefits"], (int)ratDS.Tables[0].Rows[0]["Schedule"], (int)ratDS.Tables[0].Rows[0]["Promotion"], (int)ratDS.Tables[0].Rows[0]["Recognition"], (int)ratDS.Tables[0].Rows[0]["SatisfactionLevel"], (int)ratDS.Tables[0].Rows[0]["LifeBalance"], (int)ratDS.Tables[0].Rows[0]["Recommendation"] }; Session["company"] = company; rate.InnerHtml = "<a title=\"Rate " + company + " Now and leave a review.\" class=\"rateBtn\" href=\"SubmitReview/Default.aspx?company=" + company + "\">Rate Now</a>"; companyName.InnerHtml = "<b>" + company + "</b>"; companyLogo.Src = "../Images/Logos/logo_" + companyID + ".png"; rating.setRating(ratingInfo[0]); rating.disable(2); numRatings.InnerHtml = " Based On " + ratingInfo[1] + " Ratings."; Rating10[] ratCol = new Rating10[12] { dRating1, dRating2, dRating3, dRating4, dRating5, dRating6, dRating7, dRating8, dRating9, dRating10, dRating11, dRating12 }; for (int i = 0; i < 12; i++) { ratCol[i].Visible = true; ratCol[i].setRating(indvRating[i]); ratCol[i].disable(1); } if (revDS.Tables[0].Rows.Count != 0) { //27 characters. numReviewsTotal.Visible = true; numReviewsTotal.InnerHtml = "Total " + revDS.Tables[0].Rows.Count + " Review(s) Available.<br/><a title=\"View all reviews for " + company + "\" class=\"viewAll\" href=\"View/Reviews.aspx?id=" + ((int)revDS.Tables[0].Rows[0]["Id"]) + "&mode=all&page=1\">View All</a>"; int times = revDS.Tables[0].Rows.Count; if (times > 3) times = 3; for (int a = 1; a <= times; a++) { string comment = ((string)revDS.Tables[0].Rows[a - 1]["ReviewText"]); comment.Replace("'", "'"); if (comment.Length <= 30) { reviewTable.Rows[(2 * a) - 1].Cells[0].InnerHtml = comment; } else { reviewTable.Rows[(2 * a) - 1].Cells[0].InnerHtml = comment.Substring(0, 30) + "..."; } reviewTable.Rows[(2 * a) - 1].Cells[0].InnerHtml += "<br/> <a title=\"Read the full comment\" class=\"more\" href=\"../View/Reviews.aspx?id=" + ((int)revDS.Tables[0].Rows[a - 1]["Id"]) + "\">Read More</a>"; reviewTable.Rows[(2 * a) - 1].Cells[0].Attributes["class"] = "border , centerAlign"; } } else { reviewTable.Rows[1].Cells[0].InnerHtml = "NO REVIEWS!"; reviewTable.Rows[1].Cells[0].Attributes["class"] = "centerAlign"; } } } }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { Bind(); string topReviewQuery = "SELECT TOP 4 * FROM Reviews ORDER BY Reviews.CalcRating DESC"; string topRatedCompanies = "SELECT TOP 4 CompanyRId, AverageRating, CompanyName, CompanyId FROM CompanyRatings, MainTable WHERE CompanyRatings.CompanyRId=MainTable.CompanyId ORDER BY CompanyRatings.AverageRating DESC"; string recentReviewsQuery = "SELECT TOP 4 ReviewText, Id, DateAdded FROM Reviews ORDER BY DateAdded DESC"; DatabaseManager db = new DatabaseManager(); DataSet[] queryRes = new DataSet[3]; queryRes[0] = db.GetDataSet(topReviewQuery); queryRes[1] = db.GetDataSet(topRatedCompanies); queryRes[2] = db.GetDataSet(recentReviewsQuery); Rating10[] ratCol = new Rating10[4] {Rating, Rating1, Rating2, Rating3}; for (int a = 1; a <= queryRes[0].Tables[0].Rows.Count; a++) { string comment = ((string)queryRes[0].Tables[0].Rows[a-1]["ReviewText"]); comment.Replace("'", "'"); if (comment.Length <= 27) table1in3.Rows[a].Cells[0].InnerHtml = comment; else table1in3.Rows[a].Cells[0].InnerHtml = comment.Substring(0, 27) + "..."; table1in3.Rows[a].Cells[0].InnerHtml += "<br/> <a title=\"Read the full comment\" class=\"more\" href=\"../View/Reviews.aspx?id=" + queryRes[0].Tables[0].Rows[a - 1]["Id"] + "\">Read More</a>"; table1in3.Rows[a].Cells[0].Attributes["class"] = "border"; } for (int a = 1; a <= queryRes[1].Tables[0].Rows.Count; a++) { table2in3.Rows[(2 * a) - 1].Cells[0].InnerHtml = "<a title=\"Click here to see detailed ratings for " + (string)queryRes[1].Tables[0].Rows[a - 1]["CompanyName"] + "\" class=\"sideLinks , links\" href=\"CompanyDetails.aspx?id=" + queryRes[1].Tables[0].Rows[a - 1]["CompanyId"] + "\">" + (string)queryRes[1].Tables[0].Rows[a - 1]["CompanyName"] + "</a>"; ratCol[a - 1].Visible = true; ratCol[a - 1].setRating((int)queryRes[1].Tables[0].Rows[a - 1]["AverageRating"]); ratCol[a - 1].disable(1); } for (int a = 1; a <= queryRes[2].Tables[0].Rows.Count; a++) { string comment = ((string)queryRes[2].Tables[0].Rows[a-1]["ReviewText"]); comment.Replace("'", "'"); if (comment.Length <= 27) table3in3.Rows[a].Cells[0].InnerHtml = comment; else table3in3.Rows[a].Cells[0].InnerHtml = comment.Substring(0, 27) + "..."; table3in3.Rows[a].Cells[0].InnerHtml += "<br/> <a title=\"Read the full comment\" class=\"more\" href=\"../View/Reviews.aspx?id=" + queryRes[2].Tables[0].Rows[a - 1]["Id"] + "\">Read More</a>"; table3in3.Rows[a].Cells[0].Attributes["class"] = "border"; } } like_message = Get_Message(); }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { if (Session["raterinfo"] != null) { cName.InnerHtml = "<b>" + ((RaterInfo)Session["raterinfo"]).employer + "</b>"; DatabaseManager db = new DatabaseManager(); SqlCommand com = db.GetCommand("SELECT CompanyName, CompanyId FROM MainTable WHERE MainTable.CompanyName='" + ((RaterInfo)Session["raterinfo"]).employer + "'"); db.dbCon.Open(); SqlDataReader reader = com.ExecuteReader(); reader.Read(); if (reader.HasRows) { string companyId = ((int)reader["CompanyId"]).ToString(); cLogo.Attributes["src"] = "../Images/Logos/logo_" + companyId + ".png"; } reader.Close(); db.dbCon.Close(); } else { Response.Redirect("../Error.aspx?from=revInput&data=expired"); } if (Request["error"] == "1" && Session["ratings"] != null) { int[] ratings = (int[])Session["ratings"]; HtmlTableCell[] celCol = new HtmlTableCell[12] { td, Td1, Td2, Td3, Td4, Td5, Td6, Td7, Td8, Td9, Td10, Td11 }; Rating10[] ratCol = new Rating10[12] { rating1, rating2, rating3, rating4, rating5, rating6, rating7, rating8, rating9, rating10, rating11, rating12 }; for (int i = 0; i < 12; i++) { ratCol[i].setRating(ratings[i]); if (ratings[i] == 0) celCol[i].InnerText = "* - REQUIRED"; } Session["ratings"] = null; } } }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { Bind(); if (Request.QueryString["letter"] != null || Request["spl"] != null) { DatabaseManager db = new DatabaseManager(); DataSet ds; string startLetter =""; if (Request.QueryString["letter"] != null) { startLetter = selectedLetter = Request.QueryString["letter"]; ds = db.GetDataSet("SELECT CompanyName, CompanyId, CompanyRId, AverageRating FROM MainTable, CompanyRatings WHERE MainTable.CompanyId = CompanyRatings.CompanyRId AND MainTable.CompanyName LIKE '" + startLetter + "%'"); alphabets.Rows[0].Cells[startLetter[0] - 65].Attributes["class"] = "alphacol , centerAlign , selected"; } else { string query = "SELECT CompanyName, CompanyId, CompanyRId, NumReviews, AverageRating FROM MainTable, CompanyRatings WHERE MainTable.CompanyId = CompanyRatings.CompanyRId ORDER BY "; if (Request["spl"] == "alp") { query += "CompanyName"; RadioButton1.Checked = true; orderByRes.Attributes["title"] = "Clear Alphabetically ordered search results"; } else if (Request["spl"] == "rat") { query += "AverageRating DESC"; RadioButton2.Checked = true; orderByRes.Attributes["title"] = "Clear search results ordered by Average Rating"; } else if (Request["spl"] == "nrat") { query += "NumReviews DESC"; RadioButton3.Checked = true; orderByRes.Attributes["title"] = "Clear search results ordered by No. of ratings"; } ds = db.GetDataSet(query); alphabets.Visible = false; orderByRes.InnerText = "Clear Results"; emptyTables(); orderByRes.Attributes["href"] = "Companies.aspx"; } #region Company & Rating Table Code if (ds.Tables[0].Rows.Count != 0) { int i, j; Rating10[] ratCol = new Rating10[10] { ratingCtrl1, ratingCtrl2, ratingCtrl3, ratingCtrl4, ratingCtrl5, ratingCtrl6, ratingCtrl7, ratingCtrl8, ratingCtrl9, ratingCtrl10 }; if (Request.QueryString["page"] != null) { int pageNum = int.Parse(Request.QueryString["page"]); int maxPages = (ds.Tables[0].Rows.Count / 10) + 1; numLinksTable.Rows[0].Cells[pageNum + 1].Attributes["class"] = "numCol , centerAlign , selected"; int times = ds.Tables[0].Rows.Count - ((pageNum - 1) * 10); if (times >= 10) times = 10; for (i = 0; i < times; i++) { companyNameRating.Rows[i + 1].Cells[0].InnerHtml = "<a title=\"Click here to see detailed ratings for " + ds.Tables[0].Rows[((pageNum - 1) * 10) + i]["CompanyName"] + "\" class = \"nodecor , compLinks\" href=\"CompanyDetails.aspx?id=" + ds.Tables[0].Rows[((pageNum - 1) * 10) + i]["CompanyID"] + "\">" + ds.Tables[0].Rows[((pageNum - 1) * 10) + i]["CompanyName"] + "</a>"; int rating = (int)ds.Tables[0].Rows[((pageNum - 1) * 10) + i]["AverageRating"]; ratCol[i].Visible = true; ratCol[i].setRating(rating); ratCol[i].disable(); } for (j = 0; j <= maxPages; j++) { if(Request["spl"] != null) { numLinksTable.Rows[0].Cells[j + 2].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?spl=" + Request["spl"] + "&page=" + (j + 1).ToString() + "&maxpages=" + maxPages + "\">" + (j + 1).ToString() + "</a>";} else numLinksTable.Rows[0].Cells[j + 2].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?letter=" + startLetter + "&page=" + (j + 1).ToString() + "&maxpages=" + maxPages + "\">" + (j + 1).ToString() + "</a>"; } if(Request["spl"] != null) numLinksTable.Rows[0].Cells[0].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?spl=" + Request["spl"] + "&page=1" + "&maxpages=" + maxPages + "\"><<</a>"; else numLinksTable.Rows[0].Cells[0].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?letter=" + startLetter + "&page=1" + "&maxpages=" + maxPages + "\"><<</a>"; if(Request["spl"] != null) numLinksTable.Rows[0].Cells[j + 2].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?spl=" + Request["spl"] + "&page=" + maxPages + "&maxpages=" + maxPages + "\">>></a>"; else numLinksTable.Rows[0].Cells[j + 2].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?letter=" + startLetter + "&page=" + maxPages + "&maxpages=" + maxPages + "\">>></a>"; if (pageNum != 1) { if(Request["spl"] != null) numLinksTable.Rows[0].Cells[1].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?spl=" + Request["spl"] + "&page=" + (pageNum - 1) + "&maxpages=" + maxPages + "\"><</a>"; else numLinksTable.Rows[0].Cells[1].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?letter=" + startLetter + "&page=" + (pageNum - 1) + "&maxpages=" + maxPages + "\"><</a>"; } else { if(Request["spl"] != null) numLinksTable.Rows[0].Cells[1].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?spl=" + Request["spl"] + "&page=1" + "&maxpages=" + maxPages + "\"><</a>"; else numLinksTable.Rows[0].Cells[1].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?letter=" + startLetter + "&page=1" + "&maxpages=" + maxPages + "\"><</a>"; } if (pageNum == maxPages) { if(Request["spl"] != null) numLinksTable.Rows[0].Cells[j + 1].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?spl=" + Request["spl"] + "&page=" + maxPages + "&maxpages=" + maxPages + "\">></a>"; else numLinksTable.Rows[0].Cells[j + 1].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?letter=" + startLetter + "&page=" + maxPages + "&maxpages=" + maxPages + "\">></a>"; } else { if(Request["spl"] != null) numLinksTable.Rows[0].Cells[j + 1].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?spl=" + Request["spl"] + "&page=" + (pageNum + 1) + "&maxpages=" + maxPages + "\">></a>"; else numLinksTable.Rows[0].Cells[j + 1].InnerHtml = "<a class = \"nodecor\" href=\"Companies.aspx?letter=" + startLetter + "&page=" + (pageNum + 1) + "&maxpages=" + maxPages + "\">></a>"; } } } #endregion } } like_message = Get_Message(); }
protected void submitButton_Click(object sender, EventArgs e) { int[] savedRating = new int[12]; bool error = false; HtmlTableCell[] celCol = new HtmlTableCell[12] {td, Td1, Td2, Td3, Td4, Td5, Td6, Td7, Td8, Td9, Td10, Td11}; Rating10[] ratCol = new Rating10[12]{ rating1, rating2, rating3, rating4, rating5, rating6, rating7, rating8, rating9, rating10, rating11, rating12}; for (int i = 0; i < 12; i++) { savedRating[i] = ratCol[i].GetRating(); if (savedRating[i] == 0) error = true; } Session["ratings"] = savedRating; if (error) Response.Redirect("ReviewInput.aspx?error=1"); else //Database Updation Code { if (Session["raterinfo"] != null) { string updateQuery, insertQuery; RaterInfo info = (RaterInfo)Session["raterinfo"]; string company = info.employer; string checkQuery = "SELECT CompanyName,CompanyId FROM MainTable WHERE MainTable.CompanyName='" + company+ "'"; DatabaseManager db = new DatabaseManager(); Application.Lock(); //Lock so that Data is updated properly DataSet ds = db.GetDataSet(checkQuery); if (ds.Tables[0].Rows.Count != 0) //If the company already exists in the DB. { //First Get all the already existing data for the company in DB int id = (int)ds.Tables[0].Rows[0]["CompanyId"]; string obtainDataQuery = "SELECT * FROM MainTable, CompanyRatings WHERE MainTable.CompanyId=CompanyRatings.CompanyRId AND MainTable.CompanyName='" + company + "'"; ds = db.GetDataSet(obtainDataQuery); // ------- Update Command Building Code for CompanyRatings Table -------- int[] updRes = GetUpdatedData(ds, savedRating); updateQuery = "UPDATE CompanyRatings SET "; updateQuery += StringCollection.CRCols[0] + "=@" + StringCollection.CRCols[0] + "," + StringCollection.CRCols[1] + "=@" + StringCollection.CRCols[1] + "," + StringCollection.CRCols[2] + "=@" + StringCollection.CRCols[2] + ","; updateQuery += StringCollection.CRCols[3] + "=@" + StringCollection.CRCols[3] + "," + StringCollection.CRCols[4] + "=@" + StringCollection.CRCols[4] + "," + StringCollection.CRCols[5] + "=@" + StringCollection.CRCols[5] + ","; updateQuery += StringCollection.CRCols[6] + "=@" + StringCollection.CRCols[6] + "," + StringCollection.CRCols[7] + "=@" + StringCollection.CRCols[7] + "," + StringCollection.CRCols[8] + "=@" + StringCollection.CRCols[8] + ","; updateQuery += StringCollection.CRCols[9] + "=@" + StringCollection.CRCols[9] + "," + StringCollection.CRCols[10] + "=@" + StringCollection.CRCols[10] + "," + StringCollection.CRCols[11] + "=@" + StringCollection.CRCols[11] + ","; updateQuery += StringCollection.CRCols[12] + "=@" + StringCollection.CRCols[12] + "," + StringCollection.CRCols[13] + "=@" + StringCollection.CRCols[13]; updateQuery += " WHERE CompanyRId=" + id; SqlCommand upCom = db.GetCommand(updateQuery); for (int j = 0; j < 14; j++) { upCom.Parameters.AddWithValue(StringCollection.CRCols[j], updRes[j]); } //------------------------------------------------------------------------ // ------ Insert Command Building Code for Reviews Table ---------- SqlCommand inCom=null; if(comments.Value != ""){ insertQuery = "INSERT INTO Reviews ("; insertQuery += "ReviewText, CalcRating, CompanyIDRev, Upvotes, Downvotes, Score, DateAdded) "; insertQuery += "VALUES ('" + comments.Value + "', 6, " + id + ", 0, 0, 0, GETDATE())"; inCom = db.GetCommand(insertQuery); } //------------------------------------------------------------------- bool res = true; try { db.dbCon.Open(); upCom.ExecuteNonQuery(); if(inCom != null) inCom.ExecuteNonQuery(); } catch { res = false; } Application.UnLock(); db.dbCon.Close(); if (res) { ds = db.GetUpdatedData(); if (Cache["CompanyList"] != null) { lock (Cache["CompanyList"]) { Cache["CompanyList"] = ds; } } else Cache["CompanyList"] = ds; Response.Redirect("../View/Done.aspx?from=uc"); } else Response.Redirect("../Error.aspx?from=revInput&data=dbUpdError&c=" + company); } else //If a new company is being added. { //------- Insert Command Building Code in MainTable ---------- insertQuery = "INSERT INTO MainTable ("; insertQuery += "CompanyName, Industry) "; insertQuery += "VALUES ('" + company + "', 'Demo Industry' )"; SqlCommand inCom = db.GetCommand(insertQuery); bool res = true; //------------------------------------------------------------ try { db.dbCon.Open(); inCom.ExecuteNonQuery(); } catch { res = false; } db.dbCon.Close(); if (!res) { Application.UnLock(); Response.Redirect("../Error.aspx?from=revInput&data=dbUpdError&c="+company); } else { string getNewIdQuery = "SELECT CompanyId, CompanyName FROM MainTable WHERE MainTable.CompanyName='" + company +"'"; DataSet id = db.GetDataSet(getNewIdQuery); int newId = (int)id.Tables[0].Rows[0]["CompanyId"]; int avgRating = 0; //------------- Insert Command Building Code for CompanyRatings Table ----------- insertQuery = "INSERT INTO CompanyRatings ( CompanyRId, "; for (int i = 0; i < 14; i++) { insertQuery += StringCollection.CRCols[i]; if (i != 13) insertQuery += ", "; } insertQuery += " ) "; insertQuery += "VALUES (" + newId + ", "; for (int i = 0; i < 12; i++) { insertQuery += (savedRating[i] + ", "); avgRating += savedRating[i]; } avgRating /= 12; insertQuery += "1, " + avgRating + ")"; SqlCommand inComCR = db.GetCommand(insertQuery); bool done = true; //-------------------------------------------------------------------------------- //------------- Insert Command Building Code for Reviews Table ------------------ SqlCommand inComRev = null; string _insertQuery; if (comments.Value != "") { comments.Value=comments.Value.Replace("'", "'"); _insertQuery = "INSERT INTO Reviews ("; _insertQuery += "ReviewText, CalcRating, CompanyIDRev, Upvotes, Downvotes, Score, DateAdded) "; _insertQuery += "VALUES ('" + comments.Value + "', 6, " + newId + ", 0, 0, 0, GETDATE())"; inComRev = db.GetCommand(_insertQuery); } //-------------------------------------------------------------------------------- int added = -1; try { db.dbCon.Open(); added=inComCR.ExecuteNonQuery(); if (inComRev != null) inComRev.ExecuteNonQuery(); } catch { done = false; string delQuery; SqlCommand delCom; if (added > 0) { delQuery = "DELETE FROM CompanyRatings WHERE CompanyRId=" + newId; delCom = db.GetCommand(delQuery); delCom.ExecuteNonQuery(); } delQuery = "DELETE FROM MainTable WHERE CompanyId=" + newId; delCom = db.GetCommand(delQuery); delCom.ExecuteNonQuery(); } Application.UnLock(); db.dbCon.Close(); if (done) { ds = db.GetUpdatedData(); if (Cache["CompanyList"] != null) { lock (Cache["CompanyList"]) { Cache["CompanyList"] = ds; } } else Cache["CompanyList"] = ds; Response.Redirect("../View/Done.aspx?from=uc"); } else { Response.Redirect("../Error.aspx?from=revInput&data=dbUpdError&c=" + company); } } } } else { Response.Redirect("../Error.aspx?from=revInput&data=expired"); } } }