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;
        }
    }
Exemple #2
0
    protected void FormViewOrganismType_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        TextBox txtOrganismType         = (TextBox)formViewOrganismType.FindControl("txtOrganismType");
        OrganismTypeActionStatus status = Validate(txtOrganismType.Text, actionType.update);

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

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

            OrganismTypeBLL organismTypeBLL = new OrganismTypeBLL();
            OrganismType    organismType    = organismTypeBLL.GetOrganismTyeByOrganismTypeId2((int)e.Keys["OrganismTypeId"]);

            foreach (var prop in props)
            {
                if (("System.String,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(organismType, null);
                    }
                }
            }
        }
        else
        {
            ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status));
            e.Cancel        = true;
        }
    }
Exemple #3
0
    public string GetOrganismTypeName(int organismTypeID)
    {
        OrganismTypeBLL organismTypeBLL = new OrganismTypeBLL();
        OrganismType    organismType    = organismTypeBLL.GetOrganismTypeByOrganismTypeID(organismTypeID);

        return(organismType.OrganismTypeName);
    }
Exemple #4
0
    private static OrganismTypeActionStatus Validate(string organismType, actionType act)
    {
        OrganismTypeBLL     organismTypeBLL = new OrganismTypeBLL();
        List <OrganismType> organismTypes   = organismTypeBLL.GetOrganismTypeByFilter(organismType.Trim());

        if (organismTypes.Count > 0 && act == actionType.insert)
        {
            return(OrganismTypeActionStatus.Duplicate);
        }
        else if (organismTypes.Count > 0 && organismTypes[0].OrganismTypeName == organismType && act == actionType.update)
        {
            return(OrganismTypeActionStatus.Duplicate);
        }
        else
        {
            return(OrganismTypeActionStatus.Success);
        }
    }
Exemple #5
0
    protected void ButtonDeleteSelected_Click(object sender, System.EventArgs e)
    {
        try
        {
            // Create a List to hold the OrganismTypeID values to delete
            List <Int32> OrganismTypeIDsToDelete = new List <Int32>();

            // Iterate through the OrganismTypes.Rows property
            foreach (GridViewRow row in gridViewOrganismTypes.Rows)
            {
                // Access the CheckBox
                CheckBox cb = (CheckBox)(row.FindControl("chkOrganismTypeSelector"));
                if (cb != null && cb.Checked)
                {
                    // Save the OrganismTypeID value for deletion
                    // First, get the OrganismTypeID for the selected row
                    Int32           OrganismTypeID  = (Int32)gridViewOrganismTypes.DataKeys[row.RowIndex].Value;
                    OrganismTypeBLL OrganismTypeBLL = new OrganismTypeBLL();
                    Eisk.BusinessEntities.OrganismType OrganismType = OrganismTypeBLL.GetOrganismTypeByOrganismTypeID(OrganismTypeID);

                    // Add it to the List...
                    OrganismTypeIDsToDelete.Add(OrganismTypeID);

                    // Add a confirmation message
                    ltlMessage.Text += String.Format(MessageFormatter.GetFormattedSuccessMessage("Delete successful. Organism Type <b>{0}</b> has been deleted"), OrganismType.OrganismTypeName);
                }
            }

            //perform the actual delete
            new OrganismTypeBLL().DeleteOrganismTypes(OrganismTypeIDsToDelete);
        }
        catch (Exception ex)
        {
            ltlMessage.Text = ExceptionManager.DoLogAndGetFriendlyMessageForException(ex);
        }

        //binding the grid
        gridViewOrganismTypes.PageIndex = 0;
        gridViewOrganismTypes.DataBind();
    }
Exemple #6
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;
        }
    }
    protected void btnExportData_Click(object sender, EventArgs e)
    {
        string              projectID      = (Page.RouteData.Values["project_id"] as string);
        List <ExportData>   ExportDataList = new OrganismBLL().GetExportData("", Convert.ToInt32(projectID));
        List <OrganismType> OrganismTypes  = new OrganismTypeBLL().GetAllOrganismTypesList();
        Project             project        = new ProjectBLL().GetProjectByProjectID(Convert.ToInt32(projectID));

        string name = Translate(project.ProjectName);

        name = Translate(name);

        string path = System.Web.HttpContext.Current.Server.MapPath(@System.Configuration.ConfigurationManager.AppSettings["ProjectsRoot"]) + projectID.ToString();

        // check folder exists
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
            System.IO.File.WriteAllText(path + "/" + name + ".xlsx", "");
        }

        FileInfo newFile = new FileInfo(path + @"\" + name + ".xlsx");

        File.Delete(path + @"\" + name + ".xlsx");
        using (ExcelPackage pck = new ExcelPackage(newFile))
        {
            foreach (OrganismType OrganismType in OrganismTypes)
            {
                List <ExportData> OrganismTypeList = ExportDataList.Where(instance => instance.OrganismTypeID == OrganismType.OrganismTypeID).ToList();

                if (OrganismTypeList.Count > 0)
                {
                    //Add the Content sheet
                    var ws = pck.Workbook.Worksheets.Add(OrganismType.OrganismTypeName);

                    ws.Cells["A1"].Value                     = OrganismType.OrganismTypeName;
                    ws.Cells["A1"].Style.Font.Bold           = true;
                    ws.Cells["A1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                    ws.Cells["A1:B1"].Merge                  = true;
                    ws.Cells["A1:B1"].Style.Border.BorderAround(ExcelBorderStyle.Medium);

                    //Headers
                    ws.Cells["A2"].Value = "Common Name";
                    ws.Cells["A2"].Style.Border.BorderAround(ExcelBorderStyle.Medium);
                    ws.Cells["B2"].Value = "Scientific Name";
                    ws.Cells["B2"].Style.Border.BorderAround(ExcelBorderStyle.Medium);
                    ws.Cells["A2:B2"].Style.Font.Bold = true;

                    ws.Column(1).Width = 35.00d;
                    ws.Column(2).Width = 35.00d;

                    int row = 3;
                    foreach (ExportData Organism in OrganismTypeList)
                    {
                        ws.Cells["A" + row].Value = Organism.CommonName;
                        ws.Cells["A" + row].Style.Border.BorderAround(ExcelBorderStyle.Thin);
                        ws.Cells["A" + row].Style.Border.Right.Style = ExcelBorderStyle.Medium;
                        ws.Cells["B" + row].Value = Organism.ScientificName;
                        ws.Cells["B" + row].Style.Border.BorderAround(ExcelBorderStyle.Thin);
                        row++;
                    }

                    ws.Cells["A3:B" + (row - 1)].Style.Border.BorderAround(ExcelBorderStyle.Medium);
                }
            }
            pck.Save();
            pck.Dispose();
        }

        System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
        response.ClearContent();
        response.Clear();
        response.ContentType = "application/vnd.ms-excel";
        response.AddHeader("Content-Disposition", "attachment; filename=" + name + ".xlsx");
        response.TransmitFile(path + @"/" + name + ".xlsx");
        response.End();
    }