コード例 #1
0
    protected void FormViewCommonName_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        TextBox txtCommonName         = (TextBox)formViewCommonName.FindControl("txtCommonName");
        TextBox txtScientificName     = (TextBox)formViewCommonName.FindControl("txtScientificName");
        CommonNameActionStatus status = Validate(txtCommonName.Text, txtScientificName.Text, actionType.insert);

        if (status == CommonNameActionStatus.Success)
        {
            User user = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name);

            int groupID = new Group_UsersBLL().GetGroup_UsersByUserID(user.UserID)[0].GroupID;

            CommonName     commonName     = new CommonNameBLL().GetOrCreateCommonName(txtCommonName.Text, user);
            ScientificName scientificName = new ScientificNameBLL().GetScientificNameByScientificNameID(Convert.ToInt32(Page.RouteData.Values["scientificname_id"] as string));
            OrganismType   organismType   = new OrganismTypeBLL().GetOrganismTypeByOrganismTypeID(2);
            Group          group          = new GroupBLL().GetGroupByGroupID(groupID);

            e.Values["CommonNameID"]     = commonName.CommonNameID;
            e.Values["ScientificNameID"] = scientificName.ScientificNameID;
            e.Values["OrganismTypeID"]   = organismType.OrganismTypeID;
            e.Values["GroupID"]          = group.GroupID;

            e.Values["CreatedDate"]   = DateTime.Now;
            e.Values["CreatorUserID"] = user.UserID;
            e.Values["EditedDate"]    = DateTime.Now;
            e.Values["EditorUserID"]  = user.UserID;
        }
        else
        {
            ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status));
            e.Cancel        = true;
        }
    }
コード例 #2
0
    protected void FormViewUser_DataBound(object sender, System.EventArgs e)
    {
        if (Page.Request.UrlReferrer != null)
        {
            if (Page.Request.UrlReferrer.AbsolutePath.Contains("new") && !IsPostBack)
            {
                ltlMessage.Text = MessageFormatter.GetFormattedSuccessMessage("Insert successful");
            }
        }

        string userID = Page.RouteData.Values["User_id"] as string;

        if (userID != null && userID != "0")
        {
            List <Role_Users>  role_Users  = new Role_UsersBLL().GetRole_UsersByUserID(new Guid(userID));
            List <Group_Users> group_Users = new Group_UsersBLL().GetGroup_UsersByUserID(new Guid(userID));

            DropDownList ddlRoles = (DropDownList)formViewUser.FindControl("ddlRoles");
            if (ddlRoles != null)
            {
                ddlRoles.SelectedValue = role_Users[0].RoleID.ToString();
            }

            DropDownList ddlGroups = (DropDownList)formViewUser.FindControl("ddlGroups");
            if (ddlGroups != null)
            {
                ddlGroups.SelectedValue = group_Users[0].GroupID.ToString();
            }
        }
    }
コード例 #3
0
    private static CommonNameActionStatus Validate(string commonName, string scientificName, actionType act)
    {
        User user = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name);

        int groupID = new Group_UsersBLL().GetGroup_UsersByUserID(user.UserID)[0].GroupID;

        Organism organism = new OrganismBLL().GetOrganismByScientificNameCommonName(scientificName.Trim(), commonName.Trim());

        if (organism != null && organism.GroupID == groupID)
        {
            if (act == actionType.insert)
            {
                return(CommonNameActionStatus.Duplicate);
            }
            else
            {
                return(CommonNameActionStatus.Success);
            }
        }
        else
        {
            return(CommonNameActionStatus.Success);
        }
    }