protected void ButtonDelete_Click(object sender, EventArgs e) { if (TextBoxName.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter the name of the Resource to be deleted.');", true); } else { using (SqlConnection conn = new SqlConnection(g_sqlConn)) { Connect(conn); using (SqlCommand cmd = new SqlCommand(String.Format("delete from tblResources where UserID={0} and ProjectID={1} AND Name='{2}'", Session["_CurrentUserID"], Session["_CurrentProjID"], TextBoxName.Text), conn)) { try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(String.Format("Error while executing query...{0}", ex.ToString())); } finally { Disconnect(conn); } } } DropDownListResourceSelect.Items.Clear(); DropDownListResourceSelect.DataBind(); } }
protected void ButtonNew_Click(object sender, EventArgs e) { if (TextBoxName.Text.Length == 0 || TextBoxDescription.Text.Length == 0 || TextBoxTitle.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter a name, description, and title for the Resource.');", true); } else if (TextBoxSkillsDescription.Text.Length == 0 || TextBoxPayRate.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter a description of skills and pay rate for the Resource.');", true); } else if (TextBoxStartDate.Text.Length == 0 && TextBoxEndDate.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter an available start and end date.');", true); } else { using (SqlConnection conn = new SqlConnection(g_sqlConn)) { Connect(conn); using (SqlCommand cmd = new SqlCommand("insert into tblResources(UserID,ProjectID,Name,Description,Title,PayRate, AvailableStartDate, AvailableEndDate, ListOfSkills)" + " values(@UserID, @ProjectID, @Name, @Description,@Title , @PayRate, @AvailStart, @AvailEnd, @ListOfSkills)", conn)) { cmd.Parameters.AddWithValue("@UserID", Session["_CurrentUserID"]); cmd.Parameters.AddWithValue("@ProjectID", Session["_CurrentProjID"]); cmd.Parameters.AddWithValue("@Name", TextBoxName.Text); cmd.Parameters.AddWithValue("@Description", TextBoxDescription.Text); cmd.Parameters.AddWithValue("@Title", TextBoxTitle.Text); cmd.Parameters.AddWithValue("@PayRate", TextBoxPayRate.Text); cmd.Parameters.AddWithValue("@AvailStart", TextBoxStartDate.Text); cmd.Parameters.AddWithValue("@AvailEnd", TextBoxEndDate.Text); cmd.Parameters.AddWithValue("ListOfSkills", TextBoxSkillsDescription.Text); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(String.Format("Error while executing query...{0}", ex.ToString())); } finally { Disconnect(conn); } Connect(conn); using (SqlCommand cmd2 = new SqlCommand(String.Format("SELECT ResourceID FROM tblResources WHERE Name='{0}' AND UserID={1} AND ProjectID={2}", TextBoxName.Text, Session["_CurrentUserID"], Session["_CurrentProjID"]), conn)) { SqlDataReader sdr = cmd2.ExecuteReader(); while (sdr.Read()) { Session["_CurrentResourceID"] = sdr[0].ToString(); } sdr.Close(); } Disconnect(conn); } } DropDownListResourceSelect.Items.Clear(); DropDownListResourceSelect.DataBind(); ButtonSave.Visible = true; ButtonDelete.Visible = true; } }