Пример #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!PrincipalInfo.HasAdminAccess)
            {
                AccessDenied();
            }

            CurrentStoreName = Request.QueryString["Store"];

            if (!IsPostBack)
            {
                hdivStoreTypeDoesntExist.Visible = false;

                if (string.IsNullOrEmpty(CurrentStoreName))
                {
                    hdivNoStoreTypeSelected.Visible = true;
                    hdivStoreTypeSelected.Visible = false;
                    return;
                }

                hdivNoStoreTypeSelected.Visible = false;
                hdivStoreTypeSelected.Visible = true;

                var explorer = new Store();

                Store = explorer.Explore().FirstOrDefault(s => s.Name == CurrentStoreName);

                if (Store == null)
                {
                    hdivNoStoreTypeSelected.Visible = false;
                    hdivStoreTypeSelected.Visible = false;
                    hdivStoreTypeDoesntExist.Visible = true;
                    return;
                }

                repColumnsHeader.DataSource = Store.Columns;
                repForm.DataSource = Store.Columns;
                repColumnsHeader.DataBind();
                repForm.DataBind();
                Columns = GenerateColumnData(Store);
            }
        }
Пример #2
0
        /// <summary>
        /// create new item
        /// </summary>
        /// <param name="storeInfo">entity metadata</param>
        /// <param name="storeName">store type name</param>
        /// <param name="values">key value pairs of columns and their respective values</param>
        /// <returns>newly created item identity</returns>
        public PropertyBag Create(StoreInfo storeInfo, string storeName, Dictionary<string, string> values)
        {
            try
            {
                var store = DynamicDataStoreFactory.Instance.GetStore(storeName);
                var item = new PropertyBag { Id = Identity.NewIdentity() };
                foreach (var value in values)
                {
                    if (value.Key == "Id")
                    {
                        // skip id when creating new record
                        continue;
                    }

                    var meta = storeInfo.Columns.Where(si => si.PropertyName == value.Key).First();

                    if (meta is CollectionPropertyMap)
                    {
                        throw new NotImplementedException(string.Format("Saving CollectionPropertyMap field name = {0} is not yet implemented!", value.Key));
                    }

                    item[value.Key] = value.Value;
                }

                store.Save(item);

                return item;
            }
            catch (NotImplementedException ex)
            {
                logger.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                logger.Error("Create row failed", ex);
                return null;
            }
        }
Пример #3
0
        private string GenerateColumnData(StoreInfo store)
        {
            // first column is Guid id so its always read only
            string result = @"null";

            // get other columns
            foreach (PropertyMap column in Store.Columns)
            {
                if (column.PropertyType == typeof (bool))
                {
                    result += @", {type: 'select', onblur: 'submit', data: ""{'True':'True', 'False':'False'}""}";
                    continue;
                }
                if (column.PropertyType == typeof (int))
                {
                    result += @", {cssclass: 'number'}";
                    continue;
                }
                result += @", {}"; // empty definition for to be treated as string
            }
            return result;
        }
Пример #4
0
        private int SortAndFilterData(int displayStart, 
                                      int displayLength, 
                                      int sortCol, 
                                      string sortDir, 
                                      string search, 
                                      StoreInfo storeInfo, 
                                      IEnumerable<PropertyBag> data, 
                                      ref List<List<string>> stringData)
        {
            foreach (var row in data)
            {
                bool containsSearchCriteria = string.IsNullOrEmpty(search);

                var item = new List<string> {row.Id.ToString()};
                if (!containsSearchCriteria && row.Id.ToString().Contains(search))
                {
                    containsSearchCriteria = true;
                }

                foreach (var column in storeInfo.Columns)
                {
                    if (row[column.PropertyName] != null)
                    {
                        var value = row[column.PropertyName].ToString();
                        item.Add(value);
                        if (!containsSearchCriteria && value.Contains(search))
                        {
                            containsSearchCriteria = true;
                        }
                    }
                    else
                    {
                        item.Add(null);
                    }
                }

                if (containsSearchCriteria)
                {
                    stringData.Add(item);
                }
            }

            int totalCount = stringData.Count();

            // reorder stringData and skip and take just needed
            if (sortDir == "asc")
            {
                stringData = (from sd in stringData orderby sd[sortCol] ascending select sd).Skip(displayStart).Take(displayLength).ToList();
            }
            else
            {
                stringData =
                    (from sd in stringData orderby sd[sortCol] descending select sd).Skip(displayStart).Take(displayLength).ToList();
            }

            return totalCount;
        }
Пример #5
0
        private List<List<string>> GetData(StoreInfo storeInfo, IEnumerable<PropertyBag> data)
        {
            var stringData = new List<List<string>>();
            foreach (var row in data)
            {
                var item = new List<string> {row.Id.ToString()};
                foreach (var column in storeInfo.Columns)
                {
                    item.Add(row[column.PropertyName] == null ? null : row[column.PropertyName].ToString());
                }

                stringData.Add(item);
            }

            return stringData;
        }