Example #1
0
        //private void BindGrid(ProjectTrackerContainer context, GridView GridViewTimeEntry)
        //{
        //    int bioStatId = Convert.ToInt32(ddlBioStat.SelectedValue);

        //    var query = context.TimeEntries
        //                .Join(context.Projects
        //                    , t => t.ProjectId
        //                    , p => p.Id
        //                    , (t, p) => new { t, p.Title }
        //                    )
        //                .Join(context.ServiceTypes
        //                    , tt => tt.t.ServiceTypeId
        //                    , s => s.Id
        //                    , (tt, s) => new { tt, s.Name }
        //                    )
        //                .Join(context.Date1
        //                    , ttt => ttt.tt.t.DateKey
        //                    , d => d.DateKey
        //                    , (ttt, d) => new {
        //                        ttt.tt.t.Id
        //                        ,ttt.tt.t.ProjectId
        //                        , ttt.tt.Title
        //                        , ttt.Name
        //                        , d.Date
        //                        , ttt.tt.t.Duration
        //                        , ttt.tt.t.BioStatId
        //                    }
        //                )
        //                .Where(a => a.BioStatId == bioStatId);

        //    GridViewTimeEntry.DataSource = query.ToList();
        //    GridViewTimeEntry.DataBind();
        //}

        private int GetDate(string dateEntered)
        {
            int dateKey = -1;

            using (ProjectTrackerContainer context = new ProjectTrackerContainer())
            {
                DateTime _dateEntered = Convert.ToDateTime(dateEntered);

                var entryDate = context.Date1
                                .First(d => d.Date == _dateEntered);

                if (entryDate != null)
                {
                    dateKey = entryDate.DateKey;
                }
            }

            return(dateKey);
        }
Example #2
0
        protected void ddlBioStat_Changed(Object sender, EventArgs e)
        {
            int biostatId;

            Int32.TryParse(ddlBioStat.SelectedValue, out biostatId);

            if (biostatId > 0)
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    var biostat = context.BioStats.First(x => x.Id == biostatId);

                    if (biostat != null)
                    {
                        var projects = context.ProjectBioStats
                                       .Where(p => p.BioStats_Id == biostat.Id);

                        if (projects.Count() > 0)
                        {
                            IDictionary <int, string> dropDownSource = new Dictionary <int, string>();

                            dropDownSource = projects
                                             .OrderByDescending(d => d.Project.Invest.Id)
                                             .Select(x => new { x.Project.Invest.Id, FullName = x.Project.Invest.FirstName + " " + x.Project.Invest.LastName })
                                             .Distinct()
                                             .ToDictionary(c => c.Id, c => c.FullName);
                            BindDropDownList(ddlPI, dropDownSource, string.Empty);

                            dropDownSource = projects
                                             .OrderByDescending(d => d.Project.Id)
                                             .Select(x => new { x.Project.Id, FullName = x.Project.Id + " " + x.Project.Title })
                                             .ToDictionary(c => c.Id, c => c.FullName);

                            BindDropDownList(ddlProject, dropDownSource, string.Empty);

                            //BindGrid(context, GridViewTimeEntry);
                            BindGridView();
                        }
                    }
                }
            }
        }
Example #3
0
        //protected void gvPhase_RowDeleting(object sender, GridViewDeleteEventArgs e)
        //{
        //    GridViewRow row = gvPhase.Rows[e.RowIndex];

        //    BindgvPhase(e.RowIndex);
        //}

        //protected void btnAddPhase_Click(object sender, EventArgs e)
        //{
        //    BindgvPhase(-1);
        //}

        //private void BindGridViewProjectEffort(int projectId)
        //{
        //    System.Data.DataTable dummy = new System.Data.DataTable();
        //    dummy.Columns.Add("InvoiceId");
        //    dummy.Columns.Add("ReqNum");
        //    dummy.Columns.Add("ReqDate");
        //    dummy.Columns.Add("FromDate");
        //    dummy.Columns.Add("ToDate");
        //    dummy.Columns.Add("PhdReq");
        //    dummy.Columns.Add("PhdSpt");
        //    dummy.Columns.Add("MsReq");
        //    dummy.Columns.Add("MsSpt");
        //    dummy.Rows.Add();
        //    GridViewProjectEffort.DataSource = dummy;
        //    GridViewProjectEffort.DataBind();

        //    GridViewProjectEffort.Rows[0].Cells.Clear();
        //}


        protected void GridViewTimeEntry_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridViewRow row = GridViewTimeEntry.Rows[e.RowIndex];

            Label lblId = row.FindControl("lblId") as Label;

            if (lblId != null)
            {
                bool validDate = ValidateDate();

                if (validDate)
                {
                    using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                    {
                        int       id = Convert.ToInt32(lblId.Text);
                        TimeEntry te = context.TimeEntries.First(t => t.Id == id);
                        context.TimeEntries.Remove(te);
                        context.SaveChanges();
                    }

                    BindGridView();

                    if (GridViewTimeEntry.Rows.Count > 0)
                    {
                        GridViewTimeEntry.SelectRow(GridViewTimeEntry.Rows.Count - 1);
                        GridViewTimeEntry.SelectedRow.Focus();
                    }
                }
                else
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    sb.Append(@"<script type='text/javascript'>");

                    sb.Append("alert('Can not change history input.');");

                    sb.Append(@"</script>");
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "CantDeleteScript", sb.ToString(), false);
                    //Response.Write("<script>alert('Can not delete history input.');</script>");
                }
            }
        }
Example #4
0
        //ddlBiostat_Changed
        protected void ddlBiostat_Changed(Object sender, EventArgs e)
        {
            int bioStatId;

            Int32.TryParse(ddlBiostat.SelectedValue, out bioStatId);

            if (bioStatId > 0)
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    IDictionary <int, string> dropDownSource = new Dictionary <int, string>();

                    dropDownSource = context.Publications
                                     .Join(context.PublicationBioStats, p => p.Id, b => b.Publications_Id, (p, b) => new { p.Id, p.Title, b.BioStats_Id })
                                     .Where(i => i.BioStats_Id == bioStatId)
                                     .ToDictionary(c => c.Id, c => c.Title);

                    BindDropDownList(ddlPublication, dropDownSource, string.Empty);
                }
            }
        }
Example #5
0
        protected void ddlPublication_Changed(Object sender, EventArgs e)
        {
            int pubId;

            Int32.TryParse(ddlPublication.SelectedValue, out pubId);

            if (pubId > 0)
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    var pubHist = context.PubHistories
                                  .Join(context.Publications, h => h.PublicationId, p => p.Id, (h, p) => new { h })
                                  //.Join(context.PublishStatus, ph => ph.h.StatusId, ps => ps.Id, (ph, ps) => new { ph.h.Id, ps.Name, ph.h.StartDate, ph.h.EndDate, ph.h.Creator, ph.h.PublicationId })
                                  .Where(i => i.h.PublicationId == pubId)
                                  .ToList();

                    GridViewHistory.DataSource = pubHist;
                    GridViewHistory.DataBind();
                }
            }
        }
        protected void ddlConference_Changed(Object sender, EventArgs e)
        {
            int  id     = 0;
            bool result = Int32.TryParse(ddlConference.SelectedValue, out id);

            if (id > 0)
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    var conf = context.Conferences.First(c => c.Id == id);

                    SetConference(conf);
                }
            }
            else
            {
                SetConference(null);
            }

            ddlConference.Focus();
        }
