Пример #1
0
        //protected void GridViewHistory_RowCommand(Object sender, GridViewCommandEventArgs e)
        //{
        //    if (e.CommandName == "Delete")
        //    {
        //        GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;
        //        //int id = Convert.ToInt32(e.CommandSource);


        //        Label lblId = gvr.FindControl("lblId") as Label;

        //         if (lblId != null)
        //         {
        //             using (ProjectTrackerContainer context = new ProjectTrackerContainer())
        //             {
        //                 int id = Convert.ToInt32(lblId.Text);
        //                 PubHistory ph = context.PubHistories.First(t => t.Id == id);
        //                 context.PubHistories.Remove(ph);
        //                 context.SaveChanges();

        //                 GridViewHistory.DeleteRow(gvr.RowIndex);

        //             }
        //         }
        //    }
        //}

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

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

            if (lblId != null)
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    int        id   = Convert.ToInt32(lblId.Text);
                    PubHistory hist = context.PubHistories.First(t => t.Id == id);
                    context.PubHistories.Remove(hist);
                    context.SaveChanges();

                    var pubHist = context.PubHistories
                                  .Join(context.Publications, h => h.PublicationId, p => p.Id, (h, p) => new { h })
                                  //.Join(context.PublishStatus, ph => ph.h.Status, 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 == hist.PublicationId)
                                  .ToList();

                    GridViewHistory.DataSource = pubHist;
                    GridViewHistory.DataBind();
                }

                if (GridViewHistory.Rows.Count > 0)
                {
                    GridViewHistory.SelectRow(GridViewHistory.Rows.Count - 1);
                    GridViewHistory.SelectedRow.Focus();
                }
            }
        }
Пример #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (ValidateControl())
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    TimeEntry timeEntry = new TimeEntry()
                    {
                        ProjectId     = Convert.ToInt32(ddlProject.SelectedValue),
                        BioStatId     = Convert.ToInt32(ddlBioStat.SelectedValue),
                        Duration      = Convert.ToDecimal(TextBoxTime.Text),
                        ServiceTypeId = Convert.ToInt32(ddlServiceType.SelectedValue),
                        DateKey       = GetDate(TextBoxSubmitDate.Text)
                    };

                    context.TimeEntries.Add(timeEntry);

                    context.SaveChanges();

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

                BindGridView();
            }
        }
Пример #3
0
        private void UpdateTimeEntry()
        {
            int       id;
            TimeEntry timeEntry;

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

                    if (timeEntry != null)
                    {
                        timeEntry.ServiceTypeId = Convert.ToInt32(ddlEditServiceType.SelectedValue);
                        timeEntry.DateKey       = GetDateKey(TextBoxEditDate.Text);
                        timeEntry.Duration      = Convert.ToDecimal(TextBoxEditTime.Text);
                        timeEntry.Creator       = Page.User.Identity.Name;
                        timeEntry.CreationDate  = Convert.ToDateTime(_currentDate);
                        timeEntry.Description   = TextBoxEditDesc.Text;
                        timeEntry.PhaseId       = Convert.ToInt32(ddlPhaseEdit.SelectedValue);

                        context.SaveChanges();
                    }
                }

                BindGridView();

                BindrptPhase(timeEntry.ProjectId);
            }
        }
Пример #4
0
        /// <summary>
        /// (Currently NOT being used). Save button to save "Client Request" box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (chkCompleted.Checked)
            {
                using (ProjectTrackerContainer db = new ProjectTrackerContainer())
                {
                    int rqstId = 0;
                    int.TryParse(lblClientRqstId.Text, out rqstId);

                    if (rqstId > 0)
                    {
                        var rqst = db.ClientRequest.FirstOrDefault(c => c.Id == rqstId);
                        rqst.RequestStatus = "Completed";
                        db.SaveChanges();
                    }
                }
            }

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                    "ModalScript", PageUtility.LoadEditScript(false), false);

            DataTable clientRqstTable = GetClientRqstAll();

            rptClientRqst.DataSource = clientRqstTable;
            rptClientRqst.DataBind();
        }
Пример #5
0
        protected void GridViewTimeEntry_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridViewRow row = GridViewTimeEntry.Rows[e.RowIndex];

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

            if (lblId != null)
            {
                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();
                }
            }
        }
Пример #6
0
        private bool SavePublication(int pubId, int subPubId)
        {
            using (ProjectTrackerContainer context = new ProjectTrackerContainer())
            {
                if (pubId > 0)
                {
                    Publication pub = context.Publications.First(p => p.Id == pubId);

                    if (pub != null)
                    {
                        //if (subPubId > 0)
                        //{
                        //    //update sub pub
                        //    Publication subPub = context.Publications.First(p => p.Id == subPubId);
                        //    bool isSub = true;
                        //    return UpdatePublication(context, subPub, isSub);
                        //}
                        //else
                        //{
                        //    if (PubStatus == (int)StatusEnum.SubResub)
                        //    {
                        //        if (Convert.ToDateTime(TextBoxSubmitDate.Text) > pub.SubmitDate) //resubmit
                        //        {
                        //            pub.EndDate = Convert.ToDateTime(TextBoxSubmitDate.Text);   //expire current pub
                        //            return CreateNewPublication(context, pub);
                        //        }
                        //        else
                        //        {
                        //            return UpdatePublication(context, pub, false);
                        //        }
                        //    }
                        //    else
                        //    {
                        //        return CreateNewPublication(context, pub);
                        //    }
                        //}

                        return(UpdatePublication(context, pub, false));
                    }
                }
                else
                {
                    if (PubStatus != (int)StatusEnum.SubResub)
                    {
                        lblDebugMsg.Text = "Can't insert a new publication without submit status.";
                    }
                    else
                    {
                        return(CreateNewPublication(context, null));
                    }
                }

                context.SaveChanges();

                return(true);
            }
        }
Пример #7
0
        private void WriteInvest(ProjectTrackerContainer context, Invests invest)
        {
            var result = context.Entry(invest).GetValidationResult();

            if (!result.IsValid)
            {
                lblMsg.Text = result.ValidationErrors.First().ErrorMessage;
            }
            else
            {
                context.SaveChanges();
                lblMsg.Text = "Saved successfully.";
                //ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('Investor Added Successfully!')</script>");
            }
        }
Пример #8
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>");
                }
            }
        }
Пример #9
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>");
            }
        }
Пример #10
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();
            }
        }
Пример #11
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();
        }
Пример #12
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());
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
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);
        }