Esempio n. 1
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            CatalogDto catalog = null;

            if (Parameters["CatalogId"] != null)
            {
                catalog = CatalogContext.Current.GetCatalogDto(Int32.Parse(Parameters["CatalogId"].ToString()));
            }
            else
            {
                catalog = new CatalogDto();
            }

            IDictionary context = new ListDictionary();

            context.Add("Catalog", catalog);

            ViewControl.SaveChanges(context);

            int catalogId = catalog.Catalog[0].CatalogId;

            if (catalog.HasChanges())
            {
                CatalogContext.Current.SaveCatalog(catalog);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            WarehouseDto warehouse = (WarehouseDto)Session[_WarehouseDtoEditSessionKey];

            if (WarehouseId > 0 && warehouse == null)
            {
                warehouse = WarehouseManager.GetWarehouseByWarehouseId(WarehouseId);
            }
            else if (WarehouseId == 0)
            {
                warehouse = new WarehouseDto();
            }

            IDictionary context = new ListDictionary();

            context.Add(_WarehouseDtoString, warehouse);

            ViewControl.SaveChanges(context);

            if (warehouse.HasChanges())
            {
                WarehouseManager.SaveWarehouse(warehouse);
            }

            // we don't need to store Dto in session any more
            Session.Remove(_WarehouseDtoEditSessionKey);
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            PolicyDto policy = (PolicyDto)Session[_PolicyDtoEditSessionKey];

            if (PolicyId > 0 && policy == null)
            {
                policy = PolicyManager.GetPolicyDto(PolicyId);
            }
            else if (PolicyId == 0)
            {
                policy = new PolicyDto();
            }

            IDictionary context = new ListDictionary();

            context.Add(_PolicyDtoString, policy);

            ViewControl.SaveChanges(context);

            if (policy.HasChanges())
            {
                PolicyManager.SavePolicy(policy);
            }

            // we don't need to store Dto in session any more
            Session.Remove(_PolicyDtoEditSessionKey);
        }
Esempio n. 4
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Mediachase.Commerce.Manager.Core.SaveControl.SaveEventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            JurisdictionDto jurisdiction = (JurisdictionDto)Session[_JurisdictionDtoEditSessionKey];

            if (JurisdictionGroupId > 0 && jurisdiction == null)
            {
                jurisdiction = JurisdictionManager.GetJurisdictionGroup(JurisdictionGroupId);
            }
            else if (JurisdictionGroupId == 0)
            {
                jurisdiction = new JurisdictionDto();
            }

            IDictionary context = new ListDictionary();

            context.Add(_JurisdictionDtoString, jurisdiction);

            ViewControl.SaveChanges(context);

            if (jurisdiction.HasChanges())
            {
                JurisdictionManager.SaveJurisdiction(jurisdiction);
            }

            // we don't need to store Dto in session any more
            Session.Remove(_JurisdictionDtoEditSessionKey);
        }
Esempio n. 5
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            ExpressionDto expression = (ExpressionDto)Session[_ExpressionDtoEditSessionKey];             //null;

            if (ExpressionId > 0 && expression == null)
            {
                expression = ExpressionManager.GetExpressionDto(ExpressionId);                 //Int32.Parse(Parameters["ExpressionId"].ToString()));
            }
            else if (ExpressionId == 0)
            {
                expression = new ExpressionDto();
            }

            IDictionary context = new ListDictionary();

            context.Add(_ExpressionDtoString, expression);

            ViewControl.SaveChanges(context);

            if (expression.HasChanges())
            {
                ExpressionManager.SaveExpression(expression);
            }

            // we don't need to store Dto in session any more
            Session.Remove(_ExpressionDtoEditSessionKey);
        }
