Ejemplo n.º 1
0
            protected override void OnCommand(CommandArgs e)
            {
                switch (e.Command)
                {
                case "navigate":
                    StartDate = (DateTime)e.Data["start"];
                    Update(CallBackUpdateType.Full);
                    break;

                case "previous":
                    StartDate = StartDate.AddMonths(-1);
                    Update(CallBackUpdateType.Full);
                    break;

                case "next":
                    StartDate = StartDate.AddMonths(1);
                    Update(CallBackUpdateType.Full);
                    break;

                case "today":
                    StartDate = DateTime.Today;
                    Update(CallBackUpdateType.Full);
                    break;

                case "refresh":
                    Update();
                    break;
                }
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a CalendarQuarter using a Quarter Number and a Year
 /// </summary>
 /// <param name="QuarterNumber"></param>
 /// <param name="Year"></param>
 public CalendarQuarter(int QuarterNumber, int Year)
 {
     this.QuarterNumber = QuarterNumber;
     this.Year          = Year;
     this.StartDate     = new DateTime(Year, (3 * QuarterNumber) - 2, 1);
     this.EndDate       = StartDate.AddMonths(3).AddDays(-1);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a CalendarQuarter using a single date
 /// </summary>
 /// <param name="Date"></param>
 public CalendarQuarter(DateTime Date)
 {
     this.QuarterNumber = (Date.Month + 2) / 3;
     this.Year          = Date.Year;
     this.StartDate     = new DateTime(Date.Year, (QuarterNumber - 1) * 3 + 1, 1);
     this.EndDate       = StartDate.AddMonths(3).AddDays(-1);
 }
Ejemplo n.º 4
0
 public Project(string title)
 {
     Id        = Guid.NewGuid();
     Title     = title;
     StartDate = DateTime.Now;
     EndDate   = StartDate.AddMonths(1);
 }
        protected override void OnCommand(CommandArgs e)
        {
            switch (e.Command)
            {
            case "previous":
                StartDate = StartDate.AddMonths(-1);
                LoadData();
                Update(CallBackUpdateType.Full);
                break;

            case "today":
                StartDate = DateTime.Today;
                LoadData();
                Update(CallBackUpdateType.Full);
                break;

            case "next":
                StartDate = StartDate.AddMonths(1);
                LoadData();
                Update(CallBackUpdateType.Full);
                break;

            case "refresh":
                LoadData();
                UpdateWithMessage("Refreshed", CallBackUpdateType.Full);
                break;
            }
        }
Ejemplo n.º 6
0
            protected override void OnCommand(CommandArgs e)
            {
                switch (e.Command)
                {
                case "previous":
                    StartDate = StartDate.AddMonths(-1);
                    break;

                case "next":
                    StartDate = StartDate.AddMonths(1);
                    break;

                case "today":
                    StartDate = DateTime.Today;
                    break;
                }
                var db = new drogowskazEntities();

                Events         = createEvents(db.Masses);
                DataIdField    = "Id";
                DataTextField  = "Text";
                DataStartField = "Start";
                DataEndField   = "End";
                Update(CallBackUpdateType.Full);
            }
Ejemplo n.º 7
0
        public Deposit
        (
            int percent,
            decimal value,
            AccrualsInterval interv,
            int periods
        )
        {
            Percent     = percent;
            Value       = value;
            Interval    = interv;
            StartDate   = DateTime.Now;
            LastAccrual = StartDate;
            switch (interv)
            {
            case AccrualsInterval.minute:
                FinishDate = StartDate.AddMinutes(periods);
                break;

            case AccrualsInterval.month:
                FinishDate = StartDate.AddMonths(periods);
                break;

            case AccrualsInterval.year:
                FinishDate = StartDate.AddYears(periods);
                break;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Contract object constructor. receive id of both nanny and child and boolean variable to determine if the contract is monthly or per hour.
        /// if it's per month : the salary entered is monthly salary, if not: the salary is salary per hour.
        /// start date is immediately and expiration date is in more six months.
        /// </summary>
        /// <param name="my_nannyId"></param>
        /// <param name="my_childId"></param>
        /// <param name="my_isMonthContract"></param>
        /// <param name="salary">based on the boolean field, this salary can be per month or per hour.</param>
        public Contract(Nanny my_nanny, Child my_child, bool my_isMonthContract)
        {
            NannysId        = my_nanny.id;
            childId         = my_child.id;
            isMonthContract = my_isMonthContract;

            if (isMonthContract)
            {
                monthSalary  = my_nanny.monthlyWage;
                moneyPerHour = 0;
            }

            else
            {
                monthSalary  = 0;
                moneyPerHour = my_nanny.hourWage;
            }

            // initialize start date and expiration date.
            StartDate      = DateTime.Now;
            ExpirationDate = StartDate.AddMonths(6);

            numberOfContract = -1;
            isSingedContract = false;
        }
Ejemplo n.º 9
0
    public static DateTimeSpan CompareDates(DateTime StartDate, DateTime EndDate)
    {
        DateTimeSpan R = new DateTimeSpan();

        if (StartDate.Equals(EndDate))
        {
            return(new DateTimeSpan());
        }
        bool Later;

        if (Later = StartDate > EndDate)
        {
            DateTime D = StartDate;
            StartDate = EndDate;
            EndDate   = D;
        }

        // Calculate Date Stuff
        for (DateTime D = StartDate.AddYears(1); D < EndDate; D = D.AddYears(1), R.Years++)
        {
            ;
        }
        if (R.Years > 0)
        {
            StartDate = StartDate.AddYears(R.Years);
        }
        for (DateTime D = StartDate.AddMonths(1); D < EndDate; D = D.AddMonths(1), R.Months++)
        {
            ;
        }
        if (R.Months > 0)
        {
            StartDate = StartDate.AddMonths(R.Months);
        }
        for (DateTime D = StartDate.AddDays(1); D < EndDate; D = D.AddDays(1), R.Days++)
        {
            ;
        }
        if (R.Days > 0)
        {
            StartDate = StartDate.AddDays(R.Days);
        }

        // Calculate Time Stuff
        TimeSpan T1 = EndDate - StartDate;

        R.Hours        = T1.Hours;
        R.Minutes      = T1.Minutes;
        R.Seconds      = T1.Seconds;
        R.Milliseconds = T1.Milliseconds;

        // Return answer. Negate values if the Start Date was later than the End Date
        if (Later)
        {
            return(new DateTimeSpan(-R.Years, -R.Months, -R.Days, -R.Hours, -R.Minutes, -R.Seconds, -R.Milliseconds));
        }
        return(R);
    }
Ejemplo n.º 10
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public AdvertisingEditModel()
 {
     this.IsEnable      = true;
     this.IsImageBlank  = true;
     this.IsTextBlank   = true;
     this.isUploadImage = true;
     this.StartDate     = DateTime.Now;
     this.EndDate       = StartDate.AddMonths(1);
 }
Ejemplo n.º 11
0
        public override DateTime GetFirstDate()
        {
            var day = GetDayInMonth(StartDate);

            if (day >= StartDate)
            {
                return(day);
            }
            return(GetDayInMonth(StartDate.AddMonths(1)));
        }
Ejemplo n.º 12
0
        public void calculateAmmoritazation()
        {
            double   interest;
            DateTime oneTimePayDate;
            double   oneTimePayAmount;
            DateTime paymentDate;

            amortizationList = new List <AmortizationItem>();
            double principlePaid = 0;
            double totalAmount;
            double payment;

            calcBasicLoan();

            totalAmount = TotalRepayment;
            payment     = MonthlyPayment;

            AnyAdditionalPayments(out oneTimePayDate, out oneTimePayAmount, ref payment);

            do
            {
                paymentDate    = StartDate.AddMonths(amortizationList.Count).Date;
                interest       = calcPaymentOfInterest();
                totalInterest += Math.Round(interest, 3);
                if (payment >= PrincipleAmount)
                {
                    principlePaid   = PrincipleAmount;
                    PrincipleAmount = 0;
                    amortizationList.Add(new AmortizationItem(paymentDate, principlePaid, interest, totalInterest, PrincipleAmount));
                    break;
                }
                principlePaid = (payment - interest);
                if (paymentDate.ToString("MMMM, yyyy") == oneTimePayDate.ToString("MMMM, yyyy"))
                {
                    principlePaid += oneTimePayAmount;
                    if (principlePaid >= PrincipleAmount)
                    {
                        principlePaid = PrincipleAmount;
                    }
                }
                PrincipleAmount -= principlePaid;
                if (PrincipleAmount < 0)
                {
                    PrincipleAmount = 0;
                }
                if (PrincipleAmount < payment)
                {
                    payment = PrincipleAmount;
                }
                amortizationList.Add(new AmortizationItem(paymentDate, principlePaid, interest, totalInterest, PrincipleAmount));
            }while (PrincipleAmount > 0);

            MoneySaved = totalAmount - InitialPrinciple - totalInterest;
        }
Ejemplo n.º 13
0
        public Contract(int someNanny_id)
        {
            numberOfContract = 0;
            NannysId         = someNanny_id;

            StartDate      = DateTime.Now;
            ExpirationDate = StartDate.AddMonths(6);

            numberOfContract = -1;
            isSingedContract = false;
        }
Ejemplo n.º 14
0
 protected override void OnPageChanged()
 {
     if (MovedLeft)
     {
         StartDate = StartDate.AddMonths(-1);
     }
     else
     {
         StartDate = StartDate.AddMonths(1);
     }
     ResetBuffers();
 }
 public void SetStatus()
 {
     if (StartDate < DateTime.Today || StartDate.AddMonths(contract.Period) < DateTime.Today)
     {
         contract.Status = false;
     }
     else
     {
         contract.Status = true;
     }
     NotifyPropertyChanged("Status");
 }
Ejemplo n.º 16
0
        // ------------------------------------------------
        //
        //                     Exit Window
        //
        // ------------------------------------------------

        private void exit(object sender, EventArgs e)
        {
            // StartDate = DateTime.Today;
            StartDate = Start.Value;

            ChangeDate = StartDate.AddMonths(3);

            information[4] = ChangeDate.ToString();
            information[5] = ODStart.Text;

            //save information if not null
            int pos = Array.IndexOf(information, null);

            if (pos > -1)
            {
                Console.WriteLine("values are not being saved?");

                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      box;

                //make sure if want to exit

                box = MessageBox.Show("Are you sure you want to exit?", "all fields where not filled", buttons);

                if (box == System.Windows.Forms.DialogResult.Yes)
                {
                    box = MessageBox.Show("Warring: if click yes, information maybe become lost or wrong in the future.", "incomplete", buttons);

                    if (box == System.Windows.Forms.DialogResult.Yes)
                    {
                        Console.WriteLine("Saving incomplete data");
                        CheckIFHaveFiles();
                        this.Close();
                    }
                    else if (box == System.Windows.Forms.DialogResult.No)
                    {
                        Console.WriteLine("values are not saved");
                        this.Close();
                    }
                }
            }
            else
            {
                Console.WriteLine("Saving Dates");



                information[3] = StartDate.ToString();
                information[4] = ChangeDate.ToString();

                CheckIFHaveFiles();
            }
        }
Ejemplo n.º 17
0
        private void SaveData()
        {
            decimal _Loan = 0m;

            if (decimal.TryParse(M_Loan, out _Loan))
            {
                Contract_Loan_Model CLM = new Contract_Loan_Model();
                CLM.ContractID    = UID;
                CLM.Card_ID       = Card_ID;
                CLM.Card_Name     = Card_Name;
                CLM.M_Loan        = _Loan;
                CLM.Loan_Balance  = _Loan;
                CLM.M_Loan_Months = int.Parse(M_Loan_Months);
                CLM.M_Replay_Type = M_Replay_Type;
                CLM.Current_Month = 1;
                CLM.M_Rate_Month  = _M_Rate_Month;
                CLM.M_Rate_Year   = _M_Rate_Year;
                CLM.UserID        = RequestSession.GetSessionUser().UserId.ToString();

                DateTime StartDate;
                if (DateTime.TryParse(Loan_StartDate.Value, out StartDate))
                {
                    CLM.Loan_StartDate = StartDate;

                    string _SettleDate = "";
                    int    _day        = int.Parse(StartDate.ToString("dd"));
                    if (_day < 20)//当月20号是第一期
                    {
                        _SettleDate = string.Format("{0}-{1}-20", StartDate.Year, StartDate.Month);
                    }
                    else
                    {
                        _SettleDate = string.Format("{0}-{1}-20", StartDate.Year, StartDate.AddMonths(1).Month);
                    }
                    CLM.Loan_SettleDate = DateTime.Parse(_SettleDate);
                }

                bool reslt = ciday.Contract_Loan_Add(CLM);
                if (reslt)
                {
                    this.Save.Visible = false;
                    ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>layer.msg('操作成功!');setTimeout('OpenClose()','2000');</script>");
                }
                else
                {
                    ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>layer.msg('操作失败!');</script>");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>layer.msg('贷款金额不合法!');</script>");
            }
        }
Ejemplo n.º 18
0
        private DateTime GetNextDate(int repeats, DateTime iterator)
        {
            if (this.Frequency == ScheduleFrequency.Daily)
            {
                iterator = StartDate.AddDays(Interval * repeats);
            }
            else
            {
                iterator = StartDate.AddMonths(Interval * repeats);
            }

            return(iterator);
        }
Ejemplo n.º 19
0
        private void LaporanPenjualan_Loaded(object sender, RoutedEventArgs e)
        {
            var now = DateTime.Now;

            this.StartDate = new DateTime(now.Year, now.Month, 1);
            this.EndDate   = StartDate.AddMonths(1).AddDays(-1);
            reportViewer.SetDisplayMode(DisplayMode.PrintLayout);
            reportDataSource.Name    = "DataSet1"; // Name of the DataSet we set in .rdlc
            reportViewer.ZoomMode    = ZoomMode.Percent;
            reportViewer.ZoomPercent = 120;
            reportViewer.LocalReport.ReportEmbeddedResource = "TrireksaApp.Reports.Layouts.PenjualanFromToLayout.rdlc";
            reportViewer.LocalReport.DataSources.Add(reportDataSource);
            customers          = ResourcesBase.GetMainWindowViewModel().CustomerCollection;
            shiper.ItemsSource = customers.Source;
        }
Ejemplo n.º 20
0
        public void CheckDate()
        {
            if (StartDate == default || StartDate < DateTime.UtcNow.AddYears(-2))
            {
                StartDate = DateTime.UtcNow.AddMonths(-3).StartOfMonth();
            }

            if (EndDate == default || EndDate < DateTime.UtcNow.AddYears(-2).AddMonths(3))
            {
                EndDate = DateTime.UtcNow.EndOfMonth();
            }

            if (EndDate.CompareTo(StartDate) < 0)
            {
                EndDate = StartDate.AddMonths(3).EndOfMonth();
            }
        }
Ejemplo n.º 21
0
 public bool ThisMonthIsPaid(DateTime paymentDate)
 {
     if (MonthsPaid == (paymentDate.Month - StartDate.Month) + 12 * (paymentDate.Year - StartDate.Year) + 1)
     {
         return(true);
     }
     else
     {
         if (StartDate.AddMonths(MonthsPaid) < paymentDate.Date && StartDate.AddMonths(MonthsPaid).Month <= paymentDate.Month)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
Ejemplo n.º 22
0
        public static void StartSession()
        {
            var logConfig = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "log4net.config"));

            XmlConfigurator.ConfigureAndWatch(logConfig);

            Log.Info("Starting test session");

            var bld = new SqlConnectionStringBuilder()
            {
                DataSource         = ".",
                InitialCatalog     = "master",
                IntegratedSecurity = true,
                ApplicationName    = "bfsBackupRestoreTest"
            };

            var conn = new ServerConnection(new SqlConnection(bld.ToString()));

            Server = new Server(conn);
            Server.ConnectionContext.StatementTimeout = 0;

            RootTestBackupDir = Directory.CreateDirectory("TestLogSequence");
            TestDbBackupDir   = RootTestBackupDir.CreateSubdirectory("test");

            for (var m = 0; m < TestBckupPeriodMonths; ++m)
            {
                var monthStart = StartDate.AddMonths(m);

                var monthString = monthStart.ToString("yyyy-MM-MMM");
                var monthDir    = TestDbBackupDir.CreateSubdirectory(monthString);

                File.Create(Path.Combine(monthDir.FullName, string.Format("{0}-test-full.bak", monthString))).Close();
                File.Create(Path.Combine(monthDir.FullName, string.Format("{0}-01-test-log.trn", monthString))).Close();

                for (var dayStart = monthStart.AddDays(1); dayStart.Month == monthStart.Month; dayStart = dayStart.AddDays(1))
                {
                    var name = dayStart.ToString("yyyy-MM-MMM-dd") + "-test-diff.bak";
                    File.Create(Path.Combine(monthDir.FullName, name)).Close();

                    name = dayStart.ToString("yyyy-MM-MMM-dd") + "-test-log.trn";
                    File.Create(Path.Combine(monthDir.FullName, name)).Close();
                }
            }
        }
Ejemplo n.º 23
0
        public virtual DateTime GetMaxForecastDate()
        {
            int am = _extension;

            switch (PeriodEnum)
            {
            case ForecastPeriodEnum.Bimonthly:
                am = am * 2;
                break;

            case ForecastPeriodEnum.Quarterly:
                am *= 3;
                break;

            case ForecastPeriodEnum.Yearly:
                am *= 12;
                break;
            }

            return(StartDate.AddMonths(am));
        }
Ejemplo n.º 24
0
 // Start calculation with inputed values
 public async void Calculate()
 {
     try
     {
         if (DiffPay)
         {
         }
         if (AnnuPay)
         {
             Models.AnuCalculation.CreditLength  = int.Parse(CreditLength);
             Models.AnuCalculation.RemCreditSum  = double.Parse(CreditSum);
             Models.AnuCalculation.YearFee       = double.Parse(YearFee);
             Models.AnuCalculation.TotalMonthPay = double.Parse(CreditSum);
             BindableCollection <Models.AnuResults> results = new BindableCollection <Models.AnuResults>();
             for (int i = 0; i++ < Models.AnuCalculation.CreditLength;)
             {
                 results.Add(new Models.AnuResults()
                 {
                     MonthNum      = i,
                     Date          = StartDate.AddMonths(i),
                     RemCreditSum  = System.Math.Round(Models.AnuCalculation.RemCreditSum, 2),
                     MonthPay      = System.Math.Round(Models.AnuCalculation.MonthPay, 2),
                     MonthFee      = System.Math.Round(Models.AnuCalculation.MonthFee, 2),
                     TotalMonthPay = System.Math.Round(Models.AnuCalculation.TotalMonthPay, 2)
                 });
                 Models.AnuCalculation.RemCreditSum = Models.AnuCalculation.RemCreditSum - Models.AnuCalculation.MonthPay;
             }
             var resultTab = Conductor.Items.ElementAt(Conductor.Items.IndexOf(this) + 1);
             (resultTab as ResultViewModel).IsEnabled  = true;
             (resultTab as ResultViewModel).AnuResults = results;
             Conductor.ActiveItem = resultTab;
             return;
         }
     }
     catch (System.Exception ex)
     {
         await ShowMessageAsync("Error", ex.ToString(), MessageDialogStyle.Affirmative);
     }
 }
Ejemplo n.º 25
0
            public ConsoleApplication(ICoopSimulation coopSimulation)
            {
                IConfiguration config = new ConfigurationBuilder().SetBasePath(Path.Combine(AppContext.BaseDirectory))
                                        .AddJsonFile("appsettings.json", true, true)
                                        .Build();

                SimulationCyclesInMonth    = Convert.ToInt32(config.GetSection("SimulationCyclesInMonth").Value);
                _coopSimulation            = coopSimulation;
                _coopSimulation.Time       = StartDate;
                _coopSimulation.Population = new HashSet <IFowl>()
                {
                    new FemaleRabbit(_coopSimulation)
                    {
                        BirthDate = StartDate.AddYears(-1)
                    },
                    new MaleRabbit(_coopSimulation)
                    {
                        BirthDate = StartDate.AddYears(-1)
                    },
                };

                EndDate = StartDate.AddMonths(SimulationCyclesInMonth);
            }
Ejemplo n.º 26
0
        public Result CreateStraightLineAmortizationSchedule()
        {
            if (LoanAmount == 0)
            {
                return(new Result(false, "Loan Amount cannot be zero."));
            }

            _amortizationSchedule = new List <ScheduledPayment>();

            decimal monthlyInterestRate   = AnnualInterestRate / 12m;
            decimal monthlyInterestAmount = LoanAmount * monthlyInterestRate;
            decimal principal             = LoanAmount / NumberOfPayments; // eto ung ibabawas monthly sa loan
            decimal monthlyPayment        = principal + monthlyInterestAmount;
            decimal runningBalance        = LoanAmount;

            for (int i = 1; i <= NumberOfPayments; i++)
            {
                var scheduledPayment = new ScheduledPayment
                {
                    PaymentNo = i,
                    Amount    = monthlyPayment,
                    Interest  = monthlyInterestAmount
                };
                scheduledPayment.Principal = principal;
                scheduledPayment.Date      = StartDate.AddMonths(i);
                scheduledPayment.Balance   = runningBalance - principal;
                _amortizationSchedule.Add(scheduledPayment);
                runningBalance = scheduledPayment.Balance;
            }
            // loan summary
            MonthlyPayment    = monthlyPayment;
            TotalPayments     = _amortizationSchedule.Sum(scheduledPayment => scheduledPayment.Amount);
            TotalInterestPaid = _amortizationSchedule.Sum(scheduledPayment => scheduledPayment.Interest);
            PayOffDate        = StartDate.AddMonths(NumberOfPayments);

            return(new Result(true, "CreateStraightLineAmortizationSchedule"));
        }
Ejemplo n.º 27
0
        public void CreateDiminishingAmortizationSchedule()
        {
            if (LoanAmount == 0)
            {
                return;
            }
            _amortizationSchedule = new List <ScheduledPayment>();

            decimal monthlyInterestRate   = AnnualInterestRate / 12m;
            decimal presentValueOfAnnuity =
                Convert.ToDecimal(Math.Pow((double)(1 + monthlyInterestRate), NumberOfPayments));
            decimal monthlyPayment = ((monthlyInterestRate * LoanAmount * presentValueOfAnnuity) / (presentValueOfAnnuity - 1));

            decimal runningBalance = LoanAmount;

            for (int i = 1; i <= NumberOfPayments; i++)
            {
                var scheduledPayment = new ScheduledPayment
                {
                    PaymentNo = i,
                    Amount    = monthlyPayment,
                    Interest  = runningBalance * monthlyInterestRate
                };
                scheduledPayment.Principal = monthlyPayment - scheduledPayment.Interest;
                scheduledPayment.Date      = StartDate.AddMonths(i);
                scheduledPayment.Balance   = runningBalance - scheduledPayment.Principal;
                _amortizationSchedule.Add(scheduledPayment);
                runningBalance = scheduledPayment.Balance;
            }

            // loan summary
            MonthlyPayment    = monthlyPayment;
            TotalPayments     = _amortizationSchedule.Sum(scheduledPayment => scheduledPayment.Amount);
            TotalInterestPaid = _amortizationSchedule.Sum(scheduledPayment => scheduledPayment.Interest);
            PayOffDate        = StartDate.AddMonths(NumberOfPayments);
        }
Ejemplo n.º 28
0
        protected void ChangeCalendar(CalandarChanges changes)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                Content = null;
                if (changes.HasFlag(CalandarChanges.StartDate))
                {
                    TitleLabel.Text = StartDate.ToString(TitleLabelFormat);
                    if (TitleLabels != null)
                    {
                        var tls = StartDate.AddMonths(1);
                        foreach (var tl in TitleLabels)
                        {
                            (tl as Label).Text = tls.ToString(TitleLabelFormat);
                            tls = tls.AddMonths(1);
                        }
                    }
                }

                var start        = CalendarStartDate(StartDate).Date;
                var beginOfMonth = false;
                var endOfMonth   = false;
                for (int i = 0; i < buttons.Count; i++)
                {
                    endOfMonth   |= beginOfMonth && start.Day == 1;
                    beginOfMonth |= start.Day == 1;

                    if (i < dayLabels.Count && WeekdaysShow && changes.HasFlag(CalandarChanges.StartDay))
                    {
                        var day           = start.ToString(WeekdaysFormat);
                        string showDay    = char.ToUpper(day.First()) + day.Substring(1).ToLower();
                        dayLabels[i].Text = showDay;
                    }

                    ChangeWeekNumbers(start, i);

                    if (changes.HasFlag(CalandarChanges.All))
                    {
                        buttons[i].Text = string.Format("{0}", start.Day);
                    }
                    else
                    {
                        buttons[i].TextWithoutMeasure = string.Format("{0}", start.Day);
                    }
                    buttons[i].Date = start;

                    buttons[i].IsOutOfMonth = !(beginOfMonth && !endOfMonth);
                    buttons[i].IsEnabled    = ShowNumOfMonths == 1 || !buttons[i].IsOutOfMonth;

                    SpecialDate sd = null;
                    if (SpecialDates != null)
                    {
                        sd = SpecialDates.FirstOrDefault(s => s.Date.Date == start.Date);
                    }

                    SetButtonNormal(buttons[i]);

                    if ((MinDate.HasValue && start.Date < MinDate) || (MaxDate.HasValue && start.Date > MaxDate) || (DisableAllDates && sd == null))
                    {
                        SetButtonDisabled(buttons[i]);
                    }
                    else if (buttons[i].IsEnabled && (SelectedDates?.Select(d => d.Date)?.Contains(start.Date) ?? false))
                    {
                        SetButtonSelected(buttons[i], sd);
                    }
                    else if (sd != null)
                    {
                        SetButtonSpecial(buttons[i], sd);
                    }

                    start = start.AddDays(1);
                    if (i != 0 && (i + 1) % 42 == 0)
                    {
                        beginOfMonth = false;
                        endOfMonth   = false;
                        start        = CalendarStartDate(start);
                    }
                }
                if (DisableDatesLimitToMaxMinRange)
                {
                    TitleLeftArrow.IsEnabled  = !(MinDate.HasValue && CalendarStartDate(StartDate).Date < MinDate);
                    TitleRightArrow.IsEnabled = !(MaxDate.HasValue && start > MaxDate);
                }
                Content = MainView;
            });
        }
Ejemplo n.º 29
0
        private void CreateBillsForDateRange()
        {
            var    days     = (EndDate - StartDate).TotalDays;
            double dayCount = 0.0;

            var spacings = 0;   //weeks, months, fortnights, 4weeks etc

            NewBills.Clear();
            switch (DueDateFrequency)
            {
            case DueDateFrequencies.OneWeek:
                while (dayCount <= days)
                {
                    dayCount = (StartDate.AddDays((spacings + 1) * 7) - StartDate).TotalDays;
                    spacings++;
                }
                for (int i = 0; i < spacings; i++)
                {
                    NewBills.Add(new NewMultiBillViewModel(i + 1, StartDate.AddDays(7 * i)));
                }
                break;

            case DueDateFrequencies.TwoWeek:
                while (dayCount <= days)
                {
                    dayCount = (StartDate.AddDays((spacings + 1) * 14) - StartDate).TotalDays;
                    spacings++;
                }
                for (int i = 0; i < spacings; i++)
                {
                    NewBills.Add(new NewMultiBillViewModel(i + 1, StartDate.AddDays(14 * i)));
                }
                break;

            case DueDateFrequencies.FourWeek:
                while (dayCount <= days)
                {
                    dayCount = (StartDate.AddDays((spacings + 1) * 28) - StartDate).TotalDays;
                    spacings++;
                }
                for (int i = 0; i < spacings; i++)
                {
                    NewBills.Add(new NewMultiBillViewModel(i + 1, StartDate.AddDays(28 * i)));
                }
                break;

            case DueDateFrequencies.Monthly:
                while (dayCount <= days)
                {
                    dayCount = (StartDate.AddMonths(spacings + 1) - StartDate).TotalDays;
                    spacings++;
                }
                for (int i = 0; i < spacings; i++)
                {
                    NewBills.Add(new NewMultiBillViewModel(i + 1, StartDate.AddMonths(i)));
                }
                break;

            case DueDateFrequencies.Quarterly:
                while (dayCount <= days)
                {
                    dayCount = (StartDate.AddMonths(3 * (spacings + 1)) - StartDate).TotalDays;
                    spacings++;
                }
                for (int i = 0; i < spacings; i++)
                {
                    NewBills.Add(new NewMultiBillViewModel(i + 1, StartDate.AddMonths(3 * i)));
                }
                break;

            case DueDateFrequencies.SemiAnnually:
                while (dayCount <= days)
                {
                    dayCount = (StartDate.AddMonths(6 * (spacings + 1)) - StartDate).TotalDays;
                    spacings++;
                }
                for (int i = 0; i < spacings; i++)
                {
                    NewBills.Add(new NewMultiBillViewModel(i + 1, StartDate.AddMonths(6 * i)));
                }
                break;

            case DueDateFrequencies.Yearly:
                while (dayCount <= days)
                {
                    dayCount = (StartDate.AddYears(spacings + 1) - StartDate).TotalDays;
                    spacings++;
                }
                for (int i = 0; i < spacings; i++)
                {
                    NewBills.Add(new NewMultiBillViewModel(i + 1, StartDate.AddYears(i)));
                }
                break;

            default:
                break;
            }
            RaisePropertyChanged(nameof(BillCount));
        }
Ejemplo n.º 30
0
        public bool RunScenario()
        {
            var rnd = new Random(Guid.NewGuid().GetHashCode());

            Logs.Clear();
            _employee.Clear();

            // make sure there is at least one floor for the scenario; if not, use the default scenario
            if (Floors.Count == 0)
            {
                Debug.WriteLine("Floor count was zero. Default scenario was used.");
                Floors = Defaults.Floors();
            }

            // if no start date, default to today
            if (StartDate == DateTime.MinValue)
            {
                StartDate = DateTime.Now;
                Debug.WriteLine("Start date was missing. " + StartDate.ToString("MM-dd-yyyy") + " was used.");
            }

            // if no end date or end date is less than start date, default to 4 months in the future
            if (EndDate == DateTime.MinValue || EndDate.Date < StartDate.Date)
            {
                EndDate = StartDate.AddMonths(4);
                Debug.WriteLine("End date was missing or less than start date. " + EndDate.ToString("MM-dd-yyyy") + " was used.");
            }

            // if infection starting floor is greater than scenario floors, adjust down
            if (InfectionStartingFloor > Floors.Count)
            {
                InfectionStartingFloor = Floors.Count;
            }

            // build the screnario
            BuildScenario();

            // loop through days; Mon-Fri are workdays
            while (StartDate.Date != EndDate.Date)
            {
                // if anyone is symptomatic, check to see if they decide to get tested
                _employee.Where(employee => employee.Location != Locations.Hospital && employee.Location != Locations.Testing && employee.Status == InfectionState.Symptomatic).ToList().
                ForEach(employee =>
                {
                    if (rnd.Next(0, 101) * 0.01f <= 0.35f)
                    {
                        employee.Location       = Locations.Testing;
                        employee.TreatmentCount = 1;
                    }
                });

                // if anyone was being tested and is at day 5 of testing, check to see if they go back to work or the hospital
                _employee.Where(employee => employee.Location == Locations.Testing && employee.TreatmentCount == 3).ToList().
                ForEach(employee =>
                {
                    if (employee.Status != InfectionState.Immune || employee.Status != InfectionState.Well)
                    {
                        employee.Location       = Locations.Hospital;
                        employee.TreatmentCount = 1;
                    }
                    else
                    {
                        employee.Location = Locations.Office;
                    }
                });

                // if anyone was in the hospital 5 days, they can go back to work and is considered immune
                _employee.Where(employee => employee.Location == Locations.Hospital && employee.TreatmentCount == 5).ToList().
                ForEach(employee =>
                {
                    employee.CurrentLocation = employee.AssignedLocation;
                    employee.Location        = Locations.Office;
                    employee.Status          = InfectionState.Immune;
                });

                // start workday time at 8a
                var timeOfDay = new DateTime(StartDate.Year, StartDate.Month, StartDate.Day, 8, 0, 0).TimeOfDay;

                if (StartDate.DayOfWeek != DayOfWeek.Saturday && StartDate.DayOfWeek != DayOfWeek.Sunday)
                {
                    // this loop is where the workday processing happens
                    while (timeOfDay.Hours < 17)
                    {
                        // migrate employees to breakrooms or meeting rooms
                        Migration(timeOfDay.Hours == _lunchtime);

                        // check to see whether anyone becomes infected
                        Infection(timeOfDay.Hours == _lunchtime);

                        // record logs
                        RecordLogEntries(StartDate, timeOfDay);

                        // for testing
                        //var well = _employee.Where(employee => employee.Status == InfectionState.Well).ToList();
                        //var infected = _employee.Where(employee => employee.Status == InfectionState.Infected).ToList();
                        //var incubating = _employee.Where(employee => employee.Status == InfectionState.Incubation).ToList();
                        //var symptomatic = _employee.Where(employee => employee.Status == InfectionState.Symptomatic).ToList();
                        //var immune = _employee.Where(employee => employee.Status == InfectionState.Immune).ToList();
                        //var office = _employee.Where(employee => employee.Location == Locations.Office).ToList();
                        //var breakroom = _employee.Where(employee => employee.Location == Locations.Breakroom).ToList();
                        //var meeting = _employee.Where(employee => employee.Location == Locations.Meeting).ToList();
                        //var testing = _employee.Where(employee => employee.Location == Locations.Testing).ToList();
                        //var hospital = _employee.Where(employee => employee.Location == Locations.Hospital).ToList();
                        //Debug.WriteLine(StartDate.ToString("MM-dd-yyyy") + " " + timeOfDay.ToString() + " " +
                        //    " well: " + well.Count.ToString().PadLeft(3, '0') + " infected: " + infected.Count.ToString().PadLeft(3, '0') +
                        //    " incubating: " + incubating.Count.ToString().PadLeft(3, '0') + " symptomatic: " + symptomatic.Count.ToString().PadLeft(3, '0') +
                        //    " immune: " + immune.Count.ToString().PadLeft(3, '0') + " office: " + office.Count.ToString().PadLeft(3, '0') +
                        //    " breakroom: " + breakroom.Count.ToString().PadLeft(3, '0') + " meeting: " + meeting.Count.ToString().PadLeft(3, '0') +
                        //    " testing: " + testing.Count.ToString().PadLeft(3, '0') + " hospital: " + hospital.Count.ToString().PadLeft(3, '0'));

                        // put migrated employees back in thier offices
                        _employee.Where(employee => employee.Location == Locations.Breakroom || employee.Location == Locations.Meeting).ToList().
                        ForEach(employee =>
                        {
                            employee.CurrentLocation = employee.AssignedLocation;
                            employee.Location        = Locations.Office;
                        });

                        timeOfDay += TimeSpan.FromHours(1);
                    }
                }

                // anyone being tested gets credit for a day
                _employee.Where(employee => employee.Location == Locations.Testing).ToList().
                ForEach(employee => employee.TreatmentCount++);

                // anyone in the hospital gets credit for a day
                _employee.Where(employee => employee.Location == Locations.Hospital).ToList().
                ForEach(employee => employee.TreatmentCount++);

                // anyone sick gets credit for a day and might progess to the next stage
                _employee.Where(employee => employee.Infected).ToList().
                ForEach(employee => employee.InfectionProgression());

                StartDate = StartDate.AddDays(1);
            }

            return(true);
        }