protected override PaymentRuleEntity entityFromReader(SqlDataReader reader)
        {
            int            supplierId  = (int)reader["Supplier"];
            int            customerId  = (int)reader["Customer"];
            SupplierEntity supplier    = SupplierMapper.Read(supplierId);
            CustomerEntity customer    = CustomerMapper.Read(customerId);
            BookingType    bookingType = (BookingType)Enum.Parse(typeof(BookingType), reader["BookingType"].ToString());
            decimal        percentage  = (decimal)reader["Percentage"];
            int            daysOffset  = (int)reader["DaysOffset"];
            BaseDate       baseDate    = (BaseDate)Enum.Parse(typeof(BaseDate), reader["BaseDate"].ToString());
            PaymentType    paymentType = (PaymentType)Enum.Parse(typeof(PaymentType), reader["PaymentType"].ToString());

            PaymentRuleEntity paymentRuleEntity = new PaymentRuleEntity(supplier, customer, bookingType, percentage,
                                                                        daysOffset, baseDate, paymentType);

            int      paymentRuleId = (int)reader["PaymentRuleId"];
            DateTime lastModified  = (DateTime)reader["LastModified"];
            bool     deleted       = (bool)reader["Deleted"];

            paymentRuleEntity.Id           = paymentRuleId;
            paymentRuleEntity.LastModified = lastModified;
            paymentRuleEntity.Deleted      = deleted;

            supplier.AddPaymentRule(paymentRuleEntity);

            return(paymentRuleEntity);
        }
        //GET players/Subscribe/5/edit  Show the creation form for subscribing player with ID 5 to new classes
        public ActionResult Subscribe(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var player = db.players.Find(id);

            if (player == null)
            {
                return(HttpNotFound());
            }

            //Business rules in class registeration:
            //1. Player cannot register twice in a same class
            //2.Player cannot register in a class that is currently closed
            //3. Max capacity of classes must be checked
            int today = BaseDate.CalculateDateDiffInMinutes(DateTime.Today);
            var trtrm = db.training_terms
                        .Where(a =>
                               a.e_date > today &&
                               a.player_registerations.Any(pl => pl.player_id == player.ID) == false &&
                               a.player_registerations.Count < a.max_player
                               ).ToList();

            ViewBag.training_id = new SelectList(trtrm, "ID", "term_title");

            ViewBag.player = player;
            return(View());
        }
Example #3
0
        // GET: coaches/CreateTraining
        public ActionResult CreateTraining(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var coach = db.coaches.Find(id);

            if (coach == null)
            {
                return(HttpNotFound());
            }

            //Business rules in class registeration:
            //1. Coach cannot register twice in a same class
            //2.Coach cannot register in a class that is currently closed
            int today = BaseDate.CalculateDateDiffInMinutes(DateTime.Today);
            var trtrm = db.training_terms
                        .Where(a =>
                               a.e_date > today &&
                               a.coach_training.Any(pl => pl.coach_id == coach.ID) == false
                               ).ToList();

            ViewBag.training_id = new SelectList(trtrm, "ID", "term_title");

            ViewBag.coach = coach;
            return(View());
        }
Example #4
0
        internal void AddPaymentRule(Customer customer, BookingType bookingType, decimal percentage, int daysOffset,
                                     BaseDate baseDate, PaymentType paymentType)
        {
            PaymentRule paymentRule = new PaymentRule(this, customer, bookingType, percentage, daysOffset, baseDate,
                                                      paymentType, dataAccessFacade);

            readPaymentRules();
        }
        public void AddPaymentRule(ISupplier supplier, ICustomer customer, BookingType bookingType, decimal percentage,
            int daysOffset, BaseDate baseDate, PaymentType paymentType)
        {
            Supplier supp = (Supplier)supplier;
            Customer cust = (Customer)customer;

            supp.AddPaymentRule(cust, bookingType, percentage, daysOffset, baseDate, paymentType);
        }
