示例#1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public EtapDetailForm(List<Etap> etaps, Etap currentEtap, List<MainItem> etapItems)
        {
            this.Resources["EtapsList"] = etaps;
            this.Resources["ItemsList"] = etapItems;
            this.Resources["CurrentEtap"] = currentEtap;

            InitializeComponent();
        }
示例#2
0
        /// <summary>
        /// Gets dimensions based on start and ent to fit the decades
        /// </summary>
        /// <param name="etap">Etap to process</param>
        /// <param name="pageWidth">Page width to fit in</param>
        /// <param name="xStart">Starting X coordinate of etap rect</param>
        /// <param name="width">Width of etap rect</param>
        /// <returns>Returns brush to draw the rect</returns>
        private XBrush ProcessEtap(Etap etap, double pageWidth, out double xStart, out double width)
        {
            // Construction day count rounded to whole months

            DateTime startDate = new DateTime(this.construction.StartDate.Year, this.construction.StartDate.Month, 1);
            DateTime endDate = new DateTime(this.construction.EndDate.Year, this.construction.EndDate.Month, 1).AddMonths(1);

            int dayCount =
                (endDate.Year - startDate.Year) * 365 + endDate.DayOfYear - startDate.DayOfYear;

            // Coeficient
            double dayWidth = pageWidth / dayCount;

            // Etap delay in days from construction start
            int startDelay =
                (etap.StartDate.Year - startDate.Year) * 365
                + etap.StartDate.DayOfYear - startDate.DayOfYear;

            // Etap duration in days
            int duration =
                (etap.EndDate.Year - etap.StartDate.Year) * 365
                + etap.EndDate.DayOfYear - etap.StartDate.DayOfYear;

            // Count dimensions
            xStart = startDelay * dayWidth;
            width = duration * dayWidth;

            return XBrushes.LightBlue;
        }
示例#3
0
        /// <summary>
        /// Checks that
        /// 1) if etap should have started till today, then it has some progress
        /// 2) or if etap should have ended till today, then it is completed
        /// </summary>
        /// <param name="etap">Etap to check</param>
        /// <param name="delay">Possible etap delay</param>
        /// <returns>Returns true if etap is OK, false if etap is delayed</returns>
        private bool CheckEtap(Etap etap, out int delay)
        {
            DateTime today = DateTime.Now.Date;

            delay = 0;

            // Etap should have started till today
            if (etap.StartDate.Date.CompareTo(today) == -1)
            {
                // Action differs based on comparing etap end date and today
                switch(etap.EndDate.Date.CompareTo(today))
                {
                    // Etap may have not ended yet but has to have started already
                    case 1 :
                        // Etap is running -> OK
                        if (etap.Progress > 0)
                            return true;

                        // Etap should have started already -> WRONG (count delay from start date)
                        long startDelayInTicks = today.Ticks - etap.StartDate.Date.Ticks;
                        delay = (int)new TimeSpan(startDelayInTicks).TotalDays;

                        return false;

                    // Etap ends today - it is okay
                    case 0:
                        return true;

                    // Etap should have already finished
                    case -1:

                        // Etap has already finished -> OK
                        if (etap.Progress < 100)
                            return true;

                        // Etap should have ended till today -> WRONG (count delay from end date)
                        long endDelayInTicks = today.Ticks - etap.EndDate.Date.Ticks;
                        delay = (int)new TimeSpan(endDelayInTicks).TotalDays;

                        return false;
                }
            }

            // Etap doesn't need to start yet -> OK
            return true;
        }
示例#4
0
        /// <summary>
        /// Searches etap list for an etap with requested id. 
        /// If etap is not found, returns default etap.
        /// Default etap contains items that don't fit in other etap
        /// </summary>
        /// <param name="etapList">List to be searcehed</param>
        /// <param name="etapId">ID of requested etap</param>
        /// <returns>Returns searched etap</returns>
        public Etap GetEtapById(List<Etap> etapList, int etapId)
        {
            Etap defaultEtap = null;

            // Try to find etap by id
            if (etapList != null)
            {
                foreach (Etap etap in etapList)
                {
                    // Return etap with requested id
                    if (etap.ID == etapId)
                        return etap;

                    // Check for defautl etap
                    if (etap.ID == Properties.Settings.Default.DefaultEtapID)
                        defaultEtap = etap;
                }
            }

            // Etap not found, create default one, because doesn't exist
            if (defaultEtap == null)
            {
                // Create default etap
                defaultEtap = new Etap(
                    Properties.Settings.Default.DefaultEtapID,
                    "Etapa",
                    new DateTime(),
                    new DateTime()
                );

                // Add it to etap list
                etapList.Add(defaultEtap);
            }

            // Return default etap
            return defaultEtap;
        }
示例#5
0
        /// <summary>
        /// Checks that etap doesn't start after it ends. If does, sets end on the same day as start.
        /// </summary>
        /// <param name="selectedEtap">Etap to valiade</param>
        /// <returns>Returns true if etap needed to be validated, false if etap was already calid</returns>
        private bool ValidateEtapDates(Etap selectedEtap)
        {
            // if startDate > endDate
            if (selectedEtap.StartDate.CompareTo(selectedEtap.EndDate) == 1)
            {
                MessageBoxLocalizer.ShowDialog(
                    Properties.Resources.MESSAGE_HARMONOGRAM_INVALID_DATA,
                    Properties.Resources.MESSAGE_HARMONOGRAM_TITLE_INVALID_DATA
                );

                selectedEtap.EndDate = selectedEtap.StartDate;
                return true;

            }

            return false;
        }