Example #7
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (ValidateControl())
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    int pubId = Convert.ToInt32(ddlPublication.SelectedValue);

                    PubHistory newHist = new PubHistory()
                    {
                        PublicationId = pubId,
                        StatusId      = PubStatus,
                        PaperDate     = Convert.ToDateTime(TextBoxStartDate.Text),
                        Creator       = Page.User.Identity.Name,
                        CreateDate    = Convert.ToDateTime(HiddenFieldCurrentDate.Value)
                    };

                    context.PubHistories.Add(newHist);

                    context.SaveChanges();

                    Response.Write("<script>alert('Publication History Saved.');</script>");

                    var pubHist = context.PubHistories
                                  .Join(context.Publications, h => h.PublicationId, p => p.Id, (h, p) => new { h })
                                  //.Join(context.PublishStatus, ph => ph.h.StatusId, ps => ps.Id, (ph, ps) => new { ph.h.Id, ps.Name, ph.h.PaperDate,  ph.h.Creator, ph.h.PublicationId })
                                  .Where(i => i.h.PublicationId == pubId)
                                  .ToList();

                    GridViewHistory.DataSource = pubHist;
                    GridViewHistory.DataBind();
                }
            }
            else
            {
                Response.Write("<script>alert('Please check the data entered.');</script>");
            }
        }
Example #8
0
        private void UpdateTimeEntry()
        {
            int id;

            if (Int32.TryParse(lblEditId.Text, out id))
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    TimeEntry timeEntry = context.TimeEntries.First(t => t.Id == id);

                    if (timeEntry != null)
                    {
                        timeEntry.ServiceTypeId = Convert.ToInt32(ddlEditServiceType.SelectedValue);
                        timeEntry.DateKey       = GetDate(TextBoxEditDate.Text);
                        timeEntry.Duration      = Convert.ToDecimal(TextBoxEditTime.Text);

                        context.SaveChanges();
                    }
                }

                BindGridView();
            }
        }
Example #9
0
        /// <summary>
        /// (Currently NOT being used). Obtains all "Client Request" entries.
        /// </summary>
        /// <returns></returns>
        private DataTable GetClientRqstAll()
        {
            DataTable dt = new DataTable("clientRqstTable");

            dt.Columns.Add("Id", System.Type.GetType("System.Int32"));
            dt.Columns.Add("FirstName", System.Type.GetType("System.String"));
            dt.Columns.Add("LastName", System.Type.GetType("System.String"));
            dt.Columns.Add("ProjectTitle", System.Type.GetType("System.String"));
            dt.Columns.Add("CreateDate", System.Type.GetType("System.String"));
            dt.Columns.Add("Status", System.Type.GetType("System.String"));

            using (ProjectTrackerContainer db = new ProjectTrackerContainer())
            {
                var query = db.ClientRequest
                            .Select(t => new { t.Id, t.FirstName, t.LastName, t.ProjectTitle, t.CreationDate, t.RequestStatus })
                            .OrderByDescending(t => t.Id);


                foreach (var p in query.OrderByDescending(p => p.Id).ToList())
                {
                    DataRow row = dt.NewRow();

                    row[0] = p.Id;
                    row[1] = p.FirstName;
                    row[2] = p.LastName;
                    row[3] = p.ProjectTitle;
                    row[4] = p.CreationDate != null?Convert.ToDateTime(p.CreationDate).ToShortDateString() : "";

                    row[5] = p.RequestStatus;

                    dt.Rows.Add(row);
                }
            }

            return(dt);
        }
Example #10
0
        public static List <ProjectPI> GetProjectList(int biostatId, int piId)
        {
            List <ProjectPI> lstProject = new List <ProjectPI>();

            if (biostatId > 0)
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    //var projects = context.ProjectBioStats
                    //               .OrderByDescending(d => d.Project.Id)
                    //               .Where(p => p.BioStats_Id == biostatId && (p.Project.ProjectCompletionDate == null || p.Project.ProjectCompletionDate > _leadDate));
                    var projects = context.vwProjectBiostat.Where(v => v.BiostatId == biostatId);

                    if (piId > 0)
                    {
                        projects = projects
                                   .OrderByDescending(d => d.ProjectId)
                                   .Where(p => p.InvestId == piId);
                    }

                    foreach (var p in projects.ToList())
                    {
                        lstProject.Add(new ProjectPI()
                        {
                            Id          = p.ProjectId,
                            Title       = p.Title,
                            PIFirstName = string.Empty,
                            PILastName  = string.Empty,
                            InitialDate = string.Empty
                        });
                    }
                }
            }

            return(lstProject);
        }
