protected void ButtonDelete_Click(object sender, EventArgs e) { if (TextBoxName.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter a name of the Action Item you want to delete.');", true); } else { using (SqlConnection conn = new SqlConnection(g_sqlConn)) { Connect(conn); using (SqlCommand cmd2 = new SqlCommand(String.Format("SELECT ActionItemID FROM tblActionItems WHERE Name='{0}' AND UserID={1} AND ProjectID={2}", TextBoxName.Text, Session["_CurrentUserID"], Session["_CurrentProjID"]), conn)) { SqlDataReader sdr = cmd2.ExecuteReader(); while (sdr.Read()) { Session["_CurrentActionItemID"] = sdr[0].ToString(); } sdr.Close(); } using (SqlCommand cmd3 = new SqlCommand(String.Format("UPDATE tblResources SET AssociatedActionItem = NULL WHERE AssociatedActionItem={0}", Session["_CurrentActionItemID"]), 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 tblStatusActItem where UserID={0} and ProjectID={1} and AssociatedActionItem={2}", Session["_CurrentUserID"], Session["_CurrentProjID"], Session["_CurrentActionItemID"]), conn)) { cmd.ExecuteNonQuery(); } using (SqlCommand cmd = new SqlCommand(String.Format("delete from tblActionItems 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); } } } DropDownListActItemSelect.Items.Clear(); DropDownListActItemSelect.DataBind(); GridViewActionItemsList.DataBind(); } }
protected void ButtonSave_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 Action Item.');", true); } else if (TextBoxDateCreated.Text.Length == 0 || TextBoxDateAssigned.Text.Length == 0 || TextBoxExpectedCompletionDate.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please select a date for the Date Created, Date Assigned, and Expected Completion Date fields.');", true); } else if (TextBoxStatus.Text.Length == 0 || TextBoxStatusDescription.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please select a status and enter a status description.');", true); } else { using (SqlConnection conn = new SqlConnection(g_sqlConn)) { try { Connect(conn); using (SqlCommand cmd2 = new SqlCommand(String.Format("SELECT ActionItemID FROM tblActionItems WHERE Name='{0}' AND UserID={1} AND ProjectID={2}", TextBoxName.Text, Session["_CurrentUserID"], Session["_CurrentProjID"]), conn)) { SqlDataReader sdr = cmd2.ExecuteReader(); while (sdr.Read()) { Session["_CurrentActionItemID"] = sdr[0].ToString(); } sdr.Close(); } using (SqlCommand cmd = new SqlCommand("UPDATE tblActionItems SET Name=@Name, Description=@Description, " + "DateCreated=@DateCreated, DateAssigned=@DateAssigned, ExpectedCompletionDate=@ExpComplDate," + "ActualCompletionDate=@ActComplDate, Status=@Status, StatusDescription=@StatusDescription" + " WHERE UserID=@UserID AND ProjectID=@ProjID AND ActionItemID=@ActionID", conn)) { cmd.Parameters.AddWithValue("@UserID", Session["_CurrentUserID"]); cmd.Parameters.AddWithValue("@ProjID", Session["_CurrentProjID"]); cmd.Parameters.AddWithValue("@ActionID", Session["_CurrentActionItemID"]); cmd.Parameters.AddWithValue("@Name", TextBoxName.Text); cmd.Parameters.AddWithValue("@Description", TextBoxDescription.Text); cmd.Parameters.AddWithValue("@DateCreated", TextBoxDateCreated.Text); cmd.Parameters.AddWithValue("@DateAssigned", TextBoxDateAssigned.Text); cmd.Parameters.AddWithValue("@ExpComplDate", TextBoxExpectedCompletionDate.Text); cmd.Parameters.AddWithValue("@ActComplDate", string.IsNullOrEmpty(TextBoxActualCompletionDate.Text) ? (object)DBNull.Value : TextBoxActualCompletionDate.Text); string prevSelectedVal = ListBoxStatus.SelectedItem.ToString(); SaveListBoxes(); int updatedIndex = 0; for (int i = 0; i < ListBoxStatus.Items.Count; i++) { if (ListBoxStatus.Items[i].ToString().Equals(prevSelectedVal)) { updatedIndex = i; } } cmd.Parameters.AddWithValue("@Status", updatedIndex); cmd.Parameters.AddWithValue("@StatusDescription", TextBoxStatusDescription.Text); cmd.ExecuteNonQuery(); } } catch (Exception ex) { Response.Write(String.Format("Error while executing query...{0}", ex.ToString())); } finally { Disconnect(conn); } } DropDownListActItemSelect.Items.Clear(); DropDownListActItemSelect.DataBind(); GridViewAssociateResource.DataBind(); GridViewActionItemsList.DataBind(); } }
protected void ButtonNew_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 Action Item.');", true); } else if (TextBoxDateCreated.Text.Length == 0 || TextBoxDateAssigned.Text.Length == 0 || TextBoxExpectedCompletionDate.Text.Length == 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please select a date for the Date Created, Date Assigned, and Expected Completion Date fields.');", true); } else { using (SqlConnection conn = new SqlConnection(g_sqlConn)) { try { Connect(conn); using (SqlCommand cmd = new SqlCommand("insert into tblACtionItems(UserID,ProjectID,Name,Description,DateCreated,DateAssigned,ExpectedCompletionDate)" + " values(@UserID, @ProjectID, @Name, @Description,@DateCreated,@DateAssigned, @ExpCompletionDate)", 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("@DateCreated", TextBoxDateCreated.Text); cmd.Parameters.AddWithValue("@DateAssigned", TextBoxDateAssigned.Text); cmd.Parameters.AddWithValue("@ExpCompletionDate", TextBoxExpectedCompletionDate.Text); cmd.ExecuteNonQuery(); LoadDefaultStatusListBox(); } } 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 ActionItemID FROM tblActionItems WHERE Name='{0}' AND UserID={1} AND ProjectID={2}", TextBoxName.Text, Session["_CurrentUserID"], Session["_CurrentProjID"]), conn)) { SqlDataReader sdr = cmd2.ExecuteReader(); while (sdr.Read()) { Session["_CurrentActionItemID"] = sdr[0].ToString(); } sdr.Close(); } Disconnect(conn); } DropDownListActItemSelect.Items.Clear(); DropDownListActItemSelect.DataBind(); GridViewActionItemsList.DataBind(); GridViewAssociateResource.DataBind(); ImageButtonClearActCompl.Visible = true; ImageButtonClearResource.Visible = true; TextBoxActualCompletionDate.Visible = true; LabelActComplDate.Visible = true; ImageButtonActualCompletionDate.Visible = true; ButtonDelete.Visible = true; ButtonSave.Visible = true; LabelResourceAssigned.Visible = true; TextBoxResourceAssigned.Visible = true; ButtonSelectResource.Visible = true; LabelStatus.Visible = true; TextBoxStatus.Visible = true; ButtonAddStatus.Visible = true; ButtonRemoveStatus.Visible = true; ListBoxStatus.Visible = true; ImageButtonStatusMoveUp.Visible = true; ImageButtonStatusMoveDown.Visible = true; LabelStatusDescr.Visible = true; TextBoxStatusDescription.Visible = true; LabelLastUpdated.Visible = true; TextBoxLastUpdated.Visible = true; } }