Example #6
0
        public void AddPaymentRule(ISupplier supplier, ICustomer customer, BookingType bookingType, decimal percentage,
                                   int daysOffset, BaseDate baseDate, PaymentType paymentType)
        {
            Supplier supp = (Supplier)supplier;
            Customer cust = (Customer)customer;

            supp.AddPaymentRule(cust, bookingType, percentage, daysOffset, baseDate, paymentType);
        }
Example #7
0
 /// <summary>
 /// Creates some dummy files with different previous dates, including the <see cref="BaseDate"/>.
 /// </summary>
 /// <param name="period">Rolling file period to consider.</param>
 private void CreateDummyFiles(RollingFilePeriod period)
 {
     for (var days = 0; days < 10; days++)
     {
         var date = BaseDate.AddDays(-days);
         File.Create(Path.Combine(tempFolder.FolderPath, period.GetFileName(date)));
     }
 }
Example #8
0
        public void WhenCheckingForUpdate_ReturnBool(RollingFilePeriod period, int minutesToAdd, bool expected)
        {
            CreateDummyFiles(period);
            var namer = new RollingFileNamer(tempFolder.FolderPath, period);

            var shouldUpdate = namer.ShouldUpdateFile(BaseDate.AddMinutes(minutesToAdd));

            Assert.Equal(expected, shouldUpdate);
        }
Example #9
0
        public void WhenGettingFilePath_ReturnCorrectName(RollingFilePeriod period, int minutesToAdd, string expected)
        {
            CreateDummyFiles(period);
            var namer = new RollingFileNamer(tempFolder.FolderPath, period);

            var fileName = Path.GetFileName(namer.GetFilePath(BaseDate.AddMinutes(minutesToAdd)));

            Assert.Equal(expected, fileName);
        }
 internal PaymentRuleEntity(ISupplier supplierEntity, ICustomer customerEntity, BookingType bookingType,
                            decimal percentage, int daysOffset, BaseDate baseDate, PaymentType paymentType)
 {
     Supplier    = supplierEntity;
     Customer    = customerEntity;
     BookingType = bookingType;
     Percentage  = percentage;
     DaysOffset  = daysOffset;
     BaseDate    = baseDate;
     PaymentType = paymentType;
 }
 internal PaymentRuleEntity(ISupplier supplierEntity, ICustomer customerEntity, BookingType bookingType,
     decimal percentage, int daysOffset, BaseDate baseDate, PaymentType paymentType)
 {
     Supplier = supplierEntity;
     Customer = customerEntity;
     BookingType = bookingType;
     Percentage = percentage;
     DaysOffset = daysOffset;
     BaseDate = baseDate;
     PaymentType = paymentType;
 }
        public IPaymentRule CreatePaymentRule(ISupplier supplierEntity, ICustomer customerEntity, 
            BookingType bookingType, decimal percentage, int daysOffset, BaseDate baseDate, PaymentType paymentType)
        {
            PaymentRuleEntity paymentRule = new PaymentRuleEntity(supplierEntity, customerEntity, bookingType,
                percentage, daysOffset, baseDate, paymentType);

            SupplierEntity supplier = (SupplierEntity)supplierEntity;
            supplier.AddPaymentRule(paymentRule);

            return paymentRule;
        }
Example #13
0
 public static System.DateTime?DateRelativeBaseDate(System.DateTime? original, System.DateTime? reference)
 {
     if (original != null && reference != null)
     {
         var date      = (System.DateTime)original;
         var refDate   = (System.DateTime)reference;
         var deltaDate = date.Subtract(refDate);
         var newDate   = BaseDate.Add(deltaDate);
         return(newDate);
     }
     return(null);
 }
Example #14
0
        public override DateTime?NextTime(DateTime CurrentValue)
        {
            var BaseDates = new[] { CurrentValue.Date, CurrentValue.Date.AddDays(1) };

            var PossibleDates = from BaseDate in BaseDates
                                from Time in Times
                                let NewDate = BaseDate.WithTime(Time)
                                              where NewDate > CurrentValue
                                              orderby NewDate ascending
                                              select new DateTime?(NewDate);

            return(PossibleDates.FirstOrDefault());
        }