Example #11
0
        /// <summary>
        /// Creates new instance of PI.
        ///
        ///     - If a new PI is being entered, the program checks to see if there is any exisitng PI with the
        ///     same first as last name.  If the name is new altogether, a new PI is created into the database
        ///     and an email is sent to the tracking team for review.
        ///
        ///     - If an existing PI is being saved, the program checks PI already has been reviewed by the
        ///     tracking team.  If the tracking team has already reviewed the program, the program halts the
        ///     user from saving the newly entered information.  Only the tracking team can make existing
        ///     changes to the PI form after approval.
        /// </summary>
        /// <param name="investId">PI Id in database.  0 indicates new PI, otherwise exisiting PI.</param>
        /// <returns>True if okay to save, False if unable to save.</returns>
        private bool SetPIValue(int investId)
        {
            using (ProjectTrackerContainer db = new ProjectTrackerContainer())
            {
                Invests invest;

                if (investId == 0) // new PI
                {
                    if (!TextBoxFirstName.Text.Equals(string.Empty) && !TextBoxLastName.Text.Equals(string.Empty))
                    {
                        invest = new Invests()
                        {
                            FirstName      = TextBoxFirstName.Text.Trim(),
                            LastName       = TextBoxLastName.Text.Trim(),
                            Email          = TextBoxEmail.Text,
                            Phone          = TextBoxPhone.Text,
                            AltEmail       = TextBoxAltEmail.Text,
                            AltPhone       = TextBoxAltPhone.Text,
                            Notes          = txtNotes.InnerText,
                            InvestStatusId = Convert.ToInt32(ddlStatus.SelectedValue),
                            IsApproved     = chkApproved.Checked,
                            //IsPilot = chkPilot.Checked
                        };

                        //check existing PI with same name
                        if (db.Invests.Any(i => i.FirstName == invest.FirstName && i.LastName == invest.LastName))
                        {
                            return(false);
                        }

                        if (ddlStatus.SelectedItem.Text == "Non-Hawaii Client" || ddlStatus.SelectedItem.Text == "UH Student")
                        {
                            invest.NonHawaiiClient = TextBoxNonHawaii.Text;
                        }

                        TextBox txtNonUHOther = GridViewNonUH.FooterRow.FindControl("txtNonUHOther") as TextBox;
                        invest.NonUHClient = txtNonUHOther.Text;

                        TextBox txtDegreeOther = GridViewDegree.FooterRow.FindControl("txtDegreeOther") as TextBox;
                        invest.OtherDegree = txtDegreeOther.Text;

                        TextBox txtCommunityPartnerOther = GridViewCommunityPartner.FooterRow.FindControl("txtCommunityPartnerOther") as TextBox;
                        invest.OtherCommunityPartner = txtCommunityPartnerOther.Text;

                        db.Invests.Add(invest);
                        db.SaveChanges();

                        investId = invest.Id;

                        //PageUtility.SendNotificationByEmail("PI", investId, User.Identity.Name);
                        SendNotificationEmail(invest.Id);
                    }
                }
                else // existing PI
                {
                    invest = db.Invests.First(i => i.Id == investId);

                    if (!Page.User.IsInRole("Admin") && invest.IsApproved)
                    {
                        //Response.Write("<script>alert('This PI has been approved, please contact with admin group for any changes.');</script>");
                        return(false);
                    }
                    else
                    {
                        if (invest != null && !TextBoxFirstName.Text.Equals(string.Empty) && !TextBoxLastName.Text.Equals(string.Empty))
                        {
                            invest.FirstName      = TextBoxFirstName.Text.Trim();
                            invest.LastName       = TextBoxLastName.Text.Trim();
                            invest.Email          = TextBoxEmail.Text;
                            invest.Phone          = TextBoxPhone.Text;
                            invest.AltEmail       = TextBoxAltEmail.Text;
                            invest.AltPhone       = TextBoxAltPhone.Text;
                            invest.Notes          = txtNotes.InnerText;
                            invest.InvestStatusId = Convert.ToInt32(ddlStatus.SelectedValue);

                            if (ddlStatus.SelectedItem.Text == "Non-Hawaii Client" || ddlStatus.SelectedItem.Text == "UH Student")
                            {
                                invest.NonHawaiiClient = TextBoxNonHawaii.Text;
                            }

                            TextBox txtNonUHOther = GridViewNonUH.FooterRow.FindControl("txtNonUHOther") as TextBox;
                            invest.NonUHClient = txtNonUHOther.Text;

                            TextBox txtDegreeOther = GridViewDegree.FooterRow.FindControl("txtDegreeOther") as TextBox;
                            invest.OtherDegree = txtDegreeOther.Text;

                            TextBox txtCommunityPartnerOther = GridViewCommunityPartner.FooterRow.FindControl("txtCommunityPartnerOther") as TextBox;
                            invest.OtherCommunityPartner = txtCommunityPartnerOther.Text;

                            invest.IsApproved = chkApproved.Checked;
                            //invest.IsPilot = chkPilot.Checked;

                            db.SaveChanges();
                        }
                    }
                }

                #region update PI affiliations
                List <int> newAffliIdList = GetInvestJabsomAffil();

                List <int> prevAffilIdList = new List <int>();

                ICollection <JabsomAffil> jabsomAffils = db.Invests.First(i => i.Id == investId).JabsomAffils;
                foreach (JabsomAffil affil in jabsomAffils)
                {
                    prevAffilIdList.Add(affil.Id);
                }

                var newNotPrevAffilList = newAffliIdList.Except(prevAffilIdList).ToList();
                var prevNotNewAffilList = prevAffilIdList.Except(newAffliIdList).ToList();

                if (prevNotNewAffilList.Count > 0)
                {
                    foreach (var expiredId in prevNotNewAffilList)
                    {
                        //project.ProjectBioStats.First(b => b.BioStats_Id == expiredId).EndDate = DateTime.Parse(_currentDate);
                        var jabsomAffil = jabsomAffils.First(j => j.Id == expiredId);
                        jabsomAffils.Remove(jabsomAffil);
                    }
                }

                if (newNotPrevAffilList.Count > 0)
                {
                    foreach (var newId in newNotPrevAffilList)
                    {
                        var jabsomAffil = db.JabsomAffils.First(j => j.Id == newId);
                        jabsomAffils.Add(jabsomAffil);
                    }
                }

                db.SaveChanges();
                #endregion
            }

            return(true);
        }
Example #12
0
        private void BindControl()
        {
            string userName = Page.User.Identity.Name;

            if (!userName.Equals(string.Empty))
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    var dbQuery = ((IObjectContextAdapter)context).ObjectContext.CreateQuery <DateTime>("CurrentDateTime() ");
                    HiddenFieldCurrentDate.Value = dbQuery.AsEnumerable().First().ToShortDateString();
                    DateTime currentDate = Convert.ToDateTime(HiddenFieldCurrentDate.Value);


                    IDictionary <int, string> dropDownSource = new Dictionary <int, string>();

                    //ddlBioStat
                    if (Page.User.IsInRole("Admin"))
                    {
                        dropDownSource = context.BioStats
                                         .OrderBy(b => b.Id)
                                         .ToDictionary(c => c.Id, c => c.Name);

                        BindDropDownList(ddlBioStat, dropDownSource, string.Empty);
                    }
                    else
                    {
                        var biostat = context.BioStats
                                      .First(b => b.LogonId == userName);

                        dropDownSource.Add(biostat.Id, biostat.Name);

                        BindDropDownList(ddlBioStat, dropDownSource, null);
                    }

                    //ddlProject
                    if (Page.User.IsInRole("Admin"))
                    {
                        dropDownSource = context.Projects
                                         .OrderByDescending(d => d.Id)
                                         .Select(x => new { x.Id, FullName = x.Id + " " + x.Title })
                                         .ToDictionary(c => c.Id, c => c.FullName);
                    }
                    else
                    {
                        int biostatId;
                        Int32.TryParse(ddlBioStat.SelectedValue, out biostatId);

                        if (biostatId > 0)
                        {
                            var projects = context.ProjectBioStats
                                           .Where(p => p.BioStats_Id == biostatId);

                            if (projects.Count() > 0)
                            {
                                dropDownSource = projects
                                                 .OrderByDescending(d => d.Project.Invest.Id)
                                                 .Select(x => new { x.Project.Invest.Id, FullName = x.Project.Invest.FirstName + " " + x.Project.Invest.LastName })
                                                 .Distinct()
                                                 .ToDictionary(c => c.Id, c => c.FullName);
                                BindDropDownList(ddlPI, dropDownSource, string.Empty);

                                dropDownSource = projects
                                                 .OrderByDescending(d => d.Project.Id)
                                                 .Select(x => new { x.Project.Id, FullName = x.Project.Id + " " + x.Project.Title })
                                                 .ToDictionary(c => c.Id, c => c.FullName);
                            }
                        }
                    }

                    BindDropDownList(ddlProject, dropDownSource, string.Empty);

                    //ddlServiceType and ddlEditServiceType
                    dropDownSource = context.ServiceTypes
                                     .OrderBy(b => b.Id)
                                     .Select(x => new { x.Id, x.Name })
                                     .ToDictionary(c => c.Id, c => c.Name);

                    BindDropDownList(ddlServiceType, dropDownSource, string.Empty);

                    BindDropDownList(ddlEditServiceType, dropDownSource, string.Empty);


                    TextBoxSubmitDate.Text = HiddenFieldCurrentDate.Value;

                    //ddlMonth
                    int    currentYear  = DateTime.Now.Year;
                    string currentMonth = DateTime.Now.Month.ToString();

                    dropDownSource = context.Date1.Where(d => d.Year == currentYear)
                                     .Select(x => new { id = (int)x.MonthOfYear, x.Month })
                                     .Distinct()
                                     .OrderBy(i => i.id)
                                     .ToDictionary(c => c.id, c => c.Month);

                    if (!Page.User.IsInRole("Admin"))
                    {
                        dropDownSource = dropDownSource.Select(i => i).Where(m => m.Key.ToString() == currentMonth).ToDictionary(c => c.Key, c => c.Value);
                    }

                    BindDropDownList(ddlMonth, dropDownSource, null);
                    ddlMonth.SelectedValue = currentMonth;

                    BindGridView();
                }
            }
        }
