예제 #1
0
        /// <summary>
        /// Creates the classes.
        /// </summary>
        private static void CreateClasses()
        {
            // Create main class
            MetaClass metaClass = MetaClass.Load(OrderContext.MetaDataContext, "OrderGroup");

            if (metaClass == null)
            {
                metaClass = MetaClass.Create(OrderContext.MetaDataContext, "OrderGroup", "Order Group", "OrderGroup", 0, true, "OrderGroup Class");
            }

            // create purchase order class
            MetaClass purchaseOrderClass = MetaClass.Load(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.PurchaseOrderClass.Name);

            if (purchaseOrderClass == null)
            {
                purchaseOrderClass = MetaClass.Create(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.PurchaseOrderClass.Name, "Purchase Order Class", "OrderGroup_PurchaseOrder", metaClass, MetaClassType.User, "Purchase Order Class");
            }

            MetaField field = MetaField.Load(OrderContext.MetaDataContext, "TrackingNumber");

            if (field == null)
            {
                field = MetaField.Create(OrderContext.MetaDataContext, "Mediachase.Commerce.Orders", "TrackingNumber", "Tracking Number", "Allows one to specify tracking number for the order", MetaDataType.ShortString, 50, true, false, false, true, false);
            }

            if (!purchaseOrderClass.UserMetaFields.Contains(field))
            {
                purchaseOrderClass.AddField(field);
            }


            // create cart class
            MetaClass cartOrderClass = MetaClass.Load(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.ShoppingCartClass.Name);

            if (cartOrderClass == null)
            {
                cartOrderClass = MetaClass.Create(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.ShoppingCartClass.Name, "Cart Order Class", "OrderGroup_ShoppingCart", metaClass, MetaClassType.User, "Cart Order Class");
            }

            // Create System Order Info class
            MetaClass orderFormClass = MetaClass.Load(OrderContext.MetaDataContext, "OrderForm");

            if (orderFormClass == null)
            {
                orderFormClass = MetaClass.Create(OrderContext.MetaDataContext, "OrderForm", "Order Form", "OrderForm", 0, true, "OrderForm Class");
            }

            // create purchase order class
            MetaClass orderFormExClass = MetaClass.Load(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.OrderFormClass.Name);

            if (orderFormExClass == null)
            {
                purchaseOrderClass = MetaClass.Create(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.OrderFormClass.Name, "Order Form Ex Class", "OrderFormEx", orderFormClass, MetaClassType.User, "Order Form Ex Class");
            }

            BackupMetaData();
        }
예제 #2
0
        private void AddFieldToMetaClass(MetaClass metaClass, MetaField metaField)
        {
            if (metaClass.MetaFields.Any(x => x.Name == metaField.Name))
            {
                return;
            }

            metaClass.AddField(metaField);
        }
예제 #3
0
        /// <summary>
        /// Updates the attributes.
        /// </summary>
        /// <param name="mc">The mc.</param>
        private void UpdateAttributes(MetaClass mc)
        {
            for (int i = 0; i < ItemsGrid.Items.Count; i++)
            {
                // Obtain references to row's controls
                HtmlInputCheckBox active     = (System.Web.UI.HtmlControls.HtmlInputCheckBox)ItemsGrid.Items[i].Cells[0].Controls[0];
                TextBox           weightText = (System.Web.UI.WebControls.TextBox)ItemsGrid.Items[i].FindControl("Weight");

                int weight = 0;
                // Wrap in try/catch block to catch errors in the event that someone types in
                // an invalid value for quantity
                try
                {
                    weight = Int32.Parse(weightText.Text);
                }
                catch (System.FormatException)
                {
                }
                catch (System.OverflowException)
                {
                }

                try
                {
                    // delete is unchecked
                    int       fieldId = (int)ItemsGrid.DataKeys[i];
                    MetaField field   = MetaField.Load(MDContext, fieldId);

                    if (active.Checked)
                    {
                        if (mc.UserMetaFields[field.Name] != null)
                        {
                            ((MetaField)mc.UserMetaFields[field.Name]).Weight = weight;
                        }
                        else
                        {
                            mc.AddField(fieldId, weight);
                        }
                    }
                    else
                    {
                        if (mc.UserMetaFields[field.Name] != null)
                        {
                            mc.DeleteField((int)ItemsGrid.DataKeys[i]);
                        }
                    }
                }
                catch (System.FormatException)
                {
                }
                catch (System.OverflowException)
                {
                }
            }
        }
