internal long Add(long scheduleId, long scheduleLocationId, ScheduleChange change)
        {
            var databaseId = GetNewId();

            var row = Table.NewRow();

            row["Id"]                       = databaseId;
            row["ScheduleId"]               = scheduleId;
            row["ScheduleLocationId"]       = scheduleLocationId;
            row["Category"]                 = SetNullIfEmpty(change.Category);
            row["TrainIdentity"]            = SetNullIfEmpty(change.TrainIdentity);
            row["NrsHeadCode"]              = SetNullIfEmpty(change.HeadCode);
            row["ServiceCode"]              = SetNullIfEmpty(change.ServiceCode);
            row["PortionId"]                = SetNullIfEmpty(change.PortionId);
            row["PowerType"]                = SetNullIfEmpty(change.PowerType);
            row["TimingLoadType"]           = SetNullIfEmpty(change.TimingLoadType);
            row["Speed"]                    = SetNullIfEmpty(change.Speed);
            row["OperatingCharacteristics"] = SetNullIfEmpty(change.OperatingCharacteristics);
            row["SeatClass"]                = ScheduleHeaderLoader.ConvertAccommodationClass(change.SeatClass);
            row["SleeperClass"]             = ScheduleHeaderLoader.ConvertAccommodationClass(change.SleeperClass);
            row["ReservationIndicator"]     = ScheduleHeaderLoader.ConvertReservationIndicator(change.ReservationIndicator);
            row["Catering"]                 = SetNullIfEmpty(change.Catering);
            row["Branding"]                 = SetNullIfEmpty(change.Branding);
            row["EuropeanUic"]              = SetNullIfEmpty(change.Uic);
            row["RetailServiceId"]          = SetNullIfEmpty(change.RetailServiceId);

            Table.Rows.Add(row);
            return(databaseId);
        }
        private void Add(long scheduleId, IEnumerable <IRecord> records)
        {
            ScheduleChange previous = null;

            foreach (var record in records)
            {
                long locationId;

                switch (record)
                {
                case IntermediateLocation location:
                    locationId = _locations.Add(scheduleId, location);
                    if (previous != null)        // Assumes the next location record is the one linked to the change record.
                    {
                        _changes.Add(scheduleId, locationId, previous);
                        previous = null;
                    }
                    break;

                case OriginLocation origin:
                    locationId = _locations.Add(scheduleId, origin);
                    break;

                case TerminalLocation terminal:
                    locationId = _locations.Add(scheduleId, terminal);
                    if (previous != null)
                    {
                        _changes.Add(scheduleId, locationId, previous);
                        previous = null;
                    }
                    break;

                case ScheduleChange change:
                    if (previous != null)
                    {
                        _logger.Warning("Unhandled change record {changeRecord} - schedule {id}", previous, scheduleId);
                    }
                    previous = change;
                    break;

                default:
                    _logger.Warning("Unhandled record {recordType}: {record} - schedule {id}", record.GetType(), record, scheduleId);
                    break;
                }
            }

            if (previous != null)
            {
                _logger.Warning("Unhandled change record {changeRecord} - schedule {id}", previous, scheduleId);
            }
        }
Beispiel #3
0
        protected void ToolbarButtonClick(object sender, RadToolBarEventArgs e)
        {
            switch (e.Item.Text)
            {
            case "Request":
                if (IsValid)
                {
                    var cInvoice = new CInvoice();
                    var original = cInvoice.Get(InvoiceId);
                    if (original != null)
                    {
                        var startDate = DateTime.Today;
                        var endDate   = DateTime.Today;

                        // Program
                        if (original.ProgramRegistrationId != null)
                        {
                            var cProgramRegiInfo = new CProgramRegistration();
                            var programRegiInfo  = cProgramRegiInfo.Get(Convert.ToInt32(original.ProgramRegistrationId));

                            startDate = programRegiInfo.StartDate.Value;
                            endDate   = programRegiInfo.EndDate.Value;

                            programRegiInfo.StartDate   = RadDatePickerStartDate.SelectedDate.Value;
                            programRegiInfo.EndDate     = RadDatePickerEndDate.SelectedDate.Value;
                            programRegiInfo.UpdatedId   = CurrentUserId;
                            programRegiInfo.UpdatedDate = DateTime.Now;

                            cProgramRegiInfo.Update(programRegiInfo);
                        }
                        // Homestay
                        else if (original.HomestayRegistrationId != null)
                        {
                            var cHomestayStudentRequest = new CHomestayStudentRequest();
                            var homestayStudentRequest  = cHomestayStudentRequest.GetHomestayStudentRequest(Convert.ToInt32(original.HomestayRegistrationId));

                            startDate = homestayStudentRequest.StartDate.Value;
                            endDate   = homestayStudentRequest.EndDate.Value;

                            homestayStudentRequest.StartDate             = RadDatePickerStartDate.SelectedDate.Value;
                            homestayStudentRequest.EndDate               = RadDatePickerEndDate.SelectedDate.Value;
                            homestayStudentRequest.UpdateUserId          = CurrentUserId;
                            homestayStudentRequest.UpdatedDate           = DateTime.Now;
                            homestayStudentRequest.HomestayStudentStatus = 2;     // scheduel Change

                            cHomestayStudentRequest.Update(homestayStudentRequest);
                        }
                        // Dormitory
                        else if (original.DormitoryRegistrationId != null)
                        {
                            var cDormitoryStudentRequest = new CDormitoryRegistrations();
                            var dormitoryStudentRequest  = cDormitoryStudentRequest.GetDormitoryStudentRequest(Convert.ToInt32(original.DormitoryRegistrationId));

                            startDate = dormitoryStudentRequest.StartDate.Value;
                            endDate   = dormitoryStudentRequest.EndDate.Value;

                            dormitoryStudentRequest.StartDate = RadDatePickerStartDate.SelectedDate.Value;
                            dormitoryStudentRequest.EndDate   = RadDatePickerEndDate.SelectedDate.Value;
                            dormitoryStudentRequest.DormitoryStudentStatus = 2;     // scheduel Change
                            dormitoryStudentRequest.UpdatedId   = CurrentUserId;
                            dormitoryStudentRequest.UpdatedDate = DateTime.Now;

                            cDormitoryStudentRequest.Update(dormitoryStudentRequest);
                        }

                        var cScheduleChange = new CScheduleChange();
                        var s = new ScheduleChange();

                        s.InvoiceId = original.InvoiceId;
                        s.ApplyDate = RadDatePickerApplyDate.SelectedDate.Value;
                        s.StartDate = startDate;
                        s.EndDate   = endDate;
                        s.Reason    = RadTextBoxReason.Text;
                        s.IsActive  = true;
                        s.CreatedId = CurrentUserId;

                        int scheduleChangeId = cScheduleChange.Add(s);
                        if (scheduleChangeId > 0)
                        {
                            // save uploading file
                            FileDownloadList1.SaveFile(scheduleChangeId);

                            RunClientScript("Close();");
                        }
                        else
                        {
                            ShowMessage("failed to update inqury (Add Schedule Change)");
                        }
                    }
                    else
                    {
                        ShowMessage("failed to update inqury (Original Invoice is null)");
                    }
                }
                break;

            case "Close":
                RunClientScript("Close();");
                break;
            }
        }