예제 #1
0
        public MediaInfoMatchForm(FlextourEntities cont, MEDIAINFO record)
        {
            InitializeComponent();
            context           = cont;
            rcd               = record;
            AddButton.Visible = true;

            List <MEDIARPT> resultList = loadGrid(record);

            if (resultList.Count > 0)
            {
                GridViewAddToReports.GridControl.DataSource = resultList;
            }
        }
예제 #2
0
        internal static MEDIAINFO DeactivateMediaInfo(FlextourEntities context, string section, string type, string code, string cat,
                                                      string language)
        {
            MEDIAINFO info = null;

            info = context.MEDIAINFO.FirstOrDefault(m => m.SECTION == section && m.TYPE == type && m.CODE == code && m.CAT == cat &&
                                                    m.LANG == language && string.IsNullOrEmpty(m.Agency));
            if (info != null)
            {
                info.Inactive = true;
                return(info);
            }
            else
            {
                return(new MEDIAINFO());
            }
        }
예제 #3
0
        internal static MEDIAINFO CheckAndCreateNewMediaInfo(FlextourEntities context, string section, string title, string type, string code, string cat,
                                                             string language, bool?inHouse, DateTime?resDate, DateTime?svcStart, DateTime?svcEnd, string room, bool inactive)
        {
            MEDIAINFO info = null;

            //Check and update in case this is run multiple times on the same day
            info = context.MEDIAINFO.FirstOrDefault(m => m.SECTION == section && m.TYPE == type && m.CODE == code && m.CAT == cat &&
                                                    m.ResDate_Start == resDate && m.SvcDate_Start == svcStart && m.SvcDate_End == svcEnd && m.ResDate_End == null &&
                                                    m.ROOM == room && m.LANG == language && string.IsNullOrEmpty(m.Agency) && (inHouse ?? m.Inhouse) == m.Inhouse);
            if (info == null)
            {
                info = new MEDIAINFO {
                    ResDate_Start = resDate,
                    CODE          = code,
                    TYPE          = type,
                    SECTION       = section,
                    //info.ResDate_Start = resDate;
                    LANG          = language,
                    Inactive      = inactive,
                    Agency        = string.Empty,
                    Inhouse       = inHouse ?? false,
                    CAT           = cat,
                    ROOM          = room,
                    SvcDate_Start = svcStart,
                    SvcDate_End   = svcEnd,
                    ChgDate       = DateTime.Now
                };
            }
            if (title.Length > 100)
            {
                info.TITLE = title.Substring(0, 100);
            }
            else
            {
                info.TITLE = title;
            }
            return(info);
        }
예제 #4
0
        private List <MEDIARPT> loadGrid(MEDIAINFO record)
        {
            List <MEDIARPT> resultList = new List <MEDIARPT>();

            unboundSelection.RemoveRange(0, unboundSelection.Count);
            unboundPosition.RemoveRange(0, unboundSelection.Count);
            unboundPosition.Clear();
            unboundSelection.Clear();
            GridViewAddToReports.GridControl.DataSource = null;

            lang            = record.LANG;
            code            = record.CODE;
            type            = record.TYPE;
            mediaInfoSectID = record.ID;
            IEnumerable <MEDIARPT> mediaRecs = from mrpt in context.MEDIARPT
                                               where mrpt.TYPE == type && mrpt.LANG == lang && mrpt.CODE == code
                                               select mrpt;

            foreach (MEDIARPT rec in mediaRecs)
            {
                if ((from mediaItem in context.MediaRptItem where mediaItem.REPORT_ID == rec.ID && mediaItem.SECTION_ID == mediaInfoSectID select mediaItem).Count() == 0)
                {
                    resultList.Add(rec);
                }
            }

            //04Sep12 - LRUPE: updated how we populate the array list that is bound as an object to the upbound columns
            //so that every row can store values and not a static number.
            for (int I = 0; I <= resultList.Count - 1; I++)
            {
                unboundPosition.Add("");
                unboundSelection.Add("");
            }

            return(resultList);
        }