Example #13
0
        private bool CreateNewPublication(ProjectTrackerContainer context, Publication pub)
        {
            Publication newPub = new Publication();

            //if (IsAbstract)
            //{
            //    newPub = new PubAbstract();
            //}
            //else
            //{
            //    newPub = new PubManuscript();
            //}

            newPub.Status    = PubStatus;
            newPub.StartDate = Convert.ToDateTime(HiddenFieldCurrentDate.Value);
            newPub.EndDate   = Convert.ToDateTime("2099-01-01");


            DateTime pubDate = Convert.ToDateTime(TextBoxSubmitDate.Text);

            newPub.SubmitDate = pubDate;

            //switch (newPub.Status)
            //{
            //    case (int)StatusEnum.Accepted:
            //        newPub.AcceptDate = pubDate;
            //        break;
            //    case (int)StatusEnum.Published:
            //        newPub.PubDate = pubDate;
            //        break;
            //    default:
            //        newPub.SubmitDate = pubDate;
            //        break;
            //}

            if (pub != null && pub.Id > 0)
            {
                newPub.ParentId = pub.Id;
            }

            //if (PubStatus!=(int)StatusEnum.SubResub) // sub publication
            //{
            //    newPub.ProjectId = pub.ProjectId;
            //    newPub.Title = pub.Title;
            //    newPub.Author = pub.Author;
            //    newPub.SubmitDate = pub.SubmitDate;

            //    if (pub.ConferenceId != null)
            //    {
            //        newPub.ConferenceId = pub.ConferenceId;
            //    }

            //    if (pub.JounralId != null)
            //    {
            //        newPub.JounralId = pub.JounralId;
            //    }

            //    //check if newpub already exists based on type, projectid, status and submitdate
            //    bool existingPub = context.Publications
            //                         .Any(p => p.ProjectId == ProjectId && p.Status == PubStatus && p.SubmitDate == newPub.SubmitDate);
            //    if (existingPub)
            //    {
            //        return false;
            //    }

            //    context.Publications.Add(newPub);
            //    //context.SaveChanges();

            //    //ddlChildPublication.Enabled = true;
            //    //ddlChildPublication.Items.Insert(ddlChildPublication.Items.Count, new ListItem(newPub.Id.ToString() + " " + newPub.Title, newPub.Id.ToString()));
            //}
            //else // new publication
            //{

            //check if pub already exists
            bool existingPub = context.Publications
                               .Any(p => p.ProjectId == ProjectId && p.Status == PubStatus && p.SubmitDate == newPub.SubmitDate);

            if (existingPub)
            {
                return(false);
            }

            newPub.ProjectId = ProjectId;
            newPub.Title     = TextBoxTitle.Text;
            newPub.Author    = TextAreaAuthors.InnerText;

            if (IsAbstract)
            {
                // save conference
                if (ddlConference.SelectedValue.Equals(string.Empty))
                {
                    Conference newConf = GetConference();

                    context.Conferences.Add(newConf);
                    context.SaveChanges();
                    newPub.ConferenceId = newConf.Id;
                }
                else
                {
                    newPub.ConferenceId = Convert.ToInt32(ddlConference.SelectedValue);
                }
            }

            //journal
            if (ValidateJournalControl())
            {
                bool journal = context.Journals
                               .Any(j => j.JournalName == TextBoxJournal.Text);

                if (journal)
                {
                    Journal x = context.Journals
                                .First(j => j.JournalName == TextBoxJournal.Text);

                    newPub.JounralId = x.Id;
                }
                else
                {
                    //new journal
                    Journal newJ = GetJournal();

                    context.Journals.Add(newJ);

                    context.SaveChanges();

                    newPub.JounralId = newJ.Id;
                }
            }
            else
            {
                newPub.JounralId = -1;
            }

            context.Publications.Add(newPub);
            context.SaveChanges();

            ddlPublication.Items.Insert(ddlPublication.Items.Count, new ListItem(newPub.Id.ToString() + " " + newPub.Title, newPub.Id.ToString()));

            //PublicationBioStat
            ICollection <PublicationBioStat> pubBiostatList = new Collection <PublicationBioStat>();

            foreach (GridViewRow row in GridViewBioStat.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
                    if (chkRow.Checked)
                    {
                        Label lblId     = row.FindControl("lblId") as Label;
                        int   biostatId = Convert.ToInt32(lblId.Text);

                        PublicationBioStat pubBiostat = new PublicationBioStat()
                        {
                            BioStats_Id     = biostatId,
                            Publications_Id = newPub.Id,
                            StartDate       = Convert.ToDateTime(HiddenFieldCurrentDate.Value),
                            EndDate         = Convert.ToDateTime("2099-01-01")
                        };

                        pubBiostatList.Add(pubBiostat);
                    }
                }
            }

            newPub.PublicationBioStats = pubBiostatList;

            //PublicationGrant
            ICollection <PublicationGrant> pubGrantList = new Collection <PublicationGrant>();

            foreach (GridViewRow row in GridViewGrant.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
                    if (chkRow.Checked)
                    {
                        Label lblId   = row.FindControl("lblId") as Label;
                        int   grantId = Convert.ToInt32(lblId.Text);

                        PublicationGrant pubGrant = new PublicationGrant()
                        {
                            GrantAffilId  = grantId,
                            PublicationId = newPub.Id,
                            StartDate     = Convert.ToDateTime(HiddenFieldCurrentDate.Value),
                            EndDate       = Convert.ToDateTime("2099-01-01")
                        };

                        pubGrantList.Add(pubGrant);
                    }
                }
            }

            newPub.PublicationGrants = pubGrantList;

            //}

            context.SaveChanges();

            return(true);
        }