Esempio n. 6
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            CampaignDto campaign = (CampaignDto)Session[_CampaignDtoEditSessionKey];             //null;

            if (CampaignId > 0 && campaign == null)
            {
                campaign = CampaignManager.GetCampaignDto(CampaignId);                 //Int32.Parse(Parameters[_CampaignIdString].ToString()));
            }
            else if (CampaignId == 0)
            {
                campaign = new CampaignDto();
            }

            IDictionary context = new ListDictionary();

            context.Add(_CampaignDtoString, campaign);

            ViewControl.SaveChanges(context);

            if (campaign.HasChanges())
            {
                CampaignManager.SaveCampaign(campaign);
            }

            // we don't need to store Dto in session any more
            Session.Remove(_CampaignDtoEditSessionKey);
        }
Esempio n. 7
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            try
            {
                CountryDto country = (CountryDto)Session[_CountryDtoEditSessionKey];

                if (CountryId > 0 && country == null)
                {
                    country = CountryManager.GetCountry(CountryId, true);
                }
                else if (CountryId == 0)
                {
                    country = new CountryDto();
                }

                country.EnforceConstraints = false;

                IDictionary context = new ListDictionary();
                context.Add(_CountryDtoString, country);

                ViewControl.SaveChanges(context);

                if (country.HasChanges())
                {
                    // if new country has just been created, update countryid for stateProvince rows
                    if (country.Country.Rows.Count > 0 && country.Country[0].RowState == DataRowState.Added)
                    {
                        int cId = country.Country[0].CountryId;
                        foreach (CountryDto.StateProvinceRow row in country.StateProvince.Rows)
                        {
                            row.CountryId = cId;
                        }
                    }

                    country.EnforceConstraints = true;

                    // commit changes to the db
                    CountryManager.SaveCountry(country);
                }
            }
            catch (Exception ex)
            {
                e.RunScript = false;
                DisplayErrorMessage(ex.Message);
            }
            finally
            {
                // we don't need to store Dto in session any more
                Session.Remove(_CountryDtoEditSessionKey);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            ViewControl.SaveChanges(null);
        }
Esempio n. 9
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            // Put a dictionary key that can be used by other tabs
            IDictionary dic = new ListDictionary();

            ViewControl.SaveChanges(dic);
        }
Esempio n. 10
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            PromotionDto promo = (PromotionDto)Session[_PromotionDtoEditSessionKey];

            if (promo == null && PromotionId > 0)
            {
                promo = PromotionManager.GetPromotionDto(PromotionId); //Int32.Parse(Parameters["PromotionId"].ToString()));
            }
            if (PromotionId == 0)
            {
                promo = new PromotionDto();
            }

            /*
             * // if we add a new promotion, remove all other segments from Dto that is passed to control that saves changes
             * if (PromotionId == 0 && promo != null && promo.Promotion.Count > 0)
             * {
             *      PromotionDto.PromotionRow[] rows2del = (PromotionDto.PromotionRow[])promo.Promotion.Select(String.Format("{0} <> {1}", _PromotionIdString, PromotionId));
             *      if (rows2del != null)
             *              foreach (PromotionDto.PromotionRow row in rows2del)
             *                      promo.Promotion.RemovePromotionRow(row);
             * }*/

            IDictionary context = new ListDictionary();

            context.Add(_PromotionDtoString, promo);

            ViewControl.SaveChanges(context);

            if (promo.HasChanges())
            {
                PromotionManager.SavePromotion(promo);
            }

            // we don't need to store Dto in session any more
            Session.Remove(_PromotionDtoEditSessionKey);
        }
Esempio n. 11
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            CatalogNodeDto dto = null;

            if (CatalogNodeId > 0)
            {
                dto = CatalogContext.Current.GetCatalogNodeDto(CatalogNodeId);
            }
            else
            {
                dto = new CatalogNodeDto();
            }

            // Put a dictionary key that can be used by other tabs
            IDictionary dic = new ListDictionary();

            dic.Add(_CatalogNodeDtoString, dto);

            using (TransactionScope scope = new TransactionScope())
            {
                // Call tabs save
                ViewControl.SaveChanges(dic);

                // Save modifications
                if (dto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogNode(dto);
                }

                ViewControl.CommitChanges(dic);

                scope.Complete();
            }

            // we don't need to store Dto in session any more
            Session.Remove(_CatalogNodeDtoString);
        }
