コード例 #1
0
        public void Get_Display_Name_Without_Attribute()
        {
            var model = new DisplayNameTestsModel();
            var usernameDisplayName = DisplayAttributeHelper.GetPropertyDisplayString <DisplayNameTestsModel>(o => o.PropertyWithOutDisplayName);

            Assert.AreEqual("PropertyWithOutDisplayName", usernameDisplayName);
        }
コード例 #2
0
        public void Get_Display_Name()
        {
            var model = new DisplayNameTestsModel();
            var usernameDisplayName = DisplayAttributeHelper.GetPropertyDisplayString <DisplayNameTestsModel>(o => o.Username);
            var passwordDisplayName = DisplayAttributeHelper.GetPropertyDisplayString <DisplayNameTestsModel>(o => o.Password);

            Assert.AreEqual("Username2", usernameDisplayName);
            Assert.AreEqual("Password2", passwordDisplayName);
        }
コード例 #3
0
        private void CreateItemJson(IDataItems items, string dir, JsonExportTree t, Type itemType = null)
        {
            if (items == null)
            {
                return;
            }
            t.location = items.Key;
            string path = Path.Combine(dir, $"{items.Key}.js");;        // 文件:\data\3bd9a209-cdaf-42ab-b232-1aa4636f5a17.js

            using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
            {
                #region 生成数据json
                sw.Write("var __data = [");
                int r = 0;
                //items.Filter();
                foreach (var c in items.View)
                {
                    if (r != 0)
                    {
                        sw.Write(",");
                    }
                    sw.Write(Serializer.JsonSerilize(c));
                    r++;
                }
                sw.Write("];");
                #endregion

                #region 生成列属性json
                if (itemType == null)            //如果没有传入类型,则根据泛型参数类型来获取
                {
                    if (items.GetType().IsGenericType)
                    {
                        itemType = items.GetType().GetGenericArguments()[0];
                    }
                    else
                    {
                        throw new Exception("暂时先不处理的类型问题");
                    }
                }
                sw.Write("var __columns = ");
                List <JsonExportColumn> cols = new List <JsonExportColumn>();
                foreach (var c in DisplayAttributeHelper.FindDisplayAttributes(itemType))
                {
                    if (c.Visibility != EnumDisplayVisibility.ShowInDatabase)
                    {
                        cols.Add(new JsonExportColumn()
                        {
                            field = c.PropertyName, title = c.Text
                        });
                    }
                }
                sw.Write(Serializer.JsonFastSerilize(cols));
                sw.Write(";");
                #endregion
            }
        }
コード例 #4
0
            /// <summary>
            /// Gets the display name.
            /// </summary>
            /// <param name="propertyName">Name of the property.</param>
            /// <returns></returns>
            public static string GetDisplayName(string propertyName)
            {
                Type type         = typeof(TModel);
                Type metaDataType = null;

                foreach (MetadataTypeAttribute attrib in type.GetCustomAttributes(typeof(MetadataTypeAttribute), true))
                {
                    metaDataType = attrib.MetadataClassType;
                }

                if (metaDataType == null)
                {
                    return(propertyName);
                }

                PropertyInfo pInfo = GetProperty(type, propertyName);

                return(DisplayAttributeHelper <TModel> .GetDisplayName(pInfo, metaDataType));
            }
コード例 #5
0
ファイル: Fhjun_Test.cs プロジェクト: iamoatil/S_P_F_P_r-o
        private void CreateItemJson(IDataItems items, string dir, ExportTree t, Type itemType = null)
        {
            if (items == null)
            {
                return;
            }
            t.location = items.Key;
            string path = $"{dir}{items.Key}.js";

            using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
            {
                sw.Write("var __data = [");
                int r = 0;
                items.Filter();
                foreach (var c in items.View)
                {
                    if (r != 0)
                    {
                        sw.Write(",");
                    }
                    sw.Write(Serializer.JsonSerilize(c));
                    r++;
                }
                sw.Write("];");

                sw.Write("var __columns = ");
                List <ExportColumn> cols = new List <ExportColumn>();
                foreach (var c in DisplayAttributeHelper.FindDisplayAttributes(itemType))
                {
                    if (c.Visibility != EnumDisplayVisibility.ShowInDatabase)
                    {
                        cols.Add(new ExportColumn()
                        {
                            field = c.Key, title = c.Text
                        });
                    }
                }
                sw.Write(Serializer.JsonFastSerilize(cols));
                sw.Write(";");
            }
        }
