Beispiel #1
0
        public void Generate(CommonDecl common)
        {
            if (isFirstRow)
            {
                StartGenerate(common);
                isFirstRow = false;
            }

            GenerateLine(common);
        }
        protected override void StartGenerate(CommonDecl common)
        {
            result.AppendLine(@"using System;
using System.Data;
using System.Diagnostics;
using Conta.DAL.Model;

namespace XmlDal.ServiceHandler {");

            this.Path = this.ContainerName;
        }
Beispiel #3
0
        protected override void StartGenerate(CommonDecl common)
        {
            base.StartGenerate(common);

            if (!string.IsNullOrWhiteSpace(this.Path))
            {
                result.AppendFormat("using System;\r\n\r\nnamespace {0} {{\r\n", GetNamespace());
            }

            result.AppendFormat("public partial class {0}{{\r\n", string.IsNullOrWhiteSpace(this.Path) ? ContainerName : IoPath.GetFileName(this.Path));
            CreateConstructor();
        }
Beispiel #4
0
        private string GetForeignKey(CommonDecl common)
        {
            if (string.IsNullOrEmpty(common.ForeignKey))
            {
                return(string.Empty);
            }
            else
            {
                result.AppendFormat("FOREIGN KEY( {0} ) REFERENCES {0}(id) ,\r\n", common.ForeignKey);

                return(string.Empty);
            }
        }
Beispiel #5
0
        private string GetColumnType(CommonDecl common)
        {
            if (string.IsNullOrWhiteSpace(common.TypeName))
            {
                throw new Exception("Missing column type");
            }

            var typeName = common.TypeName.Trim().ToLower();

            // check typeName
            if (typeName == "string")
            {
                // check row[2] exists
                return(string.Format(@">
                  <xs:simpleType>
                    <xs:restriction base='xs:string'>
                      <xs:maxLength value='{0}' />
                    </xs:restriction>
                  </xs:simpleType>
                </xs:element>", common.FieldSize));
            }
            else if (typeName == "int")
            {
                if (row.Count > (int)Columns.TypeInfo1 && row[(int)Columns.TypeInfo1].Value == "autoincrement")
                {
                    return(" msdata:ReadOnly='true' msdata:AutoIncrement='true' type='xs:int' />");
                }

                return(" type='xs:int'/>");
            }
            else if (typeName == "datetime")
            {
                return(" type='xs:dateTime' />");
            }
            else if (typeName == "float")
            {
                return(" type='xs:float'/>");      // TODO : decimals
            }
            else if (typeName == "bool")
            {
                return(" type='xs:boolean'/>");;
            }
            else if (typeName == "byte[]")
            {
                return(" type='xs:byte[]'/>");
            }

            throw new Exception("Unknown column type : " + typeName);
        }
Beispiel #6
0
        protected override void StartGenerate(CommonDecl common)
        {
            if (!string.IsNullOrWhiteSpace(this.Path))
            {
                result.Append(@"using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace  Conta.DAL.Model {
");
            }

            result.AppendFormat(@"public partial class {0} {{
", string.IsNullOrWhiteSpace(this.Path) ? ContainerName : IoPath.GetFileName(this.Path));
            CreateConstructor();
        }
Beispiel #7
0
        private string GetColumnType(CommonDecl common)
        {
            if (string.IsNullOrWhiteSpace(common.TypeName))
            {
                throw new Exception("Missing column type");
            }

            var typeName = common.TypeName.Trim().ToLower();

            // check typeName
            if (typeName == "string")
            {
                // check row[2] exists
                return(!string.IsNullOrWhiteSpace(common.FieldSize) && int.Parse(common.FieldSize) >= 65535 ?
                       "clob" :
                       ("varchar2(" + common.FieldSize + ")"));
            }
            else if (typeName == "int")
            {
                if (row.Count > (int)Columns.TypeInfo1 && row[(int)Columns.TypeInfo1].Value == "autoincrement")
                {
                    return("integer auto");
                }

                return("integer");
            }
            else if (typeName == "datetime")
            {
                return("date");
            }
            else if (typeName == "float")
            {
                return("float");     // TODO : decimals
            }
            else if (typeName == "bool")
            {
                return("bool");
            }
            else if (typeName == "byte[]")
            {
                return("blob");
            }

            throw new Exception("Unknown column type : " + typeName);
        }
Beispiel #8
0
        protected override void GenerateLine(CommonDecl common)
        {
            if (row.Count == 0)
            {
                return;
            }

            var type        = common.TypeName;
            var annotations = new StringBuilder();

            if (type == "string" && !string.IsNullOrWhiteSpace(common.FieldSize))
            {
                annotations.AppendFormat("[StringLength({0})]\r\n", common.FieldSize);
            }
            if (!common.IsNullable)
            {
                annotations.Append("[Required()]\r\n");
            }

            foreach (var r in (from x in row orderby x.Key descending select x))
            {
                if (r.Key == 0)
                {
                    result.Append(annotations);
                    if (string.IsNullOrWhiteSpace(common.ForeignKey))
                    {
                        result.AppendFormat("public {1} {0} {{\r\n get {{ return original.{0}; }}\r\n set {{ SetProp(original.{0}, value, v => original.{0} = v, \"{0}\"); }}\r\n }}\r\n", r.Value, type);
                    }
                    else
                    {
                        var refType = GetNamespace() + "." + common.ForeignKey;
                        result.AppendFormat("public {1} {0} {{\r\n get {{ return original.{0}; }}\r\n set {{ SetProp(original.{0}, value, v => original.{0} = v, \"{0}\"); }}\r\n }}\r\n", row[0].Value, refType);
                    }
                    result.AppendLine();
                }
                else if (r.Key == 1)
                {
                    annotations.AppendFormat("[System.ComponentModel.DisplayName(\"{0}\")]\r\n", r.Value);
                }
            }

            //result.AppendLine();

            row.Clear();
        }
Beispiel #9
0
        protected override void GenerateLine(CommonDecl common)
        {
            if (row.Count <= (int)Columns.Name)
            {
                return;     // calculated column
            }
            var type = GetColumnType(common);

            //var foreignKey = GetForeignKey(common);

            result.AppendFormat("<xs:element name='{0}'{1}\r\n", row[(int)Columns.Name].Value, type);

            //?var foreignKey = GetForeignKey(common);

            //var pk = common.PrimaryKey;
            // TODO : FK
            base.GenerateLine(common);
        }
        protected override void GenerateLine(CommonDecl common)
        {
            if (row.Count == 0)
            {
                return;
            }
            var type = common.TypeName;

            if (!string.IsNullOrEmpty(common.PrimaryKey))
            {
                result.AppendFormat(@"    class EmployeeServiceHandler : TableService<{0}, {1}> {{
        public EmployeeServiceHandler() {{
            TableName = ""{0}"";
            KeyName = ""{1}"";
        }}

        public override int GetKeyValue({0} item) {{ return item.{2}; }}

        protected override DataRow FindRow(DataTable table, {0} item) {{
            var results = table.Select(""{2} = "" + item.{2});
            Debug.Assert(results.Length <= 1);
            return results.Length == 0 ? null : results[0];
        }}
",
                                    this.Path,
                                    common.TypeName,
                                    row[0].Value);
            }

            dataToModel.AppendFormat("item.{2} = ({0})row[{1}];\r\n",
                                     common.TypeName,
                                     rowNo,
                                     row[0].Value);
            modelToData.AppendFormat("{0}row[{1}]=item.{2};\r\n",
                                     string.IsNullOrEmpty(common.PrimaryKey) ? "" : "//",
                                     rowNo,
                                     row[0].Value);

            rowNo++;
            row.Clear();
        }
Beispiel #11
0
        //private string GetNamespace() {
        //    return IoPath.GetDirectoryName(this.Path).Replace("\\", ".").Replace("/", ".");
        //}

        protected override void GenerateLine(CommonDecl common)
        {
            if (row.Count != 0)
            {
                var type = common.TypeName;
                if (string.IsNullOrWhiteSpace(common.ForeignKey))
                {
                    if (!string.IsNullOrEmpty(common.PrimaryKey))
                    {
                        result.AppendLine("[Key]");
                    }
                    result.AppendFormat("public {1} {0} {{ get; set;}}\r\n", row[0].Value, type);
                }
                else
                {
                    var refType = GetNamespace() + "." + common.ForeignKey;
                    result.AppendFormat(@"private {1} {0}Key {{ get; set;}}
public {2} {0} {{ get; set;}}
", row[0].Value, type, refType);
                }
            }

            base.GenerateLine(common);
        }
Beispiel #12
0
 protected override void GenerateLine(CommonDecl common)
 {
     toClear = true;
     // do NOT call base.Generate()
 }
Beispiel #13
0
 protected virtual void GenerateLine(CommonDecl common)
 {
     row.Clear();
 }
Beispiel #14
0
 protected virtual void StartGenerate(CommonDecl common)
 {
 }
Beispiel #15
0
 protected override void StartGenerate(CommonDecl common)
 {
     result.AppendFormat(FilePrefixFormat, string.IsNullOrWhiteSpace(this.Path) ? ContainerName : System.IO.Path.GetFileName(this.Path));
     base.StartGenerate(common);
 }