Ejemplo n.º 1
0
        /// <summary>
        /// Adds the specified requirement.
        /// </summary>
        /// <param name="requirement">The requirement.</param>
        /// <returns></returns>
        public tbl_Requirement Add(tbl_Requirement requirement)
        {
            requirement.ID = Guid.NewGuid();
            _dataContext.tbl_Requirement.AddObject(requirement);
            _dataContext.SaveChanges();

            AddHistory(new DataManager(), requirement);

            return(requirement);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the history.
        /// </summary>
        /// <param name="dataManager">The data manager.</param>
        /// <param name="requirement">The requirement.</param>
        protected void AddHistory(DataManager dataManager, tbl_Requirement requirement)
        {
            var requirementHistory = new tbl_RequirementHistory
            {
                RequirementID       = requirement.ID,
                RequirementStatusID = requirement.RequirementStatusID,
                ContactID           = CurrentUser.Instance.ContactID,
                ResponsibleID       = requirement.ResponsibleID
            };

            dataManager.RequirementHistory.Add(requirementHistory);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the requirement row.
        /// </summary>
        /// <param name="requirement">The requirement.</param>
        /// <param name="style">The style.</param>
        /// <param name="includeLastComment">if set to <c>true</c> [include last comment].</param>
        /// <returns></returns>
        private string AddRequirementRow(tbl_Requirement requirement, string style, bool includeLastComment = false)
        {
            var shortDescription = requirement.ShortDescription;

            if (PortalSettings != null)
            {
                var requirementLink = string.Format(RequirementLinkTemplate, requirement.ID);
                shortDescription = string.Format("<a href='{0}'>{1}</a>", requirementLink, shortDescription);
            }

            var row = SiteActionTemplates.RequirementRowTemplate;

            row = row.Replace("#Style#", style)
                  .Replace("#ShortDescription#", shortDescription)
                  .Replace("#Type#", requirement.tbl_RequirementType.Title)
                  .Replace("#Status#", requirement.tbl_RequirementStatus.Title)
                  .Replace("#Quantity#", requirement.Quantity > 0 ? String.Format("{0:0}", requirement.Quantity) : string.Empty)
                  .Replace("#Unit#", requirement.Quantity > 0 && requirement.UnitID.HasValue ? requirement.tbl_Unit.Title : string.Empty)
                  .Replace("#Amount#", requirement.Quantity > 0 ? requirement.Amount.ToString("F") : string.Empty)
                  .Replace("#Currency#", requirement.Quantity > 0 && requirement.CurrencyID.HasValue ? requirement.tbl_Currency.Name : string.Empty);

            var comment  = requirement.tbl_RequirementComment.FirstOrDefault(rc => rc.IsOfficialAnswer == true) ?? new tbl_RequirementComment();
            var comments = comment.Comment;

            if (includeLastComment)
            {
                var lastComment = requirement.tbl_RequirementComment.OrderByDescending(rc => rc.CreatedAt).FirstOrDefault();
                if (lastComment != null && comments != lastComment.Comment)
                {
                    if (SiteAction.ContactID.HasValue)
                    {
                        var user = DataManager.User.SelectByContactIdExtended(SiteAction.SiteID, (Guid)SiteAction.ContactID);
                        if (lastComment.DestinationUserID == user.ID)
                        {
                            comments =
                                string.Format("{0}<br/>Требует ответа:<p style='background-color:#FFABB0'>{1}</p>",
                                              comments, lastComment.Comment);
                        }
                        else
                        {
                            comments += "<br/>" + lastComment.Comment;
                        }
                    }
                    else
                    {
                        comments += "<br/>" + lastComment.Comment;
                    }
                }
            }

            return(row.Replace("#OfficialComment#", comments));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks the requests to close.
        /// </summary>
        /// <param name="requirement">The requirement.</param>
        /// <returns></returns>
        protected bool CheckRequestsToClose(tbl_Requirement requirement)
        {
            if (!requirement.tbl_RequirementStatus.IsLast)
            {
                return(false);
            }

            var requestsToClose = new List <tbl_Request>();

            foreach (tbl_Request request in requirement.tbl_Request)
            {
                if (request.tbl_Requirement.Count == request.tbl_Requirement.Count(o => o.tbl_RequirementStatus.IsLast))
                {
                    requestsToClose.Add(request);
                }
            }

            if (requirement.RequestID.HasValue)
            {
                var requestSource = DataManager.Request.SelectById(SiteId, requirement.RequestID.Value);
                if (requestSource.tbl_Requirement.Count == requestSource.tbl_Requirement.Count(o => o.tbl_RequirementStatus.IsLast))
                {
                    requestsToClose.Add(requestSource);
                }
            }

            if (!requestsToClose.Any())
            {
                return(false);
            }

            chxRequestsList.Items.Clear();

            foreach (tbl_Request request in requestsToClose)
            {
                var item = new ListItem(
                    string.Format("{0} №{1} от {2}", request.ShortDescription, request.Number,
                                  request.CreatedAt.ToString("dd.MM.yyyy")), request.ID.ToString());
                item.Selected = true;
                chxRequestsList.Items.Add(item);
            }

            if (!Page.ClientScript.IsStartupScriptRegistered("ShowCloseRequestRadWindow"))
            {
                ScriptManager.RegisterStartupScript(Page, typeof(System.Web.UI.Page), "ShowCloseRequestRadWindow", "ShowCloseRequestRadWindow();", true);
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the specified requirement.
        /// </summary>
        /// <param name="requirement">The requirement.</param>
        public void Update(tbl_Requirement requirement)
        {
            var dataManager           = new DataManager();
            var requirementInDataBase = dataManager.Requirement.SelectById(requirement.SiteID, requirement.ID);

            _dataContext.SaveChanges();

            if (requirementInDataBase.RequirementStatusID != requirement.RequirementStatusID || requirementInDataBase.ResponsibleID != requirement.ResponsibleID)
            {
                AddHistory(dataManager, requirement);
            }

            if (requirementInDataBase.ResponsibleID != requirement.ResponsibleID)
            {
                RequestNotificationService.ChangeResponsible(requirement.SiteID, requirement.ID, (Guid)requirement.ResponsibleID);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        public void BindData(bool isClear = false)
        {
            var requirements = DataManager.Requirement.SelectAll(CurrentUser.Instance.SiteID).OrderBy(o => o.CreatedAt);

            var requirement = new tbl_Requirement();

            if (SelectedRequirementId.HasValue)
            {
                requirement = requirements.SingleOrDefault(o => o.ID == SelectedRequirementId);
            }

            if (CompanyId.HasValue)
            {
                requirements = requirements.Where(o => o.CompanyID == CompanyId).OrderBy(o => o.CreatedAt);
            }

            if (SelectedRequirementId.HasValue)
            {
                if (requirement != null && SelectedStatuses.Count == 0)
                {
                    SelectedStatuses = new List <Guid>()
                    {
                        requirement.RequirementStatusID
                    }
                }
                ;

                foreach (ListItem item in chxlistRequirementStatuses.Items)
                {
                    item.Selected = SelectedStatuses.Contains(Guid.Parse(item.Value));
                }
            }

            if (SelectedStatuses.Count > 0)
            {
                requirements = requirements.Where(o => SelectedStatuses.Contains(o.RequirementStatusID)).OrderBy(o => o.CreatedAt);
            }

            rtvRequirements.DataSource        = requirements;
            rtvRequirements.DataValueField    = "ID";
            rtvRequirements.DataFieldID       = "ID";
            rtvRequirements.DataFieldParentID = "ParentID";
            rtvRequirements.DataTextField     = "Number";
            rtvRequirements.DataBind();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        public void BindData()
        {
            var requirements = DataManager.Requirement.SelectAll(CurrentUser.Instance.SiteID).OrderBy(o => o.CreatedAt);

            if (CurrentRequirementId.HasValue)
            {
                requirements = requirements.Where(o => o.ID != CurrentRequirementId).OrderBy(o => o.CreatedAt);
            }


            var requirement = new tbl_Requirement();

            if (ParentRequirementId.HasValue)
            {
                requirement = requirements.SingleOrDefault(o => o.ID == ParentRequirementId);
                if (requirement != null)
                {
                    lrlParentRequirment.Text = string.Format("Требование №{0} от {1} ({2})", requirement.Number,
                                                             requirement.CreatedAt.ToString("dd.MM.yyyy"),
                                                             requirement.ShortDescription);
                }
                else
                {
                    lrlParentRequirment.Text = string.Empty;
                }
            }

            if (CompanyId.HasValue)
            {
                requirements = requirements.Where(o => o.CompanyID == CompanyId).OrderBy(o => o.CreatedAt);
            }

            if (ParentRequirementId.HasValue)
            {
                if (requirement != null && SelectedStatuses.Count == 0)
                {
                    SelectedStatuses = new List <Guid>()
                    {
                        requirement.RequirementStatusID
                    }
                }
                ;

                foreach (ListItem item in chxlistRequirementStatuses.Items)
                {
                    item.Selected = SelectedStatuses.Contains(Guid.Parse(item.Value));
                }
            }

            if (SelectedStatuses.Count > 0)
            {
                requirements = requirements.Where(o => SelectedStatuses.Contains(o.RequirementStatusID)).OrderBy(o => o.CreatedAt);
            }

            rtvRequirements.DataSource        = requirements;
            rtvRequirements.DataValueField    = "ID";
            rtvRequirements.DataFieldID       = "ID";
            rtvRequirements.DataFieldParentID = "ParentID";
            rtvRequirements.DataTextField     = "Number";
            rtvRequirements.DataBind();
        }