コード例 #6
0
        /// <summary>
        /// 动态生成表格列
        /// </summary>
        private void BindGrid()
        {
            dg.Columns.Clear();
            object type = _arg.CurrentData is TreeNode node ? node.Type : _arg.CurrentData is AbstractDataSource sp ? sp.Type : null;

            if (type == null)
            {
                return;
            }
            //添加书签列
            DataGridTemplateColumn bmkCol = this.FindResource("bookmarkColumnTemplate") as DataGridTemplateColumn;

            dg.Columns.Add(bmkCol);

            if (type is Type t)
            {
                foreach (var attr in DisplayAttributeHelper.FindDisplayAttributes(t).OrderBy(d => d.ColumnIndex))
                {
                    if (attr.Visibility == EnumDisplayVisibility.ShowInDatabase)        //该属性不需要显示在界面上
                    {
                        continue;
                    }

                    if (attr.Owner.Name == "DataState")      //如果是状态列,则单独处理
                    {
                        DataGridTemplateColumn stateCol = new DataGridTemplateColumn()
                        {
                            Header = attr.Text, Width = attr.Width, MinWidth = 100
                        };
                        stateCol.CellTemplate = XamlResouceReader.ToDataTemplate <DataTemplate>("ThemesStyle.DataGridStyle.DataGridDataStateColumnTemplate.xaml", c => c.Replace(PROPERTY_NAME, attr.Owner.Name));
                        dg.Columns.Add(stateCol);
                    }
                    else if (attr.ColumnType == EnumColumnType.URL) //超链接列
                    {
                        DataGridTemplateColumn col = new DataGridTemplateColumn()
                        {
                            Header = attr.Text, Width = attr.Width, MinWidth = 100
                        };
                        col.CellTemplate = XamlResouceReader.ToDataTemplate <DataTemplate>("ThemesStyle.DataGridStyle.DataGridUrlColumnTemplate.xaml", c => c.Replace(PROPERTY_NAME, attr.Owner.Name));
                        dg.Columns.Add(col);
                    }
                    else if (attr.ColumnType == EnumColumnType.Image)  //图片列
                    {
                        DataGridTemplateColumn col = new DataGridTemplateColumn()
                        {
                            Header = attr.Text, Width = attr.Width, MinWidth = 100
                        };
                        col.CellTemplate = XamlResouceReader.ToDataTemplate <DataTemplate>("ThemesStyle.DataGridStyle.DataGridImageColumnTemplate.xaml", c => c.Replace(PROPERTY_NAME, attr.Owner.Name));
                        dg.Columns.Add(col);
                    }
                    else
                    {
                        DataGridBoundColumn col = new DataGridTextColumn()
                        {
                            Header = attr.Text, Binding = new Binding(attr.Owner.Name), Width = attr.Width, MinWidth = 100
                        };
                        dg.Columns.Add(col);
                    }
                }
            }
            else if (type is string)
            {
            }
        }