Example #14
0
        //protected void ddlPI_Changed(Object sender, EventArgs e)
        //{
        //    int biostatId;
        //    bool result = Int32.TryParse(ddlBioStat.SelectedValue, out biostatId);

        //    int investId;
        //    bool piResult = Int32.TryParse(ddlPI.SelectedValue, out investId);

        //    if (biostatId > 0)
        //    {
        //        using (ProjectTrackerContainer context = new ProjectTrackerContainer())
        //        {
        //            IDictionary<int, string> dropDownSource = new Dictionary<int, string>();
        //            var projects = context.ProjectBioStats
        //                           .Where(p => p.BioStats_Id == biostatId && p.Project.IsApproved && p.Project.IsProject && (p.Project.ProjectCompletionDate == null || p.Project.ProjectCompletionDate > _leadDate));

        //            if (investId > 0)
        //            {
        //                projects = projects
        //                            .Where(p => p.Project.InvestId == investId);
        //            }

        //            dropDownSource = projects
        //                                .OrderByDescending(d => d.Project.Id)
        //                                .Select(x => new { x.Project.Id, FullName = (x.Project.Id + " " + x.Project.Invest.FirstName + " " + x.Project.Invest.LastName + " | " + x.Project.Title).Substring(0, 108) })
        //                                .ToDictionary(c => c.Id, c => c.FullName);

        //            if (projects.Count() > 0)
        //            {
        //                PageUtility.BindDropDownList(ddlProject, dropDownSource, string.Empty);
        //            }

        //        }
        //    }
        //}

        private void BindControl(string projectId)
        {
            string userName = Page.User.Identity.Name;

            _currentDate = DateTime.Now.ToShortDateString();

            if (!userName.Equals(string.Empty))
            {
                IDictionary <int, string> dropDownSource = new Dictionary <int, string>();
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    //var dbQuery = ((IObjectContextAdapter)context).ObjectContext.CreateQuery<DateTime>("CurrentDateTime() ");
                    //HiddenFieldCurrentDate.Value = dbQuery.AsEnumerable().First().ToString();
                    //_currentDate = HiddenFieldCurrentDate.Value;

                    _leadDate = DateTime.Now.AddDays(-50);

                    //ddlBioStat
                    var biostat = context.BioStats.FirstOrDefault(b => b.LogonId == userName);
                    if (biostat != null)
                    {
                        if (Page.User.IsInRole("Admin"))
                        {
                            dropDownSource = context.BioStats
                                             .Where(b => b.Id > 0 && b.Id < 90)
                                             .OrderBy(b => b.Id)
                                             .ToDictionary(c => c.Id, c => c.Name);

                            PageUtility.BindDropDownList(ddlBioStat, dropDownSource, string.Empty);
                            ddlBioStat.Items.FindByText(biostat.Name).Selected = true;
                        }
                        else
                        {
                            dropDownSource.Add(biostat.Id, biostat.Name);

                            PageUtility.BindDropDownList(ddlBioStat, dropDownSource, null);
                        }

                        int biostatId;
                        Int32.TryParse(ddlBioStat.SelectedValue, out biostatId);

                        if (biostatId > 0)
                        {
                            //var projects = context.ProjectBioStats
                            //                .Where(p => p.BioStats_Id == biostatId && (p.Project.ProjectCompletionDate == null || p.Project.ProjectCompletionDate > _leadDate));
                            var projects = context.vwProjectBiostat.Where(v => v.BiostatId == biostatId);

                            if (projects.Count() > 0)
                            {
                                dropDownSource = projects
                                                 .OrderByDescending(d => d.InvestId)
                                                 .Select(x => new { x.InvestId, FullName = x.FirstName + " " + x.LastName })
                                                 .Distinct()
                                                 .ToDictionary(c => c.InvestId, c => c.FullName);

                                PageUtility.BindDropDownList(ddlBiostatChosen, dropDownSource, "Search PI");


                                int piId = 0;
                                Int32.TryParse(ddlBiostatChosen.SelectedValue, out piId);

                                if (piId > 0)
                                {
                                    projects = projects.Where(p => p.InvestId == piId);
                                }

                                dropDownSource = projects
                                                 .OrderByDescending(d => d.ProjectId)
                                                 .Select(x => new { x.ProjectId, FullName = (x.ProjectId + " " + x.FirstName + " " + x.LastName + " | " + x.Title).Substring(0, 108) })
                                                 .Distinct()
                                                 .ToDictionary(c => c.ProjectId, c => c.FullName);

                                PageUtility.BindDropDownList(ddlProject, dropDownSource, string.Empty);

                                ddlProject.SelectedValue = projectId;

                                int  _projectId;
                                bool result = Int32.TryParse(ddlProject.SelectedValue, out _projectId);

                                BindrptPhase(_projectId);
                            }
                        }
                    }

                    //ddlServiceType and ddlEditServiceType
                    dropDownSource = context.ServiceTypes
                                     .OrderBy(b => b.Id)
                                     .Select(x => new { x.Id, x.Name })
                                     .Distinct().ToDictionary(c => c.Id, c => c.Name);

                    PageUtility.BindDropDownList(ddlServiceType, dropDownSource, string.Empty);

                    PageUtility.BindDropDownList(ddlEditServiceType, dropDownSource, string.Empty);


                    TextBoxSubmitDate.Text = Convert.ToDateTime(_currentDate).ToShortDateString();

                    //ddlMonth
                    int    currentYear  = DateTime.Now.Year;
                    string currentMonth = DateTime.Now.Month.ToString();

                    dropDownSource = context.Date1.Where(d => d.Year > 2014)
                                     .Select(x => new { id = (int)x.Year, x.Year })
                                     .Distinct()
                                     .OrderBy(i => i.id)
                                     .ToDictionary(c => c.id, c => c.Year.ToString());
                    PageUtility.BindDropDownList(ddlYear, dropDownSource, null);
                    ddlYear.SelectedValue = currentYear.ToString();

                    int yearSelected = currentYear;
                    Int32.TryParse(ddlYear.SelectedValue, out yearSelected);
                    dropDownSource = context.Date1.Where(d => d.Year == yearSelected)
                                     .Select(x => new { id = (int)x.MonthOfYear, x.Month })
                                     .Distinct()
                                     .OrderBy(i => i.id)
                                     .ToDictionary(c => c.id, c => c.Month);

                    //if (!Page.User.IsInRole("Admin"))
                    //{
                    //    dropDownSource = dropDownSource.Select(i => i).Where(m => m.Key.ToString() == currentMonth).ToDictionary(c => c.Key, c => c.Value);
                    //}

                    PageUtility.BindDropDownList(ddlMonth, dropDownSource, null);
                    ddlMonth.SelectedValue = currentMonth;



                    BindGridView();
                }

                //BindGridViewProjectEffort(-1);

                //phase
                dropDownSource = new Dictionary <int, string>();
                for (int p = 0; p < 10; p++)
                {
                    string s = string.Format("Phase-{0}", p);
                    dropDownSource.Add(p, s);
                }
                PageUtility.BindDropDownList(ddlPhaseHdn, dropDownSource, "--- Select ---");
                //BindgvPhase(-1);
            }
        }
Example #15
0
        private void BindrptPhase(int projectId)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Name");
            dt.Columns.Add("Desc");
            dt.Columns.Add("StartDate");
            dt.Columns.Add("PhdHrs");
            dt.Columns.Add("MsHrs");
            dt.Columns.Add("PhdSpt");
            dt.Columns.Add("MsSpt");

            if (projectId > 0)
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    var phases = context.ProjectPhase.Where(p => p.ProjectId == projectId).OrderByDescending(p => p.Id).ToList();

                    foreach (var phase in phases)
                    {
                        ListItem newItem = new ListItem();
                        newItem.Value    = phase.Id.ToString();
                        newItem.Text     = phase.Name;
                        newItem.Selected = false;

                        ddlPhase.Items.Add(newItem);

                        DataRow dr = dt.NewRow();
                        dr[0] = phase.Name;
                        dr[1] = phase.Title;
                        dr[2] = phase.StartDate != null?Convert.ToDateTime(phase.StartDate).ToShortDateString() : "";

                        dr[3] = phase.PhdHrs;
                        dr[4] = phase.MsHrs;

                        //total spent hours
                        decimal  p = 0.5m, m = 0.5m;
                        DateTime startDate = new DateTime(2000, 1, 1), endDate = new DateTime(2099, 1, 1);
                        //ObjectParameter startDate = new ObjectParameter("StartDate", typeof(DateTime?));
                        //ObjectParameter endDate = new ObjectParameter("EndDate", typeof(DateTime?));
                        ObjectParameter phdHours = new ObjectParameter("PhdHours", typeof(decimal));
                        ObjectParameter msHours  = new ObjectParameter("MSHours", typeof(decimal));
                        var             i        = context.P_PROJECTPHASE_HOURS(projectId, phase.Name, startDate, endDate, phdHours, msHours);
                        context.SaveChanges();

                        Decimal.TryParse(phdHours.Value.ToString(), out p);
                        Decimal.TryParse(msHours.Value.ToString(), out m);

                        dr[5] = p;
                        dr[6] = m;

                        dt.Rows.Add(dr);
                    }

                    //int piId = 0;
                    //Int32.TryParse(ddlBiostatChosen.SelectedValue, out piId);

                    //if (piId > 0)
                    //{
                    //    //rebind ddlProject
                    //}
                }
            }

            if (dt.Rows.Count == 0)
            {
                DataRow emptyRow = dt.NewRow();
                dt.Rows.Add(emptyRow);
            }
            else
            {
                textAreaPhase.Value = JsonConvert.SerializeObject(dt); //.TrimStart(new char[] { '[' }).TrimEnd(new char[] { ']' });
            }

            rptPhase.DataSource = dt;
            rptPhase.DataBind();
        }
