示例#1
0
 private void GenerateSpMethod(CSharpTypeDef dcClass, string spName, DataFieldContainer dataFields,                                  string packageName, bool hasRetVal, bool returnsDataSet)
 {
     CSharpMethodDef def = new CSharpMethodDef();
       dcClass.Methods.Add(def);
       def.Comment.Summary = string.Format("Calls stored procedure '{0}'", spName);
       def.Attributes.Add(string.Format("ImplicitPmc(\"{0}\")", spName));
       if (returnsDataSet)
       {
     def.HeaderLine = string.Format("public DataSet {0}", spName);
     def.Comment.Returns = "Resulting DataSet from the stored procedure.";
       }
       else
       {
     def.HeaderLine = string.Format("public void {0}", spName);
       }
       foreach (DataFieldModel model in dataFields)
       {
     int length = (model.TypeString.IndexOf("(") > 0) ? model.TypeString.IndexOf("(") : model.TypeString.Length;
     string index = model.TypeString.Substring(0, length).ToLower();
     def.AddParam(model.NormalizedName, OracleTypeMap.GetDBType(index),                     string.Format("{0} parameter.", model.MappingName));
       }
       if (hasRetVal)
       {
     CSharpMethodparamDef def2 = new CSharpMethodparamDef("retVal", "int");
     def2.Direction = MethodParamDir.Out;
     def.Params.Add(def2);
     def.Comment.AddParam("retVal", "SP return value.");
       }
       TextWriter writer = def.Writer;
       writer.WriteLine("TraceCallEnterEvent.Raise();");
       writer.WriteLine("OracleCommand oraComm = PrepareSPCall(\"{0}\");", packageName + "." + spName);
       writer.WriteLine();
       int num2 = 1;
       foreach (DataFieldModel model2 in dataFields)
       {
     int num3 = (model2.TypeString.IndexOf("(") > 0) ? model2.TypeString.IndexOf("(") : model2.TypeString.Length;
     string str2 = model2.TypeString.Substring(0, num3).ToLower();
     writer.WriteLine(string.Format("OracleParameter p{0} = oraComm.Parameters.Add(\"i{1}\", OracleType.{2});", num2,                                       model2.Name, OracleTypeMap.GetNetOracleTypeWithSize(str2, model2.MaxLength)));
     writer.WriteLine(string.Format("p{0}.Direction = ParameterDirection.Input;", num2));
     if (OracleTypeMap.GetDBType(str2).ToLower() == "bool")
     {
       writer.WriteLine(string.Format("p{0}.Value = {1};", num2, model2.NormalizedName));
     }
     else
     {
       writer.WriteLine(string.Format("p{0}.Value = {1}.Value;", num2, model2.NormalizedName));
     }
     num2++;
       }
       if (returnsDataSet)
       {
     writer.WriteLine(string.Format(
                    "OracleParameter p{0} = oraComm.Parameters.Add(\"oresult\", OracleType.Cursor);", num2));
     writer.WriteLine(string.Format("p{0}.Direction = ParameterDirection.Output;", num2));
       }
       if (hasRetVal)
       {
     writer.WriteLine("OracleParameter returnValue = oraComm.Parameters.Add(\"returnValue\", OracleType.Number);");
     writer.WriteLine("returnValue.Direction = ParameterDirection.Output;");
       }
       writer.WriteLine("//TraceDbCommandEvent.Raise(oraComm);");
       if (returnsDataSet)
       {
     writer.WriteLine("DataSet Result = new DataSet();");
       }
       writer.WriteLine("try");
       writer.WriteLine("{");
       if (returnsDataSet)
       {
     writer.WriteLine("  OracleDataAdapter oraAdapt = new OracleDataAdapter(oraComm);");
     writer.WriteLine("  oraAdapt.Fill(Result);");
     writer.WriteLine("  TraceCallReturnEvent.Raise();");
       }
       else
       {
     writer.WriteLine("  oraComm.ExecuteNonQuery();");
     writer.WriteLine("  TraceCallReturnEvent.Raise();");
       }
       writer.WriteLine("}");
       writer.WriteLine("catch (OracleException  e)");
       writer.WriteLine("{");
       writer.WriteLine("  TraceCallReturnEvent.Raise(false);");
       writer.WriteLine("  throw e;");
       writer.WriteLine("}");
       writer.WriteLine("finally");
       writer.WriteLine("{");
       writer.WriteLine("  FinishSPCall();");
       writer.WriteLine("}");
       num2 = 0;
       if (hasRetVal)
       {
     writer.WriteLine("retVal = Convert.ToInt32(returnValue.Value);");
     writer.WriteLine("TraceInfoEvent.Raise(\"RetVal: {0}\", retVal);");
       }
       if (returnsDataSet)
       {
     writer.WriteLine("return Result;");
       }
 }
