/// <summary> /// saves changes into data base /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void save_btn_Click(object sender, EventArgs e) { //passed validation if (dataTableName.Equals("users")) { SqlCommand sqlCommand; sqlConnection.Open(); string sqlCmd = "UPDATE [Users] SET username = @newUsername, password = @newPassword, email = @newEmail, content_creator = @newContentCreator, content_consumer = @newContentConsumer, validated = @newValidated, RandomKey = @newRandomKey, user_color = @newUserColor, admin = @newAdmin Where Id = @oldId"; for (int i = 1; i < table.Controls.Count - 1; i++) {// goes through all rows that are not Header or Footer TableRow tr = (TableRow)table.Controls[i]; if (!((Image)tr.Controls[tr.Controls.Count - 1].Controls[1]).CssClass.Contains("not-changed")) {// row is changed sqlCommand = new SqlCommand(sqlCmd, sqlConnection); //cannot change id sqlCommand.Parameters.AddWithValue("@newUsername", ((TextBox)tr.Controls[1].Controls[0]).Text); sqlCommand.Parameters.AddWithValue("@newPassword", ((TextBox)tr.Controls[2].Controls[0]).Text); sqlCommand.Parameters.AddWithValue("@newEmail", ((TextBox)tr.Controls[3].Controls[0]).Text); if (((CheckBox)tr.Controls[4].Controls[0]).Checked) { sqlCommand.Parameters.AddWithValue("@newContentCreator", "True"); } else { sqlCommand.Parameters.AddWithValue("@newContentCreator", "False"); } if (((CheckBox)tr.Controls[5].Controls[0]).Checked) { sqlCommand.Parameters.AddWithValue("@newContentConsumer", "True"); } else { sqlCommand.Parameters.AddWithValue("@newContentConsumer", "False"); } if (((CheckBox)tr.Controls[6].Controls[0]).Checked) { sqlCommand.Parameters.AddWithValue("@newValidated", "True"); } else { sqlCommand.Parameters.AddWithValue("@newValidated", "False"); } sqlCommand.Parameters.AddWithValue("@newRandomKey", ((TextBox)tr.Controls[7].Controls[0]).Text); sqlCommand.Parameters.AddWithValue("@newUserColor", ((TextBox)tr.Controls[8].Controls[0]).Text); if (((CheckBox)tr.Controls[9].Controls[0]).Checked) { sqlCommand.Parameters.AddWithValue("@newAdmin", "True"); } else { sqlCommand.Parameters.AddWithValue("@newAdmin", "False"); } sqlCommand.Parameters.AddWithValue("@oldId", ((TableCell)tr.Controls[0]).ToolTip); sqlCommand.ExecuteNonQuery(); } } TableFooterRow footerRow = (TableFooterRow)table.Controls[table.Controls.Count - 1]; if (((TextBox)footerRow.Controls[1].Controls[0]).Text.Length > 0 && InsertRowFull(footerRow, 1)) { string insertCommand = "INSERT INTO [Users] VALUES(@newUsername, @newPassword, @newEmail, @newContentCreator, @newContentConsumer, @newValidated, @newRandomKey, @newUserColor, @newAdmin)"; sqlCommand = new SqlCommand(insertCommand, sqlConnection); sqlCommand.Parameters.AddWithValue("@newUsername", ((TextBox)footerRow.Controls[1].Controls[0]).Text); sqlCommand.Parameters.AddWithValue("@newPassword", ((TextBox)footerRow.Controls[2].Controls[0]).Text); sqlCommand.Parameters.AddWithValue("@newEmail", ((TextBox)footerRow.Controls[3].Controls[0]).Text); if (((CheckBox)footerRow.Controls[4].Controls[0]).Checked) { sqlCommand.Parameters.AddWithValue("@newContentCreator", "True"); } else { sqlCommand.Parameters.AddWithValue("@newContentCreator", "False"); } if (((CheckBox)footerRow.Controls[5].Controls[0]).Checked) { sqlCommand.Parameters.AddWithValue("@newContentConsumer", "True"); } else { sqlCommand.Parameters.AddWithValue("@newContentConsumer", "False"); } if (((CheckBox)footerRow.Controls[6].Controls[0]).Checked) { sqlCommand.Parameters.AddWithValue("@newValidated", "True"); } else { sqlCommand.Parameters.AddWithValue("@newValidated", "False"); } sqlCommand.Parameters.AddWithValue("@newRandomKey", ((TextBox)footerRow.Controls[7].Controls[0]).Text); sqlCommand.Parameters.AddWithValue("@newUserColor", ((TextBox)footerRow.Controls[8].Controls[0]).Text); if (((CheckBox)footerRow.Controls[9].Controls[0]).Checked) { sqlCommand.Parameters.AddWithValue("@newAdmin", "True"); } else { sqlCommand.Parameters.AddWithValue("@newAdmin", "False"); } sqlCommand.ExecuteNonQuery(); //Update WebService int id = 0; sqlCmd = "SELECT Id FROM [Users] WHERE username = @username;"; sqlCommand = new SqlCommand(sqlCmd, sqlConnection); sqlCommand.Parameters.AddWithValue("@username", ((TextBox)footerRow.Controls[1].Controls[0]).Text); SqlDataReader reader = sqlCommand.ExecuteReader(); if (reader.Read()) { id = reader.GetInt32(0); } maker_service.WebService ws = new maker_service.WebService(); ws.InsertUser(id); } sqlConnection.Close(); Response.Redirect(Request.Url.AbsoluteUri); } if (dataTableName.Equals("models")) { ws.OpenConnection(); string sqlCmd = "UPDATE [Models] SET User_Id = @newUser_Id, Creation_Date = @newCreation_Date, XML_File_Link = @newXML, name = @newName, description = @newDescription, Thumbnail = @newThumbnail Where Model_Id = @oldId"; for (int i = 1; i < table.Controls.Count - 1; i++) {// goes through all rows that are not Header or Footer TableRow tr = (TableRow)table.Controls[i]; if (!((Image)tr.Controls[tr.Controls.Count - 1].Controls[1]).CssClass.Contains("not-changed")) {// row is changed string[] parameterNames = { "@newUser_Id", "@newCreation_Date", "@newXML", "@newName", "@newDescription", "@newThumbnail", "@oldId" }; string[] parameterValues = new string[parameterNames.Length]; //cannot change id parameterValues[0] = ((TextBox)tr.Controls[1].Controls[0]).Text; parameterValues[1] = ((TextBox)tr.Controls[2].Controls[0]).Text; parameterValues[2] = ((TextBox)tr.Controls[3].Controls[0]).Text; parameterValues[3] = ((TextBox)tr.Controls[4].Controls[0]).Text; parameterValues[4] = ((TextBox)tr.Controls[5].Controls[0]).Text; parameterValues[5] = ((TextBox)tr.Controls[6].Controls[0]).Text; parameterValues[6] = ((TableCell)tr.Controls[0]).ToolTip; string[] parameterTypes = { "string", "datetime", "string", "string", "string", "string", "string" }; ws.GenericVoidQueryWithParameters(sqlCmd, parameterNames, parameterValues, parameterTypes); } } TableFooterRow footerRow = (TableFooterRow)table.Controls[table.Controls.Count - 1]; if (((TextBox)footerRow.Controls[1].Controls[0]).Text.Length > 0 && InsertRowFull(footerRow, 1)) { string[] parameterNames = { "@newUser_Id", "@newCreation_Date", "@newXML", "@newName", "@newDescription", "@newThumbnail", "@oldId" }; string[] parameterValues = new string[parameterNames.Length]; //cannot change id parameterValues[0] = ((TextBox)footerRow.Controls[1].Controls[0]).Text; parameterValues[1] = ((TextBox)footerRow.Controls[2].Controls[0]).Text; parameterValues[2] = ((TextBox)footerRow.Controls[3].Controls[0]).Text; parameterValues[3] = ((TextBox)footerRow.Controls[4].Controls[0]).Text; parameterValues[4] = ((TextBox)footerRow.Controls[5].Controls[0]).Text; parameterValues[5] = ((TextBox)footerRow.Controls[6].Controls[0]).Text; parameterValues[6] = ((TableCell)footerRow.Controls[0]).ToolTip; string[] parameterTypes = { "int", "datetime", "string", "string", "string", "string", "int" }; string insertCommand = "INSERT INTO [Models] VALUES(@newUser_Id, @newCreation_Date, @newXML, @newName, @newDescription, @newThumbnail);"; ws.GenericVoidQueryWithParameters(insertCommand, parameterNames, parameterValues, parameterTypes); } ws.CloseConnection(); Response.Redirect(Request.Url.AbsoluteUri); } if (dataTableName.Equals("downloads")) { ws.OpenConnection(); string sqlCmd = "UPDATE [Downloads] SET User_Id = @newUser_Id, Model_Id = @newModel_Id, Download_Date = @newDownload_Date WHERE Download_Id = @oldId"; for (int i = 1; i < table.Controls.Count - 1; i++) {// goes through all rows that are not Header or Footer TableRow tr = (TableRow)table.Controls[i]; if (!((Image)tr.Controls[tr.Controls.Count - 1].Controls[1]).CssClass.Contains("not-changed")) {// row is changed string[] parameterNames = { "@newUser_Id", "@newModel_Id", "@newDownload_Date", "@oldId" }; string[] parameterValues = new string[parameterNames.Length]; //cannot change id parameterValues[0] = ((TextBox)tr.Controls[1].Controls[0]).Text; parameterValues[1] = ((TextBox)tr.Controls[2].Controls[0]).Text; parameterValues[2] = ((TextBox)tr.Controls[3].Controls[0]).Text; parameterValues[3] = ((TableCell)tr.Controls[0]).ToolTip; string[] parameterTypes = { "int", "int", "datetime", "int" }; ws.GenericVoidQueryWithParameters(sqlCmd, parameterNames, parameterValues, parameterTypes); } } TableFooterRow footerRow = (TableFooterRow)table.Controls[table.Controls.Count - 1]; if (((TextBox)footerRow.Controls[1].Controls[0]).Text.Length > 0 && InsertRowFull(footerRow, 1)) { string[] parameterNames = { "@newUser_Id", "@newModel_Id", "@newDownload_Date" }; string[] parameterValues = new string[parameterNames.Length]; //cannot change id parameterValues[0] = ((TextBox)footerRow.Controls[1].Controls[0]).Text; parameterValues[1] = ((TextBox)footerRow.Controls[2].Controls[0]).Text; parameterValues[2] = ((TextBox)footerRow.Controls[3].Controls[0]).Text; string[] parameterTypes = { "int", "int", "datetime" }; string insertCommand = "INSERT INTO [Downloads] VALUES(@newUser_Id, @newModel_Id, @newDownload_Date);"; ws.GenericVoidQueryWithParameters(insertCommand, parameterNames, parameterValues, parameterTypes); } ws.CloseConnection(); Response.Redirect(Request.Url.AbsoluteUri); } if (dataTableName.Equals("ratings")) { ws.OpenConnection(); string sqlCmd = "UPDATE [Ratings] SET User_Id = @newUser_Id, Model_Id = @newModel_Id, Value = @newValue WHERE Rate_Id = @oldId"; for (int i = 1; i < table.Controls.Count - 1; i++) {// goes through all rows that are not Header or Footer TableRow tr = (TableRow)table.Controls[i]; if (!((Image)tr.Controls[tr.Controls.Count - 1].Controls[1]).CssClass.Contains("not-changed")) {// row is changed string[] parameterNames = { "@newUser_Id", "@newModel_Id", "@newValue", "@oldId" }; string[] parameterValues = new string[parameterNames.Length]; //cannot change id parameterValues[0] = ((TextBox)tr.Controls[1].Controls[0]).Text; parameterValues[1] = ((TextBox)tr.Controls[2].Controls[0]).Text; parameterValues[2] = ((TextBox)tr.Controls[3].Controls[0]).Text; parameterValues[3] = ((TableCell)tr.Controls[0]).ToolTip; string[] parameterTypes = { "int", "int", "int", "int" }; ws.GenericVoidQueryWithParameters(sqlCmd, parameterNames, parameterValues, parameterTypes); } } TableFooterRow footerRow = (TableFooterRow)table.Controls[table.Controls.Count - 1]; if (((TextBox)footerRow.Controls[1].Controls[0]).Text.Length > 0 && InsertRowFull(footerRow, 1)) { string[] parameterNames = { "@newUser_Id", "@newModel_Id", "@newValue" }; string[] parameterValues = new string[parameterNames.Length]; //cannot change id parameterValues[0] = ((TextBox)footerRow.Controls[1].Controls[0]).Text; parameterValues[1] = ((TextBox)footerRow.Controls[2].Controls[0]).Text; parameterValues[2] = ((TextBox)footerRow.Controls[3].Controls[0]).Text; string[] parameterTypes = { "int", "int", "int" }; string insertCommand = "INSERT INTO [Ratings] VALUES(@newUser_Id, @newModel_Id, @newValue);"; ws.GenericVoidQueryWithParameters(insertCommand, parameterNames, parameterValues, parameterTypes); } ws.CloseConnection(); Response.Redirect(Request.Url.AbsoluteUri); } }
/// <summary> /// create responsive table for each table by looking at the url /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { dataTableName = GetDataTableName(Request.Url.AbsoluteUri); if (dataTableName.Equals("users")) { table.CssClass = "table users-table Report1942Font"; sqlConnection = new SqlConnection(resources.ResourceManager.GetString("Connection_String")); sqlConnection.Open(); string sqlCmd = "SELECT * FROM [Users]"; SqlCommand sqlCommand = new SqlCommand(sqlCmd, sqlConnection); SqlDataReader reader = sqlCommand.ExecuteReader(); string[] titles = { "ID", "Username", "Password", "Email", "Content Creator", "Content Consumer", "Validated", "RandomKey", "User Color", "Admin" }; GenerateHeaderRow(titles); TableFooterRow footer_row = new TableFooterRow(); int i = 0; int counter = 0; if (reader.Read()) { footer_row = GenerateFooterRow(reader, ref counter); } do { table.Controls.Add(GenerateTableRow(reader, i, ref counter)); i++; } while (reader.Read()); reader.Close(); sqlConnection.Close(); title.InnerHtml = "USERS"; table.Controls.Add(footer_row); } if (dataTableName.Equals("models")) { table.CssClass = "table models-table Report1942Font"; ws = new maker_service.WebService(); string[] titles = { "Model ID", "User ID", "Date", "Data Path", "Name", "Description", "Thumbnail" }; GenerateHeaderRow(titles); ws.OpenConnection(); DataSet dataset = ws.GenericReaderQuery("SELECT * FROM [Models]"); TableFooterRow footer_row = new TableFooterRow(); int i = 0; int counter = 0; DataTableReader reader = dataset.Tables[0].CreateDataReader(); if (reader.Read()) { footer_row = GenerateFooterRow(reader, ref counter); } do { table.Controls.Add(GenerateTableRow(reader, i, ref counter)); i++; } while (reader.Read()); reader.Close(); ws.CloseConnection(); title.InnerHtml = "MODELS"; table.Controls.Add(footer_row); } if (dataTableName.Equals("downloads")) { table.CssClass = "table models-table Report1942Font"; ws = new maker_service.WebService(); string[] titles = { "Download ID", "User ID", "Model ID", "Download Date" }; GenerateHeaderRow(titles); ws.OpenConnection(); DataSet dataset = ws.GenericReaderQuery("SELECT * FROM [Downloads]"); TableFooterRow footer_row = new TableFooterRow(); int i = 0; int counter = 0; DataTableReader reader = dataset.Tables[0].CreateDataReader(); if (reader.Read()) { footer_row = GenerateFooterRow(reader, ref counter); } do { table.Controls.Add(GenerateTableRow(reader, i, ref counter)); i++; } while (reader.Read()); reader.Close(); ws.CloseConnection(); title.InnerHtml = "Downloads"; table.Controls.Add(footer_row); } if (dataTableName.Equals("ratings")) { table.CssClass = "table models-table Report1942Font"; ws = new maker_service.WebService(); string[] titles = { "Rate ID", "User ID", "Model ID", "Value" }; GenerateHeaderRow(titles); ws.OpenConnection(); DataSet dataset = ws.GenericReaderQuery("SELECT * FROM [Ratings]"); TableFooterRow footer_row = new TableFooterRow(); int i = 0; int counter = 0; DataTableReader reader = dataset.Tables[0].CreateDataReader(); if (reader.Read()) { footer_row = GenerateFooterRow(reader, ref counter); } do { table.Controls.Add(GenerateTableRow(reader, i, ref counter)); i++; } while (reader.Read()); reader.Close(); ws.CloseConnection(); title.InnerHtml = "Ratings"; table.Controls.Add(footer_row); } }