Example #16
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (ValidateControl().Equals(string.Empty))
            {
                if (ValidateSubmitDate() || Page.User.IsInRole("Admin"))
                {
                    var timeOverspend = false;
                    using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                    {
                        int phaseId = 0;
                        Int32.TryParse(ddlPhase.SelectedValue, out phaseId);

                        TimeEntry timeEntry = new TimeEntry()
                        {
                            ProjectId     = Convert.ToInt32(Request.Form[ddlProject.UniqueID]),
                            BioStatId     = Convert.ToInt32(ddlBioStat.SelectedValue),
                            Duration      = Convert.ToDecimal(TextBoxTime.Text),
                            ServiceTypeId = Convert.ToInt32(ddlServiceType.SelectedValue),
                            DateKey       = GetDateKey(TextBoxSubmitDate.Text),
                            Creator       = Page.User.Identity.Name,
                            CreationDate  = Convert.ToDateTime(_currentDate),
                            Description   = TextBoxDesc.Text,
                            PhaseId       = phaseId > 0 ? phaseId : (int?)null
                        };

                        //check if time spent total exceeds phase hour
                        var biostat = context.BioStats.FirstOrDefault(b => b.Id == timeEntry.BioStatId);
                        var phase   = ddlPhase.SelectedItem.Text;

                        var ja = JArray.Parse(textAreaPhase.Value);

                        JObject jo = ja.Children <JObject>().FirstOrDefault(o => o["Name"].ToString() == phase);
                        if (jo != null && biostat != null)
                        {
                            var hours = biostat.Type == "phd" ? "PhdHrs" : "MsHrs";
                            var spent = biostat.Type == "phd" ? "PhdSpt" : "MsSpt";

                            decimal dh = 0.0m, ds = 0.0m;
                            if (decimal.TryParse(jo[hours].ToString(), out dh) &&
                                decimal.TryParse(jo[spent].ToString(), out ds))
                            {
                                if (ds + timeEntry.Duration > dh)
                                {
                                    timeOverspend = true;
                                }
                            }
                        }

                        if (timeOverspend)
                        {
                            Response.Write("<script>alert('Spent hours can not exceed estimated hours for this phase, please create new phase.');</script>");
                        }
                        else
                        {
                            context.TimeEntries.Add(timeEntry);
                            context.SaveChanges();

                            Response.Write("<script>alert('Time Entry Saved.');</script>");

                            BindGridView();

                            int  projectId;
                            bool result = Int32.TryParse(ddlProject.SelectedValue, out projectId);
                            BindrptPhase(projectId);

                            ClearForm();
                        }

                        int investId;
                        Int32.TryParse(ddlBiostatChosen.SelectedValue, out investId);

                        if (investId > 0)
                        {
                            var projects = context.Project2
                                           .OrderByDescending(d => d.Id)
                                           .Where(p => p.PIId == investId);
                        }
                    }
                }
                else
                {
                    Response.Write("<script>alert('The date you picked is not valid.');</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('" + ValidateControl() + "');</script>");
            }

            //Response.Redirect(Request.Url.ToString());
        }
Example #17
0
        /// <summary>
        /// If there is an existing PI in the request, the pop-out form will populate with
        /// the PI information already stored into the database.
        ///
        /// Otherwise, a brand new, blank form will be presented to the user.
        /// </summary>
        /// <param name="piId"></param>
        private void BindControl(string piId)
        {
            using (ProjectTrackerContainer db = new ProjectTrackerContainer())
            {
                IDictionary <int, string> dropDownSource = new Dictionary <int, string>();

                int id = 0;
                Int32.TryParse(piId, out id);

                if (id > 0)
                {
                    var query1 = db.Invests
                                 .Join(db.InvestStatus, i => i.InvestStatusId, s => s.Id,
                                       (i, s) => new { i.Id, i.FirstName, i.LastName, i.Email, i.Phone, s.StatusValue })
                                 .Where(d => d.Id == id)
                                 .OrderBy(d => d.Id);

                    //GridView1.DataSource = query1.ToList();
                    //GridView1.DataBind();

                    rptPI.DataSource = query1.ToList();
                    rptPI.DataBind();
                }
                else
                {
                    var query = db.Invests
                                .Join(db.InvestStatus, i => i.InvestStatusId, s => s.Id,
                                      (i, s) => new { i.Id, i.FirstName, i.LastName, i.Email, i.Phone, s.StatusValue })
                                .Where(d => d.Id > 0)
                                .OrderBy(d => d.Id);

                    //GridView1.DataSource = query.ToList();
                    //GridView1.DataBind();

                    rptPI.DataSource = query.ToList();
                    rptPI.DataBind();
                }

                var statusQuery = db.InvestStatus
                                  .OrderBy(d => d.DisplayOrder);

                ddlStatus.DataSource     = statusQuery.ToList();
                ddlStatus.DataValueField = "Id";
                ddlStatus.DataTextField  = "StatusValue";

                ddlStatus.DataBind();

                //uhfaculty
                var uhfacultyQuery = db.JabsomAffils
                                     .Where(d => d.Type == "UHFaculty")
                                     .OrderBy(d => d.Id);

                ddlUHFaculty.DataSource     = uhfacultyQuery.ToList();
                ddlUHFaculty.DataValueField = "Id";
                ddlUHFaculty.DataTextField  = "Name";
                ddlUHFaculty.DataBind();
                ddlUHFaculty.Items.Insert(0, new ListItem(String.Empty, String.Empty));

                //degree
                var queryDegree = db.JabsomAffils
                                  .Where(d => d.Type == "Degree");

                GridViewDegree.DataSource = queryDegree.ToList();
                GridViewDegree.DataBind();

                //department
                var queryDept = db.JabsomAffils
                                .Where(d => d.Type == "Department");

                GridViewDept.DataSource = queryDept.ToList();
                GridViewDept.DataBind();

                var queryOffice = db.JabsomAffils
                                  .Where(d => d.Type == "Office");

                GridViewOffice.DataSource = queryOffice.ToList();
                GridViewOffice.DataBind();

                //ddlJabsomOther
                dropDownSource = db.JabsomAffils
                                 .Where(d => d.Type == "College")
                                 .ToDictionary(c => c.Id, c => c.Name);

                PageUtility.BindDropDownList(ddlJabsomOther, dropDownSource, string.Empty);

                var queryUHDept = db.JabsomAffils
                                  .Where(d => d.Type == "UHSchool");

                GridViewUHDept.DataSource = queryUHDept.ToList();
                GridViewUHDept.DataBind();

                //GridViewCommunityCollege
                var queryCommunityCollege = db.JabsomAffils
                                            .Where(d => d.Type == "CommunityCollege");

                GridViewCommunityCollege.DataSource = queryCommunityCollege.ToList();
                GridViewCommunityCollege.DataBind();

                //GridViewCommunityPartner
                var queryCommunityPartner = db.JabsomAffils
                                            .Where(d => d.Type == "CommunityPartner");

                GridViewCommunityPartner.DataSource = queryCommunityPartner.ToList();
                GridViewCommunityPartner.DataBind();

                //ddlHospital
                dropDownSource = db.JabsomAffils
                                 .Where(d => d.Type == "MajorHospital")
                                 .ToDictionary(c => c.Id, c => c.Name);

                //PageUtility.BindDropDownList(ddlHospital, dropDownSource, String.Empty);

                ////GridViewHph
                //var queryHph = db.JabsomAffils
                //               .Where(d => d.Type == "HawaiiPacificHealth");

                //GridViewHph.DataSource = queryHph.ToList();
                //GridViewHph.DataBind();

                //GridViewNonUH
                var queryNonUH = db.JabsomAffils
                                 .Where(d => d.Type == "MajorHospital");

                GridViewNonUH.DataSource = queryNonUH.ToList();
                GridViewNonUH.DataBind();

                //if (!Page.User.IsInRole("Admin"))
                //{
                //    btnAdd.Visible = false;
                //    btnSave.Visible = false;
                //}

                //var principleI = db.Invests.Where(i => i.Id > 0)
                //                .Select(x => new { FullName = x.FirstName + " " + x.LastName });
                //textAreaPI.Value = Newtonsoft.Json.JsonConvert.SerializeObject(principleI);
            }
        }