Example #15
0
 public static System.DateTime?DateRelativeBaseDate(System.DateTime? original, System.DateTime? reference)
 {
     if (original != null && reference != null)
     {
         System.DateTime date      = (System.DateTime)original;
         System.DateTime refDate   = (System.DateTime)reference;
         TimeSpan        deltaDate = date.Subtract(refDate);
         System.DateTime newDate   = BaseDate.Add(deltaDate);
         return(newDate);
     }
     else
     {
         return(null);
     }
 }
Example #16
0
        internal PaymentRule(Supplier supplier, Customer customer, BookingType bookingType, decimal percentage,
                             int daysOffset, BaseDate baseDate, PaymentType paymentType, IDataAccessFacade dataAccessFacade)
        {
            // validate
            validateCustomer(customer);
            validateSupplier(supplier);

            // Get entities for DataAccess
            ISupplier supplierEntity = supplier._supplierEntity;
            ICustomer customerEntity = customer._customerEntity;

            this.dataAccessFacade = dataAccessFacade;
            _paymentRuleEntity    = dataAccessFacade.CreatePaymentRule(supplierEntity, customerEntity, bookingType,
                                                                       percentage, daysOffset, baseDate, paymentType);
        }
Example #17
0
        internal PaymentRule(Supplier supplier, Customer customer, BookingType bookingType, decimal percentage, 
            int daysOffset, BaseDate baseDate, PaymentType paymentType, IDataAccessFacade dataAccessFacade)
        {
            // validate
            validateCustomer(customer);
            validateSupplier(supplier);

            // Get entities for DataAccess
            ISupplier supplierEntity = supplier._supplierEntity;
            ICustomer customerEntity = customer._customerEntity;

            this.dataAccessFacade = dataAccessFacade;
            _paymentRuleEntity = dataAccessFacade.CreatePaymentRule(supplierEntity, customerEntity, bookingType,
                percentage, daysOffset, baseDate, paymentType);
        }
Example #18
0
        public void SetClock(BaseDate dateTime)
        {
            //H->E S2F17 Date and Time Request
            //For Eqp request clock, use clockService.SetClockFromSource()
            Console.WriteLine("[EIB]Time Reply From Host: {0}", dateTime.LocalDateTime);

            try
            {
                //string timeFormat = UseXMLConfig.GetValueXPath("//SecsConfig/HostTimeFormat", strConfigPath);
                //bool timeZoneUTC = "true".Equals(UseXMLConfig.GetAttrXPath("//SecsConfig/HostTimeFormat", "useUTC0", strConfigPath));
                string timeFormat  = "yyyyMMddHHmmsscc";
                bool   timeZoneUTC = false;

                int yearLength = timeFormat.Count(f => f == 'y');
                int ccLength   = timeFormat.Count(f => f == 'c');

                DateTime tempDateTime;

                if (timeZoneUTC)
                {
                    tempDateTime = dateTime.LocalDateTime;
                }
                else
                {
                    tempDateTime = dateTime.GMTDateTime;
                }

                SYSTEMTIME st = new SYSTEMTIME();
                // All of these must be short
                st.wYear   = (short)tempDateTime.Year;
                st.wMonth  = (short)tempDateTime.Month;
                st.wDay    = (short)tempDateTime.Day;
                st.wHour   = (short)tempDateTime.Hour;
                st.wMinute = (short)tempDateTime.Minute;
                st.wSecond = (short)tempDateTime.Second;

                // invoke the SetSystemTime method now
                if (!SetSystemTime(ref st))
                {
                    Console.WriteLine("To change system time, Run as administrator");
                }
                //UseLog.Log(UseLog.LogCategory.Event, "To change system time, Run as administrator");
            }
            catch
            {
                Console.WriteLine("Invalid Time Format. Please Check again.");
            }
        }
Example #19
0
        public void WhenWritingInDifferentPeriod_CreateNewFile(bool async, RollingFilePeriod period, int[] minutesToAdd)
        {
            using (var temp = TempFolder.Create())
            {
                WriteLogs(async, temp.FolderPath, period, minutesToAdd);

                foreach (var minutes in minutesToAdd)
                {
                    var date         = BaseDate.AddMinutes(minutes);
                    var contentsFile = File.ReadAllLines(Path.Combine(temp.FolderPath, period.GetFileName(date)));
                    var log          = string.Format("{0} [DBG] date={1}", date.ToString(DefaultDateTimeFormat),
                                                     date.ToString(period.DateFormat));

                    Assert.Equal(log, contentsFile[0]);
                }
            }
        }
