动软代码生成器生成存储过程的源代码
动软代码生成器生成存储过程的源代码
1 using System; 2 using System.Collections.Generic; 3 using System.Text; 4 using System.IO; 5 using System.Data; 6 using System.Collections; 7 using System.Data.SqlClient; 8 using Maticsoft.Utility; 9 using Maticsoft.IDBO; 10 using Maticsoft.CodeHelper; 11 namespace Maticsoft.BuilderDALProc 12 { 13 /// <summary> 14 /// 数据访问层代码构造器(存储过程方式) 15 /// </summary> 16 public class BuilderDAL : Maticsoft.IBuilder.IBuilderDAL 17 { 18 #region 私有变量 19 protected string _key = "ID";//标识列,或主键字段 20 protected string _keyType = "int";//标识列,或主键字段类型 21 #endregion 22 23 #region 公有属性 24 IDbObject dbobj; 25 private string _dbname; 26 private string _tablename; 27 private string _modelname; //model类名 28 private string _dalname;//dal类名 29 private List<ColumnInfo> _fieldlist; 30 private List<ColumnInfo> _keys; //主键或条件字段列表 31 private string _namespace; //顶级命名空间名 32 private string _folder; //所在文件夹 33 private string _dbhelperName;//数据库访问类名 34 private string _modelpath; 35 private string _dalpath; 36 private string _idalpath; 37 private string _iclass; 38 private string _procprefix; 39 40 public IDbObject DbObject 41 { 42 set { dbobj = value; } 43 get { return dbobj; } 44 } 45 public string DbName 46 { 47 set { _dbname = value; } 48 get { return _dbname; } 49 } 50 public string TableName 51 { 52 set { _tablename = value; } 53 get { return _tablename; } 54 } 55 56 /// <summary> 57 /// 选择的字段集合 58 /// </summary> 59 public List<ColumnInfo> Fieldlist 60 { 61 set { _fieldlist = value; } 62 get { return _fieldlist; } 63 } 64 /// <summary> 65 /// 主键或条件字段 66 /// </summary> 67 public List<ColumnInfo> Keys 68 { 69 set 70 { 71 _keys = value; 72 foreach (ColumnInfo key in _keys) 73 { 74 _key = key.ColumnName; 75 _keyType = key.TypeName; 76 if (key.IsIdentity) 77 { 78 _key = key.ColumnName; 79 _keyType = CodeCommon.DbTypeToCS(key.TypeName); 80 break; 81 } 82 } 83 } 84 get { return _keys; } 85 } 86 public string NameSpace 87 { 88 set { _namespace = value; } 89 get { return _namespace; } 90 } 91 public string Folder 92 { 93 set { _folder = value; } 94 get { return _folder; } 95 } 96 97 /*============================*/ 98 99 /// <summary> 100 /// 实体类的命名空间 101 /// </summary> 102 public string Modelpath 103 { 104 set { _modelpath = value; } 105 get { return _modelpath; } 106 } 107 public string ModelName 108 { 109 set { _modelname = value; } 110 get { return _modelname; } 111 } 112 113 /// <summary> 114 /// 实体类的整个命名空间 + 类名,即等于 Modelpath+ModelName 115 /// </summary> 116 public string ModelSpace 117 { 118 get { return Modelpath + "." + ModelName; } 119 } 120 121 /*============================*/ 122 123 /// <summary> 124 /// 数据层的命名空间 125 /// </summary> 126 public string DALpath 127 { 128 set { _dalpath = value; } 129 get 130 { 131 return _dalpath; 132 } 133 } 134 public string DALName 135 { 136 set { _dalname = value; } 137 get { return _dalname; } 138 } 139 140 /*============================*/ 141 142 /// <summary> 143 /// 接口的命名空间 144 /// </summary> 145 public string IDALpath 146 { 147 set { _idalpath = value; } 148 get 149 { 150 return _idalpath; 151 } 152 } 153 /// <summary> 154 /// 接口类名 155 /// </summary> 156 public string IClass 157 { 158 set { _iclass = value; } 159 get 160 { 161 return _iclass; 162 } 163 } 164 165 /*============================*/ 166 167 public string DbHelperName 168 { 169 set { _dbhelperName = value; } 170 get { return _dbhelperName; } 171 } 172 /// <summary> 173 /// 存储过程前缀 174 /// </summary> 175 public string ProcPrefix 176 { 177 set { _procprefix = value; } 178 get { return _procprefix; } 179 } 180 181 //语言文件 182 public Hashtable Languagelist 183 { 184 get 185 { 186 return Maticsoft.CodeHelper.Language.LoadFromCfg("BuilderDALProc.lan"); 187 } 188 } 189 #endregion 190 191 #region 构造属性 192 193 /// <summary> 194 /// 选择的字段集合的-字符串 195 /// </summary> 196 public string Fields 197 { 198 get 199 { 200 StringPlus _fields = new StringPlus(); 201 foreach (ColumnInfo obj in Fieldlist) 202 { 203 _fields.Append("'" + obj.ColumnName + "',"); 204 } 205 _fields.DelLastComma(); 206 return _fields.Value; 207 } 208 } 209 /// <summary> 210 /// 字段的 select * 列表 211 /// </summary> 212 public string Fieldstrlist 213 { 214 get 215 { 216 StringPlus _fields = new StringPlus(); 217 foreach (ColumnInfo obj in Fieldlist) 218 { 219 _fields.Append(obj.ColumnName + ","); 220 } 221 _fields.DelLastComma(); 222 return _fields.Value; 223 } 224 } 225 /// <summary> 226 /// 不同数据库类的前缀 227 /// </summary> 228 public string DbParaHead 229 { 230 get 231 { 232 return CodeCommon.DbParaHead(dbobj.DbType); 233 } 234 235 } 236 /// <summary> 237 /// 不同数据库字段类型 238 /// </summary> 239 public string DbParaDbType 240 { 241 get 242 { 243 return CodeCommon.DbParaDbType(dbobj.DbType); 244 } 245 } 246 247 /// <summary> 248 /// 存储过程参数 调用符号@ 249 /// </summary> 250 public string preParameter 251 { 252 get 253 { 254 return CodeCommon.preParameter(dbobj.DbType); 255 } 256 } 257 /// <summary> 258 /// 主键或条件字段中是否有标识列 259 /// </summary> 260 public bool IsHasIdentity 261 { 262 get 263 { 264 return CodeCommon.IsHasIdentity(_keys); 265 } 266 } 267 268 private string KeysNullTip 269 { 270 get 271 { 272 if (_keys.Count == 0) 273 { 274 return "//该表无主键信息,请自定义主键/条件字段"; 275 } 276 else 277 { 278 return ""; 279 } 280 } 281 } 282 #endregion 283 284 #region 根据列信息 得到参数的列表 285 286 ///// <summary> 287 ///// 得到Where条件语句 - Parameter方式 (例如:用于Exists Delete GetModel 的where) 288 ///// </summary> 289 ///// <param name="keys"></param> 290 ///// <returns></returns> 291 //public string GetWhereExpression(List<ColumnInfo> keys) 292 //{ 293 // StringPlus strclass = new StringPlus(); 294 // foreach (ColumnInfo key in keys) 295 // { 296 // strclass.Append(key.ColumnName + "=" + preParameter + key.ColumnName + " and "); 297 // } 298 // strclass.DelLastChar("and"); 299 // return strclass.Value; 300 //} 301 302 ///// <summary> 303 ///// 生成sql语句中的参数列表(例如:用于Add Exists Update Delete GetModel 的参数传入) 304 ///// </summary> 305 ///// <param name="keys"></param> 306 ///// <returns></returns> 307 //public string GetPreParameter(List<ColumnInfo> keys) 308 //{ 309 // StringPlus strclass = new StringPlus(); 310 // StringPlus strclass2 = new StringPlus(); 311 // strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); 312 // int n = 0; 313 // foreach (ColumnInfo key in keys) 314 // { 315 // strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + key.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, key.TypeName, "") + "),"); 316 // strclass2.AppendSpaceLine(3, "parameters["+n.ToString()+"].Value = " + key.ColumnName + ";"); 317 // n++; 318 // } 319 // strclass.DelLastComma(); 320 // strclass.AppendLine("};"); 321 // strclass.Append(strclass2.Value); 322 // return strclass.Value; 323 //} 324 325 326 ///// <summary> 327 ///// 得到Where条件语句 - Parameter方式 (例如:用于Exists Delete GetModel 的where) 328 ///// </summary> 329 ///// <param name="keys"></param> 330 ///// <returns></returns> 331 //public string GetWhereExpression(List<ColumnInfo> keys, bool IdentityisPrior) 332 //{ 333 // StringPlus strClass = new StringPlus(); 334 // ColumnInfo field = Maticsoft.CodeHelper.CodeCommon.GetIdentityKey(keys); 335 // if ((IdentityisPrior) && (field != null)) //有标识字段 336 // { 337 // strClass.Append(field.ColumnName + "=" + preParameter + field.ColumnName); 338 // } 339 // else 340 // { 341 // foreach (ColumnInfo key in keys) 342 // { 343 // if (key.IsPrimaryKey) 344 // { 345 // strClass.Append(key.ColumnName + "=" + preParameter + key.ColumnName + " and "); 346 // } 347 // } 348 // strClass.DelLastChar("and"); 349 // } 350 // return strClass.Value; 351 //} 352 353 ///// <summary> 354 ///// 生成sql语句中的参数列表(例如:用于 Exists Delete GetModel 的where参数赋值) 355 ///// </summary> 356 ///// <param name="keys"></param> 357 ///// <returns></returns> 358 //public string GetPreParameter(List<ColumnInfo> keys, bool IdentityisPrior) 359 //{ 360 // StringPlus strclass = new StringPlus(); 361 // StringPlus strclass2 = new StringPlus(); 362 // strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); 363 364 // ColumnInfo field = Maticsoft.CodeHelper.CodeCommon.GetIdentityKey(keys); 365 // if ((IdentityisPrior) && (field != null)) //有标识字段 366 // { 367 // strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + field.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, field.TypeName, "") + ")"); 368 // strclass2.AppendSpaceLine(3, "parameters[0].Value = " + field.ColumnName + ";"); 369 // } 370 // else 371 // { 372 // int n = 0; 373 // foreach (ColumnInfo key in keys) 374 // { 375 // if (key.IsPrimaryKey) 376 // { 377 // strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + key.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, key.TypeName, "") + "),"); 378 // strclass2.AppendSpaceLine(3, "parameters[" + n.ToString() + "].Value = " + key.ColumnName + ";"); 379 // n++; 380 // } 381 // } 382 // strclass.DelLastComma(); 383 // } 384 // strclass.AppendLine("};"); 385 // strclass.Append(strclass2.Value); 386 // return strclass.Value; 387 388 //} 389 390 #endregion 391 392 393 #region 构造函数 394 395 public BuilderDAL() 396 { 397 } 398 public BuilderDAL(IDbObject idbobj) 399 { 400 dbobj = idbobj; 401 } 402 403 public BuilderDAL(IDbObject idbobj, string dbname, string tablename, string modelname, string dalName, 404 List<ColumnInfo> fieldlist, List<ColumnInfo> keys, string namepace, 405 string folder, string dbherlpername, string modelpath, 406 string dalpath, string idalpath, string iclass) 407 { 408 dbobj = idbobj; 409 _dbname = dbname; 410 _tablename = tablename; 411 _modelname = modelname; 412 _dalname = dalName; 413 _namespace = namepace; 414 _folder = folder; 415 _dbhelperName = dbherlpername; 416 _modelpath = modelpath; 417 418 _dalpath = dalpath; 419 _idalpath = idalpath; 420 _iclass = iclass; 421 Fieldlist = fieldlist; 422 Keys = keys; 423 foreach (ColumnInfo key in _keys) 424 { 425 _key = key.ColumnName; 426 _keyType = key.TypeName; 427 if (key.IsIdentity) 428 { 429 _key = key.ColumnName; 430 _keyType = CodeCommon.DbTypeToCS(key.TypeName); 431 break; 432 } 433 } 434 } 435 436 #endregion 437 438 439 #region 数据层(整个类) 440 441 public string GetDALCode(bool Maxid, bool Exists, bool Add, bool Update, bool Delete, bool GetModel, bool List) 442 { 443 StringPlus strclass = new StringPlus(); 444 strclass.AppendLine("using System;"); 445 strclass.AppendLine("using System.Data;"); 446 strclass.AppendLine("using System.Text;"); 447 switch (dbobj.DbType) 448 { 449 case "SQL2005": 450 case "SQL2008": 451 case "SQL2012": 452 strclass.AppendLine("using System.Data.SqlClient;"); 453 break; 454 case "SQL2000": 455 strclass.AppendLine("using System.Data.SqlClient;"); 456 break; 457 case "Oracle": 458 strclass.AppendLine("using System.Data.OracleClient;"); 459 break; 460 case "MySQL": 461 strclass.AppendLine("using MySql.Data.MySqlClient;"); 462 break; 463 case "OleDb": 464 strclass.AppendLine("using System.Data.OleDb;"); 465 break; 466 case "SQLite": 467 strclass.AppendLine("using System.Data.SQLite;"); 468 break; 469 } 470 if (IDALpath != "") 471 { 472 strclass.AppendLine("using " + IDALpath + ";"); 473 } 474 strclass.AppendLine("using Maticsoft.DBUtility;//Please add references"); 475 strclass.AppendLine("namespace " + DALpath); 476 strclass.AppendLine("{"); 477 strclass.AppendSpaceLine(1, "/// <summary>"); 478 strclass.AppendSpaceLine(1, "/// " + Languagelist["summary"].ToString() + ":" + DALName); 479 strclass.AppendSpaceLine(1, "/// </summary>"); 480 strclass.AppendSpace(1, "public partial class " + DALName); 481 if (IClass != "") 482 { 483 strclass.Append(":" + IClass); 484 } 485 strclass.AppendLine(""); 486 strclass.AppendSpaceLine(1, "{"); 487 strclass.AppendSpaceLine(2, "public " + DALName + "()"); 488 strclass.AppendSpaceLine(2, "{}"); 489 strclass.AppendSpaceLine(2, "#region Method"); 490 491 #region 方法代码 492 if (Maxid) 493 { 494 strclass.AppendLine(CreatGetMaxID()); 495 } 496 if (Exists) 497 { 498 strclass.AppendLine(CreatExists()); 499 } 500 if (Add) 501 { 502 strclass.AppendLine(CreatAdd()); 503 } 504 if (Update) 505 { 506 strclass.AppendLine(CreatUpdate()); 507 } 508 if (Delete) 509 { 510 strclass.AppendLine(CreatDelete()); 511 } 512 if (GetModel) 513 { 514 strclass.AppendLine(CreatGetModel()); 515 strclass.AppendLine(CreatDataRowToModel()); 516 } 517 if (List) 518 { 519 strclass.AppendLine(CreatGetList()); 520 strclass.AppendLine(CreatGetListByPage()); 521 strclass.AppendLine(CreatGetListByPageProc()); 522 } 523 #endregion 524 525 strclass.AppendSpaceLine(2, "#endregion Method"); 526 527 strclass.AppendSpaceLine(2, "#region MethodEx"); 528 strclass.AppendLine(""); 529 strclass.AppendSpaceLine(2, "#endregion MethodEx"); 530 531 532 strclass.AppendSpaceLine(1, "}"); 533 strclass.AppendLine("}"); 534 strclass.AppendLine(""); 535 536 return strclass.ToString(); 537 } 538 539 #endregion 540 541 542 #region 数据层(使用存储过程实现) 543 544 /// <summary> 545 /// 得到最大ID的方法代码 546 /// </summary> 547 /// <param name="TabName"></param> 548 /// <param name="ID"></param> 549 /// <returns></returns> 550 public string CreatGetMaxID() 551 { 552 StringPlus strclass = new StringPlus(); 553 if (_keys.Count > 0) 554 { 555 string keyname = ""; 556 foreach (ColumnInfo obj in _keys) 557 { 558 if (CodeCommon.DbTypeToCS(obj.TypeName) == "int") 559 { 560 keyname = obj.ColumnName; 561 if (obj.IsPrimaryKey) 562 { 563 strclass.AppendLine(""); 564 strclass.AppendSpaceLine(2, "/// <summary>"); 565 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetMaxId"].ToString()); 566 strclass.AppendSpaceLine(2, "/// </summary>"); 567 strclass.AppendSpaceLine(2, "public int GetMaxId()"); 568 strclass.AppendSpaceLine(2, "{"); 569 strclass.AppendSpaceLine(2, "return " + DbHelperName + ".GetMaxID(\"" + keyname + "\", \"" + _tablename + "\"); "); 570 strclass.AppendSpaceLine(2, "}"); 571 break; 572 } 573 } 574 } 575 } 576 return strclass.ToString(); 577 } 578 579 /// <summary> 580 /// 得到Exists方法的代码 581 /// </summary> 582 /// <param name="_tablename"></param> 583 /// <param name="_key"></param> 584 /// <returns></returns> 585 public string CreatExists() 586 { 587 StringPlus strclass = new StringPlus(); 588 if (_keys.Count > 0) 589 { 590 string strInparam = Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, false); 591 if (!string.IsNullOrEmpty(strInparam)) 592 { 593 strclass.AppendSpaceLine(2, "/// <summary>"); 594 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryExists"].ToString()); 595 strclass.AppendSpaceLine(2, "/// </summary>"); 596 strclass.AppendSpaceLine(2, "public bool Exists(" + strInparam + ")"); 597 strclass.AppendSpaceLine(2, "{"); 598 strclass.AppendSpaceLine(3, "int rowsAffected;"); 599 600 strclass.AppendLine(CodeCommon.GetPreParameter(Keys, false, dbobj.DbType)); 601 602 strclass.AppendSpaceLine(3, "int result= " + DbHelperName + ".RunProcedure(\"" + ProcPrefix + _tablename + "_Exists\",parameters,out rowsAffected);"); 603 strclass.AppendSpaceLine(3, "if(result==1)"); 604 strclass.AppendSpaceLine(3, "{"); 605 strclass.AppendSpaceLine(4, "return true;"); 606 strclass.AppendSpaceLine(3, "}"); 607 strclass.AppendSpaceLine(3, "else"); 608 strclass.AppendSpaceLine(3, "{"); 609 strclass.AppendSpaceLine(4, "return false;"); 610 strclass.AppendSpaceLine(3, "}"); 611 strclass.AppendSpaceLine(2, "}"); 612 } 613 } 614 return strclass.Value; 615 } 616 617 /// <summary> 618 /// 得到Add()的代码 619 /// </summary> 620 /// <param name="ExistsMaxId">是否有GetMaxId()生成主健</param> 621 public string CreatAdd() 622 { 623 624 if (ModelSpace == "") 625 { 626 //ModelSpace = "ModelClassName"; ; 627 } 628 StringPlus strclass = new StringPlus(); 629 StringPlus strclass2 = new StringPlus(); 630 strclass.AppendSpaceLine(2, "/// <summary>"); 631 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryadd"].ToString()); 632 strclass.AppendSpaceLine(2, "/// </summary>"); 633 string strretu = "bool"; 634 if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005" 635 || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012") && (IsHasIdentity)) 636 { 637 strretu = "int"; 638 if (_keyType != "int") 639 { 640 strretu = _keyType; 641 } 642 643 } 644 //方法定义头 645 string strFun = CodeCommon.Space(2) + "public " + strretu + " Add(" + ModelSpace + " model)"; 646 strclass.AppendLine(strFun); 647 strclass.AppendSpaceLine(2, "{"); 648 strclass.AppendSpaceLine(3, "int rowsAffected;"); 649 strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); 650 int nkey = 0; 651 int n = 0; 652 foreach (ColumnInfo field in Fieldlist) 653 { 654 string columnName = field.ColumnName; 655 string columnType = field.TypeName; 656 bool IsIdentity = field.IsIdentity; 657 string Length = field.Length; 658 659 strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + columnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, columnType, Length) + "),"); 660 661 if (field.IsIdentity) 662 { 663 nkey = n; 664 strclass2.AppendSpaceLine(3, "parameters[" + n + "].Direction = ParameterDirection.Output;"); 665 n++; 666 continue; 667 } 668 669 if ("uniqueidentifier" == columnType.ToLower()) 670 { 671 strclass2.AppendSpaceLine(3, "parameters[" + n + "].Value = Guid.NewGuid();"); 672 } 673 else 674 { 675 strclass2.AppendSpaceLine(3, "parameters[" + n + "].Value = model." + columnName + ";"); 676 } 677 n++; 678 } 679 680 strclass.DelLastComma(); 681 strclass.AppendLine("};"); 682 strclass.AppendLine(strclass2.Value); 683 strclass.AppendSpaceLine(3, "" + DbHelperName + ".RunProcedure(\"" + ProcPrefix + _tablename + "_ADD" + "\",parameters,out rowsAffected);"); 684 //重新定义方法头 685 if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005" 686 || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012") && (IsHasIdentity)) 687 { 688 strclass.AppendSpaceLine(3, "return (" + _keyType + ")parameters[" + nkey + "].Value;"); 689 } 690 strclass.AppendSpaceLine(2, "}"); 691 return strclass.Value; 692 693 } 694 695 /// <summary> 696 /// 得到Update()的代码 697 /// </summary> 698 /// <param name="DbName"></param> 699 /// <param name="_tablename"></param> 700 /// <param name="_key"></param> 701 /// <param name="ModelName"></param> 702 /// <returns></returns> 703 public string CreatUpdate() 704 { 705 if (ModelSpace == "") 706 { 707 //ModelSpace = "ModelClassName"; ; 708 } 709 StringPlus strclass = new StringPlus(); 710 StringPlus strclass2 = new StringPlus(); 711 strclass.AppendSpaceLine(2, "/// <summary>"); 712 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryUpdate"].ToString()); 713 strclass.AppendSpaceLine(2, "/// </summary>"); 714 715 strclass.AppendSpaceLine(2, "public bool Update(" + ModelSpace + " model)"); 716 strclass.AppendSpaceLine(2, "{"); 717 strclass.AppendSpaceLine(3, "int rowsAffected=0;"); 718 strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); 719 int n = 0; 720 721 foreach (ColumnInfo field in Fieldlist) 722 { 723 string columnName = field.ColumnName; 724 string columnType = field.TypeName; 725 string Length = field.Length; 726 727 strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + columnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, columnType, Length) + "),"); 728 strclass2.AppendSpaceLine(3, "parameters[" + n + "].Value = model." + columnName + ";"); 729 n++; 730 } 731 732 strclass.DelLastComma(); 733 strclass.AppendLine("};"); 734 strclass.AppendLine(strclass2.Value); 735 strclass.AppendSpaceLine(3, "" + DbHelperName + ".RunProcedure(\"" + ProcPrefix + _tablename + "_Update" + "\",parameters,out rowsAffected);"); 736 737 strclass.AppendSpaceLine(3, "if (rowsAffected > 0)"); 738 strclass.AppendSpaceLine(3, "{"); 739 strclass.AppendSpaceLine(4, "return true;"); 740 strclass.AppendSpaceLine(3, "}"); 741 strclass.AppendSpaceLine(3, "else"); 742 strclass.AppendSpaceLine(3, "{"); 743 strclass.AppendSpaceLine(4, "return false;"); 744 strclass.AppendSpaceLine(3, "}"); 745 746 strclass.AppendSpaceLine(2, "}"); 747 return strclass.Value; 748 749 } 750 /// <summary> 751 /// 得到Delete的代码 752 /// </summary> 753 /// <param name="_tablename"></param> 754 /// <param name="_key"></param> 755 /// <returns></returns> 756 public string CreatDelete() 757 { 758 StringPlus strclass = new StringPlus(); 759 strclass.AppendSpaceLine(2, "/// <summary>"); 760 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDelete"].ToString()); 761 strclass.AppendSpaceLine(2, "/// </summary>"); 762 strclass.AppendSpaceLine(2, "public bool Delete(" + CodeCommon.GetInParameter(Keys, true) + ")"); 763 strclass.AppendSpaceLine(2, "{"); 764 strclass.AppendSpaceLine(3, "int rowsAffected=0;"); 765 766 strclass.AppendLine(CodeCommon.GetPreParameter(Keys, true, dbobj.DbType)); 767 768 strclass.AppendSpaceLine(3, "" + DbHelperName + ".RunProcedure(\"" + ProcPrefix + _tablename + "_Delete" + "\",parameters,out rowsAffected);"); 769 770 strclass.AppendSpaceLine(3, "if (rowsAffected > 0)"); 771 strclass.AppendSpaceLine(3, "{"); 772 strclass.AppendSpaceLine(4, "return true;"); 773 strclass.AppendSpaceLine(3, "}"); 774 strclass.AppendSpaceLine(3, "else"); 775 strclass.AppendSpaceLine(3, "{"); 776 strclass.AppendSpaceLine(4, "return false;"); 777 strclass.AppendSpaceLine(3, "}"); 778 779 strclass.AppendSpaceLine(2, "}"); 780 781 782 #region 联合主键优先的删除(既有标识字段,又有非标识主键字段) 783 784 if ((Maticsoft.CodeHelper.CodeCommon.HasNoIdentityKey(Keys)) && (Maticsoft.CodeHelper.CodeCommon.GetIdentityKey(Keys) != null)) 785 { 786 strclass.AppendSpaceLine(2, "/// <summary>"); 787 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDelete"].ToString()); 788 strclass.AppendSpaceLine(2, "/// </summary>"); 789 strclass.AppendSpaceLine(2, "public bool Delete(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, false) + ")"); 790 strclass.AppendSpaceLine(2, "{"); 791 strclass.AppendSpaceLine(3, KeysNullTip); 792 strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); 793 strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablename + " \");"); 794 strclass.AppendSpaceLine(3, "strSql.Append(\" where " + CodeCommon.GetWhereParameterExpression(Keys, false, dbobj.DbType) + "\");"); 795 strclass.AppendLine(CodeCommon.GetPreParameter(Keys, false, dbobj.DbType)); 796 797 strclass.AppendSpaceLine(3, "int rows=" + DbHelperName + ".ExecuteSql(strSql.ToString(),parameters);"); 798 strclass.AppendSpaceLine(3, "if (rows > 0)"); 799 strclass.AppendSpaceLine(3, "{"); 800 strclass.AppendSpaceLine(4, "return true;"); 801 strclass.AppendSpaceLine(3, "}"); 802 strclass.AppendSpaceLine(3, "else"); 803 strclass.AppendSpaceLine(3, "{"); 804 strclass.AppendSpaceLine(4, "return false;"); 805 strclass.AppendSpaceLine(3, "}"); 806 807 strclass.AppendSpaceLine(2, "}"); 808 } 809 810 #endregion 811 812 #region 批量删除方法 813 814 string keyField = ""; 815 if (Keys.Count == 1) 816 { 817 keyField = Keys[0].ColumnName; 818 } 819 else 820 { 821 foreach (ColumnInfo field in Keys) 822 { 823 if (field.IsIdentity) 824 { 825 keyField = field.ColumnName; 826 break; 827 } 828 } 829 } 830 if (keyField.Trim().Length > 0) 831 { 832 strclass.AppendSpaceLine(2, "/// <summary>"); 833 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDeletelist"].ToString()); 834 strclass.AppendSpaceLine(2, "/// </summary>"); 835 strclass.AppendSpaceLine(2, "public bool DeleteList(string " + keyField + "list )"); 836 strclass.AppendSpaceLine(2, "{"); 837 strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); 838 strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablename + " \");"); 839 strclass.AppendSpaceLine(3, "strSql.Append(\" where " + keyField + " in (\"+" + keyField + "list + \") \");"); 840 strclass.AppendSpaceLine(3, "int rows=" + DbHelperName + ".ExecuteSql(strSql.ToString());"); 841 strclass.AppendSpaceLine(3, "if (rows > 0)"); 842 strclass.AppendSpaceLine(3, "{"); 843 strclass.AppendSpaceLine(4, "return true;"); 844 strclass.AppendSpaceLine(3, "}"); 845 strclass.AppendSpaceLine(3, "else"); 846 strclass.AppendSpaceLine(3, "{"); 847 strclass.AppendSpaceLine(4, "return false;"); 848 strclass.AppendSpaceLine(3, "}"); 849 strclass.AppendSpaceLine(2, "}"); 850 } 851 #endregion 852 853 854 return strclass.Value; 855 856 } 857 858 /// <summary> 859 /// 得到GetModel()的代码 860 /// </summary> 861 /// <param name="DbName"></param> 862 /// <param name="_tablename"></param> 863 /// <param name="_key"></param> 864 /// <param name="ModelName"></param> 865 /// <returns></returns> 866 public string CreatGetModel() 867 { 868 if (ModelSpace == "") 869 { 870 //ModelSpace = "ModelClassName"; ; 871 } 872 StringPlus strclass = new StringPlus(); 873 strclass.AppendSpaceLine(2, "/// <summary>"); 874 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetModel"].ToString()); 875 strclass.AppendSpaceLine(2, "/// </summary>"); 876 strclass.AppendSpaceLine(2, "public " + ModelSpace + " GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ")"); 877 strclass.AppendSpaceLine(2, "{"); 878 879 strclass.AppendLine(CodeCommon.GetPreParameter(Keys, true, dbobj.DbType)); 880 881 strclass.AppendSpaceLine(3, "" + ModelSpace + " model=new " + ModelSpace + "();"); 882 strclass.AppendSpaceLine(3, "DataSet ds= " + DbHelperName + ".RunProcedure(\"" + ProcPrefix + _tablename + "_GetModel" + "\",parameters,\"ds\");"); 883 884 strclass.AppendSpaceLine(3, "if(ds.Tables[0].Rows.Count>0)"); 885 strclass.AppendSpaceLine(3, "{"); 886 887 #region 888 /* 889 foreach (ColumnInfo field in Fieldlist) 890 { 891 string columnName = field.ColumnName; 892 string columnType = field.TypeName; 893 894 strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"]!=null && ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); 895 strclass.AppendSpaceLine(4, "{"); 896 #region 897 switch (CodeCommon.DbTypeToCS(columnType)) 898 { 899 case "int": 900 { 901 //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); 902 //strclass.AppendSpaceLine(4, "{"); 903 strclass.AppendSpaceLine(5, "model." + columnName + "=int.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); 904 //strclass.AppendSpaceLine(4, "}"); 905 } 906 break; 907 case "long": 908 { 909 //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); 910 //strclass.AppendSpaceLine(4, "{"); 911 strclass.AppendSpaceLine(5, "model." + columnName + "=long.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); 912 //strclass.AppendSpaceLine(4, "}"); 913 } 914 break; 915 case "decimal": 916 { 917 //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); 918 //strclass.AppendSpaceLine(4, "{"); 919 strclass.AppendSpaceLine(5, "model." + columnName + "=decimal.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); 920 //strclass.AppendSpaceLine(4, "}"); 921 } 922 break; 923 case "float": 924 { 925 //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); 926 //strclass.AppendSpaceLine(4, "{"); 927 strclass.AppendSpaceLine(5, "model." + columnName + "=float.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); 928 //strclass.AppendSpaceLine(4, "}"); 929 } 930 break; 931 case "DateTime": 932 { 933 //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); 934 //strclass.AppendSpaceLine(4, "{"); 935 strclass.AppendSpaceLine(5, "model." + columnName + "=DateTime.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); 936 //strclass.AppendSpaceLine(4, "}"); 937 } 938 break; 939 case "string": 940 { 941 //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"]!=null)"); 942 //strclass.AppendSpaceLine(4, "{"); 943 strclass.AppendSpaceLine(5, "model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();"); 944 //strclass.AppendSpaceLine(4, "}"); 945 } 946 break; 947 case "bool": 948 { 949 //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); 950 //strclass.AppendSpaceLine(4, "{"); 951 strclass.AppendSpaceLine(5, "if((ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()==\"1\")||(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString().ToLower()==\"true\"))"); 952 strclass.AppendSpaceLine(5, "{"); 953 strclass.AppendSpaceLine(6, "model." + columnName + "=true;"); 954 strclass.AppendSpaceLine(5, "}"); 955 strclass.AppendSpaceLine(5, "else"); 956 strclass.AppendSpaceLine(5, "{"); 957 strclass.AppendSpaceLine(6, "model." + columnName + "=false;"); 958 strclass.AppendSpaceLine(5, "}"); 959 //strclass.AppendSpaceLine(4, "}"); 960 } 961 break; 962 case "byte[]": 963 { 964 //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); 965 //strclass.AppendSpaceLine(4, "{"); 966 strclass.AppendSpaceLine(5, "model." + columnName + "=(byte[])ds.Tables[0].Rows[0][\"" + columnName + "\"];"); 967 //strclass.AppendSpaceLine(4, "}"); 968 } 969 break; 970 case "uniqueidentifier": 971 case "Guid": 972 { 973 //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); 974 //strclass.AppendSpaceLine(4, "{"); 975 strclass.AppendSpaceLine(5, "model." + columnName + "=new Guid(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); 976 //strclass.AppendSpaceLine(4, "}"); 977 } 978 break; 979 default: 980 strclass.AppendSpaceLine(5, "//model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();"); 981 break; 982 983 } 984 #endregion 985 strclass.AppendSpaceLine(4, "}"); 986 }*/ 987 #endregion 988 989 strclass.AppendSpaceLine(4, "return DataRowToModel(ds.Tables[0].Rows[0]);"); 990 strclass.AppendSpaceLine(3, "}"); 991 strclass.AppendSpaceLine(3, "else"); 992 strclass.AppendSpaceLine(3, "{"); 993 strclass.AppendSpaceLine(4, "return null;"); 994 strclass.AppendSpaceLine(3, "}"); 995 strclass.AppendSpaceLine(2, "}"); 996 return strclass.Value; 997 998 } 999 /// <summary> 1000 /// DataRowToModel的代码 1001 /// </summary> 1002 public string CreatDataRowToModel() 1003 { 1004 if (ModelSpace == "") 1005 { 1006 //ModelSpace = "ModelClassName"; ; 1007 } 1008 StringPlus strclass = new StringPlus(); 1009 strclass.AppendLine(); 1010 strclass.AppendSpaceLine(2, "/// <summary>"); 1011 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetModel"].ToString()); 1012 strclass.AppendSpaceLine(2, "/// </summary>"); 1013 strclass.AppendSpaceLine(2, "public " + ModelSpace + " DataRowToModel(DataRow row)"); 1014 strclass.AppendSpaceLine(2, "{"); 1015 strclass.AppendSpaceLine(3, "" + ModelSpace + " model=new " + ModelSpace + "();"); 1016 1017 strclass.AppendSpaceLine(3, "if (row != null)"); 1018 strclass.AppendSpaceLine(3, "{"); 1019 1020 #region 字段赋值 1021 foreach (ColumnInfo field in Fieldlist) 1022 { 1023 string columnName = field.ColumnName; 1024 string columnType = field.TypeName; 1025 1026 //strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); 1027 //strclass.AppendSpaceLine(4, "{"); 1028 #region 1029 switch (CodeCommon.DbTypeToCS(columnType)) 1030 { 1031 case "int": 1032 { 1033 strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); 1034 strclass.AppendSpaceLine(4, "{"); 1035 strclass.AppendSpaceLine(5, "model." + columnName + "=int.Parse(row[\"" + columnName + "\"].ToString());"); 1036 strclass.AppendSpaceLine(4, "}"); 1037 } 1038 break; 1039 case "long": 1040 { 1041 strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); 1042 strclass.AppendSpaceLine(4, "{"); 1043 strclass.AppendSpaceLine(5, "model." + columnName + "=long.Parse(row[\"" + columnName + "\"].ToString());"); 1044 strclass.AppendSpaceLine(4, "}"); 1045 } 1046 break; 1047 case "decimal": 1048 { 1049 strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); 1050 strclass.AppendSpaceLine(4, "{"); 1051 strclass.AppendSpaceLine(5, "model." + columnName + "=decimal.Parse(row[\"" + columnName + "\"].ToString());"); 1052 strclass.AppendSpaceLine(4, "}"); 1053 } 1054 break; 1055 case "float": 1056 { 1057 strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); 1058 strclass.AppendSpaceLine(4, "{"); 1059 strclass.AppendSpaceLine(5, "model." + columnName + "=float.Parse(row[\"" + columnName + "\"].ToString());"); 1060 strclass.AppendSpaceLine(4, "}"); 1061 } 1062 break; 1063 case "DateTime": 1064 { 1065 strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); 1066 strclass.AppendSpaceLine(4, "{"); 1067 strclass.AppendSpaceLine(5, "model." + columnName + "=DateTime.Parse(row[\"" + columnName + "\"].ToString());"); 1068 strclass.AppendSpaceLine(4, "}"); 1069 } 1070 break; 1071 case "string": 1072 { 1073 strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null)"); 1074 strclass.AppendSpaceLine(4, "{"); 1075 strclass.AppendSpaceLine(5, "model." + columnName + "=row[\"" + columnName + "\"].ToString();"); 1076 strclass.AppendSpaceLine(4, "}"); 1077 } 1078 break; 1079 case "bool": 1080 { 1081 strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); 1082 strclass.AppendSpaceLine(4, "{"); 1083 strclass.AppendSpaceLine(5, "if((row[\"" + columnName + "\"].ToString()==\"1\")||(row[\"" + columnName + "\"].ToString().ToLower()==\"true\"))"); 1084 strclass.AppendSpaceLine(5, "{"); 1085 strclass.AppendSpaceLine(6, "model." + columnName + "=true;"); 1086 strclass.AppendSpaceLine(5, "}"); 1087 strclass.AppendSpaceLine(5, "else"); 1088 strclass.AppendSpaceLine(5, "{"); 1089 strclass.AppendSpaceLine(6, "model." + columnName + "=false;"); 1090 strclass.AppendSpaceLine(5, "}"); 1091 strclass.AppendSpaceLine(4, "}"); 1092 } 1093 break; 1094 case "byte[]": 1095 { 1096 strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); 1097 strclass.AppendSpaceLine(4, "{"); 1098 strclass.AppendSpaceLine(5, "model." + columnName + "=(byte[])row[\"" + columnName + "\"];"); 1099 strclass.AppendSpaceLine(4, "}"); 1100 } 1101 break; 1102 case "uniqueidentifier": 1103 case "Guid": 1104 { 1105 strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); 1106 strclass.AppendSpaceLine(4, "{"); 1107 strclass.AppendSpaceLine(5, "model." + columnName + "= new Guid(row[\"" + columnName + "\"].ToString());"); 1108 strclass.AppendSpaceLine(4, "}"); 1109 } 1110 break; 1111 default: 1112 strclass.AppendSpaceLine(5, "//model." + columnName + "=row[\"" + columnName + "\"].ToString();"); 1113 break; 1114 } 1115 #endregion 1116 //strclass.AppendSpaceLine(4, "}"); 1117 } 1118 #endregion 1119 1120 strclass.AppendSpaceLine(3, "}"); 1121 strclass.AppendSpaceLine(3, "return model;"); 1122 strclass.AppendSpaceLine(2, "}"); 1123 return strclass.ToString(); 1124 } 1125 1126 1127 /// <summary> 1128 /// 得到GetList()的代码 1129 /// </summary> 1130 /// <param name="_tablename"></param> 1131 /// <param name="_key"></param> 1132 /// <returns></returns> 1133 public string CreatGetList() 1134 { 1135 //StringPlus strclass = new StringPlus(); 1136 //strclass.AppendSpaceLine(2, "/// <summary>"); 1137 //strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString()); 1138 //strclass.AppendSpaceLine(2, "/// </summary>"); 1139 //strclass.AppendSpaceLine(2, "public DataSet GetList(string strWhere)"); 1140 //strclass.AppendSpaceLine(2, "{"); 1141 ////strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); 1142 ////strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + _key + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, _keyType, "") + ")"); 1143 ////strclass.AppendSpaceLine(4, "};"); 1144 ////strclass.AppendSpaceLine(3, "parameters[0].Value = strWhere;"); 1145 //strclass.AppendSpaceLine(3, "return " + DbHelperName + ".RunProcedure(\"" + ProcPrefix + _tablename + "_GetList" + "\",null,\"ds\");"); 1146 //strclass.AppendSpaceLine(2, "}"); 1147 //return strclass.Value; 1148 1149 1150 StringPlus strclass = new StringPlus(); 1151 1152 strclass.AppendSpaceLine(2, "/// <summary>"); 1153 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString()); 1154 strclass.AppendSpaceLine(2, "/// </summary>"); 1155 strclass.AppendSpaceLine(2, "public DataSet GetList(string strWhere)"); 1156 strclass.AppendSpaceLine(2, "{"); 1157 strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); 1158 strclass.AppendSpace(3, "strSql.Append(\"select "); 1159 strclass.AppendLine(Fieldstrlist + " \");"); 1160 strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableName + " \");"); 1161 strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")"); 1162 strclass.AppendSpaceLine(3, "{"); 1163 strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);"); 1164 strclass.AppendSpaceLine(3, "}"); 1165 strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());"); 1166 strclass.AppendSpaceLine(2, "}"); 1167 1168 if ((dbobj.DbType == "SQL2000") || 1169 (dbobj.DbType == "SQL2005") || 1170 (dbobj.DbType == "SQL2008") || 1171 (dbobj.DbType == "SQL2012")) 1172 { 1173 strclass.AppendLine(); 1174 strclass.AppendSpaceLine(2, "/// <summary>"); 1175 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList2"].ToString()); 1176 strclass.AppendSpaceLine(2, "/// </summary>"); 1177 strclass.AppendSpaceLine(2, "public DataSet GetList(int Top,string strWhere,string filedOrder)"); 1178 strclass.AppendSpaceLine(2, "{"); 1179 strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); 1180 strclass.AppendSpaceLine(3, "strSql.Append(\"select \");"); 1181 strclass.AppendSpaceLine(3, "if(Top>0)"); 1182 strclass.AppendSpaceLine(3, "{"); 1183 strclass.AppendSpaceLine(4, "strSql.Append(\" top \"+Top.ToString());"); 1184 strclass.AppendSpaceLine(3, "}"); 1185 strclass.AppendSpaceLine(3, "strSql.Append(\" " + Fieldstrlist + " \");"); 1186 strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableName + " \");"); 1187 strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")"); 1188 strclass.AppendSpaceLine(3, "{"); 1189 strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);"); 1190 strclass.AppendSpaceLine(3, "}"); 1191 strclass.AppendSpaceLine(3, "strSql.Append(\" order by \" + filedOrder);"); 1192 strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());"); 1193 strclass.AppendSpaceLine(2, "}"); 1194 } 1195 1196 return strclass.Value; 1197 1198 } 1199 1200 1201 /// <summary> 1202 /// 得到分页方法的代码 1203 /// </summary> 1204 public string CreatGetListByPage() 1205 { 1206 StringPlus strclass = new StringPlus(); 1207 strclass.AppendSpaceLine(2, "/// <summary>"); 1208 strclass.AppendSpaceLine(2, "/// " + Languagelist["GetRecordCount"].ToString()); 1209 strclass.AppendSpaceLine(2, "/// </summary>"); 1210 strclass.AppendSpaceLine(2, "public int GetRecordCount(string strWhere)"); 1211 strclass.AppendSpaceLine(2, "{"); 1212 strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); 1213 strclass.AppendSpaceLine(3, "strSql.Append(\"select count(1) FROM " + TableName + " \");"); 1214 strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")"); 1215 strclass.AppendSpaceLine(3, "{"); 1216 strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);"); 1217 strclass.AppendSpaceLine(3, "}"); 1218 strclass.AppendSpaceLine(3, "object obj = DbHelperSQL.GetSingle(strSql.ToString());"); 1219 strclass.AppendSpaceLine(3, "if (obj == null)"); 1220 strclass.AppendSpaceLine(3, "{"); 1221 strclass.AppendSpaceLine(4, "return 0;"); 1222 strclass.AppendSpaceLine(3, "}"); 1223 strclass.AppendSpaceLine(3, "else"); 1224 strclass.AppendSpaceLine(3, "{"); 1225 strclass.AppendSpaceLine(4, "return Convert.ToInt32(obj);"); 1226 strclass.AppendSpaceLine(3, "}"); 1227 strclass.AppendSpaceLine(2, "}"); 1228 1229 1230 1231 strclass.AppendSpaceLine(2, "/// <summary>"); 1232 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList3"].ToString()); 1233 strclass.AppendSpaceLine(2, "/// </summary>"); 1234 strclass.AppendSpaceLine(2, "public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)"); 1235 strclass.AppendSpaceLine(2, "{"); 1236 strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); 1237 strclass.AppendSpaceLine(3, "strSql.Append(\"SELECT * FROM ( \");"); 1238 strclass.AppendSpaceLine(3, "strSql.Append(\" SELECT ROW_NUMBER() OVER (\");"); 1239 strclass.AppendSpaceLine(3, "if (!string.IsNullOrEmpty(orderby.Trim()))"); 1240 strclass.AppendSpaceLine(3, "{"); 1241 strclass.AppendSpaceLine(4, "strSql.Append(\"order by T.\" + orderby );"); 1242 strclass.AppendSpaceLine(3, "}"); 1243 strclass.AppendSpaceLine(3, "else"); 1244 strclass.AppendSpaceLine(3, "{"); 1245 strclass.AppendSpaceLine(4, "strSql.Append(\"order by T." + _key + " desc\");"); 1246 strclass.AppendSpaceLine(3, "}"); 1247 1248 strclass.AppendSpaceLine(3, "strSql.Append(\")AS Row, T.* from " + TableName + " T \");"); 1249 strclass.AppendSpaceLine(3, "if (!string.IsNullOrEmpty(strWhere.Trim()))"); 1250 strclass.AppendSpaceLine(3, "{"); 1251 strclass.AppendSpaceLine(4, "strSql.Append(\" WHERE \" + strWhere);"); 1252 strclass.AppendSpaceLine(3, "}"); 1253 1254 strclass.AppendSpaceLine(3, "strSql.Append(\" ) TT\");"); 1255 strclass.AppendSpaceLine(3, "strSql.AppendFormat(\" WHERE TT.Row between {0} and {1}\", startIndex, endIndex);"); 1256 1257 strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());"); 1258 strclass.AppendSpaceLine(2, "}"); 1259 1260 return strclass.Value; 1261 } 1262 1263 1264 1265 /// <summary> 1266 /// 得到GetList()的代码 1267 /// </summary> 1268 /// <param name="_tablename"></param> 1269 /// <param name="_key"></param> 1270 /// <returns></returns> 1271 public string CreatGetListByPageProc() 1272 { 1273 StringPlus strclass = new StringPlus(); 1274 strclass.AppendSpaceLine(2, "/*"); 1275 strclass.AppendSpaceLine(2, "/// <summary>"); 1276 strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList3"].ToString()); 1277 strclass.AppendSpaceLine(2, "/// </summary>"); 1278 strclass.AppendSpaceLine(2, "public DataSet GetList(int PageSize,int PageIndex,string strWhere)"); 1279 strclass.AppendSpaceLine(2, "{"); 1280 strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); 1281 strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "tblName\", " + DbParaDbType + ".VarChar, 255),"); 1282 strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "fldName\", " + DbParaDbType + ".VarChar, 255),"); 1283 strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "PageSize\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "int") + "),"); 1284 strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "PageIndex\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "int") + "),"); 1285 strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "IsReCount\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "bit") + "),"); 1286 strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "OrderType\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "bit") + "),"); 1287 strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "strWhere\", " + DbParaDbType + ".VarChar,1000),"); 1288 strclass.AppendSpaceLine(5, "};"); 1289 strclass.AppendSpaceLine(3, "parameters[0].Value = \"" + TableName + "\";"); 1290 strclass.AppendSpaceLine(3, "parameters[1].Value = \"" + _key + "\";"); 1291 strclass.AppendSpaceLine(3, "parameters[2].Value = PageSize;"); 1292 strclass.AppendSpaceLine(3, "parameters[3].Value = PageIndex;"); 1293 strclass.AppendSpaceLine(3, "parameters[4].Value = 0;"); 1294 strclass.AppendSpaceLine(3, "parameters[5].Value = 0;"); 1295 strclass.AppendSpaceLine(3, "parameters[6].Value = strWhere; "); 1296 strclass.AppendSpaceLine(3, "return " + DbHelperName + ".RunProcedure(\"UP_GetRecordByPage\",parameters,\"ds\");"); 1297 strclass.AppendSpaceLine(2, "}*/"); 1298 return strclass.Value; 1299 } 1300 1301 #endregion//数据层 1302 1303 1304 1305 } 1306 }
上面的几个DLL是没有给出源代码的
通过反编译看到codehelper中的某个类混淆了