Ejemplo n.º 1
0
    protected void GrdRegistration_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        Organisation org = OrganisationDB.GetByID(GetFormID());

        if (org == null)
        {
            HideTableAndSetErrorMessage("", "Invalid URL Parameters");
            return;
        }

        DataTable dt       = Session["registerstafftoorg_data"] as DataTable;
        bool      tblEmpty = (dt.Rows.Count == 1 && dt.Rows[0][0] == DBNull.Value);

        if (!tblEmpty && e.Row.RowType == DataControlRowType.DataRow)
        {
            Label     lblId     = (Label)e.Row.FindControl("lblId");
            DataRow[] foundRows = dt.Select("register_staff_id=" + lblId.Text);
            DataRow   thisRow   = foundRows[0];


            DropDownList ddlStaff = (DropDownList)e.Row.FindControl("ddlStaff");
            if (ddlStaff != null)
            {
                Staff[]   incList_orig = RegisterStaffDB.GetStaffOf(org.OrganisationID);
                Staff[]   incList      = Staff.RemoveByID(incList_orig, Convert.ToInt32(thisRow["staff_id"]));
                DataTable staff        = StaffDB.GetDataTable_AllNotInc(incList);
                staff.DefaultView.Sort = "surname ASC";
                foreach (DataRowView row in staff.DefaultView)
                {
                    ddlStaff.Items.Add(new ListItem(row["surname"].ToString() + ", " + row["firstname"].ToString() + " " + row["middlename"].ToString(), row["staff_id"].ToString()));
                }
                ddlStaff.SelectedValue = thisRow["staff_id"].ToString();
            }

            ImageButton btnDelete = (ImageButton)e.Row.FindControl("btnDelete");
            if (btnDelete != null)
            {
                bool is_deleted = Convert.ToBoolean(thisRow["registration_is_deleted"]);
                if (is_deleted)
                {
                    btnDelete.CommandName   = "_UnDelete";
                    btnDelete.ImageUrl      = "~/images/tick-24.png";
                    btnDelete.AlternateText = "UnDelete";
                    btnDelete.ToolTip       = "UnDelete";

                    btnDelete.Visible = false;
                }
            }

            Utilities.AddConfirmationBox(e);
            if ((e.Row.RowState & DataControlRowState.Edit) > 0)
            {
                Utilities.SetEditRowBackColour(e, System.Drawing.Color.LightGoldenrodYellow);
            }
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            DropDownList ddlStaff = (DropDownList)e.Row.FindControl("ddlNewStaff");
            if (ddlStaff != null)
            {
                Staff[]   incList = RegisterStaffDB.GetStaffOf(org.OrganisationID);
                DataTable staff   = StaffDB.GetDataTable_AllNotInc(incList);
                staff.DefaultView.Sort = "surname ASC";
                foreach (DataRowView row in staff.DefaultView)
                {
                    ddlStaff.Items.Add(new ListItem(row["surname"].ToString() + ", " + row["firstname"].ToString() + " " + row["middlename"].ToString(), row["staff_id"].ToString()));
                }

                if (staff.Rows.Count == 0)
                {
                    hideFotter = true;
                }
            }
        }
    }