Example #20
0
        /// <summary>
        /// Writes logs using a sink.
        /// </summary>
        /// <param name="async">Indicates whether the asynchronous sink should be created.</param>
        /// <param name="logFolderPath">Log files folder path.</param>
        /// <param name="period">Rolling file period.</param>
        /// <param name="minutesToAdd">Minutes to add for each writing.</param>
        private void WriteLogs(bool async, string logFolderPath, RollingFilePeriod period, int[] minutesToAdd)
        {
            foreach (var minutes in minutesToAdd)
            {
                var date = BaseDate.AddMinutes(minutes);
                timeProviderMock.Setup(m => m.CurrentDateTime).Returns(date);

                var sink    = CreateSink(async, logFolderPath, period);
                var entries = new List <ILogEntry>()
                {
                    new LogEntry("date", date.ToString(period.DateFormat))
                };

                sink.Write(GenericLogLevelName.Debug, entries);

                ((IDisposable)sink).Dispose();
            }
        }
Example #21
0
        /// <summary>
        /// Builds the id.
        /// </summary>
        /// <returns></returns>
        private string BuildUniqueId()
        {
            switch (AssetType)
            {
            case AssetTypesEnum.Bond:
                if (MaturityDate != null)
                {
                    return($"{Id}.{Coupon}.{((DateTime) MaturityDate).ToShortDateString()}");
                }
                break;

            case AssetTypesEnum.IRFutureOption:
            case AssetTypesEnum.IRPutFutureOption:
            case AssetTypesEnum.IRCallFutureOption:
            case AssetTypesEnum.IRCap:
            case AssetTypesEnum.IRFloor:
            case AssetTypesEnum.Caplet:
            case AssetTypesEnum.Floorlet:
                if (Strike != null)
                {
                    return($"{Id}-{Strike}-{BaseDate.ToShortDateString()}");
                }
                break;

            case AssetTypesEnum.CommoditySpot:
            case AssetTypesEnum.CommodityForward:
            case AssetTypesEnum.CommodityFuture: return($"{Id}.{BaseDate.ToShortDateString()}");

            default:
                if (MarketQuote != null)
                {
                    return($"{Id}-{MarketQuote}-{BaseDate.ToShortDateString()}");
                }
                break;
            }
            return(Id);
        }
