protected void Button_Save_Click(object sender, EventArgs e) { if (TextBoxName.Text.Length == 0 || TextBoxDescription.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter a name and description for the Deliverable.');", true); } else if (TextBoxStartDate.Text.Length == 0 || TextBoxDueDate.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter a start and due date for the deliverable.');", true); } else { using (SqlConnection conn = new SqlConnection(g_sqlConn)) { Connect(conn); using (SqlCommand cmd2 = new SqlCommand(String.Format("SELECT DeliverableID FROM tblDeliverables WHERE Name='{0}' AND UserID={1} AND ProjectID={2}", TextBoxName.Text, Session["_CurrentUserID"], Session["_CurrentProjID"]), conn)) { SqlDataReader sdr = cmd2.ExecuteReader(); while (sdr.Read()) { Session["_CurrentDelivID"] = sdr[0].ToString(); } sdr.Close(); } using (SqlCommand cmd = new SqlCommand("UPDATE tblDeliverables SET Name=@Name, Description=@Description, StartDate=@StartDate, DueDate=@DueDate WHERE UserID=@UserID AND ProjectID=@ProjID AND DeliverableID=@DelivID", conn)) { cmd.Parameters.AddWithValue("@Name", TextBoxName.Text); cmd.Parameters.AddWithValue("@Description", TextBoxDescription.Text); cmd.Parameters.AddWithValue("@UserID", Session["_CurrentUserID"]); cmd.Parameters.AddWithValue("@ProjID", Session["_CurrentProjID"]); cmd.Parameters.AddWithValue("@DelivID", Session["_CurrentDelivID"]); cmd.Parameters.AddWithValue("@StartDate", TextBoxStartDate.Text); cmd.Parameters.AddWithValue("@DueDate", TextBoxDueDate.Text); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(String.Format("Error while executing query...{0}", ex.ToString())); } finally { Disconnect(conn); } } } DropDownListDelivSelect.Items.Clear(); DropDownListDelivSelect.DataBind(); GridViewListDeliverables.DataBind(); } }
protected void Button_Del_Click(object sender, EventArgs e) { if (TextBoxName.Text.Length == 0 || TextBoxDescription.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter a name of the Deliverable to delete.');", true); } else { using (SqlConnection conn = new SqlConnection(g_sqlConn)) { Connect(conn); using (SqlCommand cmd2 = new SqlCommand(String.Format("SELECT DeliverableID FROM tblDeliverables WHERE Name='{0}' AND UserID={1} AND ProjectID={2}", TextBoxName.Text, Session["_CurrentUserID"], Session["_CurrentProjID"]), conn)) { SqlDataReader sdr = cmd2.ExecuteReader(); while (sdr.Read()) { Session["_CurrentDelivID"] = sdr[0].ToString(); } sdr.Close(); } using (SqlCommand cmd3 = new SqlCommand(String.Format("UPDATE tblTasks SET AssociatedDeliverable = NULL WHERE AssociatedDeliverable={0}", Session["_CurrentDelivID"]), conn)) { try { cmd3.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(String.Format("Error while executing query...{0}", ex.ToString())); } } using (SqlCommand cmd = new SqlCommand(String.Format("delete from tblDeliverables 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); } } } DropDownListDelivSelect.Items.Clear(); DropDownListDelivSelect.DataBind(); GridViewListDeliverables.DataBind(); GridViewAssociatedTasks.DataBind(); } }