Esempio n. 12
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            try
            {
                ViewControl.SaveChanges(null);
            }
            catch (Exception ex)
            {
                e.RunScript = false;
                DisplayErrorMessage(ex.Message);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Mediachase.Commerce.Manager.Core.SaveControl.SaveEventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            TaxDto tax = null;

            if (TaxId > 0)
            {
                tax = (TaxDto)Session[_TaxDtoEditSessionKey];
            }

            if (tax == null && TaxId > 0)
            {
                tax = TaxManager.GetTax(TaxId);
            }

            CreateEmptyDto(ref tax, true);

            IDictionary dic = new ListDictionary();

            dic.Add(_TaxDtoString, tax);

            ViewControl.SaveChanges(dic);

            // save changes
            if (tax.HasChanges())
            {
                TaxManager.SaveTax(tax);
            }

            ViewControl.CommitChanges(dic);

            // we don't need to store Dto in session any more
            Session.Remove(_TaxDtoEditSessionKey);
        }
Esempio n. 14
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Mediachase.Commerce.Manager.Core.SaveControl.SaveEventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            ShippingMethodDto sm = null;

            if (ShippingOptionId != Guid.Empty)
            {
                sm = (ShippingMethodDto)Session[GetShippingMethodSessionKey()];
            }

            if (sm == null && ShippingOptionId != Guid.Empty)
            {
                sm = ShippingManager.GetShippingOption(ShippingOptionId, true);
            }

            CreateEmptyDto(ref sm, true);

            IDictionary dic = new ListDictionary();

            dic.Add(_ShippingMethodDtoString, sm);

            ViewControl.SaveChanges(dic);

            // save changes
            if (sm.HasChanges())
            {
                ShippingManager.SaveShipping(sm);
            }

            ViewControl.CommitChanges(dic);

            // we don't need to store Dto in session any more
            Session.Remove(GetShippingMethodSessionKey());
        }
Esempio n. 15
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Mediachase.Commerce.Manager.Core.SaveControl.SaveEventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            PaymentMethodDto pm = null;

            if (PaymentMethodId != Guid.Empty)
            {
                pm = (PaymentMethodDto)Session[_PaymentMethodDtoEditSessionKey];
            }

            if (pm == null && PaymentMethodId != Guid.Empty)
            {
                pm = PaymentManager.GetPaymentMethod(PaymentMethodId, true);
            }

            CreateEmptyDto(ref pm, true);

            IDictionary dic = new ListDictionary();

            dic.Add(_PaymentMethodDtoString, pm);

            ViewControl.SaveChanges(dic);

            // save changes
            if (pm.HasChanges())
            {
                PaymentManager.SavePayment(pm);
            }

            ViewControl.CommitChanges(dic);

            // we don't need to store Dto in session any more
            Session.Remove(GetPaymentMethodSessionKey());
        }