コード例 #7
0
        private void PropertyViewControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!IsUserControl_Loaded)
            {//只加载一次
                IsUserControl_Loaded = true;
            }
            else
            {
                return;
            }

            if (this.DataContext == null)
            {
                return;
            }
            var obj = this.DataContext as DataPreviewPluginArgument;
            Dictionary <string, string> dic = new Dictionary <string, string>();

            if (obj.CurrentData is string file)
            {
                if (!File.Exists(file))
                {
                    return;
                }
                FileInfo fi = new FileInfo(file);
                dic[Languagekeys.FileName]   = fi.Name;
                dic[Languagekeys.FullPath]   = fi.FullName;
                dic[Languagekeys.FileSize]   = $"{FileHelper.GetFileSize(fi.Length)} ({fi.Length} {Languagekeys.Bytes})";
                dic[Languagekeys.CreateTime] = fi.CreationTime.ToString();
                dic[Languagekeys.ModifyTime] = fi.LastWriteTime.ToString();
                dic[Languagekeys.AccessTime] = fi.LastAccessTime.ToString();
                dic[Languagekeys.Attributes] = fi.Attributes.HasFlag(FileAttributes.ReadOnly) ? (string)Languagekeys.ZhiDu : "";
            }
            else if (obj.CurrentData != null)
            {
                //foreach (var pro in obj.CurrentData.GetType().GetProperties())
                //{
                //    dic[pro.Name] = pro.GetValue(obj.CurrentData).ToSafeString();
                //}
                foreach (var attr in DisplayAttributeHelper.FindDisplayAttributes(obj.CurrentData.GetType()).OrderBy(d => d.ColumnIndex))
                {
                    if (attr.Visibility == EnumDisplayVisibility.ShowInDatabase)        //该属性不需要显示在界面上
                    {
                        continue;
                    }
                    dic[attr.Text] = attr.GetValue(obj.CurrentData).ToSafeString();
                }
            }

            int row = 0;

            foreach (var p in dic)
            {
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(0, GridUnitType.Auto)
                });

                TextBlock tb = new TextBlock()
                {
                    Text = p.Key + " :"
                };
                tb.VerticalAlignment   = VerticalAlignment.Center;
                tb.HorizontalAlignment = HorizontalAlignment.Right;
                tb.TextWrapping        = TextWrapping.Wrap;
                tb.Margin = new Thickness(3);
                grid.Children.Add(tb);
                tb.SetValue(Grid.RowProperty, row);

                TextBlock tb2 = new TextBlock()
                {
                    Text = p.Value
                };
                tb2.VerticalAlignment   = VerticalAlignment.Center;
                tb2.HorizontalAlignment = HorizontalAlignment.Left;
                tb2.Margin = new Thickness(3);
                grid.Children.Add(tb2);
                tb2.SetValue(Grid.RowProperty, row);
                tb2.SetValue(Grid.ColumnProperty, 1);
                row++;
            }
        }
コード例 #8
0
        ///// <summary>
        ///// 获取DynamicX属性名对应的列名
        ///// </summary>
        ///// <param name="view"></param>
        ///// <param name="keyName"></param>
        ///// <returns></returns>
        //private string GetColumnNameFromDynamicX(Domains.DataView view, string keyName)
        //{
        //    if (view == null)
        //    {
        //        return keyName;
        //    }
        //    for (int i = 0; i < view.DataViewCollections.Count; i++)
        //    {
        //        var item = view.DataViewCollections[i].FirstOrDefault(s => s.Code == keyName);
        //        if (item != null)
        //        {
        //            return item.Name;
        //        }
        //    }
        //    return keyName;
        //}
        /// <summary>
        /// 根据普通节点生成xml
        /// </summary>
        /// <param name="xmldoc"></param>
        /// <param name="dataList"></param>
        /// <param name="current"></param>
        /// <param name="lstBcpNodes"></param>
        private void CreateXmlTreeNodeFromSampleSource(XmlDocument xmldoc, SimpleDataSource dataSource, DataParsePluginInfo pluginInfo, XmlNode current, List <BcpNode> lstBcpNodes)
        {
            var dataList = dataSource.Items;

            if (dataList.Count == 0)
            {
                return;
            }

            XmlNode      xmlnode = xmldoc.CreateElement("node");
            XmlAttribute attr    = xmldoc.CreateAttribute("text");

            attr.Value = "root";
            xmlnode.Attributes.Append(attr);
            current.AppendChild(xmlnode);

            DataTable dt = null;

            var atts = DisplayAttributeHelper.FindDisplayAttributes((Type)dataSource.Type);

            if (atts.IsValid())
            {
                dt = new DataTable();
                dt.Columns.Add("I050008");
                foreach (var a in atts)
                {
                    dt.Columns.Add(a.Text);
                }

                foreach (var data in dataList.View)
                {
                    DataRow dr = dt.NewRow();
                    foreach (var a in atts)
                    {
                        dr[a.Text] = a.GetValue(data);
                    }
                    dt.Rows.Add(dr);
                }
            }
            else
            {
                //dt = new DataTable();
                //dt.Columns.Add("I050008");
                //foreach (var model in dataList.View)
                //{
                //    var info = model as DynamicEx;
                //    foreach (var pair in info.Members)
                //    {
                //        if (pair.Key != "XLYLogString")
                //        {
                //            string key = GetColumnNameFromDynamicX(view, pair.Key);
                //            if (!dt.Columns.Contains(key))
                //                dt.Columns.Add(key);
                //        }
                //    }
                //    DataRow dr = dt.NewRow();
                //    foreach (var pair in info.Members)
                //    {
                //        if (pair.Key != "XLYLogString")
                //        {
                //            string key = GetColumnNameFromDynamicX(view, pair.Key);
                //            dr[key] = pair.Value == null ? string.Empty : pair.Value.ToString();
                //        }
                //    }
                //    dt.Rows.Add(dr);
                //}
            }

            BcpNode bcpNode = new BcpNode()
            {
                DataTable = dt, TreeNode = null, XmlNode = xmlnode
            };

            lstBcpNodes.Add(bcpNode);
        }