Example #22
0
 /// <summary>
 /// 日期屬性重設
 /// </summary>
 private void DatePropertyReset()
 {
     if (BasePerior == "W")
     {
         BaseFirstDate  = BaseDate.ezBaseWeekFirstDate();
         BaseLastDate   = BaseDate.ezBaseWeekLastDate();
         PriorFirstDate = BaseDate.ezPriorWeekFirstDate();
         PriorLastDate  = BaseDate.ezPriorWeekLastDate();
     }
     if (BasePerior == "M")
     {
         BaseFirstDate  = BaseDate.ezBaseMonthFirstDate();
         BaseLastDate   = BaseDate.ezBaseMonthLastDate();
         PriorFirstDate = BaseDate.ezPriorMonthFirstDate();
         PriorLastDate  = BaseDate.ezPriorMonthLastDate();
     }
     if (BasePerior == "Y")
     {
         BaseFirstDate  = BaseDate.ezBaseYearFirstDate();
         BaseLastDate   = BaseDate.ezBaseYearLastDate();
         PriorFirstDate = BaseDate.ezPriorYearFirstDate();
         PriorLastDate  = BaseDate.ezPriorYearLastDate();
     }
 }
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (supplierTabControl.IsSelected)
                {
                    if (selectedSupplier == null)
                    {
                        string       name = nameTextBox.Text;
                        SupplierType type = (SupplierType)supplierTypeComboBox.SelectedItem;
                        string       note = noteTextBox.Text;

                        ISupplier supplier = supplierController.CreateSupplier(name, note, type);
                        supplier.AccountName = accountNameTextBox.Text;
                        supplier.AccountNo   = accountNoTextBox.Text;
                        supplier.AccountType = (AccountType)accountTypeComboBox.SelectedItem;
                        supplier.Bank        = bankTextBox.Text;
                        supplier.OwnerId     = ownerIdTextBox.Text;

                        supplierController.UpdateSupplier(supplier);
                        refreshDataGrid();
                        suppliersDataGrid.SelectedItem = null;
                        setValuesInTextBoxes();
                    }
                    else
                    {
                        int currentIndex = suppliersDataGrid.SelectedIndex;

                        selectedSupplier.Name        = nameTextBox.Text;
                        selectedSupplier.Type        = (SupplierType)supplierTypeComboBox.SelectedItem;
                        selectedSupplier.Note        = noteTextBox.Text;
                        selectedSupplier.AccountName = accountNameTextBox.Text;
                        selectedSupplier.AccountNo   = accountNoTextBox.Text;
                        selectedSupplier.AccountType = (AccountType)accountTypeComboBox.SelectedItem;
                        selectedSupplier.Bank        = bankTextBox.Text;
                        selectedSupplier.OwnerId     = ownerIdTextBox.Text;

                        supplierController.UpdateSupplier(selectedSupplier);
                        refreshDataGrid();
                        suppliersDataGrid.SelectedIndex = currentIndex;
                    }
                }
                else if (paymentRuleTabControl.IsSelected)
                {
                    ICustomer customer = null;

                    foreach (ICustomer theCustomer in customerController.ReadAllCustomers())
                    {
                        if (theCustomer.Name == customerTextBox.Text)
                        {
                            customer = theCustomer;
                        }
                    }

                    ISupplier   supplier    = selectedSupplier;
                    BookingType bookingType = (BookingType)bookingTypeComboBox.SelectedItem;
                    decimal     percentage;
                    decimal.TryParse(percentageTextBox.Text, NumberStyles.Any, culture, out percentage);
                    int daysOffSet;
                    int.TryParse(daysOffsetTextBox.Text, out daysOffSet);
                    BaseDate    baseDate    = (BaseDate)baseDateComboBox.SelectedItem;
                    PaymentType paymentType = (PaymentType)paymentTypeComboBox.SelectedItem;


                    supplierController.AddPaymentRule(supplier, customer, bookingType, percentage, daysOffSet, baseDate,
                                                      paymentType);
                    refreshPaymentRuleDataGrid();
                    setPaymentRuleValuesInTextBoxes();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #24
0
 /// <inheritdoc />
 public virtual DateTime GetDateTime() => BaseDate.AddDays(GetInt());
Example #25
0
        // TB
        #region Public PaymentRule Methods
        public IPaymentRule CreatePaymentRule(ISupplier supplierEntity, ICustomer customerEntity,
                                              BookingType bookingType, decimal percentage, int daysOffset, BaseDate baseDate, PaymentType paymentType)
        {
            SupplierEntity s = (SupplierEntity)supplierEntity;
            CustomerEntity c = (CustomerEntity)customerEntity;

            return(paymentRuleMapper.Create(s, c, bookingType, percentage, daysOffset, baseDate, paymentType));
        }
Example #26
0
 private void ChangeMonth(string month)
 {
     BaseDate = BaseDate.AddMonths(Int32.Parse(month));
     SetDays(BaseDate);
 }
        public IPaymentRule CreatePaymentRule(ISupplier supplierEntity, ICustomer customerEntity,
                                              BookingType bookingType, decimal percentage, int daysOffset, BaseDate baseDate, PaymentType paymentType)
        {
            PaymentRuleEntity paymentRule = new PaymentRuleEntity(supplierEntity, customerEntity, bookingType,
                                                                  percentage, daysOffset, baseDate, paymentType);

            SupplierEntity supplier = (SupplierEntity)supplierEntity;

            supplier.AddPaymentRule(paymentRule);

            return(paymentRule);
        }
        internal PaymentRuleEntity Create(SupplierEntity supplierEntity, CustomerEntity customerEntity,
                                          BookingType bookingType, decimal percentage, int daysOffset, BaseDate baseDate, PaymentType paymentType)
        {
            PaymentRuleEntity paymentRuleEntity = new PaymentRuleEntity(supplierEntity, customerEntity, bookingType,
                                                                        percentage, daysOffset, baseDate, paymentType);

            insert(paymentRuleEntity);

            // could be done in PaymentRuleEntity constructor? Almost Inversion Of Control!
            supplierEntity.AddPaymentRule(paymentRuleEntity);

            return(paymentRuleEntity);
        }
Example #29
0
        private CalendarBar?ContinuationForNextWeek()
        {
            var nextDate = BaseDate.AddDays(DisplayWidth());

            return((nextDate <= EndDate) ? new CalendarBar(Item, nextDate) : null);
        }
Example #30
0
        internal void AddPaymentRule(Customer customer, BookingType bookingType, decimal percentage, int daysOffset, 
            BaseDate baseDate, PaymentType paymentType)
        {
            PaymentRule paymentRule = new PaymentRule(this, customer, bookingType, percentage, daysOffset, baseDate,
                paymentType, dataAccessFacade);

            readPaymentRules();
        }
        // GET(Json): trainings/Preview
        public JsonResult PreviewDrills(int id)
        {
            var training = db.training_terms.Where(a => a.ID == id)
                           .Include(a => a.training_patterns
                                    .Select(aa => aa.pattern.items.Select(c => c.drill)))
                           .FirstOrDefault();

            var plans = new List <training_plan_preview>();

            var patterns = training.training_patterns.OrderBy(a => a.s_date).OrderBy(a => a.orders);

            //Load all patterns related to today
            foreach (var pattern in patterns)
            {
                //Check wether has any drill for this pattern or not
                if (pattern.pattern.items.Count() > 0)
                {
                    foreach (var item in pattern.pattern.items)
                    {
                        var eventItem = new training_plan_preview();
                        //Check wether is this event recurring or not
                        if (item.periodic)
                        {
                            if (item.weekday == 8)
                            {
                                eventItem.daysofWeek = "['0','2','4']";
                            }
                            else if (item.weekday == 9)
                            {
                                eventItem.daysofWeek = "['1','3','5','6']";
                            }
                            else if (item.weekday == 10)
                            {
                                eventItem.daysofWeek = "";
                            }
                            else
                            {
                                eventItem.daysofWeek = ((item.weekday - 2) >= 0)? "['" + (item.weekday - 2) + "']" : "['6']";
                            }

                            var strt = BaseDate.GetDateFromDateOffsetSystemStartDate(pattern.s_date);
                            var endd = BaseDate.GetDateFromDateOffsetSystemStartDate(pattern.e_date);

                            eventItem.recureStart = strt.Year.ToString() + "/" + strt.Month + "/" + strt.Day;
                            eventItem.recureEnd   = endd.Year.ToString() + "/" + endd.Month + "/" + endd.Day;

                            eventItem.classification = item.ID.ToString() + "_" + item.pattern_id + "_" + item.drill_id;
                        }
                        else
                        {
                            eventItem.drill_dt = pattern.s_date;
                        }
                        var dd = DateTime.Today;
                        eventItem.drill_id    = item.drill_id;
                        eventItem.drill_title = item.drill.drill_title;
                        eventItem.startTime   = pattern.training.start_time;
                        eventItem.endTime     = pattern.training.end_time;
                        plans.Add(eventItem);
                    }
                }
            }
            return(new JsonResult {
                Data = plans, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #32
0
        public IPaymentRule CreatePaymentRule(ISupplier supplierEntity, ICustomer customerEntity, 
            BookingType bookingType, decimal percentage, int daysOffset, BaseDate baseDate, PaymentType paymentType)
        {
            SupplierEntity s = (SupplierEntity)supplierEntity;
            CustomerEntity c = (CustomerEntity)customerEntity;

            return paymentRuleMapper.Create(s, c, bookingType, percentage, daysOffset, baseDate, paymentType);
        }