Example #18
0
        /// <summary>
        /// Brings out the pop-out form and populates form with the information
        /// corresponding to the PI listed on the same row as the "Edit" button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptPI_ItemCommand(Object sender, RepeaterCommandEventArgs e)
        {
            if (((Button)e.CommandSource).Text.Equals("Edit"))
            {
                int investId = 0;
                int.TryParse(((Button)e.CommandSource).CommandArgument, out investId);

                if (investId > 0)
                {
                    Invests invest;
                    ICollection <JabsomAffil> jabsomAffilList;

                    using (ProjectTrackerContainer db = new ProjectTrackerContainer())
                    {
                        invest = db.Invests.First(i => i.Id == investId);
                        //DetailsView1.DataSource = query;
                        //DetailsView1.DataBind();

                        //BindDropDownList(ddlProject, dropDownSource, "Add a new project");

                        jabsomAffilList = invest.JabsomAffils;
                    }

                    lblInvestId.Text        = invest.Id.ToString();
                    TextBoxFirstName.Text   = invest.FirstName;
                    TextBoxLastName.Text    = invest.LastName;
                    TextBoxEmail.Text       = invest.Email;
                    TextBoxPhone.Text       = invest.Phone;
                    TextBoxAltEmail.Text    = invest.AltEmail;
                    TextBoxAltPhone.Text    = invest.AltPhone;
                    txtNotes.InnerText      = invest.Notes;// (Add textbox notes box here)
                    ddlStatus.SelectedValue = invest.InvestStatusId.ToString();
                    TextBoxNonHawaii.Text   = invest.NonHawaiiClient;

                    TextBox txtNonUHOther = GridViewNonUH.FooterRow.FindControl("txtNonUHOther") as TextBox;
                    if (invest.NonUHClient != null)
                    {
                        txtNonUHOther.Text = invest.NonUHClient;
                    }
                    else
                    {
                        txtNonUHOther.Text = string.Empty;
                    }

                    TextBox txtDegreeOther = GridViewDegree.FooterRow.FindControl("txtDegreeOther") as TextBox;
                    if (invest.OtherDegree != null)
                    {
                        txtDegreeOther.Text = invest.OtherDegree;
                    }
                    else
                    {
                        txtDegreeOther.Text = string.Empty;
                    }

                    TextBox txtCommunityPartnerOther = GridViewCommunityPartner.FooterRow.FindControl("txtCommunityPartnerOther") as TextBox;
                    if (invest.OtherCommunityPartner != null)
                    {
                        txtCommunityPartnerOther.Text = invest.OtherCommunityPartner;
                    }
                    else
                    {
                        txtCommunityPartnerOther.Text = string.Empty;
                    }

                    chkApproved.Checked = invest.IsApproved;
                    //chkPilot.Checked = invest.IsPilot;

                    //bind jabsom affils
                    //if (jabsomAffilList.Count > 0)
                    //{
                    Bind_JabsomAffil(jabsomAffilList);
                    //}

                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    sb.Append(@"<script type='text/javascript'>");
                    sb.Append("$('#editModal').modal('show');");
                    sb.Append(@"</script>");
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                            "ModalScript", sb.ToString(), false);
                }
            }
        }
Example #19
0
        private bool UpdatePublication(ProjectTrackerContainer context, Publication pub, bool isSub)
        {
            if (ValidateJournalControl())
            {
                var journalExists = context.Journals
                                    .Any(j => j.JournalName == TextBoxJournal.Text);

                if (journalExists)
                {
                    var journal = context.Journals
                                  .First(j => j.JournalName == TextBoxJournal.Text);

                    pub.JounralId = journal.Id;
                }
                else
                {
                    //new journal
                    Journal newJournal = GetJournal();

                    context.Journals.Add(newJournal);

                    context.SaveChanges();

                    pub.JounralId = newJournal.Id;
                }
            }

            if (isSub)
            {
                //sub-publication can change date
                DateTime pubDate = Convert.ToDateTime(TextBoxSubmitDate.Text);
                switch (pub.Status)
                {
                case (int)StatusEnum.Accepted:
                    pub.AcceptDate = pubDate;
                    break;

                case (int)StatusEnum.Published:
                    pub.PubDate = pubDate;
                    break;

                default:
                    pub.SubmitDate = pubDate;
                    break;
                }
            }
            else
            {
                //update PublicationBioStat
                #region Update ProjectBioStat
                ICollection <PublicationBioStat> prevBiostats = pub.PublicationBioStats
                                                                .Where(b => b.EndDate > DateTime.Parse(_currentDate)).ToList();

                List <int> newMemberList = GetSelectedRow_GridView(GridViewBioStat);

                List <int> prevMemberList = new List <int>();

                if (prevBiostats.Count > 0)
                {
                    foreach (PublicationBioStat biostat in prevBiostats)
                    {
                        prevMemberList.Add(biostat.BioStats_Id);
                    }
                }

                var newNotPrevList = newMemberList.Except(prevMemberList).ToList();
                var prevNotNewList = prevMemberList.Except(newMemberList).ToList();

                foreach (var expiredId in prevNotNewList)
                {
                    pub.PublicationBioStats.First(b => b.BioStats_Id == expiredId).EndDate = DateTime.Parse(_currentDate);
                }
                foreach (var newMemberId in newNotPrevList)
                {
                    pub.PublicationBioStats.Add(new PublicationBioStat()
                    {
                        Publications_Id = pub.Id,
                        BioStats_Id     = newMemberId,
                        StartDate       = DateTime.Parse(_currentDate),
                        EndDate         = _endDate
                    });
                }
                #endregion

                // update ProjectGrant
                #region Update Project Grants
                ICollection <PublicationGrant> prevGrants = pub.PublicationGrants
                                                            .Where(b => b.EndDate > DateTime.Parse(_currentDate)).ToList();

                List <int> newGrantList = GetSelectedRow_GridView(GridViewGrant);

                List <int> prevGrantList = new List <int>();
                if (prevGrants.Count > 0)
                {
                    foreach (PublicationGrant grant in prevGrants)
                    {
                        prevGrantList.Add(grant.GrantAffilId);
                    }
                }

                var newNotPrevGrantList = newGrantList.Except(prevGrantList).ToList();
                var prevNotNewGrantList = prevGrantList.Except(newGrantList).ToList();

                foreach (var removeId in prevNotNewGrantList)
                {
                    PublicationGrant pg = pub.PublicationGrants.First(d => d.PublicationId == pub.Id && d.GrantAffilId == removeId);
                    context.PublicationGrants.Remove(pg);
                }
                foreach (var newGrantId in newNotPrevGrantList)
                {
                    pub.PublicationGrants.Add(new PublicationGrant()
                    {
                        PublicationId = pub.Id,
                        GrantAffilId  = newGrantId,
                        StartDate     = DateTime.Parse(_currentDate),
                        EndDate       = _endDate
                    });
                }
                #endregion

                //update conference
                if (IsAbstract)
                {
                    // save conference
                    if (ddlConference.SelectedValue.Equals(string.Empty))
                    {
                        Conference newConf = GetConference();

                        context.Conferences.Add(newConf);
                        context.SaveChanges();
                        pub.ConferenceId = newConf.Id;
                    }
                    else
                    {
                        pub.ConferenceId = Convert.ToInt32(ddlConference.SelectedValue);
                    }
                }
            }

            context.SaveChanges();

            return(true);
        }