示例#2
0
 private void GenerateSpMethod(CSharpTypeDef dcClass, SqlSpInfo spInfo, bool hasRetVal, bool returnsDataSet)
 {
     CSharpMethodDef def = new CSharpMethodDef();
       dcClass.Methods.Add(def);
       def.Comment.Summary = string.Format("Calls stored procedure '{0}'", spInfo.Name);
       def.Attributes.Add(string.Format("ImplicitPmc(\"{0}\")", spInfo.Name));
       if (returnsDataSet)
       {
     def.HeaderLine = string.Format("public DataSet {0}", spInfo.Name);
     def.Comment.Returns = "Resulting DataSet from the stored procedure.";
       }
       else
       {
     def.HeaderLine = string.Format("public void {0}", spInfo.Name);
       }
       foreach (SqlSpParamInfo info in spInfo.Parameters)
       {
     if (info.Direction != ParameterDirection.ReturnValue)
     {
       if (info.Direction == ParameterDirection.Output)
       {
     CSharpMethodparamDef def2 = new CSharpMethodparamDef(info.NormalName, SqlTypeMap.GetDBType(info.Type));
     def2.Direction = MethodParamDir.Ref;
     def.Params.Add(def2);
     def.Comment.AddParam(info.NormalName, string.Format("{0} parameter.", info.Name));
       }
       else
       {
     def.AddParam(info.NormalName, SqlTypeMap.GetDBType(info.Type), string.Format("{0} parameter.", info.Name));
       }
     }
       }
       if (hasRetVal)
       {
     CSharpMethodparamDef def3 = new CSharpMethodparamDef("retVal", "int");
     def3.Direction = MethodParamDir.Out;
     def.Params.Add(def3);
     def.Comment.AddParam("retVal", "SP return value.");
       }
       TextWriter writer = def.Writer;
       writer.WriteLine("TraceCallEnterEvent.Raise();");
       writer.WriteLine("SqlCommand sqlComm = PrepareSPCall(\"[dbo].[{0}]\");", spInfo.Name);
       if (hasRetVal)
       {
     writer.WriteLine("SqlParameter returnValue = sqlComm.Parameters.Add(\"@RETURNVALUE\", SqlDbType.Int);");
     writer.WriteLine("returnValue.Direction = ParameterDirection.ReturnValue;");
       }
       int num = 1;
       foreach (SqlSpParamInfo info2 in spInfo.Parameters)
       {
     if (info2.Direction == ParameterDirection.ReturnValue)
     {
       continue;
     }
     writer.WriteLine(string.Format("SqlParameter p{0} = sqlComm.Parameters.Add(\"{1}\", {2});", num, info2.Name,                                       info2.SqlParamTypeName));
     if (info2.Direction == ParameterDirection.Output)
     {
       writer.WriteLine(string.Format("p{0}.Direction = ParameterDirection.Output;", num));
     }
     else if (SqlTypeMap.GetDBType(info2.Type).ToLower() == "bool")
     {
       writer.WriteLine(string.Format("p{0}.Value = {1};", num, info2.NormalName));
     }
     else if (SqlTypeMap.GetDBType(info2.Type).ToLower() == "dbdecimal")
     {
       writer.WriteLine(string.Format("p{0}.Precision = {1};", num, info2.Precision));
       writer.WriteLine(string.Format("p{0}.Scale = {1};", num, info2.Scale));
       writer.WriteLine(string.Format("p{0}.Value = {1};", num, info2.NormalName));
     }
     else
     {
       writer.WriteLine(string.Format("p{0}.Value = {1}.Value;", num, info2.NormalName));
     }
     num++;
       }
       writer.WriteLine("TraceDbCommandEvent.Raise(sqlComm);");
       if (returnsDataSet)
       {
     writer.WriteLine("DataSet Result = new DataSet();");
       }
       writer.WriteLine("try");
       writer.WriteLine("{");
       if (returnsDataSet)
       {
     writer.WriteLine("  SqlDataAdapter sqlAdapt = new SqlDataAdapter(sqlComm);");
     writer.WriteLine("  sqlAdapt.Fill(Result);");
     writer.WriteLine("  TraceCallReturnEvent.Raise();");
       }
       else
       {
     writer.WriteLine("  sqlComm.ExecuteNonQuery();");
     writer.WriteLine("  TraceCallReturnEvent.Raise();");
       }
       writer.WriteLine("}");
       writer.WriteLine("catch (SqlException e)");
       writer.WriteLine("{");
       writer.WriteLine("  TraceCallReturnEvent.Raise(false);");
       writer.Write("  SqlErrorHandler.Handle(e, ");
       if (spInfo.Parameters.Count > 1)
       {
     writer.WriteLine(string.Format("{0}.ToString());", spInfo.Parameters[1].NormalName));
       }
       else
       {
     writer.WriteLine("\"<unknown>\");");
       }
       writer.WriteLine("}");
       writer.WriteLine("finally");
       writer.WriteLine("{");
       writer.WriteLine("  FinishSPCall();");
       writer.WriteLine("}");
       num = 0;
       foreach (SqlSpParamInfo info3 in spInfo.Parameters)
       {
     if (info3.Direction == ParameterDirection.Output)
     {
       writer.WriteLine(string.Format("{0}.Value = p{1}.Value;", info3.NormalName, num));
     }
     num++;
       }
       if (hasRetVal)
       {
     writer.WriteLine("retVal = (int)returnValue.Value;");
     writer.WriteLine("TraceInfoEvent.Raise(\"RetVal: {0}\", retVal);");
       }
       if (returnsDataSet)
       {
     writer.WriteLine("return Result;");
       }
 }
示例#3
0
 public void AddParam(string name, string type, string comment)
 {
     XmlCommentParamDef def2;
       CSharpMethodparamDef def = new CSharpMethodparamDef(name, type);
       Params.Add(def);
       def2.Name = name;
       def2.Description = comment;
       Comment.Params.Add(def2);
 }