예제 #4
0
        private void dgAvailableFields_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            MetaClass selectedMetaClass = GetSelectedMetaClass();
            int       fieldsCount       = selectedMetaClass.UserMetaFields.Count;

            if (e.CommandName == "Copy" && selectedMetaClass != null)
            {
                foreach (DataGridItem item in dgAvailableFields.Items)
                {
                    foreach (Control control in item.Cells[1].Controls)
                    {
                        if (control is CheckBox)
                        {
                            CheckBox checkBox = (CheckBox)control;
                            if (checkBox.Enabled && checkBox.Checked)
                            {
                                int fieldId = int.Parse(item.Cells[0].Text);
                                fieldsCount++;
                                selectedMetaClass.AddField(fieldId, fieldsCount);
                                checkBox.Checked = false;
                            }
                        }
                    }
                }
                Response.Redirect("~/Admin/Customization.aspx", true);
            }
            if (e.CommandName == "CopyOne" && selectedMetaClass != null)
            {
                foreach (Control control in e.Item.Cells[1].Controls)
                {
                    if (control is CheckBox)
                    {
                        CheckBox checkBox = (CheckBox)control;
                        int      fieldId  = int.Parse(e.Item.Cells[0].Text);
                        fieldsCount++;
                        selectedMetaClass.AddField(fieldId, fieldsCount);
                        checkBox.Checked = false;
                    }
                }
                Response.Redirect("~/Admin/Customization.aspx", true);
            }
        }
예제 #5
0
        private static void RestoreFromVersion10(XmlNode root)
        {
            #region -- Restore Meta Classes --
            XmlNodeList xmlMetaClassList = root.SelectNodes("MetaClass");

            foreach (XmlNode xmlMetaClass in xmlMetaClassList)
            {
                string ParentClass = xmlMetaClass.SelectSingleNode("ParentClass").InnerXml;

                MetaClass parent = null;

                if (!string.IsNullOrEmpty(ParentClass))
                {
                    parent = MetaClass.Load(ParentClass);

                    if (parent == null)
                    {
                        XmlNode xmlParentMetaClass = root.SelectSingleNode(string.Format(_culture, "MetaClass[Name='{0}']", ParentClass));
                        parent = LoadMetaClassVersion10(xmlParentMetaClass, null);
                    }
                }

                LoadMetaClassVersion10(xmlMetaClass, parent);
            }

            #endregion

            #region -- Restore Meta Fields --
            XmlNodeList xmlMetaFieldList = root.SelectNodes("MetaField");

            foreach (XmlNode xmlMetaField in xmlMetaFieldList)
            {
                MetaField mf = LoadMetaFieldVersion10(xmlMetaField);

                XmlNodeList xmlOwnerMetaClassList = xmlMetaField.SelectNodes("OwnerMetaClass");

                foreach (XmlNode xmlOwnerMetaClass in xmlOwnerMetaClassList)
                {
                    MetaClass ownerMC = MetaClass.Load(xmlOwnerMetaClass.InnerXml);
                    if (!ownerMC.MetaFields.Contains(mf))
                    {
                        ownerMC.AddField(mf);
                    }
                }
            }
            #endregion
        }
        protected virtual void TryAddMetaField(Mediachase.MetaDataPlus.MetaDataContext context,
                                               MetaClass metaClass,
                                               string name,
                                               MetaDataType metaDataType,
                                               int length)
        {
            var metaField = MetaField.Load(context, name) ?? MetaField.Create(
                context: context,
                metaNamespace: metaClass.Namespace,
                name: name,
                friendlyName: name,
                description: name,
                dataType: metaDataType,
                length: length,
                allowNulls: true,
                multiLanguageValue: false,
                allowSearch: false,
                isEncrypted: false);

            if (metaClass.MetaFields.All(x => x.Id != metaField.Id))
            {
                metaClass.AddField(metaField);
            }
        }
