Beispiel #1
0
        public static string GetSaveBindData(IList <ColumnEntity> columns, string type, int tabCount)
        {
            string               tab  = CodeUtils.GetTab(tabCount);
            StringBuilder        sb   = new StringBuilder();
            IList <ColumnEntity> list = FilterColumns(columns, false);

            foreach (ColumnEntity col in list)
            {
                string   line     = string.Empty;
                string   attr     = "Text";
                DataType dataType = DataTypeManager.Parse(col.DataType);
                if (dataType == DataType.Boolean)
                {
                    attr = "Checked";
                }
                if (type == "save")
                {
                    if (dataType != DataType.Boolean)
                    {
                        attr += ".Trim()";
                    }
                    line = string.Format("entity.{0}=this.cmp{1}.{2};", col.Field, col.Field, attr);
                }
                else
                {
                    line = string.Format("this.cmp{0}.{1}=entity.{2};", col.Field, attr, col.Field);
                }
                sb.AppendLine(tab + line);
            }
            return(StringHelper.DeleteEnd(sb.ToString(), CodeUtils.Line));
        }
Beispiel #2
0
        public static string GetQueryItem(IList <ColumnEntity> columns, int tabCount)
        {
            string tab = CodeUtils.GetTab(tabCount);
            IList <ColumnEntity> list = FilterColumns(columns, true);
            StringBuilder        sb   = new StringBuilder();

            foreach (var item in list)
            {
                string   upperName = StringHelper.Capitalize(item.Field);
                DataType dataType  = DataTypeManager.Parse(item.DataType);
                if (dataType == DataType.String)
                {
                    sb.AppendLine(tab + "if (!string.IsNullOrEmpty(entity." + upperName + "))");
                    sb.AppendLine(tab + "{");
                    sb.AppendLine(tab + CodeUtils.Tab + "query = query.Where(o => o." + upperName + ".Contains(entity." + upperName + "));");
                    sb.AppendLine(tab + "}");
                }
                else
                {
                    sb.AppendLine(tab + "if (entity." + upperName + ".HasValue)");
                    sb.AppendLine(tab + "{");
                    sb.AppendLine(tab + CodeUtils.Tab + "query = query.Where(o => o." + upperName + "==entity." + upperName + ".Value);");
                    sb.AppendLine(tab + "}");
                }
            }
            return(StringHelper.DeleteEnd(sb.ToString(), CodeUtils.Line));
        }
Beispiel #3
0
        public static string GetEasyUIColumn(ColumnEntity col)
        {
            StringBuilder sb    = new StringBuilder();
            int           width = col.Width <= 0 ? 100 : col.Width;

            sb.Append("{");
            sb.Append("field:\"" + col.Field + "\",title:\"" + col.Display + "\",");
            sb.Append("align:\"" + col.Align.ToString().ToLower() + "\",width:" + width + "");
            if (!col.Sortable)
            {
                sb.Append(",sortable:false");
            }
            if (!string.IsNullOrEmpty(col.FormatString))
            {
                sb.Append(",formatter:song.column.render.format(\"" + col.FormatString + "\")");
            }
            DataType dataType = DataTypeManager.Parse(col.DataType);

            if (dataType == DataType.Boolean)
            {
                sb.Append(",formatter:song.column.render.yesno");
            }
            sb.Append("}");
            return(sb.ToString());
        }