Example #20
0
        protected void ddlPublication_Changed(Object sender, EventArgs e)
        {
            int  pubId;
            bool result = Int32.TryParse(ddlPublication.SelectedValue, out pubId);

            if (result)
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    Publication pub = context.Publications.First(p => p.Id == pubId);

                    IDictionary <int, string> dropDownSource = new Dictionary <int, string>();

                    if (pub.ProjectId > 0)
                    {
                        ddlProject.SelectedValue = pub.ProjectId.ToString();

                        BindGridViewFile();
                    }
                    else
                    {
                        ddlProject.ClearSelection();
                    }

                    TextBoxSubmitDate.Text    = pub.SubmitDate.ToString();
                    TextBoxTitle.Text         = pub.Title;
                    TextAreaAuthors.InnerText = pub.Author;

                    if (PubType == PubTypeEnum.Abstract.ToString())
                    {
                        Conference conf = context.Conferences.First(c => c.Id == pub.ConferenceId);

                        SetConference(conf);

                        //dropDownSource = context.Publications.OfType<PubAbstract>()
                        //                .Where(p => p.ParentId == pub.Id)
                        //                .ToDictionary(c => c.Id, c => (c.Id + " " + (StatusEnum)c.Status));
                    }
                    else
                    {
                        //dropDownSource = context.Publications.OfType<PubManuscript>()
                        //                .Where(p => p.ParentId == pub.Id)
                        //                .ToDictionary(c => c.Id, c => (c.Id + " " + (StatusEnum)c.Status));
                    }

                    //ddlChildPublication.Enabled = true;
                    //BindDropDownList(ddlChildPublication, dropDownSource, "Add a new sub");

                    List <int> biostats = new List <int>();
                    foreach (var pubBiostat in pub.PublicationBioStats)
                    {
                        if (pubBiostat.EndDate > DateTime.Parse(_currentDate))
                        {
                            biostats.Add(pubBiostat.BioStats_Id);
                        }
                    }
                    if (biostats.Count > 0)
                    {
                        SelectRow_GridView(GridViewBioStat, biostats);
                    }

                    SetPubStatus(pub.Status);

                    List <int> grants = new List <int>();
                    foreach (var pubGrant in pub.PublicationGrants)
                    {
                        if (pubGrant.EndDate > DateTime.Parse(_currentDate))
                        {
                            grants.Add(pubGrant.GrantAffilId);
                        }
                    }
                    if (grants.Count > 0)
                    {
                        SelectRow_GridView(GridViewGrant, grants);
                    }

                    if (pub.JounralId > 0)
                    {
                        Journal journal = context.Journals.First(j => j.Id == pub.JounralId);

                        if (journal != null)
                        {
                            SetJournal(journal);
                        }
                    }
                }
            }
            else
            {
                ClearForm();
            }
        }
Example #21
0
        private void BindControl()
        {
            //ddlPubType
            foreach (Enum pubType in Enum.GetValues(typeof(PubTypeEnum)))
            {
                ListItem item = new ListItem(Enum.GetName(typeof(PubTypeEnum), pubType), pubType.ToString());
                ddlPubType.Items.Add(item);
            }

            using (ProjectTrackerContainer context = new ProjectTrackerContainer())
            {
                var dbQuery = ((IObjectContextAdapter)context).ObjectContext.CreateQuery <DateTime>("CurrentDateTime() ");
                HiddenFieldCurrentDate.Value = dbQuery.AsEnumerable().First().ToShortDateString();
                DateTime currentDate = Convert.ToDateTime(HiddenFieldCurrentDate.Value);


                IDictionary <int, string> dropDownSource = new Dictionary <int, string>();

                //ddlProject
                dropDownSource = context.Projects
                                 .OrderByDescending(d => d.Id)
                                 .Select(x => new { x.Id, FullName = x.Id + " " + x.Title })
                                 .ToDictionary(c => c.Id, c => c.FullName);

                BindDropDownList(ddlProject, dropDownSource, string.Empty);

                //GridViewGrant
                var query = context.GrantAffils
                            .Where(d => d.Id < 4)
                            .OrderBy(d => d.Id);

                GridViewGrant.DataSource = query.ToList();
                GridViewGrant.DataBind();

                ////ddlBiostat
                dropDownSource = context.BioStats
                                 .OrderBy(b => b.Id)
                                 .ToDictionary(c => c.Id, c => c.Name);

                //BindDropDownList(ddlBiostat, dropDownSource, String.Empty);

                GridViewBioStat.DataSource = dropDownSource;
                GridViewBioStat.DataBind();

                if (PubType == PubTypeEnum.Abstract.ToString())
                {
                    //ddlConference
                    dropDownSource = context.Conferences
                                     .Where(d => d.EndDate >= currentDate)
                                     .ToDictionary(c => c.Id, c => (c.ConfName + " | " + c.ConfLoc));

                    BindDropDownList(ddlConference, dropDownSource, "Add a new conference");

                    //dropDownSource = context.Publications.OfType<PubAbstract>()
                    //                .Where(p => p.Status == (int)StatusEnum.SubResub)
                    //                .ToDictionary(c => c.Id, c => (c.Id + " " + c.Title));
                }
                else
                {
                    //dropDownSource = context.Publications.OfType<PubManuscript>()
                    //                .Where(p => p.Status == (int)StatusEnum.SubResub)
                    //                .ToDictionary(c => c.Id, c => (c.Id + " " + c.Title));
                }

                BindDropDownList(ddlPublication, dropDownSource, NewPubItem);
            }
        }