Beispiel #1
0
    public string GetErrorMessage(OrganismActionStatus status)
    {
        switch (status)
        {
        case OrganismActionStatus.DuplicateCommonName:
            return("Organism already exists. Please enter a different one.");

        case OrganismActionStatus.DuplicateScientificName:
            return("Organism Scientific Name already exists. Please enter a different one.");

        default:
            return("Error");
        }
    }
Beispiel #2
0
    protected void FormViewOrganism_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        TextBox              txtCommonName     = (TextBox)formViewOrganism.FindControl("txtCommonName");
        TextBox              txtScientificName = (TextBox)formViewOrganism.FindControl("txtScientificName");
        DropDownList         ddlOrganismType   = (DropDownList)formViewOrganism.FindControl("ddlOrganismType");
        OrganismActionStatus status            = Validate(txtCommonName.Text, txtScientificName.Text, Convert.ToInt32(ddlOrganismType.SelectedValue), actionType.insert);

        if (status == OrganismActionStatus.Success)
        {
            e.Values["OrganismTypeID"] = ddlOrganismType.SelectedValue;
            e.Values["CreatedDate"]    = DateTime.Now;
            e.Values["EditedDate"]     = DateTime.Now;
        }
        else
        {
            ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status));
            e.Cancel        = true;
        }
    }
Beispiel #3
0
    protected void FormViewOrganism_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        TextBox              txtCommonName     = (TextBox)formViewOrganism.FindControl("txtCommonName");
        TextBox              txtScientificName = (TextBox)formViewOrganism.FindControl("txtScientificName");
        DropDownList         ddlOrganismType   = (DropDownList)formViewOrganism.FindControl("ddlOrganismType");
        OrganismActionStatus status            = Validate(txtCommonName.Text, txtScientificName.Text, Convert.ToInt32(ddlOrganismType.SelectedValue), actionType.update);

        if (status == OrganismActionStatus.Success)
        {
            Type           myType = (typeof(Organism));
            PropertyInfo[] props  = myType.GetProperties();

            string[] arrNewValues = new string[e.NewValues.Keys.Count];
            e.NewValues.Keys.CopyTo(arrNewValues, 0);

            OrganismBLL     organismBLL     = new OrganismBLL();
            OrganismTypeBLL organismTypeBLL = new OrganismTypeBLL();
            OrganismType    organismType    = organismTypeBLL.GetOrganismTypeByOrganismTypeID(Convert.ToInt32(ddlOrganismType.SelectedValue));
            Organism        organism        = organismBLL.GetOrganismByOrganismId2((int)e.Keys["OrganismId"]);

            foreach (var prop in props)
            {
                if (("System.String,System.Int32,System.Int,System.DateTime,System.Guid").IndexOf((prop.PropertyType).FullName) >= 0) // Si la propiedad es de tipo Guid, String, Int o DateTime
                {
                    if (!arrNewValues.Contains(prop.Name))
                    {
                        e.NewValues[prop.Name] = prop.GetValue(organism, null);
                    }
                }
            }

            e.NewValues["OrganismTypeID"]            = organismType.OrganismTypeID;
            Page.RouteData.Values["organismtype_id"] = organismType.OrganismTypeID.ToString();
        }
        else
        {
            ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status));
            e.Cancel        = true;
        }
    }