예제 #5
0
        private void ImportProduct(Item item, BackgroundWorker worker)
        {
            try {
                SupplierProduct suppProd = null;
                //Set up the main COMP record
                bool productAddedOrNameChanged = false;
                var  comp = _context.COMP
                            .Include(c => c.ProductAge)
                            .Include(c => c.SupplierProductAge)
                            .Include(c => c.SupplierProduct)
                            .FirstOrDefault(c => c.CODE == item.InternalCode);
                if (comp == null)
                {
                    productAddedOrNameChanged = true;
                    comp = new COMP()
                    {
                        CODE                  = item.InternalCode,
                        NAME                  = item.Name,
                        RSTR_CDE              = "O",
                        Inactive              = "N",
                        AdminClosed           = false,
                        PickupInfoRequired    = false,
                        DropoffInfoRequired   = false,
                        VendorPrepayReqd      = false,
                        AccountingServiceItem = true,
                        MealsIncluded         = false,
                        RATE_BASIS            = "D",
                        ProximitySearch       = false,
                        WeightRequired        = false,
                        DOBRequired           = false,
                        Allow_Freesell        = false,
                        Multiple_Times        = "0",
                        SERV_TYPE             = searchLookUpEditServiceType.EditValue.ToString(),
                        CITY                  = searchLookUpEditCity.EditValue.ToString()
                    };
                    _context.COMP.AddObject(comp);
                }
                else
                {
                    if (comp.AdminClosed || comp.Inactive == "Y")
                    {
                        return;
                    }
                    suppProd = comp.SupplierProduct.FirstOrDefault(sp => sp.Supplier_GUID == _supplierConnection.Supplier_GUID &&
                                                                   sp.ProductCodeSupplier == item.Pk.ToString());
                }
                if (suppProd == null)
                {
                    suppProd = new SupplierProduct()
                    {
                        Product_Type          = "OPT",
                        Product_Code_Internal = item.InternalCode,
                        ProductCodeSupplier   = item.Pk.ToString(),
                        Supplier_GUID         = _supplierConnection.Supplier_GUID,
                        Inactive = false,
                    };
                    suppProd.COMP = comp;
                    _context.SupplierProduct.AddObject(suppProd);
                }
                suppProd.Custom1          = _company;
                suppProd.SupplierCommPct  = spinEditCommPct.Value;
                suppProd.SupplierCommFlat = spinEditCommFlat.Value;
                suppProd.MarkupPct        = spinEditMarkupPct.Value;
                suppProd.MarkupFlat       = spinEditMarkupFlat.Value;

                //Don't overwrite name because staff change it manually
                //if (comp.NAME != item.Name) {
                //    productAddedOrNameChanged = true;
                //}
                //comp.NAME = item.Name;
                if (item.Is_pickup_ever_available)
                {
                    comp.PUDRP_REQ = "P";
                    comp.TRSFR_TYP = "O";
                }
                else
                {
                    comp.TRSFR_TYP = "N";
                }
                comp.StartingPrice    = item.StartingPrice;
                comp.StartingCost     = Math.Round(item.StartingPrice * (1 - ((suppProd.SupplierCommPct ?? 0) / 100)), 2) - (suppProd.SupplierCommFlat ?? 0);
                comp.StartingAgentNet = Math.Round((comp.StartingCost ?? 0) * (1 + ((suppProd.MarkupPct ?? 0) / 100)), 2) - (suppProd.MarkupFlat ?? 0);
                //Other location types seem to be "pre", "start", "end"
                //TODO: Each location can also have notes, which are rarely provided and often duplicate other information
                //Should the location notes be stored somewhere?
                //There is also an item.Location property which holds the whole address as a single string
                var mainLocation = item.Locations.FirstOrDefault(l => l.Type == "primary");
                if (mainLocation == null)
                {
                    mainLocation = item.Locations.FirstOrDefault();
                }
                if (mainLocation != null)
                {
                    var address = mainLocation.Address;
                    comp.ADDR1   = address.Street;
                    comp.COUNTRY = address.Country;
                    comp.ZIP     = address.Postal_code;
                    comp.STATE   = address.Province;
                    comp.TOWN    = address.City;
                    if (mainLocation.Latitude != null && mainLocation.Longitude != null)
                    {
                        var geo = comp.GeoCode;
                        if (geo == null)
                        {
                            geo = new GeoCode();
                            _context.GeoCode.AddObject(geo);
                            comp.GeoCode = geo;
                        }
                        geo.AgentInitials = _sys.User.Name;
                        geo.PushLat       = (double)mainLocation.Latitude;
                        geo.PushLong      = (double)mainLocation.Longitude;
                    }
                }

                if (Configurator.ImportCancellationPolicies)
                {
                    //Cancellation policy has a type field which so far is only ever "hours-before-start"
                    int daysPrior = (int)Math.Ceiling(item.Effective_cancellation_policy.Cutoff_hours_before / 24) + (_supplierConnection.ExtraNightsPriorForCxlPolicy ?? 0);
                    FindOrAddCxlfee(_sys, _context, comp.CODE, daysPrior, 100);
                }

                //Set up the age mappings
                foreach (var custType in item.Customer_prototypes.Where(cp => cp.Selected))
                {
                    SupplierProductAge suppProdAge = null;
                    ProductAge         prodAge     = null;
                    if (custType.InternalId != null)
                    {
                        suppProdAge = comp.SupplierProductAge.FirstOrDefault(sp => sp.Id == custType.InternalId);
                    }
                    if (suppProdAge == null)
                    {
                        suppProdAge = new SupplierProductAge()
                        {
                            Product_Code  = comp.CODE,
                            Product_Type  = "OPT",
                            Supplier_GUID = _supplierConnection.Supplier_GUID,
                            SupplierId    = custType.Pk.ToString()
                        };
                        _context.SupplierProductAge.AddObject(suppProdAge);
                    }
                    else
                    {
                        prodAge = suppProdAge.ProductAge;
                    }
                    if (prodAge == null)
                    {
                        //If there is already a ProductAge record with the same age limits, reuse it rather than creating a new one
                        prodAge = comp.ProductAge.FirstOrDefault(pa => pa.FromAge == custType.FromAge && pa.ToAge == custType.ToAge);
                        if (prodAge == null)
                        {
                            prodAge = new ProductAge()
                            {
                                Product_Type = "OPT",
                                Product_Code = comp.CODE,
                            };
                            comp.ProductAge.Add(prodAge);
                            _context.ProductAge.AddObject(prodAge);
                        }
                    }
                    suppProdAge.SupplierName = custType.Display_name;
                    prodAge.FromAge          = custType.FromAge;
                    prodAge.ToAge            = custType.ToAge;
                    prodAge.Description      = custType.PaxType;
                    switch (custType.PaxType.ToLower())
                    {
                    case "adult":
                        prodAge.PluralDescription = "Adults";
                        break;

                    case "child":
                        prodAge.PluralDescription = "Children";
                        break;

                    case "junior":
                        prodAge.PluralDescription = "Juniors";
                        break;

                    case "infant":
                        prodAge.PluralDescription = "Infants";
                        break;

                    case "senior":
                        prodAge.PluralDescription = "Seniors";
                        break;
                    }
                    if (custType.ToAge == null || custType.ToAge >= 18)
                    {
                        prodAge.IsAdult      = true;
                        prodAge.TreatAsAdult = true;
                    }
                    suppProdAge.ProductAge = prodAge;
                }

                //Set up the media information
                MEDIAINFO mainInfo = MediaHelper.CheckAndCreateNewMediaInfo(_context, _sys.Settings.MainMediaSection, item.Name,
                                                                            "OPT", comp.CODE, string.Empty, "ENG", Configurator.CreateNewInfoAsInHouse, null);

                List <string> texts = new List <string>();
                if (!string.IsNullOrEmpty(item.Headline))
                {
                    texts.Add(item.Headline);
                }
                if (!string.IsNullOrEmpty(item.Description_text))
                {
                    texts.Add(item.Description_text);
                }
                if (!string.IsNullOrEmpty(item.Description_safe_html))
                {
                    texts.Add(item.Description_safe_html);
                }
                string.Join("<br/><br/>", texts);
                mainInfo.TEXT = item.Headline + item.Description_text + item.Description_safe_html;
                string imagePath = MediaHelper.GetOrPutImage(_sys, "OPT", comp.CODE, _prefix, comp.CITY, item.Image_cdn_url, string.Empty, false);
                mainInfo.IMAGE1 = imagePath;
                imagePath       = MediaHelper.GetOrPutImage(_sys, "OPT", comp.CODE, _prefix, comp.CITY, item.Image_cdn_url, "thumb_", true);
                mainInfo.IMAGE4 = imagePath;

                //Some companies have booking notes that are clearly intended for after making a booking because they say
                //"Thank you for your booking". Others have useful info about what to bring and what to expect. We can't tell the difference
                //so just always use the booking notes
                MEDIAINFO fullInfo = MediaHelper.CheckAndCreateNewMediaInfo(_context, Configurator.FullDescMediaReportSection, _fullDescTitles[0],
                                                                            "OPT", comp.CODE, string.Empty, "ENG", Configurator.CreateNewInfoAsInHouse, null);
                fullInfo.TEXT = CreateBulletList(item.Description_bullets) + item.Booking_notes_safe_html;

                MEDIAINFO termsInfo = new MEDIAINFO();
                if (!string.IsNullOrEmpty(item.Cancellation_policy_safe_html))
                {
                    termsInfo = MediaHelper.CheckAndCreateNewMediaInfo(_context, Configurator.TermsMediaReportSection, _termsTitles[0],
                                                                       "OPT", comp.CODE, string.Empty, "ENG", Configurator.CreateNewInfoAsInHouse, null);
                    termsInfo.TEXT = item.Cancellation_policy_safe_html;
                }

                //Download the images and attach to the main media section
                List <RESOURCE> resources = new List <RESOURCE>();
                if (Configurator.DownloadImages)
                {
                    foreach (var image in item.Images)
                    {
                        imagePath = MediaHelper.GetOrPutImage(_sys, "OPT", comp.CODE, _prefix, comp.CITY, image.Image_cdn_url, string.Empty, false);
                        MediaHelper.CheckAndAddResource(_context, resources, mainInfo, imagePath, string.Empty, "1");       //1=medium res
                    }
                }

                var rptGeninfo = MediaHelper.CheckAndCreateNewMediaRpt(_context, _sys.Settings.MainMediaReport, "OPT", comp.CODE,
                                                                       "ENG", null);
                var rptVoucher = MediaHelper.CheckAndCreateNewMediaRpt(_context, Configurator.VoucherMediaReportType, "OPT", comp.CODE,
                                                                       "ENG", null);

                if ((!string.IsNullOrEmpty(mainInfo.TEXT) || resources.Count > 0))
                {
                    MediaHelper.CheckAndAddInfoToReports(_context, new MEDIARPT[] { rptGeninfo, rptVoucher }, mainInfo, 0);
                    if (mainInfo.ID == 0)
                    {
                        _context.MEDIAINFO.AddObject(mainInfo);
                    }
                }
                if (!string.IsNullOrEmpty(fullInfo.TEXT))
                {
                    MediaHelper.CheckAndAddInfoToReports(_context, new MEDIARPT[] { rptGeninfo }, fullInfo, 1);
                    if (fullInfo.ID == 0)
                    {
                        _context.MEDIAINFO.AddObject(fullInfo);
                    }
                }
                if (!string.IsNullOrEmpty(termsInfo.TEXT))
                {
                    MediaHelper.CheckAndAddInfoToReports(_context, new MEDIARPT[] { rptGeninfo, rptVoucher }, termsInfo, 2);
                    if (termsInfo.ID == 0)
                    {
                        _context.MEDIAINFO.AddObject(termsInfo);
                    }
                }
                if (rptGeninfo.ID == 0 && rptGeninfo.MediaRptItem.Count > 0)
                {
                    _context.MEDIARPT.AddObject(rptGeninfo);
                }
                if (rptVoucher.ID == 0 && rptVoucher.MediaRptItem.Count > 0)
                {
                    _context.MEDIARPT.AddObject(rptVoucher);
                }

                List <MEDIAINFO> infos = new List <MEDIAINFO>()
                {
                    mainInfo, fullInfo, termsInfo
                };
                MediaHelper.SetMediaInfosChgDate(_context, infos, _update);
                MediaHelper.SetServiceChgDate(_context, comp, _update, _sys.User.Name);

                _context.SaveChanges();
                if (productAddedOrNameChanged)
                {
                    AccountingAPI.InvokeForProduct(_sys.Settings.TourAccountingURL, "OPT", comp.CODE);
                }

                //Update the image resources with the id of the linked media section
                if (resources.Count > 0)
                {
                    foreach (var resource in resources)
                    {
                        resource.LINK_VALUE = mainInfo.ID.ToString();
                        _context.RESOURCE.AddObject(resource);
                    }
                    _context.SaveChanges();
                }

                try {
                    worker.ReportProgress(0, $"Updating website for {item.Name}");
                    _context.usp_RefreshSingleProduct("OPT", comp.CODE, _sys.Settings.MainMediaReport, _sys.Settings.FeaturedMediaSection,
                                                      _sys.Settings.MainMediaReport, _sys.Settings.MainMediaSection);
                }
                catch {
                    NLog.LogManager.GetCurrentClassLogger().Trace(" Refresh Product Failed");
                }
            }
            catch (DbEntityValidationException ex) {
                string details = string.Join(Environment.NewLine, ex.EntityValidationErrors.Select(e =>
                                                                                                   string.Join(Environment.NewLine, e.ValidationErrors.Select(v =>
                                                                                                                                                              string.Format("{0} - {1}", v.PropertyName, v.ErrorMessage)))));
                details += Environment.NewLine;
                NLog.LogManager.GetCurrentClassLogger().Error(ex, details);
                System.Diagnostics.Debugger.Break();
            }
            catch (Exception ex) {
                NLog.LogManager.GetCurrentClassLogger().Error(ex);
                System.Diagnostics.Debugger.Break();
            }
        }
