Ejemplo n.º 1
0
        private string SetNullKeysCondtition()
        {
            string returnValue = string.Empty;

            foreach (KeyValuePair <string, KeyColumn> kvp in Session.Keys)
            {
                switch (GetDatatableSqlBase.GetSqlBaseType(kvp.Key, kvp.Value.Type, 0, false))
                {
                case "string":
                    returnValue = string.Concat(returnValue, "(!", kvp.Key, ".Equals(string.Empty)) && ");
                    break;

                case "DateTime?":
                    returnValue = string.Concat(returnValue, "(DateTime.Parse(", kvp.Key, ".ToString()) != Null.MinDate) && ");
                    break;

                default: returnValue = string.Concat(returnValue, "(", kvp.Key, " != 0", ") && "); break;
                }
            }

            if (!returnValue.Equals(string.Empty))
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 3).Trim();
                returnValue = string.Concat("(", returnValue, ")");
                return(returnValue);
            }
            else
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 2
0
        private string SetDeclarationKeys()
        {
            string returnValue = string.Empty;

            foreach (KeyValuePair <string, KeyColumn> kvp in Session.Keys)
            {
                if (!kvp.Key.StartsWith("VERSION_"))
                {
                    returnValue = string.Concat(returnValue, GetDatatableSqlBase.GetSqlBaseType(kvp.Key, kvp.Value.Type, 0, false), " ", kvp.Key, ",");
                }
            }

            if (!returnValue.Equals(string.Empty))
            {
                return(returnValue.Substring(0, returnValue.Length - 1));
            }
            else
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 3
0
        private string GetDeclareRelationship(string className)
        {
            DataTable dt = GetDatatableSqlBase.GetRelationship(className);

            if (dt.Rows.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("\t\tDictionary<string, Dictionary<string, string>> relationship = new Dictionary<string, Dictionary<string, string>>() {");

                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append(string.Concat("\n\t\t {\"", dr["REFDTBNAME"].ToString(), "\",new Dictionary<string,string>() { {\"", dr["REFSCOLUMN"].ToString(), "\",\"", dr["REFDCOLUMN"].ToString(), "\"}} },"));
                }

                sb.Append("\n\t\t};");
                return(sb.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 4
0
        private string GetDeclareIndex(string className)
        {
            DataTable dt = GetDatatableSqlBase.GetIndex(className);

            if (dt.Rows.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("\t\tDictionary<string, Dictionary<string, string>> index = new Dictionary<string, Dictionary<string, string>>() {");

                foreach (DataRow dr in dt.Rows)
                {
                    //sb.Append(string.Format("\n\t\t //{{0},new Dictionary<string,string>() { {{1},{2}}} }", dr["REFDTBNAME"].ToString(), dr["REFSCOLUMN"].ToString(), dr["REFDCOLUMN"].ToString()));
                    sb.Append(string.Concat("\n\t\t {\"", dr["SYSKEYS.IXNAME"].ToString(), "\",new Dictionary<string,string>() { {\"", dr["SYSINDEXES.TBNAME"].ToString(), " \",\"", dr["SYSKEYS.COLNAME"].ToString(), "\"}} },"));
                }

                sb.Append("\n\t\t};");
                return(sb.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 5
0
        private void SetAllKeys(ref string declarationParametersKeys, ref string listParameterKeys, ref string parametersKeysWithOutType, ref string isNullKeys, ref string parameters)
        {
            foreach (KeyValuePair <string, KeyColumn> kvp in Session.Keys)
            {
                string columnName = string.Empty;
                string dbType     = string.Empty;
                if (!kvp.Key.StartsWith("VERSION_"))
                {
                    //SetDeclarationKeys
                    declarationParametersKeys = string.Concat(declarationParametersKeys, GetDatatableSqlBase.GetSqlBaseType(kvp.Key, kvp.Value.Type, 0, false), " ", kvp.Key, ",");
                    //SetParametersKeys
                    listParameterKeys = string.Concat(listParameterKeys, "parameter", kvp.Key, ",");
                    //SetParametersKeysWithOutType
                    parametersKeysWithOutType = string.Concat(parametersKeysWithOutType, kvp.Key, ",");
                    //SetNullKeysCondtition
                    switch (GetDatatableSqlBase.GetSqlBaseType(kvp.Key, kvp.Value.Type, 0, false))
                    {
                    case "string":
                        isNullKeys = string.Concat(isNullKeys, "(!", kvp.Key, ".Equals(string.Empty)) && ");
                        break;

                    case "DateTime?":
                        isNullKeys = string.Concat(isNullKeys, "(DateTime.Parse(", kvp.Key, ".ToString()) != Null.MinDate) && ");
                        break;

                    default: isNullKeys = string.Concat(isNullKeys, "(", kvp.Key, " != 0", ") && "); break;
                    }
                    //GetParametersDictionaryList
                    columnName = kvp.Key;
                    dbType     = GetDBType(kvp.Value.Type);
                    if (!kvp.Value.Size.ToString().Equals("0"))
                    {
                        dbType = string.Concat(dbType, ", ", kvp.Value.Size);
                    }
                    parameters = string.Concat(parameters, "\n");
                    parameters = string.Format("{0}\t\t\tSQLBaseParameter parameter{1} = new SQLBaseParameter(\"{1}\", DbType.{2}); \n", parameters, GetPublic(kvp.Key), dbType);
                    parameters = string.Concat(parameters, "\t\t\tDataHelper.ManageParameter(ref parameter", GetPublic(kvp.Key), ", ", GetPublic(kvp.Key), "); \n");
                }
            }

            if (!declarationParametersKeys.Equals(string.Empty))
            {
                declarationParametersKeys = declarationParametersKeys.Substring(0, declarationParametersKeys.Length - 1);
            }
            else
            {
                declarationParametersKeys = string.Empty;
            }

            if (!listParameterKeys.Equals(string.Empty))
            {
                listParameterKeys = listParameterKeys.Substring(0, listParameterKeys.Length - 1);
            }
            else
            {
                listParameterKeys = string.Empty;
            }

            if (!parametersKeysWithOutType.Equals(string.Empty))
            {
                parametersKeysWithOutType = parametersKeysWithOutType.Substring(0, parametersKeysWithOutType.Length - 1);
            }
            else
            {
                parametersKeysWithOutType = string.Empty;
            }

            if (!isNullKeys.Equals(string.Empty))
            {
                isNullKeys = isNullKeys.Substring(0, isNullKeys.Length - 3).Trim();
                isNullKeys = string.Concat("(", isNullKeys, ")");
            }
            else
            {
                isNullKeys = string.Empty;
            }
        }
Ejemplo n.º 6
0
        public bool BuildTemplate(DataTable dt, Provider provider)
        {
            string    tableName = dt.Rows[0]["Table"].ToString().Trim();
            KeyColumn key       = new KeyColumn();

            key.Name     = dt.Rows[0]["Name"].ToString();
            key.NetType  = dt.Rows[0]["Type"].ToString();
            key.Sequence = 1;
            key.Type     = dt.Rows[0]["Type"].ToString();
            key.Size     = int.Parse(dt.Rows[0]["Length"].ToString());
            Dictionary <string, KeyColumn> keys = new Dictionary <string, KeyColumn>();

            keys.Add(key.Name, key);
            Session.Keys = keys;
            string keyType        = "int";
            string isAutomaticKey = "false";
            string typeKey        = string.Empty;

            if (Session.Keys.Count == 0)
            {
                return(false);
            }

            string privateField = string.Empty;

            if (Session.Framework == Framework.net20)
            {
                privateField = GetPrivateField(dt);
            }
            string publicField               = GetPublicField(dt);
            string mapping                   = GetMapping(dt);
            string parameters                = string.Empty; // GetParameters(dt, tableName);
            string parametersList            = string.Empty;
            string parametersListInsert      = string.Empty;
            string parametersListUpdate      = string.Empty;
            string parametersListDelete      = string.Empty;
            string parametersListClone       = string.Empty;
            string declarationParametersKeys = string.Empty;
            string parameterKeys             = string.Empty;
            string listParameterKeys         = string.Empty;
            string isNullKeys                = string.Empty;
            string parametersKeysWithOutType = string.Empty;
            string queryInsert               = string.Empty;
            string queryUpdate               = string.Empty;
            string queryDelete               = string.Empty;
            string fieldBoolean              = string.Empty;
            string queryByUpdVer             = string.Empty;
            string structureField            = string.Empty;
            string isSingleKey               = "true";

            if (Session.Keys.Count > 1)
            {
                isSingleKey = "false";
            }

            string template = string.Empty;

            template = ManageTemplate.GetTemplate("CrudTemplateAutoTask.ico");

            //parametersListInsert = GetParametersList(dt, tableName, false);
            //parametersListUpdate = GetParametersList(dt, tableName, false);
            //parametersListDelete = GetParametersList(dt, tableName, true);

            GetParametersListAll(dt, ref parametersListInsert, ref parametersListDelete, ref parametersListClone, ref parameters, provider);
            parametersListUpdate = parametersListInsert;
            SetAllKeys(ref declarationParametersKeys, ref listParameterKeys, ref parametersKeysWithOutType, ref isNullKeys, ref parameterKeys);
            structureField = GetStructure(dt);

            fieldBoolean = CustomBoolean.GetList();

            //declarationParametersKeys = SetDeclarationKeys();
            //parameterKeys = GetParametersDictionaryList(Session.Keys, tableName);
            //listParameterKeys = SetParametersKeys();
            //isNullKeys = SetNullKeysCondtition();

            template = template.Replace("#Version#", Session.Version);
            template = template.Replace("#Date#", System.DateTime.Now.ToString("dd/MM/yyyy"));

            template = template.Replace("#Owner#", Session.Owner);
            template = template.Replace("***NameSpace***", Session.NamespaceDataLayer);
            template = template.Replace("***ClassName***", tableName);
            template = template.Replace("***StructureField***", structureField);
            template = template.Replace("***PrivateField***", privateField);
            template = template.Replace("***PublicField***", publicField);
            template = template.Replace("***MappingDataReader***", mapping);
            template = template.Replace("***MappingDataTable***", mapping);
            template = template.Replace("***Parameters***", parameters);
            template = template.Replace("***KetType***", keyType);
            template = template.Replace("***isAutomaticKey***", isAutomaticKey);
            foreach (KeyValuePair <string, KeyColumn> kvp in Session.Keys)
            {
                template = template.Replace("***TableKey***", kvp.Key);
                if (!kvp.Value.NetType.Equals("String"))
                {
                    template = template.Replace("***TableKeyType***", string.Concat(kvp.Value.NetType, ".Parse"));
                }
                else
                {
                    template = template.Replace("***TableKeyType***", string.Empty);
                }
                break;
            }

            template = template.Replace("***DeclarationParameterKeys***", declarationParametersKeys);
            template = template.Replace("***ParameterKeys***", parameterKeys);
            template = template.Replace("***ListParameterKeys***", listParameterKeys);

            template = template.Replace("***ParametersListInsert***", parametersListInsert);
            template = template.Replace("***ParametersListUpdate***", parametersListUpdate);
            template = template.Replace("***ParametersListDelete***", parametersListDelete);
            template = template.Replace("***ParametersListClone***", parametersListClone);

            template = template.Replace("***Collection***", Session.GetCollectionFunction);
            //template = template.Replace("#GetCollectionSql#", GetViewSql(dt, tableName, true));
            //template = template.Replace("#GetCollectionSqlWithOutOrder#", GetViewSql(dt, tableName, false));
            template = template.Replace("#GetCollectionByKeys#", "GetCollectionByKeys");
            template = template.Replace("***FieldBoolean***", fieldBoolean);
            template = template.Replace("***IsSingleKey***", isSingleKey);
            template = template.Replace("***TypeKey***", keyType);

            if (Session.SuperClass)
            {
                string    minorField            = string.Empty;
                string    tableNameRelationship = string.Empty;
                DataTable dtRelationship        = GetDatatableSqlBase.GetRelationship(tableName);
                foreach (DataRow drRelationship in dtRelationship.Rows)
                {
                    if (!tableNameRelationship.Equals(drRelationship["REFDTBNAME"].ToString()))
                    {
                        tableNameRelationship = drRelationship["REFDTBNAME"].ToString();
                        DataTable dtMinor = GetDatatableSqlBase.GetSchema(drRelationship["REFDTBNAME"].ToString());
                        minorField = string.Concat(minorField, GetPublicFieldForSuperClass(dtMinor, tableNameRelationship));
                    }
                    tableNameRelationship = drRelationship["REFDTBNAME"].ToString();
                }

                template = template.Replace("***SuperClass***", minorField);
                template = template.Replace("***DeclareRelationship***", GetDeclareRelationship(tableName));
                template = template.Replace("***DeclareIndex***", GetDeclareIndex(tableName));
            }
            else
            {
                template = template.Replace("***SuperClass***", string.Empty);
                template = template.Replace("***DeclareRelationship***", string.Empty);
                template = template.Replace("***DeclareIndex***", string.Empty);
            }

            //GetSql(dt, tableName, ref queryInsert, ref queryUpdate, ref queryDelete);
            //template = template.Replace("#GetByCodeSql#", GetByCodeSql(dt, tableName));
            //template = template.Replace("#GetByCodeSqlUpdVer#", GetByCodeSqlUpdVer(dt, tableName));

            template = template.Replace("***SWITCHCUSTOMFIELDS***", GetSwitchCustomFields(dt));
            template = template.Replace("***FIELDENUM***", GetFieldEnum(dt));

            template = template.Replace("***InsertSql***", queryInsert);
            template = template.Replace("#UpdateSql#", queryUpdate);
            template = template.Replace("#DeleteSql#", queryDelete);
            template = template.Replace("***Insert***", string.Format(Session.InsertFunction, tableName));
            template = template.Replace("#InsertKey#", "InsertKey");
            template = template.Replace("***Update***", string.Format(Session.UpdateFunction, tableName));
            template = template.Replace("***Delete***", string.Format(Session.DeleteFunction, tableName));
            template = template.Replace("***Read***", string.Format(Session.ReadFunction, tableName));
            template = template.Replace("***GetCollection***", string.Format(Session.GetCollectionFunction, tableName));
            template = template.Replace("***GetByCode***", string.Format(Session.GetByCodeFunction, tableName));
            template = template.Replace("***IsUnknown***", Session.IsUnknown);
            template = template.Replace("***IsUnknownCondtition***", isNullKeys);

            template = template.Replace("***CheckExist***", string.Empty);

            bool isValid = false;

            if (!(ManageTemplate.WriteTemplate(Session.Folder, template, string.Concat(tableName, ""), null)))
            {
                return(false);
            }
            //{
            //    #region Class Plus

            //    //if (Session.CreateCustomClass)
            //    //{
            //    //    template = ManageTemplate.GetTemplate("CrudTemplatePlusSqlBase.ico");

            //    //    template = template.Replace("#Version#", Session.Version);
            //    //    template = template.Replace("#Date#", System.DateTime.Now.ToString("dd/MM/yyyy"));
            //    //    template = template.Replace("***NameSpace***", Session.Namespace);
            //    //    template = template.Replace("***ClassName***", tableName);
            //    //    template = template.Replace("***Collection***", Session.GetCollectionFunction);
            //    //    template = template.Replace("***Insert***", string.Format(Session.InsertFunction, tableName));
            //    //    template = template.Replace("#InsertKey#", "InsertKey");
            //    //    template = template.Replace("***Update***", string.Format(Session.UpdateFunction, tableName));
            //    //    template = template.Replace("***Delete***", string.Format(Session.DeleteFunction, tableName));
            //    //    template = template.Replace("***Read***", string.Format(Session.ReadFunction, tableName));
            //    //    template = template.Replace("***GetCollection***", string.Format(Session.GetCollectionFunction, tableName));
            //    //    template = template.Replace("#GetCollectionByKeys#", "GetCollectionByKeys");
            //    //    template = template.Replace("***GetByCode***", string.Format(Session.GetByCodeFunction, tableName));
            //    //    template = template.Replace("***IsUnknown***", Session.IsUnknown);
            //    //    template = template.Replace("***DeclarationParameterKeys***", declarationParametersKeys);
            //    //    template = template.Replace("***DeclarationParameterKeysWithOutType***", parametersKeysWithOutType);

            //    //    if (!ManageTemplate.WriteTemplate(Session.Folder, template, tableName, null)) return false;
            //    //}

            //    //template = ManageTemplate.GetTemplate("Interface.ico");

            //    //template = template.Replace("#Version#", Session.Version);
            //    //template = template.Replace("#Date#", System.DateTime.Now.ToString("dd/MM/yyyy"));
            //    //template = template.Replace("***NameSpace***", Session.Namespace);
            //    //template = template.Replace("***ClassName***", tableName);

            //    //if (ManageTemplate.WriteTemplate(Session.Folder, template, string.Concat("I", tableName), null)) return true;
            //    //else return false;

            //    #endregion

            //    return false;
            //}
            return(true);
        }