Beispiel #4
0
        public static void InitMappingConfig(string fileName = null)
        {
            if (Mappings != null)
            {
                return;
            }
            if (string.IsNullOrEmpty(fileName))
            {
                fileName = Path.Combine(PathHelper.GetConfigPath, "DataTypeMapping.xml");
            }
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("文件:" + fileName + "不存在");
            }
            XmlHelper   helper       = new XmlHelper(fileName);
            XmlNodeList mappingNodes = helper.Root.SelectNodes("dataTypeMapping");

            if (mappingNodes != null)
            {
                Mappings = new List <DataTypeMapping>();
                foreach (XmlNode mappingNode in mappingNodes)
                {
                    DataType dataType = DataType.Object;
                    try
                    {
                        dataType = DataTypeManager.Parse(mappingNode.Attributes["type"].Value);
                    }
                    catch { }
                    if (dataType != DataType.Object)
                    {
                        DataTypeMapping dataTypeMapping = new DataTypeMapping()
                        {
                            DataType = dataType
                        };
                        XmlNodeList langNodes = mappingNode.ChildNodes;
                        if (langNodes != null)
                        {
                            foreach (XmlNode langNode in langNodes)
                            {
                                if (langNode.NodeType == XmlNodeType.Element)
                                {
                                    DataTypeLanguage lang = new DataTypeLanguage()
                                    {
                                        Language = langNode.Name
                                    };
                                    string langText = langNode.InnerText.Trim();
                                    if (!string.IsNullOrEmpty(langText))
                                    {
                                        lang.DataTypeHelper = langText.Split(',').ToList();
                                    }
                                    XmlAttribute attrLength = langNode.Attributes["replaceLength"];
                                    if (attrLength != null)
                                    {
                                        lang.ReplaceLength = attrLength.Value;
                                    }
                                    XmlAttribute attrReplace = langNode.Attributes["replace"];
                                    if (attrReplace != null)
                                    {
                                        string replaceValue = attrReplace.Value.Trim();
                                        if (!string.IsNullOrEmpty(replaceValue))
                                        {
                                            lang.ReplaceTypes = replaceValue.Split(',').ToList();
                                        }
                                    }
                                    dataTypeMapping.Languages.Add(lang);
                                }
                            }
                        }
                        Mappings.Add(dataTypeMapping);
                    }
                }
            }
        }
Beispiel #5
0
        protected void ReaderColumns(TableEntity tableEntity, List <ColumnInfo> columns)
        {
            if (columns != null && columns.Count > 0)
            {
                ColumnEntity[] listColumns = service.GetColumnList(tableEntity.ID.ToString());
                int            i           = 0;
                foreach (ColumnInfo column in columns)
                {
                    i++;
                    try
                    {
                        //获取服务器字段信息
                        ColumnEntity columnEntity = listColumns.Where(o => o.Field == column.Field).FirstOrDefault();
                        if (columnEntity == null)
                        {
                            columnEntity = new ColumnEntity();
                        }
                        DataType dataType = DataTypeManager.ParseDbDataType(DbType, column.DataType.ToLower());
                        columnEntity.Field        = column.Field;
                        columnEntity.DataType     = dataType.ToString();
                        columnEntity.Required     = !column.IsNullable;
                        columnEntity.DefaultValue = column.DefaultValue;
                        ModelReaderHelper.SetLength(columnEntity, dataType, column.Length, column.Precision);
                        ModelReaderHelper.SetColumnEditor(columnEntity, dataType);
                        if (columnEntity.ID <= 0)
                        {
                            //新增字段
                            columnEntity.SortID  = i;
                            columnEntity.Display = string.IsNullOrEmpty(column.Display) ? column.Field : column.Display;
                            ModelReaderHelper.SetDefault(columnEntity);
                            columnEntity.TableID = tableEntity.ID;
                            ModelReaderHelper.SetFormatString(columnEntity, dataType);

                            ModelReaderHelper.SetAlign(columnEntity, dataType);
                            //设置主键信息
                            if (column.IsDataKey)
                            {
                                ModelReaderHelper.SetColumnDataKey(columnEntity);
                                //更新表的主键信息
                                tableEntity.DataKey     = column.Field;
                                tableEntity.DataKeyType = column.IsIdentity ?
                                                          WSH.CodeBuilder.DispatchServers.DataKeyType.IdEntity :
                                                          WSH.CodeBuilder.DispatchServers.DataKeyType.Guid;
                                tableEntity.DefaultSortName = column.Field;
                                tableEntity.DefaultSortMode = DispatchServers.SortMode.Asc;
                                service.UpdateTable(tableEntity);
                            }
                            columnEntity.CreateTime = DateTime.Now;
                            service.AddColumn(columnEntity);
                        }
                        else
                        {
                            columnEntity.EditTime = DateTime.Now;
                            service.UpdateColumn(columnEntity);
                        }
                    }
                    catch (Exception ex)
                    {
                        Error.AppendLine(string.Format("读取数据表:{0}的{1}字段出错:", tableEntity.TableName, column.Field) + ex.Message);
                    }
                }
            }
        }