Esempio n. 16
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Mediachase.Commerce.Manager.Core.SaveControl.SaveEventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            CatalogEntryDto       dto         = null;
            CatalogRelationDto    relation    = null;
            CatalogAssociationDto association = null;

            using (TransactionScope scope = new TransactionScope())
            {
                if (CatalogEntryId > 0)
                {
                    dto         = (CatalogEntryDto)Session[_CatalogEntryDtoString];
                    relation    = (CatalogRelationDto)Session[_CatalogRelationDtoString];
                    association = (CatalogAssociationDto)Session[_CatalogAssociationDtoString];
                }

                if (association == null && CatalogEntryId > 0)
                {
                    association = LoadAssociation();
                }

                if (relation == null && CatalogEntryId > 0)
                {
                    relation = LoadRelation();
                }

                if (dto == null && CatalogEntryId > 0)
                {
                    dto = LoadEntry();
                }

                CreateEmptyDtos(ref dto, ref relation, ref association, true);

                // Put a dictionary key that can be used by other tabs
                IDictionary dic = new ListDictionary();
                dic.Add(_CatalogEntryDtoString, dto);
                dic.Add(_CatalogRelationDtoString, relation);
                dic.Add(_CatalogAssociationDtoString, association);

                // Call tabs save
                ViewControl.SaveChanges(dic);

                // Save modifications
                if (dto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogEntry(dto);
                }

                // get current CatalogEntryId
                int currentCatalogEntryId = this.CatalogEntryId;
                if (dto.CatalogEntry != null && dto.CatalogEntry.Rows.Count > 0)
                {
                    currentCatalogEntryId = dto.CatalogEntry[0].CatalogEntryId;
                }

                // Modify relationship
                CatalogRelationDto.NodeEntryRelationRow relRow = null;

                // Find existing row
                if (relation.NodeEntryRelation.Count > 0)
                {
                    foreach (CatalogRelationDto.NodeEntryRelationRow row in relation.NodeEntryRelation.Rows)
                    {
                        if (row.CatalogEntryId == currentCatalogEntryId && row.CatalogId == ParentCatalogId && row.CatalogNodeId == ParentCatalogNodeId)
                        {
                            relRow = row;
                            break;
                        }
                    }
                }

                // If no existing record found, create a new one
                if (ParentCatalogId > 0 && ParentCatalogNodeId > 0)
                {
                    if (relRow == null)
                    {
                        relRow = relation.NodeEntryRelation.NewNodeEntryRelationRow();
                    }

                    if (ParentCatalogId > 0)
                    {
                        relRow.CatalogId = ParentCatalogId;
                    }

                    if (this.ParentCatalogNodeId > 0)
                    {
                        relRow.CatalogNodeId = this.ParentCatalogNodeId;
                    }

                    relRow.CatalogEntryId = currentCatalogEntryId;

                    // Attach if it is a new row
                    if (relRow.RowState == DataRowState.Detached)
                    {
                        relRow.SortOrder = 0;
                        relation.NodeEntryRelation.Rows.Add(relRow);
                    }
                }

                // Update newly added entry relationships with a parent catalog entry id
                if (relation.CatalogEntryRelation.Rows.Count > 0)
                {
                    foreach (CatalogRelationDto.CatalogEntryRelationRow row in relation.CatalogEntryRelation.Rows)
                    {
                        if (row.RowState == DataRowState.Added && row.ParentEntryId <= 0)
                        {
                            row.ParentEntryId = currentCatalogEntryId;
                        }
                    }
                }

                if (relation.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(relation);
                }

                // Update newly added entry relationships with a parent catalog entry id
                if (association.CatalogAssociation.Rows.Count > 0)
                {
                    foreach (CatalogAssociationDto.CatalogAssociationRow row in association.CatalogAssociation.Rows)
                    {
                        if (row.RowState == DataRowState.Added && row.CatalogEntryId <= 0)
                        {
                            row.CatalogEntryId = currentCatalogEntryId;
                        }
                    }
                }

                // Save association modifications
                if (association.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogAssociation(association);
                }

                // Call commit changes
                ViewControl.CommitChanges(dic);

                // Save modifications
                if (dto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogEntry(dto);
                }

                // Save relation modifications
                if (relation.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(relation);
                }

                // Save association modifications
                if (association.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogAssociation(association);
                }

                // Complete transaction
                scope.Complete();

                // we don't need to store Dto in session any more
                Session.Remove(_CatalogEntryDtoString);
                Session.Remove(_CatalogRelationDtoString);
                Session.Remove(_CatalogAssociationDtoString);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            try
            {
                // Always load, since we need application data
                SiteDto dto = (SiteDto)Session[_SiteEditSessionKey];

                if (dto == null && SiteId != Guid.Empty)
                {
                    if (NeedCopy)
                    {
                        dto = new SiteDto();
                    }
                    else
                    {
                        dto = CMSContext.Current.GetSiteDto(SiteId, true);
                    }
                }
                else if (dto == null && SiteId == Guid.Empty)
                {
                    dto = new SiteDto();
                }

                // Put a dictionary key that can be used by other tabs
                IDictionary dic = new ListDictionary();
                dic.Add(_SiteDtoDestinationString, dto);

                dto.EnforceConstraints = false;

                ViewControl.SaveChanges(dic);

                // get saveddto from the dictionary
                dto = (SiteDto)dic[_SiteDtoDestinationString];

                // Save modifications
                if (dto.HasChanges())
                {
                    if (dto.Site.Count > 0)
                    {
                        // update siteId for the GlobalVariable rows that have just been addded
                        SiteDto.main_GlobalVariablesRow[] variableRows = (SiteDto.main_GlobalVariablesRow[])dto.main_GlobalVariables.Select("", "", DataViewRowState.Added);
                        if (variableRows != null && variableRows.Length > 0)
                        {
                            foreach (SiteDto.main_GlobalVariablesRow row in variableRows)
                            {
                                row.SiteId = dto.Site[0].SiteId;
                            }
                        }
                    }

                    dto.EnforceConstraints = true;

                    CMSContext.Current.SaveSite(dto);

                    if (NeedCopy && SiteId != Guid.Empty)
                    {
                        CopyHelper helper = new CopyHelper();

                        //Menu copy
                        helper.CopySiteMenu(SiteId, dto.Site[0].SiteId);

                        //Folders and pages copy
                        helper.CopySiteContent(SiteId, dto.Site[0].SiteId);
                    }
                }

                // Call commit changes
                ViewControl.CommitChanges(dic);
            }
            catch (SiteImportExportException ex)
            {
                e.RunScript = false;
                DisplayErrorMessage(ex.Message);
            }
            finally
            {
                // we don't need to store Dto in session any more
                Session.Remove(_SiteEditSessionKey);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void SaveButton_Click(object sender, SaveControl.SaveEventArgs e)
        {
            Page.Validate("Precision");

            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            MetaField field = CurrentMetaField;

            //if (AttributeId > 0)
            //    field = MetaField.Load(MDContext, AttributeId);

            if (field == null)
            {
                int          DataTypeId = int.Parse(ddlType.SelectedItem.Value);
                MetaDataType type;
                if (DataTypeId != 0)
                {
                    type = MetaType.Load(MDContext, DataTypeId).MetaDataType;
                }
                else
                {
                    if (chkMultiline.Checked && chkEditable.Checked)
                    {
                        type = MetaDataType.DictionaryMultiValue;
                    }
                    else if (!chkMultiline.Checked && chkEditable.Checked)
                    {
                        type = MetaDataType.DictionarySingleValue;
                    }
                    else if (chkMultiline.Checked && !chkEditable.Checked)
                    {
                        type = MetaDataType.EnumMultiValue;
                    }
                    else
                    {
                        type = MetaDataType.EnumSingleValue;
                    }
                }

                try
                {
                    field = MetaField.Create(MDContext, FieldNamespace, MetaField.GetUniqueName(MDContext, tbName.Text), tbFriendlyName.Text, tbDescription.Text,
                                             type, 0, chkAllowNulls.Checked, chkSaveHistory.Checked, chkMultiLanguage.Checked, chkAllowSearch.Checked, chkIsEncrypted.Checked);
                }
                catch (System.Data.SqlClient.SqlException sqlException)
                {
                    if (sqlException.Number == 2627 || sqlException.Number == 50000)
                    {
                        DisplayErrorMessage(RM.GetString("ATTRIBUTEEDIT_ERROR_FIELDNAMEDUPLICTAION"));
                        return;
                    }
                }
            }
            else
            {
                try
                {
                    // MetaData bug:
                    // setting value for AllowSearch works only in the beginning of transaction

                    if (field.AllowSearch != chkAllowSearch.Checked)
                    {
                        field.AllowSearch = chkAllowSearch.Checked;
                    }

                    field.IsEncrypted  = chkIsEncrypted.Checked;
                    field.FriendlyName = tbFriendlyName.Text;
                    field.Description  = tbDescription.Text;
                    //field.Namespace = field.Namespace;
                    field.SaveHistory        = chkSaveHistory.Checked;
                    field.MultiLanguageValue = chkMultiLanguage.Checked;
                }
                catch (Exception)
                {
                    throw;
                }
            }

            // Add dictionary elements if needed
            if (IsDictionaryType(field.DataType))
            {
                foreach (ListItem li in DicSingleValueCtrl.Items)
                {
                    if (li.Value == "-1")
                    {
                        // add new value to the dictionary
                        field.Dictionary.Add(li.Text);
                    }
                }
            }

            // Decimal and numeric properties
            if (field.DataType == MetaDataType.Decimal || field.DataType == MetaDataType.Numeric)
            {
                field.Attributes["MdpPrecision"] = tbPrecision.Text;
                field.Attributes["MdpScale"]     = tbScale.Text;
            }

            // Image properties
            if (field.DataType == MetaDataType.ImageFile || field.DataType == MetaDataType.Image)
            {
                field.Attributes["AutoResize"]   = chkAutoResizeImage.Checked.ToString();
                field.Attributes["ImageWidth"]   = ImageWidth.Text;
                field.Attributes["ImageHeight"]  = ImageHeight.Text;
                field.Attributes["StretchImage"] = chkStretchImage.Checked.ToString();

                field.Attributes["CreateThumbnail"]  = chkAutoGenerateThumbnail.Checked.ToString();
                field.Attributes["ThumbnailWidth"]   = ThumbnailWidth.Text;
                field.Attributes["ThumbnailHeight"]  = ThumbnailHeight.Text;
                field.Attributes["StretchThumbnail"] = chkStretchThumbnail.Checked.ToString();
            }

            if (CanBeCompared(field.DataType))
            {
                field.Attributes["UseInComparing"] = chkUseInComparing.Checked.ToString();
            }
            else
            {
                field.Attributes["UseInComparing"] = Boolean.FalseString;
            }

            if (AllowSearch(field.DataType))
            {
                field.Attributes["IndexStored"] = IndexStored.Checked.ToString();
                field.Attributes["IndexField"]  = IndexOptionsList.SelectedValue;
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            try
            {
                CurrencyDto currency = (CurrencyDto)Session[_CurrencyDtoEditSessionKey];

                if (CurrencyId > 0 && currency == null)
                {
                    currency = CurrencyManager.GetCurrencyDto();
                }
                else if (CurrencyId == 0)
                {
                    currency = LoadFresh();
                }

                IDictionary context = new ListDictionary();
                context.Add(_CurrencyDtoContextString, currency);
                context.Add(_CurrencyIdContextString, CurrencyId);

                ViewControl.SaveChanges(context);

                if (currency.HasChanges())
                {
                    CurrencyDto.CurrencyRow currentCurrencyRow = null;

                    // search for the row that has just been added
                    CurrencyDto.CurrencyRow[] tempCurrencyRows = (CurrencyDto.CurrencyRow[])currency.Currency.Select("", "", DataViewRowState.Added);
                    if (tempCurrencyRows != null && tempCurrencyRows.Length > 0)
                    {
                        currentCurrencyRow = tempCurrencyRows[0];
                    }

                    if (currentCurrencyRow != null)
                    {
                        int cId = currentCurrencyRow.CurrencyId;

                        // if new currency has just been created, update currencyid for CurrencyRate rows
                        CurrencyDto.CurrencyRateRow[] rateRows = (CurrencyDto.CurrencyRateRow[])currency.CurrencyRate.Select("", "", DataViewRowState.Added | DataViewRowState.ModifiedCurrent);
                        if (rateRows != null && rateRows.Length > 0)
                        {
                            foreach (CurrencyDto.CurrencyRateRow row in rateRows)
                            {
                                row.FromCurrencyId = cId;
                            }
                        }
                    }

                    currency.EnforceConstraints = true;

                    // commit changes to the db
                    CurrencyManager.SaveCurrency(currency);
                }
            }
            catch (Exception ex)
            {
                e.RunScript = false;
                DisplayErrorMessage(ex.Message);
            }
            finally
            {
                // we don't need to store Dto in session any more
                Session.Remove(_CurrencyDtoEditSessionKey);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e)
        {
            // Validate form
            if (!this.Page.IsValid)
            {
                e.RunScript = false;
                return;
            }

            SegmentDto    segment    = (SegmentDto)Session[_SegmentDtoEditSessionKey];
            ExpressionDto expression = (ExpressionDto)Session[_ExpressionDtoEditSessionKey];

            if (segment == null && SegmentId > 0)
            {
                segment = SegmentManager.GetSegmentDto(SegmentId);
            }
            else if (segment == null && SegmentId == 0)
            {
                segment = new SegmentDto();
            }


            if (expression == null && SegmentId > 0)
            {
                expression = ExpressionManager.GetExpressionBySegmentDto(SegmentId);
            }
            else if (expression == null && SegmentId == 0)
            {
                expression = new ExpressionDto();
            }

            /*
             * // if we add a new segment, remove all other segments from Dto that is passed to control that saves changes
             * if (SegmentId == 0 && segment != null && segment.Segment.Count > 0)
             * {
             *      SegmentDto.SegmentRow[] rows2del = (SegmentDto.SegmentRow[])segment.Segment.Select(String.Format("{0} <> {1}", _SegmentIdString, SegmentId));
             *      if (rows2del != null)
             *              foreach (SegmentDto.SegmentRow row in rows2del)
             *                      segment.Segment.RemoveSegmentRow(row);
             * }*/

            IDictionary context = new ListDictionary();

            context.Add(_SegmentDtoString, segment);
            context.Add(_ExpressionDtoString, expression);

            ViewControl.SaveChanges(context);

            // save expressionDto
            if (expression.HasChanges())
            {
                ExpressionManager.SaveExpression(expression);
            }

            // update segment conditions
            foreach (ExpressionDto.ExpressionRow tmpRow in expression.Expression.Rows)
            {
                // skip deleted rows
                if (tmpRow.RowState == DataRowState.Deleted)
                {
                    continue;
                }

                // add SegmentConditionRow
                SegmentDto.SegmentConditionRow[] segmentConditionRows = (SegmentDto.SegmentConditionRow[])segment.SegmentCondition.Select(String.Format("ExpressionId={0}", tmpRow.ExpressionId));
                if (segmentConditionRows == null || segmentConditionRows.Length == 0)
                {
                    // add new expression
                    SegmentDto.SegmentConditionRow newSCRow = segment.SegmentCondition.NewSegmentConditionRow();
                    newSCRow.ExpressionId = tmpRow.ExpressionId;
                    newSCRow.SegmentId    = segment.Segment[0].SegmentId;

                    if (newSCRow.RowState == DataRowState.Detached)
                    {
                        segment.SegmentCondition.Rows.Add(newSCRow);
                    }
                }
            }

            // save segmentDto
            if (segment.HasChanges())
            {
                SegmentManager.SaveSegment(segment);
            }

            // we don't need to store Dto in session any more
            Session.Remove(_SegmentDtoEditSessionKey);
            Session.Remove(_ExpressionDtoEditSessionKey);
        }