예제 #6
0
 internal static void CheckAndAddResource(FlextourEntities context, List <RESOURCE> resources, MEDIAINFO section, string imagePath,
                                          string description, string resolution)
 {
     if (!string.IsNullOrEmpty(imagePath))
     {
         bool resourceExists = false;
         if (section.ID != 0)
         {
             string id = section.ID.ToString();
             resourceExists = context.RESOURCE.Any(r => r.LINK_TABLE == "MEDIAITEM" && r.RECTYPE == "IMAGE" &&
                                                   r.ITEM == imagePath && r.LINK_VALUE == id);
         }
         if (!resourceExists)
         {
             RESOURCE resource = new RESOURCE();
             resource.LINK_TABLE = "MEDIAITEM";
             resource.RECTYPE    = "IMAGE";
             resource.TAG        = resolution; //resolution
             resource.ITEM       = imagePath;
             if (description.Length <= 50)
             {
                 resource.DESCRIPTION = description;
             }
             else
             {
                 resource.DESCRIPTION = description.Substring(0, 50);
             }
             resources.Add(resource);
         }
     }
 }
예제 #7
0
        internal static void CheckAndAddInfoToReports(FlextourEntities context, MEDIARPT[] addToReports, MEDIAINFO info, short?position)
        {
            foreach (var rpt in addToReports)
            {
                MediaRptItem rptItem = null;
                if (rpt.ID > 0 && info.ID > 0)
                {
                    continue;
                    //Checking each existing report and section to see if they are linked is too slow...

                    //If the report and media info section were previously saved, check if they were also linked
                    //together by MediaRptItem
                    //rptItem = context.MediaRptItem.FirstOrDefault(mri => mri.REPORT_ID == rpt.ID && mri.SECTION_ID == info.ID);
                }
                if (rptItem == null)
                {
                    rptItem                  = new MediaRptItem();
                    rptItem.MEDIARPT         = rpt;
                    rptItem.MEDIARPT.ChgDate = DateTime.Now;
                    rptItem.MEDIAINFO        = info;
                    rptItem.POSITION         = position;
                    rpt.MediaRptItem.Add(rptItem);
                }
            }
        }