private string GetFunctionDefinition(StoreProcedure storeProcedure) { if (storeProcedure == null) { throw new ArgumentNullException("StoreProcedure"); } int iTabCnt = 2; StringBuilder sb = new StringBuilder(); sb.Append(GetFunSummary(storeProcedure)); sb.Append(CodeHelper.AddTab(2) + functionAuthority); switch (storeProcedure.ProcExecuteReturnType) { case StoreProcedure.ExecuteReturnType.NonQuery: sb.Append("int "); break; case StoreProcedure.ExecuteReturnType.DataReader: sb.Append("SqlDataReader "); break; case StoreProcedure.ExecuteReturnType.Scalar: sb.Append("object "); break; case StoreProcedure.ExecuteReturnType.Dataset: sb.Append("DataSet "); break; case StoreProcedure.ExecuteReturnType.DataTable: sb.Append("DataTable "); break; } #region 添加参数 sb.Append(storeProcedure.Name.Replace(" ", "") + "("); foreach (SPField var in storeProcedure.Parameters) { sb.Append(", "); if (var.PARAMETER_MODE.Trim().ToUpper() == "IN") { sb.Append(CodeHelper.ConvertDBTypeToDoNetType(var.DATA_TYPE) + " " + CodeHelper.GetPureParmName(var.PARAMETER_NAME)); } else { sb.Append("ref " + CodeHelper.ConvertDBTypeToDoNetType(var.DATA_TYPE) + " " + CodeHelper.GetPureParmName(var.PARAMETER_NAME)); } } if (storeProcedure.NeedReturnValue) { sb.Append(", ref int RETURN_VALUE"); } switch (this.connectType) { case ConnectType.ConnectionString: sb.Append(", string connectionString"); break; case ConnectType.SqlConnection: sb.Append(", SqlConnection connection"); break; } if (needTransaction && this.connectType == ConnectType.SqlConnection) { sb.Append(", SqlTransaction transaction"); } sb.Replace("(, ", "("); sb.Append(")"); #endregion sb.Append("\r\n" + CodeHelper.AddTab(2) + "{\r\n"); iTabCnt = 3; sb.AppendLine(CodeHelper.AddTab(iTabCnt) + "@@CreateCommand\r\n"); sb.AppendLine(CodeHelper.AddTab(iTabCnt) + "@@CommandExecute"); sb.AppendLine(CodeHelper.AddTab(2) + "}\r\n"); return(sb.ToString()); }
private string GetSetByRefVal(StoreProcedure storeProcedure, int tabCnt) { if (storeProcedure == null) { throw new ArgumentNullException("StoreProcedure"); } int iTabCnt = tabCnt; string strTabs = CodeHelper.AddTab(iTabCnt); StringBuilder sb = new StringBuilder(); foreach (SPField var in storeProcedure.Parameters) { if (var.PARAMETER_MODE.Trim().ToUpper() != "IN") { sb.AppendLine(strTabs + string.Format("{0} = ({1})command.Parameters[\"@{0}\"].Value;", CodeHelper.GetPureParmName(var.PARAMETER_NAME), CodeHelper.ConvertDBTypeToDoNetType(var.DATA_TYPE))); } } if (storeProcedure.NeedReturnValue) { sb.AppendLine(strTabs + "RETURN_VALUE = (int)command.Parameters[\"@RETURN_VALUE\"].Value;"); } return(sb.ToString()); }