コード例 #1
0
ファイル: CSharpWriter.cs プロジェクト: jcrajat/DAL_Design
        private static void WriteDBSaveTableAutoNextIdTyped(ref StringBuilder nSourceCode, List<Parameter> nTableColumns,
                                                            List<Parameter> nPrimaryKeys, Parameter nKeyParam,
                                                            string ObjetNameFormated, bool nMultiKeyParam)
        {
            if (nPrimaryKeys.Count > 0 && nKeyParam != null && CMData.DataBase.DataBase.IsNumericType(nKeyParam))
            {
                string FunctionName = nMultiKeyParam
                                          ? "DBSaveTableAutoNextId_for_" + nKeyParam.Name
                                          : "DBSaveTableAutoNextId";

                DataBaseClassWriter.Write(nSourceCode, 3, "/// <summary>");
                DataBaseClassWriter.Write(nSourceCode, 3,
                                          "/// Actualiza los registros de la tabla de acuerdo a los estados de cada registro");
                DataBaseClassWriter.Write(nSourceCode, 3, "/// </summary>");

                DataBaseClassWriter.Write(nSourceCode, 3, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
                DataBaseClassWriter.Write(nSourceCode, 3,
                                          "public void " + FunctionName + "(" + ObjetNameFormated +
                                          "DataTable nDataTable)");
                DataBaseClassWriter.Write(nSourceCode, 3, "{");
                DataBaseClassWriter.Write(nSourceCode, 4, "List<Parameter> nColumnsMapping = new List<Parameter>();");
                DataBaseClassWriter.Write(nSourceCode, 4, "List<Parameter> nPrimaryKeysMapping = new List<Parameter>();");

                foreach (var par in nTableColumns)
                {
                    DataBaseClassWriter.Write(nSourceCode, 4,
                                              "nColumnsMapping.Add(new Parameter(\"" + par.Name + "\", DbType." +
                                              par.Type.ToString() + ", \"" + par.SpecificType + "\", null, " +
                                              DataBaseClassWriter.getBoolean(par.IsNullable, LanguajeType.CSharp) + ", " +
                                              par.MaxLength + ", " + par.Precision + ", " + par.Scale +
                                              ", ParameterDirection." + par.Direction.ToString() + "));");
                }

                foreach (var par in nPrimaryKeys)
                {
                    DataBaseClassWriter.Write(nSourceCode, 4,
                                              "nPrimaryKeysMapping.Add(new Parameter(\"" + par.Name + "\", DbType." +
                                              par.Type.ToString() + ", \"" + par.SpecificType + "\", null, " +
                                              DataBaseClassWriter.getBoolean(par.IsNullable, LanguajeType.CSharp) + ", " +
                                              par.MaxLength + ", " + par.Precision + ", " + par.Scale +
                                              ", ParameterDirection." + par.Direction.ToString() + "));");
                }

                DataBaseClassWriter.Write(nSourceCode, 4,
                                          "base.DBSaveTableAutoNextId(nDataTable, nColumnsMapping , nPrimaryKeysMapping , \"" +
                                          nKeyParam.Name + "\");");
                DataBaseClassWriter.Write(nSourceCode, 3, "}");
                DataBaseClassWriter.Write(nSourceCode, 0, "");
            }
        }
コード例 #2
0
ファイル: CSharpWriter.cs プロジェクト: jcrajat/DAL_Design
        private static void WriteDBNextId(ref StringBuilder nSourceCode, List<Parameter> nPrimaryKeys,
                                          Parameter nKeyParam, bool nMultiKeyParam)
        {
            if (nKeyParam != null && CMData.DataBase.DataBase.IsNumericType(nKeyParam))
            {
                var paramKeyType = DataBaseClassWriter.GetApplicationStringType(nKeyParam.Type, LanguajeType.CSharp);
                var opetarionParams = "";
                string FunctionName = nMultiKeyParam ? "DBNextId_for_" + nKeyParam.Name : "DBNextId";

                foreach (var par in nPrimaryKeys)
                {
                    if (par.Name != nKeyParam.Name)
                    {
                        if (opetarionParams != "") opetarionParams += ", ";
                        opetarionParams = opetarionParams +
                                          DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.CSharp,
                                                                                       par.IsNullable) + " n" + par.Name;
                    }
                }

                DataBaseClassWriter.Write(nSourceCode, 3, "/// <summary>");
                DataBaseClassWriter.Write(nSourceCode, 3,
                                          "/// Calcula el siguiente identificador para un nuevo registro de la tabla");
                DataBaseClassWriter.Write(nSourceCode, 3, "/// </summary>");
                DataBaseClassWriter.Write(nSourceCode, 3, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
                DataBaseClassWriter.Write(nSourceCode, 3,
                                          "public " + paramKeyType + " " + FunctionName + "(" + opetarionParams + ")");
                DataBaseClassWriter.Write(nSourceCode, 3, "{");

                DataBaseClassWriter.Write(nSourceCode, 4, "List<Parameter> nInParams = new List<Parameter>();");
                DataBaseClassWriter.Write(nSourceCode, 4, "string nIdColumn = \"" + nKeyParam.Name + "\";");

                foreach (var par in nPrimaryKeys)
                {
                    if (par.Name != nKeyParam.Name)
                        DataBaseClassWriter.Write(nSourceCode, 4,
                                                  "nInParams.Add(new Parameter(\"" + par.Name + "\", DbType." +
                                                  par.Type.ToString() + ", \"" + par.SpecificType + "\", n" + par.Name +
                                                  ", " +
                                                  DataBaseClassWriter.getBoolean(par.IsNullable, LanguajeType.CSharp) +
                                                  ", " + par.MaxLength + ", " + par.Precision + ", " + par.Scale +
                                                  ", ParameterDirection." + par.Direction.ToString() + "));");
                }

                DataBaseClassWriter.Write(nSourceCode, 4,
                                          "return " + paramKeyType +
                                          ".Parse(base.DBNextId(nInParams, nIdColumn).ToString());");
                DataBaseClassWriter.Write(nSourceCode, 3, "}");
                DataBaseClassWriter.Write(nSourceCode, 0, "");
            }
        }