/// <summary> /// 得到整个类的代码 /// </summary> public string GetBLLCodeStr() { StringPlus strclass = new StringPlus(); strclass.AppendLine("using System;"); strclass.AppendLine("using System.Data;"); strclass.AppendLine("using System.Collections.Generic;"); strclass.AppendLine("using System.Text.RegularExpressions;"); strclass.AppendLine("using " + ModelSpace + ";"); strclass.AppendLine("using " + DALSpace + ";"); strclass.AppendLine("namespace " + BLLSpace + ""); strclass.AppendLine("{"); strclass.AppendSpaceLine(1, "/// <summary>"); strclass.AppendSpaceLine(1, "/// 业务逻辑类" + BLLName + " 的摘要说明。"); strclass.AppendSpaceLine(1, "/// </summary>"); strclass.AppendSpaceLine(1, "public class " + BLLName); strclass.AppendSpaceLine(1, "{"); strclass.AppendSpaceLine(2, "public " + BLLName + "()"); strclass.AppendSpaceLine(2, "{}"); strclass.AppendSpaceLine(2, "#region 成员方法"); #region 方法代码 strclass.AppendLine(CreatBLLGetVaule()); strclass.AppendLine(CreatBLLGetCounts()); strclass.AppendLine(CreatBLLADD()); strclass.AppendLine(CreatBLLUpdate()); strclass.AppendLine(CreatBLLDelete()); strclass.AppendLine(CreatBLLGetModel()); strclass.AppendLine(CreatBLLGetMaxID()); strclass.AppendLine(CreatBLLGetList()); strclass.AppendLine(CreatBLLBindForm()); #endregion strclass.AppendSpaceLine(2, "#endregion 成员方法"); strclass.AppendSpaceLine(1, "}"); strclass.AppendLine("}"); strclass.AppendLine(""); return(strclass.Value); }
public string CreatBLLUpdate() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 更新一条数据"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static void Update(" + ModelName + " model)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "" + DALName + ".Instance.Update(model);"); strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
/// <summary> /// 生成完整sModel类 /// </summary> public string CreatModelStr(List <ColumnInfo> fieldlist) { StringPlus strclass = new StringPlus(); strclass.AppendLine("using System;"); strclass.AppendLine("namespace " + _namespace); strclass.AppendLine("{"); strclass.AppendSpaceLine(1, "/// <summary>"); strclass.AppendSpaceLine(1, "/// 实体类" + _modelname + " 。(属性说明自动提取数据库字段的描述信息)"); strclass.AppendSpaceLine(1, "/// </summary>"); strclass.AppendSpaceLine(1, "[Serializable]"); strclass.AppendSpaceLine(1, "public class " + _modelname); strclass.AppendSpaceLine(1, "{"); strclass.AppendSpaceLine(2, "public " + _modelname + "()"); strclass.AppendSpaceLine(2, "{}"); strclass.AppendLine(CreatModelMethod(fieldlist)); strclass.AppendSpaceLine(1, "}"); strclass.AppendLine("}"); strclass.AppendLine(""); return(strclass.Value); }
public string CreatBLLGetVaule() { StringPlus strclass = new StringPlus(); strclass.AppendLine(""); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 返回单个字符串"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static string GetValue(string col,string where)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetValue(col,where);"); strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
public string CreatBLLADD() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 增加一条数据"); strclass.AppendSpaceLine(2, "/// </summary>"); string strretu = "int"; strclass.AppendSpaceLine(2, "public static " + strretu + " Add(" + ModelName + " model)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.Add(model);"); strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
public string CreatBLLGetList() { StringPlus strclass = new StringPlus(); //返回DataSet strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 获得数据列表"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static List<" + ModelName + "> GetList(string strWhere,string strFieldOrder)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetList(strWhere,strFieldOrder);"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "public static List<" + ModelName + "> GetList(SQLPara para)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetList(para);"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "public static List<" + ModelName + "> GetList(string strWhere, string strFieldOrder, int PageSize, int page)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetList(strWhere,strFieldOrder,PageSize,page);"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "public static List<" + ModelName + "> GetList(SQLPara para, int PageSize, int page)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetList(para,PageSize,page);"); strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
public string CreatBLLBindForm() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 绑定表单数据"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static " + ModelName + " BindForm(" + ModelName + " model)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, KeysNullTip); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.BindForm(model);"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 安全方式绑定表单数据"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static " + ModelName + " SafeBindForm(" + ModelName + " model)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, KeysNullTip); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.SafeBindForm(model);"); strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
public string CreatBLLGetModel() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 得到一个对象实体"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static " + ModelName + " GetModel(" + Key.CSTypeName + " " + Key.ColumnName + ")"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, KeysNullTip); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetModel(" + Key.ColumnName + ");"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 得到一个对象实体 by where条件"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static " + ModelName + " GetModel(string where)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, KeysNullTip); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetModel(where);"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "public static " + ModelName + " GetModel(SQLPara para)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, KeysNullTip); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetModel(para);"); strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
public string CreatBLLDelete() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 删除一条数据"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static void Delete(" + Key.CSTypeName + " " + Key.ColumnName + ")"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, KeysNullTip); strclass.AppendSpaceLine(3, "" + DALName + ".Instance.Delete(" + Key.ColumnName + ");"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 删除多条数据 by where条件"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static void Delete(string where)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, KeysNullTip); strclass.AppendSpaceLine(3, "" + DALName + ".Instance.Delete(where);"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 删除多条数据"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static void Delete(SQLPara para)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, KeysNullTip); strclass.AppendSpaceLine(3, "" + DALName + ".Instance.Delete(para);"); strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
public string CreatBLLGetMaxID() { StringPlus strclass = new StringPlus(); if (_keys.Count > 0) { string keyname = ""; foreach (ColumnInfo obj in _keys) { if (CodeCommon.DbTypeToCS(obj.TypeName) == "int") { keyname = obj.ColumnName; if (obj.IsPK) { strclass.AppendLine(""); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 得到最大ID"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static int GetMaxId()"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetMaxID(\"\");"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "public static int GetMaxId(SQLPara para)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetMaxID(para);"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "public static int GetMaxId(string strWhere)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.GetMaxID(strWhere);"); strclass.AppendSpaceLine(2, "}"); break; } } } } return(strclass.Value); }
public string CreatBLLGetCounts() { StringPlus strclass = new StringPlus(); strclass.AppendLine(""); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 返回记录条数"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public static int Counts(string where)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.Counts(where);"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "public static int Counts(SQLPara para)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "return " + DALName + ".Instance.Counts(para);"); strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
/// <summary> /// 生成实体类的属性 /// </summary> /// <returns></returns> public string CreatModelMethod(List <ColumnInfo> fieldlist) { StringPlus strclass = new StringPlus(); StringPlus strclass1 = new StringPlus(); StringPlus strclass2 = new StringPlus(); strclass.AppendSpaceLine(2, "#region Model"); foreach (ColumnInfo field in fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; bool IsIdentity = field.IsIdentity; bool ispk = field.IsPK; bool cisnull = field.cisNull; string deText = field.DeText; columnType = CodeCommon.DbTypeToCS(columnType); string isnull = ""; string devalue = ""; //if (CodeCommon.isValueType(columnType)) //{ // if ((!IsIdentity) && (!ispk) && (cisnull)) // { // isnull = "?";//代表可空类型 // } //} switch (columnType.ToLower()) { case "int": devalue = "0"; break; case "longint": devalue = "0"; break; case "string": devalue = "\"\""; break; case "datetime": devalue = "DateTime.Now"; break; case "bool": devalue = "false"; break; case "decimal": devalue = "0"; break; } strclass1.AppendSpaceLine(2, "private " + columnType + isnull + " _" + columnName.ToLower() + "=" + devalue + ";");//私有变量 strclass2.AppendSpaceLine(2, "/// <summary>"); strclass2.AppendSpaceLine(2, "/// " + deText); strclass2.AppendSpaceLine(2, "/// </summary>"); strclass2.AppendSpaceLine(2, "public " + columnType + isnull + " " + columnName);//属性 strclass2.AppendSpaceLine(2, "{"); strclass2.AppendSpaceLine(3, "set{" + " _" + columnName.ToLower() + "=value;}"); strclass2.AppendSpaceLine(3, "get{return " + "_" + columnName.ToLower() + ";}"); strclass2.AppendSpaceLine(2, "}"); } strclass.Append(strclass1.Value); strclass.Append(strclass2.Value); strclass.AppendSpaceLine(2, "#endregion Model"); return(strclass.Value); }