最近研究C#,发现写代码很麻烦,特别是创建实体、模型、接口、工厂、存储过程之类,网上有些开源的,但是不完整,也不能完整的按需求生成,于是,花了三天的时候,结合前辈的一些经验,整合了一些代码生成器,以下是存储过程的生成方法,可以借鉴一下,水平有限,请多指教。
1 /// <summary> 2 /// 创建存储过程 3 /// </summary> 4 public string GetStorage(CodeTable codeTable) 5 { 6 7 Model.Servers server = Common.Config.GetServer(codeTable.ServerID); 8 if (server == null) 9 { 10 return string.Empty; 11 } 12 StringBuilder storage = new StringBuilder(import.GetImport_Storage()); 13 14 string dbName = codeTable.DbName; 15 string tableName = codeTable.TableName; 16 DataSet dataSet = idata.RunQuery(codeTable.ServerID, dbName, tableName); 17 DataRow[] rows = dataSet.Tables[0].Select("Table_Name = ‘" + tableName + "‘"); 18 19 foreach (DataRow dr in rows) 20 { 21 string Prefix = "Lls_"; 22 storage.Append(CreateSelectAll(Prefix + tableName + "_SelectAll", tableName, rows) + "\r\n\r\n"); 23 storage.Append(CreateSelectRow(Prefix + tableName + "_SelectRow", tableName, rows) + "\r\n\r\n"); 24 storage.Append(CreateInsert(Prefix + tableName + "_Insert", tableName, rows) + "\r\n\r\n"); 25 storage.Append(CreateUpdate(Prefix + tableName + "_Update", tableName, rows) + "\r\n\r\n"); 26 storage.Append(CreateDeleteRow(Prefix + tableName + "_DeleteRow", tableName, rows) + "\r\n\r\n"); 27 break; 28 } 29 return storage.ToString(); 30 }
时间: 2024-10-21 13:55:04