コード例 #9
0
        /// <summary>
        /// 根据树形节点生成xml
        /// </summary>
        /// <param name="xmldoc"></param>
        /// <param name="nodes"></param>
        /// <param name="current"></param>
        /// <param name="lstBcpNodes"></param>
        private void CreateXmlTreeNodeFromTreeSource(XmlDocument xmldoc, List <TreeNode> nodes, DataParsePluginInfo pluginInfo, XmlNode current, List <BcpNode> lstBcpNodes)
        {
            if (nodes.IsValid())
            {
                foreach (var n in nodes)
                {
                    XmlNode      xmlnode = xmldoc.CreateElement("node"); //因为xml节点中不能包含特殊字符(如空格),所以节点定义格式为<node text="我的 好友">
                    XmlAttribute attr    = xmldoc.CreateAttribute("text");
                    attr.Value = n.Text;
                    xmlnode.Attributes.Append(attr);
                    current.AppendChild(xmlnode);

                    DataTable dt = null;
                    if (n.Total > 0)
                    {
                        if (n.Type is Type t)
                        {
                            var atts = DisplayAttributeHelper.FindDisplayAttributes(t);
                            if (!atts.IsValid())
                            {
                                continue;
                            }
                            dt = new DataTable();
                            dt.Columns.Add("I050008");
                            foreach (var a in atts)
                            {
                                dt.Columns.Add(a.Text);
                            }

                            foreach (var i in n.Items.View)
                            {
                                DataRow dr = dt.NewRow();
                                foreach (var a in atts)
                                {
                                    dr[a.Text] = a.GetValue(i);
                                }
                                dt.Rows.Add(dr);
                            }
                        }
                        else
                        {
                            //dt = new DataTable();
                            //dt.Columns.Add("I050008");
                            //Domains.DataView dv = pluginInfo.DataView[0];
                            //for (int i = 0; i < pluginInfo.DataView.Count; i++)
                            //{
                            //    if (pluginInfo.DataView[i].Type == n.Type.ToString())
                            //    {
                            //        dv = pluginInfo.DataView[i];
                            //    }
                            //}
                            //foreach (var model in n.Items.View)
                            //{
                            //    var info = model as DynamicEx;
                            //    foreach (var pair in info.Members)
                            //    {
                            //        string key = GetColumnNameFromDynamicX(dv, pair.Key);
                            //        if (!dt.Columns.Contains(key))
                            //            dt.Columns.Add(key);
                            //    }
                            //    DataRow dr = dt.NewRow();
                            //    foreach (var pair in info.Members)
                            //    {
                            //        string key = GetColumnNameFromDynamicX(dv, pair.Key);
                            //        dr[key] = pair.Value == null ? string.Empty : pair.Value.ToString();
                            //    }
                            //    dt.Rows.Add(dr);
                            //}
                        }
                    }

                    BcpNode bcpNode = new BcpNode()
                    {
                        DataTable = dt, TreeNode = n, XmlNode = xmlnode
                    };
                    lstBcpNodes.Add(bcpNode);

                    if (n.TreeNodes.IsValid())
                    {
                        CreateXmlTreeNodeFromTreeSource(xmldoc, n.TreeNodes, pluginInfo, xmlnode, lstBcpNodes);
                    }
                }
            }
        }