예제 #7
0
        public void OrderSystem_LineItemMetaDataSave()
        {
            bool      metaFieldExists  = false;
            MetaField brandField       = null;
            string    fieldName        = "Brand";
            bool      metaFieldAdded   = false;
            string    testForValue     = "Test";
            string    returnedValue    = "";
            Cart      cart             = null;
            Cart      newCart          = null;
            Cart      retrieveTestCart = null;
            Guid      customerId       = Guid.NewGuid();

            //Create cart. This cart is just used to get the lineitem meta class information
            try
            {
                cart = OrderHelper.CreateCartSimple(customerId);
            }
            catch (Exception exc)
            {
                if (exc.Message == "'maxValue' must be greater than zero.\r\nParameter name: maxValue")
                {
                    Assert.Fail("Check your ApplicationId");
                }
                else
                {
                    throw exc;
                }
            }

            //first make sure the meta field exists in the collection for the LineItem  collection
            MetaDataContext context = OrderContext.MetaDataContext;
            MetaClass       mc      = cart.OrderForms[0].LineItems[0].MetaClass;

            for (int i = 0; i < mc.MetaFields.Count; i++)
            {
                if (mc.MetaFields[i].Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase))
                {
                    brandField      = mc.MetaFields[i];
                    metaFieldExists = true;
                    break;
                }
            }

            if (!metaFieldExists)
            {
                brandField = MetaField.Load(context, fieldName);

                if (brandField == null)
                {
                    brandField     = MetaField.Create(context, "Mediachase.Commerce.Orders.System", fieldName, fieldName, "", MetaDataType.ShortString, 100, true, false, false, false, false);
                    metaFieldAdded = true;
                }
                mc.AddField(brandField);
            }

            //use a new customer id for the new cart
            customerId = Guid.NewGuid();

            //Create a new cart that will be used to add meta data to and save
            newCart = OrderHelper.CreateRetrieveOneLineItemCart(customerId);

            //now add a value for this new metafield in the first lineitem in the cart
            newCart.OrderForms[0].LineItems[0][fieldName] = testForValue;
            newCart.AcceptChanges();

            //now retrieve the cart anew and test
            retrieveTestCart = Cart.LoadByCustomerAndName(newCart.CustomerId, newCart.Name);

            //check for the value
            if (retrieveTestCart.OrderForms[0].LineItems[0][fieldName] != null)
            {
                returnedValue = retrieveTestCart.OrderForms[0].LineItems[0][fieldName].ToString();
            }

            if (!metaFieldExists)
            {
                mc.DeleteField(brandField);
            }

            //delete the field if added
            if (metaFieldAdded)
            {
                MetaField.Delete(context, brandField.Id);
            }

            if (testForValue != returnedValue)
            {
                Assert.Fail("Value was not saved");
            }
        }
예제 #8
0
        protected void btnSave_ServerClick(object sender, System.EventArgs e)
        {
            if (tbName.Text.Length == 0)
            {
                tbName.Text = tbFriendlyName.Text;
            }
            tbName.Text = cyr2lat(tbName.Text);
            tbName.Text = tbName.Text.Replace(" ", "_").Replace("-", "_").Replace("_&_", "_").Replace("/", "_").Replace("~", "_").Replace("`", "_");
            reNameVal.Validate();
            if (!reNameVal.IsValid)
            {
                if (int.Parse(ddlType.SelectedValue) == 0)
                {
                    tbName.Text = "Dictionary_Field";
                }
                else
                {
                    tbName.Text = ((MetaDataType)(int.Parse(ddlType.SelectedValue))).ToString() + "_Field";
                }
            }
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            int          DataTypeId = int.Parse(ddlType.SelectedItem.Value);
            MetaDataType type;

            if (DataTypeId != 0)
            {
                type = MetaType.Load(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;
                }
            }

            bool SaveHistory = false;

            if (chkSaveHistory.Visible)
            {
                SaveHistory = chkSaveHistory.Checked;
            }

            bool AllowSearch = false;

            if (chkAllowSearch.Visible)
            {
                AllowSearch = chkAllowSearch.Checked;
            }

            MetaField field      = null;
            string    sNameSpace = Mediachase.MetaDataPlus.MetaNamespace.UserRoot;

            try
            {
                field = MetaField.Create(sNameSpace, MetaFieldFix.GetUniqueName(tbName.Text), tbFriendlyName.Text, tbDescription.Text,
                                         type, true, SaveHistory, AllowSearch);
            }
            catch (SqlException sqlException)
            {
                if (sqlException.Number == 2627 || sqlException.Number == 50000)
                {
                    lblErrorMessage.Text    = LocRM.GetString("FieldNameDuplictaion");
                    lblErrorMessage.Visible = true;
                    return;
                }
            }
            int iClassId = -1;

            if (_classId > 0)
            {
                iClassId = _classId;
            }

            if (iClassId > 0)
            {
                MetaClass mc = MetaClass.Load(iClassId);

                mc.AddField(field);

                if (trAllowNulls.Visible)
                {
                    mc.SetFieldIsRequired(field.Name, !chkAllowNulls.Checked);
                }
            }
            if (field.Dictionary != null)
            {
                DataView dv = ((DataTable)ViewState["DicItems"]).DefaultView;
                dv.Sort = "Index";
                foreach (DataRowView dr in dv)
                {
                    field.Dictionary.Add(dr["Value"].ToString());
                }
            }

            if (Request["Back"] == "All")
            {
                Response.Redirect("~/Admin/MasterDataManager.aspx", true);
            }
            else
            {
                Response.Redirect("~/Admin/Customization.aspx", true);
            }
        }