public string Proc(string nameSpace, string className, string sa, string password) { string SQL = @" USE [{0}] DECLARE @objid INT SELECT @objid = object_id FROM sys.all_objects WHERE object_id = OBJECT_ID('{1}') SELECT name, 'type' = TYPE_NAME(user_type_id), max_length, precision, scale, is_output FROM sys.all_parameters WHERE object_id = @objid ORDER BY parameter_id "; SqlCmd cmd = new SqlCmd(databaseName.Provider, string.Format(SQL, databaseName.Name, spName)); // cmd.ChangeConnection(sa,password); DataTable dt = cmd.FillDataTable(); DPCollection<SpParamDpo> parameters = new DPCollection<SpParamDpo>(dt); string comment = string.Format("//Machine Generated Code by {0} at {1}", ActiveAccount.Account.UserName, DateTime.Today); string usingString = @"{0} using System; using System.Data; using Sys.Data; "; comment = string.Format(usingString, comment); string clss = @"{0} namespace {1} {{ public partial class {2} {{ {3} }} }} "; string func = @" private static object ___{0}(int __xtype{6}{1}) {{ SqlCmd cmd = new SqlCmd(""{2}..[{0}]""); {3} object __result = null; if(__xtype == 1) cmd.ExecuteNonQuery(); else if(__xtype == 2) __result = cmd.FillDataTable(); else if(__xtype == 3) __result = cmd.FillDataSet(); {4} return __result; }} public static void {0}({1}) {{ ___{0}(1{5}); }} public static DataTable dt_{0}({1}) {{ return (DataTable)___{0}(2{5}); }} public static DataSet ds_{0}({1}) {{ return (DataSet)___{0}(3{5}); }} public const string {7} = @""{8}""; "; string signuture1 = ""; string code1 = ""; string code2 = ""; string signuture2 = ""; string tab = " "; foreach (SpParamDpo param in parameters) { SpParam p = new SpParam(param); if (signuture1 != "") signuture1 += ", "; if (signuture2 != "") signuture2 += ", "; signuture1 += p.signuture1(); signuture2 += p.signuture2(); code1 += tab + p.param1(); code2 += tab + p.param2(); } string method = string.Format(func, spName, signuture1, databaseName.Name, code1, code2, signuture2 == "" ? "" : ", " + signuture2, signuture1 == "" ? "" : ", ", this.spDefVariable, escapeSpDef() ); return string.Format(clss, comment, nameSpace, className, method); }
private static void ImportSpecializations(DPCollection <REST.DTO.Specialization> specializations, ForeignDoctor foreignDoctor) { if (specializations == null) { return; } specializations .Items .Where(s => s.Id != null && s.Name != null) .ToList() .ForEach(s => { var foreignSpecialization = foreignDoctor.ForeignSpecializations .SingleOrDefault(fs => fs.Id == s.Id && fs.ForeignDoctorId == foreignDoctor.Id) ?? new ForeignSpecialization(); foreignSpecialization.ForeignDoctor = foreignDoctor; foreignSpecialization.Id = s.Id; foreignSpecialization.Name = s.Name; if (false == foreignDoctor.ForeignSpecializations.Exists(fs => fs.Id == s.Id)) { foreignDoctor.ForeignSpecializations.Add(foreignSpecialization); } }); }
public string Proc(string nameSpace, string className, string sa, string password) { string SQL = @" USE [{0}] DECLARE @objid INT SELECT @objid = object_id FROM sys.all_objects WHERE object_id = OBJECT_ID('{1}') SELECT name, 'type' = TYPE_NAME(user_type_id), max_length, precision, scale, is_output FROM sys.all_parameters WHERE object_id = @objid ORDER BY parameter_id "; SqlCmd cmd = new SqlCmd(databaseName.Provider, string.Format(SQL, databaseName.Name, spName)); // cmd.ChangeConnection(sa,password); DataTable dt = cmd.FillDataTable(); DPCollection <SpParamDpo> parameters = new DPCollection <SpParamDpo>(dt); string comment = string.Format("//Machine Generated Code by {0} at {1}", ActiveAccount.Account.UserName, DateTime.Today); string usingString = @"{0} using System; using System.Data; using Sys.Data; "; comment = string.Format(usingString, comment); string clss = @"{0} namespace {1} {{ public partial class {2} {{ {3} }} }} "; string func = @" private static object ___{0}(int __xtype{6}{1}) {{ SqlCmd cmd = new SqlCmd(""{2}..[{0}]""); {3} object __result = null; if(__xtype == 1) cmd.ExecuteNonQuery(); else if(__xtype == 2) __result = cmd.FillDataTable(); else if(__xtype == 3) __result = cmd.FillDataSet(); {4} return __result; }} public static void {0}({1}) {{ ___{0}(1{5}); }} public static DataTable dt_{0}({1}) {{ return (DataTable)___{0}(2{5}); }} public static DataSet ds_{0}({1}) {{ return (DataSet)___{0}(3{5}); }} public const string {7} = @""{8}""; "; string signuture1 = ""; string code1 = ""; string code2 = ""; string signuture2 = ""; string tab = " "; foreach (SpParamDpo param in parameters) { SpParam p = new SpParam(param); if (signuture1 != "") { signuture1 += ", "; } if (signuture2 != "") { signuture2 += ", "; } signuture1 += p.signuture1(); signuture2 += p.signuture2(); code1 += tab + p.param1(); code2 += tab + p.param2(); } string method = string.Format(func, spName, signuture1, databaseName.Name, code1, code2, signuture2 == "" ? "" : ", " + signuture2, signuture1 == "" ? "" : ", ", this.spDefVariable, escapeSpDef() ); return(string.Format(clss, comment, nameSpace, className, method)); }