public string CreatPROCDelete() { StringPlus strclass = new StringPlus(); //strclass.Append("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].["); //strclass.Append("" + ProcPrefix + ""+_tablename+"_Delete"); //strclass.AppendLine("]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)"); //strclass.AppendLine("drop procedure [dbo].[" + ProcPrefix + ""+_tablename+"_Delete]"); //strclass.AppendLine("GO"); strclass.AppendLine("------------------------------------"); strclass.AppendLine("--用途:删除一条记录 "); strclass.AppendLine("--项目名称:" + ProjectName); strclass.AppendLine("--说明:"); strclass.AppendLine("--时间:" + DateTime.Now.ToString()); strclass.AppendLine("------------------------------------"); strclass.AppendLine("CREATE PROCEDURE " + ProcPrefix + "" + _tablename + "_Delete"); strclass.AppendLine(GetInParameter(Keys, false)); strclass.AppendLine(" AS "); strclass.AppendSpaceLine(1, "DELETE " + _tablename); strclass.AppendSpaceLine(1, " WHERE " + GetWhereExpression(Keys)); strclass.AppendLine(""); strclass.AppendLine("GO"); return(strclass.Value); }
/// <summary> /// 得到Delete的代码 /// </summary> /// <param name="_tablename"></param> /// <param name="_key"></param> /// <returns></returns> public string CreatDelete() { StringPlus strclass = new StringPlus(); strclass.AppendLine(""); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 删除一条数据"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public void Delete(" + LTP.CodeHelper.CodeCommon.GetInParameter(Keys) + ")"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); if (dbobj.DbType != "OleDb") { strclass.AppendSpaceLine(3, "strSql.Append(\"delete " + _tablename + " \");"); } else { strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablename + " \");"); } strclass.AppendSpaceLine(3, "strSql.Append(\" where " + LTP.CodeHelper.CodeCommon.GetWhereExpression(Keys) + "\" );"); strclass.AppendSpaceLine(3, DbHelperName + ".ExecuteSql(strSql.ToString());"); strclass.AppendSpace(2, "}"); return(strclass.ToString()); }
public string GetAddDesigner() { StringPlus stringPlus = new StringPlus(); stringPlus.AppendLine(); foreach (ColumnInfo current in this.Fieldlist) { string columnName = current.ColumnName; string typeName = current.TypeName; string arg_3B_0 = current.Description; bool arg_42_0 = current.IsPrimaryKey; if (!current.IsIdentity && !this.isFilterColume(columnName) && !("uniqueidentifier" == typeName.ToLower())) { string a; if ((a = CodeCommon.DbTypeToCS(typeName.Trim().ToLower()).ToLower()) != null) { if (a == "datetime" || a == "smalldatetime") { stringPlus.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.TextBox txt" + columnName + ";"); continue; } if (a == "bool") { stringPlus.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.CheckBox chk" + columnName + ";"); continue; } } stringPlus.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.TextBox txt" + columnName + ";"); } } stringPlus.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Button btnSave;"); stringPlus.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Button btnCancel;"); return(stringPlus.ToString()); }
/// <summary> /// 显示窗体的html代码 /// </summary> public string GetShowDesigner() { StringPlus strclass = new StringPlus(); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.DeText; if (deText.Trim() == "") { deText = columnName; } switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower()) { case "bool": strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.CheckBox chk" + columnName + ";"); break; default: strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Label lbl" + columnName + ";"); break; } } return(strclass.ToString()); }
public string CreatPROCGetList(DataTable dtColumn) { StringPlus strclass = new StringPlus(); StringPlus strclass1 = new StringPlus(); strclass.AppendLine("------------------------------------"); strclass.AppendLine("--用途:查询记录信息 "); strclass.AppendLine("--项目名称:" + ProjectName); strclass.AppendLine("--说明:"); strclass.AppendLine("--时间:" + DateTime.Now.ToString()); strclass.AppendLine("------------------------------------"); foreach (DataRow row in dtColumn.Rows) { string columnName = row["ColumnName"].ToString(); strclass1.Append("[" + columnName + "],"); } strclass1.DelLastComma(); strclass.AppendLine("CREATE PROCEDURE " + ProcPrefix + "" + _tablename + "_GetList"); strclass.AppendLine(" AS "); strclass.AppendSpaceLine(1, "SELECT "); strclass.AppendSpaceLine(1, strclass1.Value); strclass.AppendSpaceLine(1, " FROM " + _tablename); //strclass.AppendSpaceLine(1," WHERE "); strclass.AppendLine(""); strclass.AppendLine("GO"); return(strclass.Value); }
/// <summary> /// 得到Add()的代码 /// </summary> /// <param name="ExistsMaxId">是否有GetMaxId()生成主健</param> public string CreatAdd() { if (ModelSpace == "") { ModelSpace = "ModelClassName";; } StringPlus strclass = new StringPlus(); StringPlus strclass2 = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 增加一条数据"); strclass.AppendSpaceLine(2, "/// </summary>"); string strretu = "void"; if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005") && (IsHasIdentity)) { strretu = "int"; } //方法定义头 string strFun = CodeCommon.Space(2) + "public " + strretu + " Add(" + ModelSpace + " model)"; strclass.AppendLine(strFun); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "int rowsAffected;"); strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); int nkey = 0; int n = 0; foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; bool IsIdentity = field.IsIdentity; string Length = field.Length; strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + columnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, columnType, Length) + "),"); if (field.IsIdentity) { nkey = n; strclass2.AppendSpaceLine(3, "parameters[" + n + "].Direction = ParameterDirection.Output;"); n++; continue; } strclass2.AppendSpaceLine(3, "parameters[" + n + "].Value = model." + columnName + ";"); n++; } strclass.DelLastComma(); strclass.AppendLine("};"); strclass.AppendLine(strclass2.Value); strclass.AppendSpaceLine(3, "" + DbHelperName + ".RunProcedure(\"" + ProcPrefix + _tablename + "_ADD" + "\",parameters,out rowsAffected);"); //重新定义方法头 if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005") && (IsHasIdentity)) { strclass.AppendSpaceLine(3, "return (" + _keyType + ")parameters[" + nkey + "].Value;"); } strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
/// <summary> /// 生成完整Model类 /// </summary> public string CreatModel() { StringPlus strclass = new StringPlus(); strclass.AppendLine("using System;"); strclass.AppendLine("namespace " + Modelpath); strclass.AppendLine("{"); strclass.AppendSpaceLine(1, "/// <summary>"); if (TableDescription.Length > 0) { strclass.AppendSpaceLine(1, "/// " + TableDescription.Replace("\r\n", "\r\n\t///")); } else { strclass.AppendSpaceLine(1, "/// " + _modelname + ":" + Languagelist["summary"].ToString()); } strclass.AppendSpaceLine(1, "/// </summary>"); strclass.AppendSpaceLine(1, "[Serializable]"); strclass.AppendSpaceLine(1, "public partial class " + _modelname); strclass.AppendSpaceLine(1, "{"); strclass.AppendSpaceLine(2, "public " + _modelname + "()"); strclass.AppendSpaceLine(2, "{}"); strclass.AppendLine(CreatModelMethod()); strclass.AppendSpaceLine(1, "}"); strclass.AppendLine("}"); strclass.AppendLine(""); return(strclass.ToString()); }
/// <summary> /// 得到Update()的代码 /// </summary> /// <param name="DbName"></param> /// <param name="_tablename"></param> /// <param name="_key"></param> /// <param name="ModelName"></param> /// <returns></returns> public string CreatUpdate() { //if (ModelSpace == "") //{ // ModelSpace = "ModelClassName"; ; //} StringPlus strclass = new StringPlus(); StringPlus strclass2 = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 更新一条数据"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public void Update(" + ModelSpace + " model)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "Database db = DatabaseFactory.CreateDatabase();"); strclass.AppendSpaceLine(3, "DbCommand dbCommand = db.GetStoredProcCommand(\"" + ProcPrefix + _tablename + "_Update\");"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string Length = field.Length; strclass.AppendSpaceLine(3, "db.AddInParameter(dbCommand, \"" + columnName + "\", DbType." + CSToProcType(columnType) + ", model." + columnName + ");"); } strclass.AppendSpaceLine(3, "db.ExecuteNonQuery(dbCommand);"); strclass.AppendSpaceLine(2, "}"); return(strclass.Value); }
/// <summary> /// 得到GetList()的代码 /// </summary> /// <param name="_tablename"></param> /// <param name="_key"></param> /// <returns></returns> public string CreatGetListByPageProc() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/*"); //strclass.AppendSpaceLine(2, "/// <summary>"); //strclass.AppendSpaceLine(2, "/// 分页获取数据列表"); //strclass.AppendSpaceLine(2, "/// </summary>"); //strclass.AppendSpaceLine(2, "public DataSet GetList(int PageSize,int PageIndex,string strWhere)"); //strclass.AppendSpaceLine(2, "{"); //strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "tblName\", " + DbParaDbType + ".VarChar, 255),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "fldName\", " + DbParaDbType + ".VarChar, 255),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "PageSize\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "int") + "),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "PageIndex\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "int") + "),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "IsReCount\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "bit") + "),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "OrderType\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "bit") + "),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "strWhere\", " + DbParaDbType + ".VarChar,1000),"); //strclass.AppendSpaceLine(5, "};"); //strclass.AppendSpaceLine(3, "parameters[0].Value = \"" + TableName + "\";"); //strclass.AppendSpaceLine(3, "parameters[1].Value = \"" + _key + "\";"); //strclass.AppendSpaceLine(3, "parameters[2].Value = PageSize;"); //strclass.AppendSpaceLine(3, "parameters[3].Value = PageIndex;"); //strclass.AppendSpaceLine(3, "parameters[4].Value = 0;"); //strclass.AppendSpaceLine(3, "parameters[5].Value = 0;"); //strclass.AppendSpaceLine(3, "parameters[6].Value = strWhere; "); //strclass.AppendSpaceLine(3, "return " + DbHelperName + ".RunProcedure(\"UP_GetRecordByPage\",parameters,\"ds\");"); //strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "*/"); return(strclass.Value); }
public string CreatPROCGetList() { StringPlus strclass = new StringPlus(); //strclass.Append("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].["); //strclass.Append("" + ProcPrefix + ""+_tablename+"_GetList"); //strclass.AppendLine("]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)"); //strclass.AppendLine("drop procedure [dbo].[" + ProcPrefix + ""+_tablename+"_GetList]"); //strclass.AppendLine("GO"); strclass.AppendLine("------------------------------------"); strclass.AppendLine("--用途:查询记录信息 "); strclass.AppendLine("--项目名称:" + ProjectName); strclass.AppendLine("--说明:"); strclass.AppendLine("--时间:" + DateTime.Now.ToString()); strclass.AppendLine("------------------------------------"); strclass.AppendLine("CREATE PROCEDURE " + ProcPrefix + "" + _tablename + "_GetList"); strclass.AppendLine(" AS "); strclass.AppendSpaceLine(1, "SELECT "); strclass.AppendSpaceLine(1, Fieldstrlist); strclass.AppendSpaceLine(1, " FROM " + _tablename); //strclass.AppendSpaceLine(1," WHERE "); strclass.AppendLine(""); strclass.AppendLine("GO"); return(strclass.Value); }
public string CreatPROCUpdate() { StringPlus strclass = new StringPlus(); StringPlus strclass1 = new StringPlus(); strclass.AppendLine("------------------------------------"); strclass.AppendLine("--用途:修改一条记录 "); strclass.AppendLine("--项目名称:" + ProjectName); strclass.AppendLine("--说明:"); strclass.AppendLine("--时间:" + DateTime.Now.ToString()); strclass.AppendLine("------------------------------------"); strclass.AppendLine("CREATE PROCEDURE " + ProcPrefix + "" + _tablename + "_Update"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; bool IsIdentity = field.IsIdentity; bool IsPK = field.IsPK; string Length = field.Length; string Preci = field.Preci; string Scale = field.Scale; switch (columnType.ToLower()) { case "decimal": case "numeric": strclass.AppendLine("" + columnName + "_in " + columnType + "(" + Preci + "," + Scale + "),"); break; case "varchar": case "nvarchar": case "char": case "nchar": strclass.AppendLine("" + columnName + "_in " + columnType + "(" + Length + "),"); break; default: strclass.AppendLine("" + columnName + "_in " + columnType + ","); break; } if (IsKeys(columnName)) { continue; } strclass1.Append("" + columnName + " = " + columnName + "_in ,"); } strclass.DelLastComma(); strclass1.DelLastComma(); strclass.AppendLine(""); strclass.AppendLine(" AS "); strclass.AppendLine("BEGIN"); strclass.AppendSpaceLine(1, "UPDATE " + _tablename + " SET "); strclass.AppendSpaceLine(1, strclass1.Value); strclass.AppendSpaceLine(1, "WHERE " + GetWhereExpression(Keys)); strclass.AppendLine(""); strclass.AppendLine("COMMIT;"); strclass.AppendLine("END;"); return(strclass.Value); }
public string GetQueryModelList() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 直接执行 SQL 查询 (LINQ to SQL)"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "IEnumerable<" + ModelSpace + "> GetQueryModelList(string strWhere);"); return(strclass.Value); }
/// <summary> /// 获得linq 表查询 /// </summary> /// <returns></returns> public string GetTableModelList() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "///查询表对象的集合"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "Table<" + ModelSpace + "> GetTableModelList();"); return(strclass.Value); }
public string CreatGetMaxID2() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 根据条件得到最大ID"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendLine(" object GetMaxId(string fieldName, string strWhere);"); return(strclass.ToString()); }
public string CreatUpdate() { StringPlus stringPlus = new StringPlus(); stringPlus.AppendSpaceLine(2, "/// <summary>"); stringPlus.AppendSpaceLine(2, "/// 更新一条数据"); stringPlus.AppendSpaceLine(2, "/// </summary>"); stringPlus.AppendSpaceLine(2, "bool Update(" + this.ModelSpace + " model);"); return(stringPlus.ToString()); }
/// <summary> /// 生成完整Model类 /// </summary> public string CreatModelMethodT() { StringPlus strclass = new StringPlus(); strclass.AppendLine(CreatModelMethod()); strclass.AppendSpaceLine(2, "private List<" + ModelNameSon + "> _" + ModelNameSon.ToLower() + "s;");//私有变量 strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 【Model】: 子类 "); strclass.AppendSpaceLine(2, "/// </summary>"); //strclass.AppendSpaceLine(2, "[Serializable]"); strclass.AppendSpaceLine(2, "public List<" + ModelNameSon + "> " + ModelNameSon + "s");//属性 strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "set{" + " _" + ModelNameSon.ToLower() + "s=value;}"); strclass.AppendSpaceLine(3, "get{return " + "_" + ModelNameSon.ToLower() + "s;}"); strclass.AppendSpaceLine(2, "}"); if (Modelpath.Contains("Maticsoft"))//如果为默认命名空间直接返回 { return(strclass.ToString()); } else//否则直接替换原始命名空间 { return(strclass.ToString().Replace("Maticsoft", Modelpath.Split('.')[0])); } }
public string CreatModelMethodT() { StringPlus stringPlus = new StringPlus(); stringPlus.AppendLine(base.CreatModelMethod()); stringPlus.AppendSpaceLine(2, string.Concat(new string[] { "private List<", this.ModelNameSon, "> _", this.ModelNameSon.ToLower(), "s;" })); stringPlus.AppendSpaceLine(2, "/// <summary>"); stringPlus.AppendSpaceLine(2, "/// 子类 "); stringPlus.AppendSpaceLine(2, "/// </summary>"); stringPlus.AppendSpaceLine(2, string.Concat(new string[] { "public List<", this.ModelNameSon, "> ", this.ModelNameSon, "s" })); stringPlus.AppendSpaceLine(2, "{"); stringPlus.AppendSpaceLine(3, "set{ _" + this.ModelNameSon.ToLower() + "s=value;}"); stringPlus.AppendSpaceLine(3, "get{return _" + this.ModelNameSon.ToLower() + "s;}"); stringPlus.AppendSpaceLine(2, "}"); return(stringPlus.ToString()); }
public string CreatUpdate2() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 更新一条数据"); strclass.AppendSpaceLine(2, "/// " + "注意:参数要使用防SQL注入过滤"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "bool Update(string strWhere,string[] fields,object[] values);"); return(strclass.ToString()); }
public string CreatGetModel2() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 得到一个对象实体"); strclass.AppendSpaceLine(2, "/// " + "注意:参数要使用防SQL注入过滤"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, ModelSpace + " GetModelWhere(string strWhere);"); return(strclass.ToString()); }
public string CreatPROCUpdate(DataTable dtColumn) { StringPlus strclass = new StringPlus(); StringPlus strclass1 = new StringPlus(); strclass.AppendLine("------------------------------------"); strclass.AppendLine("--用途:修改一条记录 "); strclass.AppendLine("--项目名称:" + ProjectName); strclass.AppendLine("--说明:"); strclass.AppendLine("--时间:" + DateTime.Now.ToString()); strclass.AppendLine("------------------------------------"); strclass.AppendLine("CREATE PROCEDURE " + ProcPrefix + "" + _tablename + "_Update"); foreach (DataRow row in dtColumn.Rows) { string columnName = row["ColumnName"].ToString(); string columnType = row["TypeName"].ToString(); string Length = row["Length"].ToString(); string Preci = row["Preci"].ToString(); string Scale = row["Scale"].ToString(); switch (columnType.ToLower()) { case "decimal": case "numeric": strclass.AppendLine("@" + columnName + " " + columnType + "(" + Preci + "," + Scale + "),"); break; case "varchar": case "nvarchar": case "char": case "nchar": strclass.AppendLine("@" + columnName + " " + columnType + "(" + Length + "),"); break; default: strclass.AppendLine("@" + columnName + " " + columnType + ","); break; } if (ID == columnName) { continue; } strclass1.Append("[" + columnName + "] = @" + columnName + ","); } strclass.DelLastComma(); strclass1.DelLastComma(); strclass.AppendLine(""); strclass.AppendLine(" AS "); strclass.AppendSpaceLine(1, "UPDATE " + _tablename + " SET "); strclass.AppendSpaceLine(1, strclass1.Value); strclass.AppendSpaceLine(1, "WHERE [" + ID + "] = @" + ID); strclass.AppendLine(""); strclass.AppendLine("GO"); return(strclass.Value); }
public string CreatGetModel() { StringPlus stringPlus = new StringPlus(); stringPlus.AppendSpaceLine(2, "/// <summary>"); stringPlus.AppendSpaceLine(2, "/// 得到一个对象实体"); stringPlus.AppendSpaceLine(2, "/// </summary>"); stringPlus.AppendSpaceLine(2, this.ModelSpace + " GetModel(" + CodeCommon.GetInParameter(this.Keys, true) + ");"); stringPlus.AppendSpaceLine(2, this.ModelSpace + " DataRowToModel(DataRow row);"); return(stringPlus.ToString()); }
public string CreatGetModel() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 得到一个对象实体"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, ModelSpace + " GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ");"); strclass.AppendSpaceLine(2, ModelSpace + " DataRowToModel(DataRow row);"); return(strclass.ToString()); }
public string CreatDelete2() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 删除一条数据"); strclass.AppendSpaceLine(2, "/// " + "注意:参数要使用防SQL注入过滤"); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "bool DeleteWhere(string strWhere);"); return(strclass.ToString()); }
/// <summary> /// 生成完整单个Model类 /// </summary> public string CreatModel() { if (_modelname == "") { _modelname = TableName; } StringPlus strclass = new StringPlus(); StringPlus strclass1 = new StringPlus(); StringPlus strclass2 = new StringPlus(); strclass.AppendLine("using System;"); strclass.AppendLine("namespace " + Modelpath); strclass.AppendLine("{"); strclass.AppendSpaceLine(1, "/// <summary>"); strclass.AppendSpaceLine(1, "/// 实体类" + _modelname + " 。(属性说明自动提取数据库字段的描述信息)"); strclass.AppendSpaceLine(1, "/// </summary>"); strclass.AppendSpaceLine(1, "public class " + _modelname); strclass.AppendSpaceLine(1, "{"); strclass.AppendSpaceLine(2, "public " + _modelname + "()"); strclass.AppendSpaceLine(2, "{}"); strclass.AppendLine(CreatModelMethod()); strclass.AppendSpaceLine(1, "}"); strclass.AppendLine("}"); strclass.AppendLine(""); return(strclass.ToString()); }
public string CreatBLLADD() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// 增加一条数据"); strclass.AppendSpaceLine(2, "/// </summary>"); string strretu = "void"; if ((DbType == "SQL2000" || DbType == "SQL2005") && (IsHasIdentity)) { strretu = "int "; } strclass.AppendSpaceLine(2, "public " + strretu + " Add(" + ModelSpace + " model)"); strclass.AppendSpaceLine(2, "{"); if (strretu == "void") { strclass.AppendSpaceLine(3, "dal.Add(model);"); } else { strclass.AppendSpaceLine(3, "return dal.Add(model);"); } strclass.AppendSpaceLine(2, "}"); return(strclass.ToString()); }
public string GetIDALCode(bool Maxid, bool Exists, bool Add, bool Update, bool Delete, bool GetModel, bool List) { StringPlus strclass = new StringPlus(); strclass.AppendLine("using System;"); strclass.AppendLine("using System.Data;"); strclass.AppendLine("namespace " + IDALpath); strclass.AppendLine("{"); strclass.AppendSpaceLine(1, "/// <summary>"); strclass.AppendSpaceLine(1, "/// 接口层" + TableDescription); strclass.AppendSpaceLine(1, "/// </summary>"); strclass.AppendSpaceLine(1, "public interface " + IClass); strclass.AppendSpaceLine(1, "{"); strclass.AppendSpaceLine(2, "#region 成员方法"); if (Maxid) { strclass.Append(CreatGetMaxID()); } if (Exists) { strclass.Append(CreatExists()); } if (Add) { strclass.Append(CreatAdd()); } if (Update) { strclass.Append(CreatUpdate()); } if (Delete) { strclass.Append(CreatDelete()); } if (GetModel) { strclass.Append(CreatGetModel()); } if (List) { strclass.Append(CreatGetList()); } strclass.AppendSpaceLine(2, "#endregion 成员方法"); strclass.AppendSpaceLine(2, "#region MethodEx"); strclass.AppendLine(""); strclass.AppendSpaceLine(2, "#endregion MethodEx"); strclass.AppendLine(" } "); strclass.AppendLine("}"); return(strclass.ToString()); }
public string CreatBLLADD() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryadd"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); string strretu = "bool"; if ((DbType == "SQL2000" || DbType == "SQL2005" || DbType == "SQL2008" || DbType == "SQL2012" || DbType == "SQLite") && (IsHasIdentity)) { strretu = "int "; if (_keyType != "int") { strretu = _keyType; } } strclass.AppendSpaceLine(2, "public " + strretu + " Add(" + ModelSpace + " model)"); strclass.AppendSpaceLine(2, "{"); if (strretu == "void") { strclass.AppendSpaceLine(3, "dal.Add(model);"); } else { strclass.AppendSpaceLine(3, "return dal.Add(model);"); } strclass.AppendSpaceLine(2, "}"); return(strclass.ToString()); }
/// <summary> /// 删除页面 /// </summary> /// <returns></returns> public string CreatDeleteForm() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(1, "if(!Page.IsPostBack)"); strclass.AppendSpaceLine(1, "{"); strclass.AppendSpaceLine(2, BLLSpace + " bll=new " + BLLSpace + "();"); switch (_keyType.Trim()) { case "int": case "smallint": case "float": case "numeric": case "decimal": case "datetime": case "smalldatetime": strclass.AppendSpaceLine(2, _keyType + " " + _key + "=" + _keyType + ".Parse(Request.Params[\"id\"]);"); break; default: strclass.AppendSpaceLine(2, "string " + _key + "=Request.Params[\"id\"];"); break; } strclass.AppendSpaceLine(2, "bll.Delete(" + _key + ");"); strclass.AppendSpaceLine(2, "Response.Redirect(\"index.aspx\");"); strclass.AppendSpaceLine(1, "}"); return(strclass.Value); }
/// <summary> /// 得到表示层显示窗体的html代码 /// </summary> public string GetShowAspx() { StringPlus strclass = new StringPlus(); strclass.AppendLine(); strclass.AppendLine("<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.DeText; if (deText.Trim() == "") { deText = columnName; } strclass.AppendSpaceLine(1, "<tr>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">"); strclass.AppendSpaceLine(2, deText); strclass.AppendSpaceLine(1, ":</td>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">"); switch (columnType.Trim()) { case "bit": strclass.AppendSpaceLine(2, "<asp:CheckBox ID=\"chk" + columnName + "\" Text=\"" + deText + "\" runat=\"server\" Checked=\"False\" />"); break; default: strclass.AppendSpaceLine(2, "<asp:Label id=\"lbl" + columnName + "\" runat=\"server\"></asp:Label>"); break; } strclass.AppendSpaceLine(1, "</td></tr>"); } strclass.AppendLine("</table>"); return(strclass.ToString()); }
public string GetAddAspxCs() { if (this.ibw == null) { return("//请选择有效的表示层代码组件!"); } string addAspxCs = this.ibw.GetAddAspxCs(); StringPlus stringPlus = new StringPlus(); stringPlus.AppendSpaceLine(2, "protected void btnSave_Click(object sender, EventArgs e)"); stringPlus.AppendSpaceLine(2, "{"); stringPlus.AppendSpaceLine(3, addAspxCs); stringPlus.AppendSpaceLine(2, "}"); return(stringPlus.ToString()); }
/// <summary> /// ��������Model�� /// </summary> public string CreatModelMethodT() { StringPlus strclass = new StringPlus(); strclass.AppendLine(CreatModelMethod()); strclass.AppendSpaceLine(2, "private List<" + ModelNameSon + "> _" + ModelNameSon.ToLower() + "s;");//˽�б��� strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// ���� "); strclass.AppendSpaceLine(2, "/// </summary>"); //strclass.AppendSpaceLine(2, "[Serializable]"); strclass.AppendSpaceLine(2, "public List<" + ModelNameSon + "> " + ModelNameSon + "s");//���� strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "set{" + " _" + ModelNameSon.ToLower() + "s=value;}"); strclass.AppendSpaceLine(3, "get{return " + "_" + ModelNameSon.ToLower() + "s;}"); strclass.AppendSpaceLine(2, "}"); return strclass.ToString(); }
/// <summary> /// �õ���ʾ���б�����html���� /// </summary> public string GetListAspx() { StringPlus strclass = new StringPlus(); strclass.AppendLine(); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; bool ispk = field.IsPrimaryKey; bool IsIdentity = field.IsIdentity; deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName); if (IsIdentity) { continue; } if (isFilterColume(columnName)) { continue; } switch (columnType.Trim().ToLower()) { case "bit": case "dateTime": strclass.AppendSpaceLine(2, "<asp:BoundField DataField=\"" + columnName + "\" HeaderText=\"" + deText + "\" SortExpression=\"" + columnName + "\" ItemStyle-HorizontalAlign=\"Center\" /> "); break; default: strclass.AppendSpaceLine(2, "<asp:BoundField DataField=\"" + columnName + "\" HeaderText=\"" + deText + "\" SortExpression=\"" + columnName + "\" ItemStyle-HorizontalAlign=\"Center\" /> "); break; } } return strclass.ToString(); }
/// <summary> /// ɾ��ҳ�� /// </summary> /// <returns></returns> public string GetDeleteAspxCs() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(1, "if(!Page.IsPostBack)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, BLLSpace + " bll=new " + BLLSpace + "();"); switch (_keyType.Trim()) { case "int": case "long": case "smallint": case "float": case "numeric": case "decimal": case "datetime": case "smalldatetime": strclass.AppendSpaceLine(3, _keyType + " " + _key + "=" + _keyType + ".Parse(Request.Params[\"id\"]);"); break; default: strclass.AppendSpaceLine(3, "string " + _key + "=Request.Params[\"id\"];"); break; } strclass.AppendSpaceLine(3, "bll.Delete(" + _key + ");"); strclass.AppendSpaceLine(3, "Response.Redirect(\"list.aspx\");"); strclass.AppendSpaceLine(2, "}"); return strclass.Value; }
/// <summary> /// �õ�GetModel()�Ĵ��� /// </summary> /// <param name="DbName"></param> /// <param name="_tablename"></param> /// <param name="_key"></param> /// <param name="ModelName"></param> /// <returns></returns> public string CreatGetModel() { if (ModelSpace == "") { //ModelSpace = "ModelClassName"; ; } StringPlus strclass = new StringPlus(); strclass.AppendLine(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetModel"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public " + ModelSpace + " GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ")"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpace(3, "strSql.Append(\"select "); if (dbobj.DbType == "SQL2005" || dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012") { strclass.Append(" top 1 "); } strclass.AppendLine(" \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" " + Fieldstrlist + " \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" from " + _tablename + " \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" where " + Maticsoft.CodeHelper.CodeCommon.GetWhereExpression(Keys, true) + "\" );"); strclass.AppendSpaceLine(3, ModelSpace + " model=new " + ModelSpace + "();"); strclass.AppendSpaceLine(3, "DataSet ds=" + DbHelperName + ".Query(strSql.ToString());"); strclass.AppendSpaceLine(3, "if(ds.Tables[0].Rows.Count>0)"); strclass.AppendSpaceLine(3, "{"); #region /* foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"]!=null && ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); #region switch (CodeCommon.DbTypeToCS(columnType)) { case "int": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=int.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "long": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=long.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "decimal": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=decimal.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "float": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=float.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "DateTime": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=DateTime.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "string": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"]!=null)"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();"); //strclass.AppendSpaceLine(4, "}"); } break; case "bool": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "if((ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()==\"1\")||(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString().ToLower()==\"true\"))"); strclass.AppendSpaceLine(5, "{"); strclass.AppendSpaceLine(6, "model." + columnName + "=true;"); strclass.AppendSpaceLine(5, "}"); strclass.AppendSpaceLine(5, "else"); strclass.AppendSpaceLine(5, "{"); strclass.AppendSpaceLine(6, "model." + columnName + "=false;"); strclass.AppendSpaceLine(5, "}"); //strclass.AppendSpaceLine(4, "}"); } break; case "byte[]": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=(byte[])ds.Tables[0].Rows[0][\"" + columnName + "\"];"); //strclass.AppendSpaceLine(4, "}"); } break; case "uniqueidentifier": case "Guid": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=new Guid(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; default: strclass.AppendSpaceLine(5, "//model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();"); break; } #endregion strclass.AppendSpaceLine(4, "}"); } */ #endregion strclass.AppendSpaceLine(4, "return DataRowToModel(ds.Tables[0].Rows[0]);"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return null;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpace(2, "}"); return strclass.ToString(); }
/// <summary> /// �õ�GetList()�Ĵ��� /// </summary> public string CreatGetList() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public DataSet GetList(string strWhere)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpace(3, "strSql.Append(\"select "); strclass.AppendLine(Fieldstrlist + " \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableNameParent + " \");"); strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());"); strclass.AppendSpaceLine(2, "}"); if ((dbobj.DbType == "SQL2000") || (dbobj.DbType == "SQL2005") || (dbobj.DbType == "SQL2008") || (dbobj.DbType == "SQL2012")) { strclass.AppendLine(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList2"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public DataSet GetList(int Top,string strWhere,string filedOrder)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "strSql.Append(\"select \");"); strclass.AppendSpaceLine(3, "if(Top>0)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\" top \"+Top.ToString());"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "strSql.Append(\" " + Fieldstrlist + " \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableNameParent + " \");"); strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "strSql.Append(\" order by \" + filedOrder);"); strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());"); strclass.AppendSpaceLine(2, "}"); } return strclass.Value; }
/// <summary> /// �õ��Ĵ���Ĵ��� /// </summary> public string GetUpdateShowAspxCs() { StringPlus strclass = new StringPlus(); strclass.AppendLine(); string key = Key; strclass.AppendSpaceLine(1, "private void ShowInfo(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ")"); strclass.AppendSpaceLine(1, "{"); strclass.AppendSpaceLine(2, BLLSpace + " bll=new " + BLLSpace + "();"); strclass.AppendSpaceLine(2, ModelSpace + " model=bll.GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetFieldstrlist(Keys, true) + ");"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; bool ispk = field.IsPrimaryKey; bool IsIdentity = field.IsIdentity; if (isFilterColume(columnName)) { continue; } //���Զ���-�����ֶδ��� //if ((columnName.IndexOf("_cLang") > 0) && (columnType.Trim().ToLower() == "varchar")) //{ // strclass.AppendSpaceLine(2, "UCDroplistLanguage1.LanguageCode =model." + columnName + ";"); // continue; //} //if (columnName.IndexOf("_iAuthority") > 0) //{ // strclass.AppendSpaceLine(2, "UCDroplistPermission1.PermissionID =model." + columnName + ";"); // continue; //} //if (columnName.IndexOf("_cCurrency") > 0)//���Ҵ��� //{ // strclass.AppendSpaceLine(2, "UCDroplistCurrency1.CurrencyCode =model." + columnName + ";"); // continue; //} //if (columnName.IndexOf("_cCurrencyUnit") > 0)//���Ҵ��� //{ // strclass.AppendSpaceLine(2, "UCDroplistCurrencyUnit1.CurrencyUnitID =model." + columnName + ";"); // continue; //} switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower()) { case "int": case "long": case "smallint": case "float": case "numeric": case "decimal": case "datetime": case "smalldatetime": if ((ispk) || (IsIdentity)) { strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();"); } else { strclass.AppendSpaceLine(2, "this.txt" + columnName + ".Text=model." + columnName + ".ToString();"); } break; case "bool": strclass.AppendSpaceLine(2, "this.chk" + columnName + ".Checked=model." + columnName + ";"); break; case "byte[]": strclass.AppendSpaceLine(2, "this.txt" + columnName + ".Text=model." + columnName + ".ToString();"); break; case "guid": case "uniqueidentifier": strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();"); break; default: if ((ispk) || (IsIdentity)) { strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ";"); } else { strclass.AppendSpaceLine(2, "this.txt" + columnName + ".Text=model." + columnName + ";"); } break; } } strclass.AppendLine(); strclass.AppendSpaceLine(1, "}"); return strclass.Value; }
/// <summary> /// �õ��Ĵ���Ĵ��� /// </summary> public string GetUpdateAspxCs() { StringPlus strclass = new StringPlus(); StringPlus strclass0 = new StringPlus(); StringPlus strclass1 = new StringPlus(); StringPlus strclass2 = new StringPlus(); strclass.AppendLine(); strclass.AppendSpaceLine(3, "string strErr=\"\";"); //bool ishasuser = false; foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; bool ispk = field.IsPrimaryKey; bool IsIdentity = field.IsIdentity; //���Զ���-�����ֶδ��� //if ( // (columnName.IndexOf("_iCreator") > 0) || //ҳ�治��Ҫ��2�� // (columnName.IndexOf("_dateCreate") > 0) || // (columnName.IndexOf("_bValid") > 0) || // (columnName.IndexOf("_dateValid") > 0) || // (columnName.IndexOf("_dateExpire") > 0) // ) //{ // continue; //} //if ((!ishasuser) && (columnName.IndexOf("_iMaintainer") > 0)) //{ // strclass0.AppendSpaceLine(4, "User currentUser;"); // strclass0.AppendSpaceLine(3, "if (Session[\"UserInfo\"] != null)"); // strclass0.AppendSpaceLine(3, "{"); // strclass0.AppendSpaceLine(4, "currentUser = (User)Session[\"UserInfo\"];"); // strclass0.AppendSpaceLine(3, "}else{"); // strclass0.AppendSpaceLine(4, "return;"); // strclass0.AppendSpaceLine(3, "}"); // ishasuser = true; //} deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName); //���Զ���-�����ֶδ��� //if ((columnName.IndexOf("_cLang") > 0) && (columnType.Trim().ToLower() == "varchar"))//���Դ��� //{ // strclass2.AppendSpaceLine(3, "model." + columnName + "= UCDroplistLanguage1.LanguageCode;"); // continue; //} //if (columnName.IndexOf("_iAuthority") > 0)//Ȩ��ɫ���� //{ // strclass2.AppendSpaceLine(3, "model." + columnName + "= UCDroplistPermission1.PermissionID;"); // continue; //} //if (columnName.IndexOf("_cCurrency") > 0)//���Ҵ��� //{ // strclass2.AppendSpaceLine(3, "model." + columnName + "= UCDroplistCurrency1.CurrencyCode;"); // continue; //} //if (columnName.IndexOf("_cCurrencyUnit") > 0)//���Ҵ��� //{ // strclass2.AppendSpaceLine(3, "model." + columnName + "= UCDroplistCurrencyUnit1.CurrencyUnitID;"); // continue; //} switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower()) { case "int": case "smallint": if ((ispk) || (IsIdentity)) { strclass0.AppendSpaceLine(3, "int " + columnName + "=int.Parse(this.lbl" + columnName + ".Text);"); } else { strclass0.AppendSpaceLine(3, "int " + columnName + "=int.Parse(this.txt" + columnName + ".Text);"); strclass1.AppendSpaceLine(3, "if(!PageValidate.IsNumber(txt" + columnName + ".Text))"); strclass1.AppendSpaceLine(3, "{"); strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\"; "); strclass1.AppendSpaceLine(3, "}"); } break; case "long": if ((ispk) || (IsIdentity)) { strclass0.AppendSpaceLine(3, "long " + columnName + "=long.Parse(this.lbl" + columnName + ".Text);"); } else { strclass0.AppendSpaceLine(3, "long " + columnName + "=long.Parse(this.txt" + columnName + ".Text);"); strclass1.AppendSpaceLine(3, "if(!PageValidate.IsNumber(txt" + columnName + ".Text))"); strclass1.AppendSpaceLine(3, "{"); strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\"; "); strclass1.AppendSpaceLine(3, "}"); } break; case "float": case "numeric": case "decimal": if ((ispk) || (IsIdentity)) { strclass0.AppendSpaceLine(3, "decimal " + columnName + "=decimal.Parse(this.lbl" + columnName + ".Text);"); } else { strclass0.AppendSpaceLine(3, "decimal " + columnName + "=decimal.Parse(this.txt" + columnName + ".Text);"); strclass1.AppendSpaceLine(3, "if(!PageValidate.IsDecimal(txt" + columnName + ".Text))"); strclass1.AppendSpaceLine(3, "{"); strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\"; "); strclass1.AppendSpaceLine(3, "}"); } break; case "datetime": case "smalldatetime": strclass0.AppendSpaceLine(3, "DateTime " + columnName + "=DateTime.Parse(this.txt" + columnName + ".Text);"); strclass1.AppendSpaceLine(3, "if(!PageValidate.IsDateTime(txt" + columnName + ".Text))"); strclass1.AppendSpaceLine(3, "{"); strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\"; "); strclass1.AppendSpaceLine(3, "}"); break; case "bool": strclass0.AppendSpaceLine(3, "bool " + columnName + "=this.chk" + columnName + ".Checked;"); break; case "byte[]": strclass0.AppendSpaceLine(3, "byte[] " + columnName + "= new UnicodeEncoding().GetBytes(this.txt" + columnName + ".Text);"); break; case "guid": case "uniqueidentifier": strclass0.AppendSpaceLine(3, "Guid " + columnName + "= new Guid(this.lbl" + columnName + ".Text);"); break; default: if ((ispk) || (IsIdentity)) { strclass0.AppendSpaceLine(3, "string " + columnName + "=this.lbl" + columnName + ".Text;"); } else { strclass0.AppendSpaceLine(3, "string " + columnName + "=this.txt" + columnName + ".Text;"); strclass1.AppendSpaceLine(3, "if(this.txt" + columnName + ".Text.Trim().Length==0)"); strclass1.AppendSpaceLine(3, "{"); strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "����Ϊ�գ�\\\\n\"; "); strclass1.AppendSpaceLine(3, "}"); } break; } strclass2.AppendSpaceLine(3, "model." + columnName + "=" + columnName + ";"); } strclass.AppendLine(strclass1.ToString()); strclass.AppendSpaceLine(3, "if(strErr!=\"\")"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "MessageBox.Show(this,strErr);"); strclass.AppendSpaceLine(4, "return;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendLine(strclass0.ToString()); strclass.AppendLine(); strclass.AppendSpaceLine(3, ModelSpace + " model=new " + ModelSpace + "();"); strclass.AppendLine(strclass2.ToString()); strclass.AppendSpaceLine(3, BLLSpace + " bll=new " + BLLSpace + "();"); strclass.AppendSpaceLine(3, "bll.Update(model);"); strclass.AppendSpaceLine(3, "Maticsoft.Common.MessageBox.ShowAndRedirect(this,\"����ɹ���\",\"list.aspx\");"); return strclass.ToString(); }
/// <summary> /// ��ʾ�����html���� /// </summary> public string GetShowDesigner() { StringPlus strclass = new StringPlus(); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName); switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower()) { //case "bool": // strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.CheckBox chk" + columnName + ";"); // break; default: strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Label lbl" + columnName + ";"); break; } } return strclass.ToString(); }
/// <summary> /// �õ�GetList()�Ĵ��� /// </summary> /// <param name="_tablename"></param> /// <param name="_key"></param> /// <returns></returns> public string CreatGetListByPageProc() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/*"); //strclass.AppendSpaceLine(2, "/// <summary>"); //strclass.AppendSpaceLine(2, "/// "+Languagelist["summaryGetList3"].ToString()); //strclass.AppendSpaceLine(2, "/// </summary>"); //strclass.AppendSpaceLine(2, "public DataSet GetList(int PageSize,int PageIndex,string strWhere)"); //strclass.AppendSpaceLine(2, "{"); //strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "tblName\", " + DbParaDbType + ".VarChar, 255),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "fldName\", " + DbParaDbType + ".VarChar, 255),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "PageSize\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "int") + "),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "PageIndex\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "int") + "),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "IsReCount\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "bit") + "),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "OrderType\", " + DbParaDbType + "." + CodeCommon.CSToProcType(dbobj.DbType, "bit") + "),"); //strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "strWhere\", " + DbParaDbType + ".VarChar,1000),"); //strclass.AppendSpaceLine(5, "};"); //strclass.AppendSpaceLine(3, "parameters[0].Value = \"" + TableName + "\";"); //strclass.AppendSpaceLine(3, "parameters[1].Value = \"" + _key + "\";"); //strclass.AppendSpaceLine(3, "parameters[2].Value = PageSize;"); //strclass.AppendSpaceLine(3, "parameters[3].Value = PageIndex;"); //strclass.AppendSpaceLine(3, "parameters[4].Value = 0;"); //strclass.AppendSpaceLine(3, "parameters[5].Value = 0;"); //strclass.AppendSpaceLine(3, "parameters[6].Value = strWhere; "); //strclass.AppendSpaceLine(3, "return " + DbHelperName + ".RunProcedure(\"UP_GetRecordByPage\",parameters,\"ds\");"); //strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "*/"); return strclass.Value; }
/// <summary> /// �õ���ҳ�����Ĵ��� /// </summary> public string CreatGetListByPage() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["GetRecordCount"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public int GetRecordCount(string strWhere)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "strSql.Append(\"select count(1) FROM " + TableName + " \");"); strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "object obj = DbHelperSQL.GetSingle(strSql.ToString());"); strclass.AppendSpaceLine(3, "if (obj == null)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return 0;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return Convert.ToInt32(obj);"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(2, "}"); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList3"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "strSql.Append(\"SELECT * FROM ( \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" SELECT ROW_NUMBER() OVER (\");"); strclass.AppendSpaceLine(3, "if (!string.IsNullOrEmpty(orderby.Trim()))"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\"order by T.\" + orderby );"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\"order by T." + _IdentityKey + " desc\");"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "strSql.Append(\")AS Row, T.* from " + TableName + " T \");"); strclass.AppendSpaceLine(3, "if (!string.IsNullOrEmpty(strWhere.Trim()))"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\" WHERE \" + strWhere);"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "strSql.Append(\" ) TT\");"); strclass.AppendSpaceLine(3, "strSql.AppendFormat(\" WHERE TT.Row between {0} and {1}\", startIndex, endIndex);"); strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());"); strclass.AppendSpaceLine(2, "}"); return strclass.Value; }
/// <summary> /// �õ�Exists�����Ĵ��� /// </summary> /// <param name="_tablename"></param> /// <param name="ID"></param> /// <returns></returns> public string CreatExists() { StringPlus strclass = new StringPlus(); if (_keys.Count > 0) { string strInparam = Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, false); if (!string.IsNullOrEmpty(strInparam)) { strclass.AppendLine(""); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryExists"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public bool Exists(" + strInparam + ")"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "strSql.Append(\"select count(1) from " + _tablename + "\");"); strclass.AppendSpaceLine(3, "strSql.Append(\" where " + Maticsoft.CodeHelper.CodeCommon.GetWhereExpression(Keys, false) + "\");"); strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Exists(strSql.ToString());"); strclass.AppendSpace(2, "}"); } } return strclass.ToString(); }
/// <summary> /// �õ�Delete�Ĵ��� /// </summary> /// <param name="_tablename"></param> /// <param name="_key"></param> /// <returns></returns> public string CreatDelete() { StringPlus strclass = new StringPlus(); strclass.AppendLine(""); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDelete"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public bool Delete(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ")"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); //if (dbobj.DbType != "OleDb") //{ // strclass.AppendSpaceLine(3, "strSql.Append(\"delete " + _tablename + " \");" ); //} //else //{ strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablename + " \");"); //} strclass.AppendSpaceLine(3, "strSql.Append(\" where " + Maticsoft.CodeHelper.CodeCommon.GetWhereExpression(Keys, true) + "\" );"); strclass.AppendSpaceLine(3, "int rowsAffected=" + DbHelperName + ".ExecuteSql(strSql.ToString());"); strclass.AppendSpaceLine(3, "if (rowsAffected > 0)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return true;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return false;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpace(2, "}"); #region �����������ȵ�ɾ��(���б�ʶ�ֶΣ����зDZ�ʶ�����ֶ�) if ((Maticsoft.CodeHelper.CodeCommon.HasNoIdentityKey(Keys)) && (Maticsoft.CodeHelper.CodeCommon.GetIdentityKey(Keys) != null)) { strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDelete"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public bool Delete(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, false) + ")"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, KeysNullTip); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablename + " \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" where " + GetWhereExpression(Keys, false) + "\");"); strclass.AppendLine(GetPreParameter(Keys, false)); strclass.AppendSpaceLine(3, "int rows=" + DbHelperName + ".ExecuteSql(strSql.ToString(),parameters);"); strclass.AppendSpaceLine(3, "if (rows > 0)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return true;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return false;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(2, "}"); } #endregion #region ����ɾ������ string keyField = ""; if (Keys.Count == 1) { keyField = Keys[0].ColumnName; } else { foreach (ColumnInfo field in Keys) { if (field.IsIdentity) { keyField = field.ColumnName; break; } } } if (keyField.Trim().Length > 0) { strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDeletelist"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public bool DeleteList(string " + keyField + "list )"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablename + " \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" where " + keyField + " in (\"+" + keyField + "list + \") \");"); strclass.AppendSpaceLine(3, "int rows=" + DbHelperName + ".ExecuteSql(strSql.ToString());"); strclass.AppendSpaceLine(3, "if (rows > 0)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return true;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return false;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(2, "}"); } #endregion return strclass.ToString(); }
/// <summary> /// DataRowToModel�Ĵ��� /// </summary> public string CreatDataRowToModel() { if (ModelSpace == "") { //ModelSpace = "ModelClassName"; ; } StringPlus strclass = new StringPlus(); strclass.AppendLine(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetModel"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public " + ModelSpace + " DataRowToModel(DataRow row)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "" + ModelSpace + " model=new " + ModelSpace + "();"); strclass.AppendSpaceLine(3, "if (row != null)"); strclass.AppendSpaceLine(3, "{"); #region �ֶθ�ֵ foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; //strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); #region switch (CodeCommon.DbTypeToCS(columnType)) { case "int": { strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=int.Parse(row[\"" + columnName + "\"].ToString());"); strclass.AppendSpaceLine(4, "}"); } break; case "long": { strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=long.Parse(row[\"" + columnName + "\"].ToString());"); strclass.AppendSpaceLine(4, "}"); } break; case "decimal": { strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=decimal.Parse(row[\"" + columnName + "\"].ToString());"); strclass.AppendSpaceLine(4, "}"); } break; case "float": { strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=float.Parse(row[\"" + columnName + "\"].ToString());"); strclass.AppendSpaceLine(4, "}"); } break; case "DateTime": { strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=DateTime.Parse(row[\"" + columnName + "\"].ToString());"); strclass.AppendSpaceLine(4, "}"); } break; case "string": { strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null)"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=row[\"" + columnName + "\"].ToString();"); strclass.AppendSpaceLine(4, "}"); } break; case "bool": { strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "if((row[\"" + columnName + "\"].ToString()==\"1\")||(row[\"" + columnName + "\"].ToString().ToLower()==\"true\"))"); strclass.AppendSpaceLine(5, "{"); strclass.AppendSpaceLine(6, "model." + columnName + "=true;"); strclass.AppendSpaceLine(5, "}"); strclass.AppendSpaceLine(5, "else"); strclass.AppendSpaceLine(5, "{"); strclass.AppendSpaceLine(6, "model." + columnName + "=false;"); strclass.AppendSpaceLine(5, "}"); strclass.AppendSpaceLine(4, "}"); } break; case "byte[]": { strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=(byte[])row[\"" + columnName + "\"];"); strclass.AppendSpaceLine(4, "}"); } break; case "uniqueidentifier": case "Guid": { strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "= new Guid(row[\"" + columnName + "\"].ToString());"); strclass.AppendSpaceLine(4, "}"); } break; default: strclass.AppendSpaceLine(5, "//model." + columnName + "=row[\"" + columnName + "\"].ToString();"); break; } #endregion //strclass.AppendSpaceLine(4, "}"); } #endregion strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "return model;"); strclass.AppendSpaceLine(2, "}"); return strclass.ToString(); }
/// <summary> /// �õ���ʾ����ʾ�����html���� /// </summary> public string GetShowAspx() { StringPlus strclass = new StringPlus(); strclass.AppendLine(); strclass.AppendLine("<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName); strclass.AppendSpaceLine(1, "<tr>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">"); strclass.AppendSpaceLine(2, deText); strclass.AppendSpaceLine(1, "��</td>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">"); switch (columnType.Trim().ToLower()) { //case "bit": // strclass.AppendSpaceLine(2, "<asp:CheckBox ID=\"chk" + columnName + "\" Text=\"" + deText + "\" runat=\"server\" Checked=\"False\" />" ); // break; default: strclass.AppendSpaceLine(2, "<asp:Label id=\"lbl" + columnName + "\" runat=\"server\"></asp:Label>"); break; } strclass.AppendSpaceLine(1, "</td></tr>"); } strclass.AppendLine("</table>"); return strclass.ToString(); }
/// <summary> /// �õ���ʾ����ʾ����Ĵ��� /// </summary> public string GetShowAspxCs() { StringPlus strclass = new StringPlus(); strclass.AppendLine(); string key = Key; strclass.AppendSpaceLine(1, "private void ShowInfo(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ")"); strclass.AppendSpaceLine(1, "{"); strclass.AppendSpaceLine(2, BLLSpace + " bll=new " + BLLSpace + "();"); strclass.AppendSpaceLine(2, ModelSpace + " model=bll.GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetFieldstrlist(Keys, true) + ");"); //bool ishasuser = false; foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; bool ispk = field.IsPrimaryKey; bool IsIdentity = field.IsIdentity; //if ((ispk) || (IsIdentity)) //{ // continue; //} #region �����ֶδ��� //���Զ���-�����ֶδ��� //if (columnName.IndexOf("_iAuthority") > 0) //{ // continue; //} //if ((columnName.IndexOf("_cLang") > 0) && (columnType.Trim().ToLower() == "varchar"))//���Դ��� //{ // strclass.AppendSpaceLine(2, "BLL.SysManage.MultiLanguage bllML = new BLL.SysManage.MultiLanguage();"); // strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text= bllML.GetLanguageNameByCache(model." + columnName + ");"); // continue; //} //if ((!ishasuser) && ((columnName.IndexOf("_iCreator") > 0) || (columnName.IndexOf("_iMaintainer") > 0))) //{ // strclass.AppendSpaceLine(2, "Maticsoft.Accounts.Bus.User user = new Maticsoft.Accounts.Bus.User();"); // ishasuser = true; //} //if ((columnName.IndexOf("_iCreator") > 0) || (columnName.IndexOf("_iMaintainer") > 0)) //{ // strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text= user.GetTrueNameByCache(model." + columnName + ");"); // ishasuser = true; // continue; //} #endregion switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower()) { case "int": case "long": case "smallint": case "float": case "numeric": case "decimal": case "datetime": case "smalldatetime": strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();"); break; case "bool": strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + "?\"��\":\"��\";"); break; case "byte[]": strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();"); break; case "guid": case "uniqueidentifier": strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();"); break; default: strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ";"); break; } } strclass.AppendLine(); strclass.AppendSpaceLine(1, "}"); return strclass.ToString(); }
/// <summary> /// �õ�ij�ֶ����ֵ�ķ�������(ֻ��������int�͵����������) /// </summary> /// <param name="TabName"></param> /// <param name="ID"></param> /// <returns></returns> public string CreatGetMaxID() { 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.IsPrimaryKey) { strclass.AppendLine(""); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetMaxId"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public int GetMaxId()"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(2, "return " + DbHelperName + ".GetMaxID(\"" + keyname + "\", \"" + _tablename + "\"); "); strclass.AppendSpaceLine(2, "}"); break; } } } } return strclass.ToString(); }
/// <summary> /// �õ���ʾ�����Ӵ����html���� /// </summary> public string GetUpdateAspx() { StringPlus strclass = new StringPlus(); strclass.AppendLine(""); strclass.AppendLine("<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">"); bool hasDate = false; foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; bool ispk = field.IsPrimaryKey; bool IsIdentity = field.IsIdentity; deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName); if (isFilterColume(columnName)) { continue; } if ((ispk) || (IsIdentity) || (columnType.Trim().ToLower() == "uniqueidentifier")) { strclass.AppendSpaceLine(1, "<tr>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">"); strclass.AppendSpaceLine(2, deText); strclass.AppendSpaceLine(1, "��</td>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">"); strclass.AppendSpaceLine(2, "<asp:label id=\"lbl" + columnName + "\" runat=\"server\"></asp:label>"); strclass.AppendSpaceLine(1, "</td></tr>"); } else { // strclass.AppendSpaceLine(1, "<tr>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">"); strclass.AppendSpaceLine(2, deText); strclass.AppendSpaceLine(1, "��</td>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">"); switch (columnType.Trim().ToLower()) { case "datetime": case "smalldatetime": //strclass.AppendSpaceLine(2, "<INPUT onselectstart=\"return false;\" onkeypress=\"return false\" id=\"txt" + columnName + "\" onfocus=\"setday(this)\""); //strclass.AppendSpaceLine(2, " readOnly type=\"text\" size=\"10\" name=\"Text1\" runat=\"server\">"); strclass.AppendSpaceLine(2, "<asp:TextBox ID=\"txt" + columnName + "\" runat=\"server\" Width=\"70px\" onfocus=\"setday(this)\"></asp:TextBox>"); hasDate = true; break; case "bit": strclass.AppendSpaceLine(2, "<asp:CheckBox ID=\"chk" + columnName + "\" Text=\"" + deText + "\" runat=\"server\" Checked=\"False\" />"); break; default: strclass.AppendSpaceLine(2, "<asp:TextBox id=\"txt" + columnName + "\" runat=\"server\" Width=\"200px\"></asp:TextBox>"); break; } strclass.AppendSpaceLine(1, "</td></tr>"); } } ////��ť //strclass.AppendSpaceLine(1, "<tr>"); //strclass.AppendSpaceLine(1, "<td height=\"25\" colspan=\"2\"><div align=\"center\">"); //strclass.AppendSpaceLine(2, "<asp:Button ID=\"btnSave\" runat=\"server\" Text=\"�� ���� ��\" OnClick=\"btnSave_Click\" ></asp:Button>"); ////strclass.AppendSpaceLine(2, "<asp:Button ID=\"btnCancel\" runat=\"server\" Text=\"�� ȡ�� ��\" OnClick=\"btnCancel_Click\" ></asp:Button>"); //strclass.AppendSpaceLine(1, "</div></td></tr>"); strclass.AppendLine("</table>"); if (hasDate) { strclass.AppendLine("<script src=\"/js/calendar1.js\" type=\"text/javascript\"></script>"); } return strclass.Value; }
private string BuilderModel() { StringPlus plus = new StringPlus(); StringPlus plus2 = new StringPlus(); StringPlus plus3 = new StringPlus(); plus.AppendSpaceLine(2, "#region Model"); foreach (ColumnInfo column in Columns) { plus2.AppendSpaceLine(2, "private " + column.TypeName + " _" + column.ColumnName + ";"); plus3.AppendSpaceLine(2, "/// <summary>"); plus3.AppendSpaceLine(2, "/// " + column.DeText); plus3.AppendSpaceLine(2, "/// </summary>"); plus3.AppendSpaceLine(2, "public " + column.TypeName + " " + column.ColumnName); plus3.AppendSpaceLine(2, "{"); plus3.AppendSpaceLine(3, "get{ return _" + column.ColumnName + "; }"); plus3.AppendSpaceLine(3, "set"); plus3.AppendSpaceLine(3, "{"); plus3.AppendSpaceLine(4, "this.OnPropertyValueChange(_." + column.ColumnName + ",_" + column.ColumnName + ",value);"); plus3.AppendSpaceLine(4, "this._" + column.ColumnName + "=value;"); plus3.AppendSpaceLine(3, "}"); plus3.AppendSpaceLine(2, "}"); } plus.Append(plus2.Value); plus.Append(plus3.Value); plus.AppendSpaceLine(2, "#endregion"); return plus.ToString(); }
/// <summary> /// �Ĵ����html���� /// </summary> public string GetUpdateDesigner() { StringPlus strclass = new StringPlus(); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; bool ispk = field.IsPrimaryKey; bool IsIdentity = field.IsIdentity; deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName); if (isFilterColume(columnName)) { continue; } if ((ispk) || (IsIdentity) || (columnType.Trim().ToLower() == "uniqueidentifier")) { strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Label lbl" + columnName + ";"); } else { switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower()) { case "datetime": case "smalldatetime": strclass.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.TextBox txt" + columnName + ";"); break; case "bool": strclass.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.CheckBox chk" + columnName + ";"); break; default: strclass.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.TextBox txt" + columnName + ";"); break; } } } //��ť strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Button btnSave;"); strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Button btnCancel;"); return strclass.Value; }
/// <summary> /// �õ���ʾ�����Ӵ����html���� /// </summary> public string GetAddAspx() { StringPlus strclass = new StringPlus(); strclass.AppendLine(); strclass.AppendLine("<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">"); bool hasDate = false; foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; bool ispk = field.IsPrimaryKey; bool IsIdentity = field.IsIdentity; if (IsIdentity) { continue; } if (isFilterColume(columnName)) { continue; } if (columnType.Trim().ToLower() == "uniqueidentifier") { continue; } deText = CodeHelper.CodeCommon.CutDescText(deText, 15, columnName); strclass.AppendSpaceLine(1, "<tr>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">"); strclass.AppendSpaceLine(2, deText); strclass.AppendSpaceLine(1, "��</td>"); strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">"); switch (columnType.Trim().ToLower()) { case "datetime": case "smalldatetime": strclass.AppendSpaceLine(2, "<asp:TextBox ID=\"txt" + columnName + "\" runat=\"server\" Width=\"70px\" onfocus=\"setday(this)\"></asp:TextBox>"); hasDate = true; break; case "bit": strclass.AppendSpaceLine(2, "<asp:CheckBox ID=\"chk" + columnName + "\" Text=\"" + deText + "\" runat=\"server\" Checked=\"False\" />"); break; case "uniqueidentifier": break; default: strclass.AppendSpaceLine(2, "<asp:TextBox id=\"txt" + columnName + "\" runat=\"server\" Width=\"200px\"></asp:TextBox>"); break; } strclass.AppendSpaceLine(1, "</td></tr>"); } strclass.AppendLine("</table>"); if (hasDate) { strclass.AppendLine("<script src=\"/js/calendar1.js\" type=\"text/javascript\"></script>"); } return strclass.ToString(); }
/// <summary> /// �õ�GetModel()�Ĵ��� /// </summary> public string CreatGetModel() { //if (ModelSpaceParent == "") //{ // ModelSpaceParent = "ModelClassName"; ; //} StringPlus strclass = new StringPlus(); strclass.AppendLine(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetModel"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public " + ModelSpaceParent + " GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(KeysParent, true) + ")"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "strSql.Append(\"select " + Fieldstrlist + " from " + _tablenameparent + " \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" where " + CodeCommon.GetWhereParameterExpression(KeysParent, true, dbobj.DbType) + "\");"); strclass.AppendLine(CodeCommon.GetPreParameter(KeysParent, true, dbobj.DbType)); strclass.AppendSpaceLine(3, "" + ModelSpaceParent + " model=new " + ModelSpaceParent + "();"); strclass.AppendSpaceLine(3, "DataSet ds=" + DbHelperName + ".Query(strSql.ToString(),parameters);"); strclass.AppendSpaceLine(3, "if(ds.Tables[0].Rows.Count>0)"); strclass.AppendSpaceLine(3, "{"); //�������� strclass.AppendSpaceLine(4, "#region ������Ϣ"); foreach (ColumnInfo field in FieldlistParent) { string columnName = field.ColumnName; string columnType = field.TypeName; strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"]!=null && ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(4, "{"); #region �ֶ����� switch (CodeCommon.DbTypeToCS(columnType)) { case "int": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=int.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "long": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=long.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "decimal": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=decimal.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "float": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=float.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "DateTime": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=DateTime.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; case "string": { strclass.AppendSpaceLine(5, "model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();"); } break; case "bool": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "if((ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()==\"1\")||(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString().ToLower()==\"true\"))"); strclass.AppendSpaceLine(5, "{"); strclass.AppendSpaceLine(6, "model." + columnName + "=true;"); strclass.AppendSpaceLine(5, "}"); strclass.AppendSpaceLine(5, "else"); strclass.AppendSpaceLine(5, "{"); strclass.AppendSpaceLine(6, "model." + columnName + "=false;"); strclass.AppendSpaceLine(5, "}"); //strclass.AppendSpaceLine(4, "}"); } break; case "byte[]": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=(byte[])ds.Tables[0].Rows[0][\"" + columnName + "\"];"); //strclass.AppendSpaceLine(4, "}"); } break; case "Guid": { //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model." + columnName + "=new Guid(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(4, "}"); } break; default: strclass.AppendSpaceLine(5, "//model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();"); break; } #endregion strclass.AppendSpaceLine(4, "}"); } strclass.AppendSpaceLine(4, "#endregion ������Ϣend"); strclass.AppendLine(); #region �ӱ����� strclass.AppendSpaceLine(4, "#region �ӱ���Ϣ"); strclass.AppendSpaceLine(4, "StringBuilder strSql2=new StringBuilder();"); strclass.AppendSpaceLine(4, "strSql2.Append(\"select " + FieldstrlistSon + " from " + _tablenameson + " \");"); strclass.AppendSpaceLine(4, "strSql2.Append(\" where " + CodeCommon.GetWhereParameterExpression(KeysSon, true, dbobj.DbType)+ "\");"); strclass.AppendLine(GetPreParameter(KeysParent, "2")); strclass.AppendSpaceLine(4, "DataSet ds2=" + DbHelperName + ".Query(strSql2.ToString(),parameters2);"); strclass.AppendSpaceLine(4, "if(ds2.Tables[0].Rows.Count>0)"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "#region �ӱ��ֶ���Ϣ"); strclass.AppendSpaceLine(5, "int i = ds2.Tables[0].Rows.Count;"); strclass.AppendSpaceLine(5, "List<" + ModelSpaceSon + "> models = new List<" + ModelSpaceSon + ">();"); strclass.AppendSpaceLine(5, ModelSpaceSon + " modelt;"); strclass.AppendSpaceLine(5, "for (int n = 0; n < i; n++)"); strclass.AppendSpaceLine(5, "{"); strclass.AppendSpaceLine(6, "modelt = new " + ModelSpaceSon + "();"); foreach (ColumnInfo field in FieldlistSon) { string columnName = field.ColumnName; string columnType = field.TypeName; strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"]!=null && ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")"); strclass.AppendSpaceLine(6, "{"); #region �ֶ����� switch (CodeCommon.DbTypeToCS(columnType)) { case "int": { //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(6, "{"); strclass.AppendSpaceLine(7, "modelt." + columnName + "=int.Parse(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(6, "}"); } break; case "decimal": { //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(6, "{"); strclass.AppendSpaceLine(7, "modelt." + columnName + "=decimal.Parse(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(6, "}"); } break; case "DateTime": { //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(6, "{"); strclass.AppendSpaceLine(7, "modelt." + columnName + "=DateTime.Parse(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(6, "}"); } break; case "string": { strclass.AppendSpaceLine(7, "modelt." + columnName + "=ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString();"); } break; case "bool": { //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(6, "{"); strclass.AppendSpaceLine(7, "if((ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()==\"1\")||(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString().ToLower()==\"true\"))"); strclass.AppendSpaceLine(7, "{"); strclass.AppendSpaceLine(8, "modelt." + columnName + "=true;"); strclass.AppendSpaceLine(7, "}"); strclass.AppendSpaceLine(7, "else"); strclass.AppendSpaceLine(7, "{"); strclass.AppendSpaceLine(8, "modelt." + columnName + "=false;"); strclass.AppendSpaceLine(7, "}"); //strclass.AppendSpaceLine(6, "}"); } break; case "byte[]": { //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(6, "{"); strclass.AppendSpaceLine(7, "modelt." + columnName + "=(byte[])ds2.Tables[0].Rows[n][\"" + columnName + "\"];"); //strclass.AppendSpaceLine(6, "}"); } break; case "Guid": { //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")"); //strclass.AppendSpaceLine(6, "{"); strclass.AppendSpaceLine(7, "modelt." + columnName + "=new Guid(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString());"); //strclass.AppendSpaceLine(6, "}"); } break; default: strclass.AppendSpaceLine(7, "modelt." + columnName + "=ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString();"); break; } #endregion strclass.AppendSpaceLine(6, "}"); } strclass.AppendSpaceLine(6, "models.Add(modelt);"); strclass.AppendSpaceLine(5, "}"); strclass.AppendSpaceLine(5, "model." + ModelNameSon + "s = models;"); strclass.AppendSpaceLine(5, "#endregion �ӱ��ֶ���Ϣend"); strclass.AppendSpaceLine(4, "}"); strclass.AppendSpaceLine(4, "#endregion �ӱ���Ϣend"); #endregion strclass.AppendLine(); strclass.AppendSpaceLine(4, "return model;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return null;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(2, "}"); return strclass.ToString(); }
/// <summary> /// �õ���ʾ�����Ӵ���Ĵ��� /// </summary> public string GetAddAspxCs() { StringPlus strclass = new StringPlus(); StringPlus strclass0 = new StringPlus(); StringPlus strclass1 = new StringPlus(); StringPlus strclass2 = new StringPlus(); strclass.AppendLine(); strclass.AppendSpaceLine(3, "string strErr=\"\";"); //bool ishasuser = false; foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.Description; bool ispk = field.IsPrimaryKey; bool IsIdentity = field.IsIdentity; if ((IsIdentity)) { continue; } if ("uniqueidentifier" == columnType.ToLower()) { continue; } //���Զ���-�����ֶδ��� //if ((!ishasuser) && ((columnName.IndexOf("_iCreator") > 0) || (columnName.IndexOf("_iMaintainer") > 0))) //{ // strclass0.AppendSpaceLine(3, "User currentUser;"); // strclass0.AppendSpaceLine(3, "if (Session[\"UserInfo\"] != null)"); // strclass0.AppendSpaceLine(3, "{"); // strclass0.AppendSpaceLine(4, "currentUser = (User)Session[\"UserInfo\"];"); // strclass0.AppendSpaceLine(3, "}else{"); // strclass0.AppendSpaceLine(4, "return;"); // strclass0.AppendSpaceLine(3, "}"); // ishasuser = true; //} deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName); switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower()) { case "int": case "smallint": strclass0.AppendSpaceLine(3, "int " + columnName + "=int.Parse(this.txt" + columnName + ".Text);"); strclass1.AppendSpaceLine(3, "if(!PageValidate.IsNumber(txt" + columnName + ".Text))"); strclass1.AppendSpaceLine(3, "{"); strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\"; "); strclass1.AppendSpaceLine(3, "}"); break; case "float": case "numeric": case "decimal": strclass0.AppendSpaceLine(3, "decimal " + columnName + "=decimal.Parse(this.txt" + columnName + ".Text);"); strclass1.AppendSpaceLine(3, "if(!PageValidate.IsDecimal(txt" + columnName + ".Text))"); strclass1.AppendSpaceLine(3, "{"); strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\"; "); strclass1.AppendSpaceLine(3, "}"); break; case "datetime": case "smalldatetime": strclass0.AppendSpaceLine(3, "DateTime " + columnName + "=DateTime.Parse(this.txt" + columnName + ".Text);"); strclass1.AppendSpaceLine(3, "if(!PageValidate.IsDateTime(txt" + columnName + ".Text))"); strclass1.AppendSpaceLine(3, "{"); strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\"; "); strclass1.AppendSpaceLine(3, "}"); break; case "bool": strclass0.AppendSpaceLine(3, "bool " + columnName + "=this.chk" + columnName + ".Checked;"); break; case "byte[]": strclass0.AppendSpaceLine(3, "byte[] " + columnName + "= new UnicodeEncoding().GetBytes(this.txt" + columnName + ".Text);"); break; case "guid": case "uniqueidentifier": break; default: strclass0.AppendSpaceLine(3, "string " + columnName + "=this.txt" + columnName + ".Text;"); strclass1.AppendSpaceLine(3, "if(this.txt" + columnName + ".Text.Trim().Length==0)"); strclass1.AppendSpaceLine(3, "{"); strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "����Ϊ�գ�\\\\n\"; "); strclass1.AppendSpaceLine(3, "}"); break; } strclass2.AppendSpaceLine(3, "model." + columnName + "=" + columnName + ";"); } strclass.AppendLine(strclass1.ToString()); strclass.AppendSpaceLine(3, "if(strErr!=\"\")"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "MessageBox.Show(this,strErr);"); strclass.AppendSpaceLine(4, "return;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendLine(strclass0.ToString()); strclass.AppendSpaceLine(3, ModelSpace + " model=new " + ModelSpace + "();"); strclass.AppendLine(strclass2.ToString()); strclass.AppendSpaceLine(3, BLLSpace + " bll=new " + BLLSpace + "();"); strclass.AppendSpaceLine(3, "bll.Add(model);"); strclass.AppendSpaceLine(3, NameSpace + ".Common.MessageBox.ShowAndRedirect(this,\"����ɹ���\",\"add.aspx\");"); return strclass.Value; }
/// <summary> /// �õ�GetList()�Ĵ��� /// </summary> /// <param name="_tablename"></param> /// <param name="_key"></param> /// <returns></returns> public string CreatGetList() { StringPlus strclass = new StringPlus(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public DataSet GetList(string strWhere)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpace(3, "strSql.Append(\"select "); strclass.AppendLine(Fieldstrlist + " \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableName + " \");"); strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());"); strclass.AppendSpaceLine(2, "}"); if ((dbobj.DbType == "SQL2000") || (dbobj.DbType == "SQL2005") || (dbobj.DbType == "SQL2008") || (dbobj.DbType == "SQL2012")) { strclass.AppendLine(); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList2"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public DataSet GetList(int Top,string strWhere,string filedOrder)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "strSql.Append(\"select \");"); strclass.AppendSpaceLine(3, "if(Top>0)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\" top \"+Top.ToString());"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "strSql.Append(\" " + Fieldstrlist + " \");"); strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableName + " \");"); strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "strSql.Append(\" order by \" + filedOrder);"); strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());"); strclass.AppendSpaceLine(2, "}"); } //����List<> strclass.AppendLine(); // ���峬 2015-10-13 strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public List<" + ModelSpace + "> GetModelList(string strWhere)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "DataSet ds = GetList(strWhere);"); strclass.AppendSpaceLine(3, "return DataTableToList(ds.Tables[0]);"); strclass.AppendSpaceLine(2, "}"); //����List<> strclass.AppendLine();// ���峬 2015-10-13 strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public List<" + ModelSpace + "> DataTableToList(DataTable dt)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "List<" + ModelSpace + "> modelList = new List<" + ModelSpace + ">();"); strclass.AppendSpaceLine(3, "int rowsCount = dt.Rows.Count;"); strclass.AppendSpaceLine(3, "if (rowsCount > 0)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, ModelSpace + " model;"); strclass.AppendSpaceLine(4, "for (int n = 0; n < rowsCount; n++)"); strclass.AppendSpaceLine(4, "{"); strclass.AppendSpaceLine(5, "model = DataRowToModel(dt.Rows[n]);"); strclass.AppendSpaceLine(5, "if (model != null)"); strclass.AppendSpaceLine(5, "{"); strclass.AppendSpaceLine(6, "modelList.Add(model);"); strclass.AppendSpaceLine(5, "}"); strclass.AppendSpaceLine(4, "}"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "return modelList;"); strclass.AppendSpaceLine(2, "}"); return strclass.Value; }
/// <summary> /// �õ�Update�����Ĵ��� /// </summary> /// <param name="DbName"></param> /// <param name="_tablename"></param> /// <param name="_key"></param> /// <param name="ModelName"></param> /// <returns></returns> public string CreatUpdate() { if (ModelSpace == "") { //ModelSpace = "ModelClassName"; ; } StringPlus strclass = new StringPlus(); strclass.AppendLine(""); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryUpdate"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); strclass.AppendSpaceLine(2, "public bool Update(" + ModelSpace + " model)"); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "strSql.Append(\"update " + _tablename + " set \");"); if (Fieldlist.Count == 0) { Fieldlist = Keys; } foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string Length = field.Length; bool IsIdentity = field.IsIdentity; bool isPK = field.IsPrimaryKey; bool nullable = field.Nullable; if (field.IsIdentity || field.IsPrimaryKey || (Keys.Contains(field))) { continue; } if (columnType.ToLower() == "timestamp") { continue; } strclass.AppendSpaceLine(3, "if (model." + columnName + " != null)"); strclass.AppendSpaceLine(3, "{"); if ((dbobj.DbType == "Oracle") && (columnType.ToLower() == "date" || columnType.ToLower() == "datetime")) { strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "=to_date('\" + model." + columnName + ".ToString() + \"','YYYY-MM-DD HH24:MI:SS'),\");"); } else if (columnType.ToLower() == "bit") { strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "=\"+ (model." + columnName + "? 1 : 0) +\",\");"); } else if (CodeCommon.IsAddMark(columnType.Trim())) { strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "='\"+model." + columnName + "+\"',\");"); } else { strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "=\"+model." + columnName + "+\",\");"); } strclass.AppendSpaceLine(3, "}"); if (nullable) { strclass.AppendSpaceLine(3, "else");//��null����� strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "= null ,\");"); strclass.AppendSpaceLine(3, "}"); } } //ȥ�����Ķ��� strclass.AppendSpaceLine(3, "int n = strSql.ToString().LastIndexOf(\",\");"); strclass.AppendSpaceLine(3, "strSql.Remove(n, 1);"); strclass.AppendSpaceLine(3, "strSql.Append(\" where " + Maticsoft.CodeHelper.CodeCommon.GetModelWhereExpression(Keys, true) + "\");"); strclass.AppendSpaceLine(3, "int rowsAffected=" + DbHelperName + ".ExecuteSql(strSql.ToString());"); strclass.AppendSpaceLine(3, "if (rowsAffected > 0)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return true;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return false;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpace(2, "}"); return strclass.ToString(); }
public string GetDALCode(bool Maxid, bool Exists, bool Add, bool Update, bool Delete, bool GetModel, bool List) { StringPlus strclass = new StringPlus(); strclass.AppendLine("using System;"); strclass.AppendLine("using System.Data;"); strclass.AppendLine("using System.Text;"); strclass.AppendLine("using System.Collections.Generic;"); switch (dbobj.DbType) { case "SQL2005": case "SQL2008": case "SQL2012": strclass.AppendLine("using System.Data.SqlClient;"); break; case "SQL2000": strclass.AppendLine("using System.Data.SqlClient;"); break; case "Oracle": strclass.AppendLine("using System.Data.OracleClient;"); break; case "MySQL": strclass.AppendLine("using MySql.Data.MySqlClient;"); break; case "OleDb": strclass.AppendLine("using System.Data.OleDb;"); break; case "SQLite": strclass.AppendLine("using System.Data.SQLite;"); break; } if (IDALpath != "") { strclass.AppendLine("using " + IDALpath + ";"); } // strclass.AppendLine("using Maticsoft.DBUtility;//Please add references"); // ���峬 2014-10-21 ��Ϊ����Ŀ���ݿ���� strclass.AppendLine("using " + NameSpace + ".DBUtility;"); strclass.AppendLine("namespace " + DALpath); strclass.AppendLine("{"); strclass.AppendSpaceLine(1, "/// <summary>"); strclass.AppendSpaceLine(1, "/// " + Languagelist["summary"].ToString() + ":" + DALName); strclass.AppendSpaceLine(1, "/// </summary>"); strclass.AppendSpace(1, "public partial class " + DALName); if (IClass != "") { strclass.Append(":" + IClass); } strclass.AppendLine(""); strclass.AppendSpaceLine(1, "{"); strclass.AppendSpaceLine(2, "public " + DALName + "()"); strclass.AppendSpaceLine(2, "{}"); strclass.AppendSpaceLine(2, "#region Method"); #region �������� if (Maxid) { strclass.AppendLine(CreatGetMaxID()); } if (Exists) { strclass.AppendLine(CreatExists()); } if (Add) { strclass.AppendLine(CreatAdd()); } if (Update) { strclass.AppendLine(CreatUpdate()); } if (Delete) { strclass.AppendLine(CreatDelete()); } if (GetModel) { strclass.AppendLine(CreatGetModel()); strclass.AppendLine(CreatDataRowToModel()); } if (List) { strclass.AppendLine(CreatGetList()); strclass.AppendLine(CreatGetListByPage()); strclass.AppendLine(CreatGetListByPageProc()); } #endregion strclass.AppendSpaceLine(2, "#endregion Method"); //strclass.AppendSpaceLine(2, "#region MethodEx"); //strclass.AppendLine(""); //strclass.AppendSpaceLine(2, "#endregion MethodEx"); strclass.AppendSpaceLine(1, "}"); strclass.AppendLine("}"); strclass.AppendLine(""); return strclass.ToString(); }
private string BuilderMethod() { StringPlus plus = new StringPlus(); plus.AppendSpaceLine(2, "#region Method"); //只读 if (IsView) { plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 是否只读"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override bool IsReadOnly()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return true;"); plus.AppendSpaceLine(2, "}"); } Model.ColumnInfo identityColumn = Columns.Find(delegate(Model.ColumnInfo col) { return col.IsIdentity; }); if (null != identityColumn) { plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 获取实体中的标识列"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override Field GetIdentityField()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return _." + identityColumn.ColumnName + ";"); plus.AppendSpaceLine(2, "}"); } List<Model.ColumnInfo> primarykeyColumns = Columns.FindAll(delegate(Model.ColumnInfo col) { return col.IsPK; }); if (null != primarykeyColumns && primarykeyColumns.Count > 0) { plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 获取实体中的主键列"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override Field[] GetPrimaryKeyFields()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return new Field[] {"); StringPlus plus2 = new StringPlus(); foreach (Model.ColumnInfo col in primarykeyColumns) { plus2.AppendSpaceLine(4, "_." + col.ColumnName + ","); } plus.Append(plus2.ToString().TrimEnd().Substring(0, plus2.ToString().TrimEnd().Length - 1)); plus.AppendLine("};"); plus.AppendSpaceLine(2, "}"); } plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 获取列信息"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override Field[] GetFields()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return new Field[] {"); StringPlus plus3 = new StringPlus(); foreach (ColumnInfo col in Columns) { plus3.AppendSpaceLine(4, "_." + col.ColumnName + ","); } plus.Append(plus3.ToString().TrimEnd().Substring(0, plus3.ToString().TrimEnd().Length - 1)); plus.AppendLine("};"); plus.AppendSpaceLine(2, "}"); plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 获取值信息"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override object[] GetValues()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return new object[] {"); StringPlus plus4 = new StringPlus(); foreach (ColumnInfo col in Columns) { plus4.AppendSpaceLine(4, "this._" + col.ColumnName + ","); } plus.Append(plus4.ToString().TrimEnd().Substring(0, plus4.ToString().TrimEnd().Length - 1)); plus.AppendLine("};"); plus.AppendSpaceLine(2, "}"); //2015-08-10注释 //plus.AppendSpaceLine(2, "/// <summary>"); //plus.AppendSpaceLine(2, "/// 给当前实体赋值"); //plus.AppendSpaceLine(2, "/// </summary>"); //plus.AppendSpaceLine(2, "public override void SetPropertyValues(IDataReader reader)"); //plus.AppendSpaceLine(2, "{"); //foreach (ColumnInfo col in Columns) //{ // plus.AppendSpaceLine(3, "this._" + col.ColumnName + " = DataUtils.ConvertValue<" + col.TypeName + ">(reader[\"" + col.ColumnNameRealName + "\"]);"); //} //plus.AppendSpaceLine(2, "}"); //2015-08-10注释 //plus.AppendSpaceLine(2, "/// <summary>"); //plus.AppendSpaceLine(2, "/// 给当前实体赋值"); //plus.AppendSpaceLine(2, "/// </summary>"); //plus.AppendSpaceLine(2, "public override void SetPropertyValues(DataRow row)"); //plus.AppendSpaceLine(2, "{"); //foreach (ColumnInfo col in Columns) //{ // plus.AppendSpaceLine(3, "this._" + col.ColumnName + " = DataUtils.ConvertValue<" + col.TypeName + ">(row[\"" + col.ColumnNameRealName + "\"]);"); //} //plus.AppendSpaceLine(2, "}"); plus.AppendSpaceLine(2, "#endregion"); plus.AppendLine(); plus.AppendSpaceLine(2, "#region _Field"); plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 字段信息"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public class _"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "/// <summary>"); plus.AppendSpaceLine(3, "/// * "); plus.AppendSpaceLine(3, "/// </summary>"); plus.AppendSpaceLine(3, "public readonly static Field All = new Field(\"*\",\"" + TableName + "\");"); foreach (ColumnInfo col in Columns) { plus.AppendSpaceLine(3, "/// <summary>"); plus.AppendSpaceLine(3, "/// " + col.DeText); plus.AppendSpaceLine(3, "/// </summary>"); plus.AppendSpaceLine(3, "public readonly static Field " + col.ColumnName + " = new Field(\"" + col.ColumnNameRealName + "\",\"" + TableName + "\",\"" + (string.IsNullOrEmpty(col.DeText) ? col.ColumnNameRealName : col.DeText) + "\");"); } plus.AppendSpaceLine(2, "}"); plus.AppendSpaceLine(2, "#endregion"); plus.AppendLine(); return plus.ToString(); }
private string BuilderModel() { StringPlus plus = new StringPlus(); StringPlus plus2 = new StringPlus(); StringPlus plus3 = new StringPlus(); plus.AppendSpaceLine(2, "#region Model"); foreach (ColumnInfo column in Columns) { if (!string.IsNullOrWhiteSpace(column.DefaultVal)) { var val = ""; if (column.TypeName.ToLower().Contains("bool")) { switch (val) { case "b'0'": val = "0"; break; case "b'1'": val = "1"; break; } val = DataUtils.ConvertValue<bool>(column.DefaultVal) ? "true" : "false"; } else if (column.TypeName.ToLower().Contains("string")) { val = "\"" + column.DefaultVal + "\""; } else if (column.TypeName.ToLower().Contains("guid")) { Guid tempGuid; if (Guid.TryParse(column.DefaultVal, out tempGuid)) { val = "Guid.Parse(\"" + column.DefaultVal + "\")"; } else { val = "Guid.NewGuid()"; } } else if (column.TypeName.ToLower().Contains("int")) { val = column.DefaultVal; } else if (column.TypeName.ToLower().Contains("decimal")) { val = column.DefaultVal + "M"; } else if (column.TypeName.ToLower().Contains("float")) { val = column.DefaultVal + "F"; } if (string.IsNullOrWhiteSpace(val)) { plus2.AppendSpaceLine(2, "private " + column.TypeName + " _" + column.ColumnName + ";"); } else { plus2.AppendSpaceLine(2, "private " + column.TypeName + " _" + column.ColumnName + " = " + val + ";"); } } else { plus2.AppendSpaceLine(2, "private " + column.TypeName + " _" + column.ColumnName + ";"); } plus3.AppendSpaceLine(2, "/// <summary>"); plus3.AppendSpaceLine(2, "/// " + column.DeText); plus3.AppendSpaceLine(2, "/// </summary>"); plus3.AppendSpaceLine(2, "public " + column.TypeName + " " + column.ColumnName); plus3.AppendSpaceLine(2, "{"); plus3.AppendSpaceLine(3, "get{ return _" + column.ColumnName + "; }"); plus3.AppendSpaceLine(3, "set"); plus3.AppendSpaceLine(3, "{"); plus3.AppendSpaceLine(4, "this.OnPropertyValueChange(_." + column.ColumnName + ",_" + column.ColumnName + ",value);"); plus3.AppendSpaceLine(4, "this._" + column.ColumnName + "=value;"); plus3.AppendSpaceLine(3, "}"); plus3.AppendSpaceLine(2, "}"); } plus.Append(plus2.Value); plus.Append(plus3.Value); plus.AppendSpaceLine(2, "#endregion"); return plus.ToString(); }
/// <summary> /// ����sql����еIJ����б�(���磺���� Exists Delete GetModel ��where������ֵ) /// </summary> /// <param name="keys"></param> /// <returns></returns> public string GetPreParameter(List<ColumnInfo> keys, bool IdentityisPrior) { StringPlus strclass = new StringPlus(); StringPlus strclass2 = new StringPlus(); strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {"); ColumnInfo field = Maticsoft.CodeHelper.CodeCommon.GetIdentityKey(keys); if ((IdentityisPrior) && (field != null)) //�б�ʶ�ֶ� { strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + field.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, field.TypeName, "") + ")"); strclass2.AppendSpaceLine(3, "parameters[0].Value = " + field.ColumnName + ";"); } else { int n = 0; foreach (ColumnInfo key in keys) { if (key.IsPrimaryKey) { strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + key.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, key.TypeName, "") + "),"); strclass2.AppendSpaceLine(3, "parameters[" + n.ToString() + "].Value = " + key.ColumnName + ";"); n++; } } strclass.DelLastComma(); } strclass.AppendLine("};"); strclass.Append(strclass2.Value); return strclass.Value; }
public string Builder() { Columns = DbToCS.DbtoCSColumns(Columns); StringPlus plus = new StringPlus(); plus.AppendLine("//------------------------------------------------------------------------------"); plus.AppendLine("// <auto-generated>"); plus.AppendLine("// 此代码由工具生成。"); plus.AppendLine("// 运行时版本:" + Environment.Version.ToString()); plus.AppendLine("// Support: http://www.cnblogs.com/huxj"); plus.AppendLine("// Website: http://ITdos.com/Dos/ORM/Index.html"); plus.AppendLine("// 对此文件的更改可能会导致不正确的行为,并且如果"); plus.AppendLine("// 重新生成代码,这些更改将会丢失。"); plus.AppendLine("// </auto-generated>"); plus.AppendLine("//------------------------------------------------------------------------------"); plus.AppendLine(); plus.AppendLine(); plus.AppendLine("using System;"); plus.AppendLine("using System.Data;"); plus.AppendLine("using System.Data.Common;"); plus.AppendLine("using Dos.ORM;"); plus.AppendLine("using Dos.ORM.Common;"); plus.AppendLine(); plus.AppendLine("namespace " + NameSpace); plus.AppendLine("{"); plus.AppendLine(); plus.AppendSpaceLine(1, "/// <summary>"); plus.AppendSpaceLine(1, "/// 实体类" + ClassName + " 。(属性说明自动提取数据库字段的描述信息)"); plus.AppendSpaceLine(1, "/// </summary>"); plus.AppendSpaceLine(1, "[Serializable]"); plus.AppendSpaceLine(1, "public partial class " + ClassName + " : Entity "); plus.AppendSpaceLine(1, "{"); plus.AppendSpaceLine(2, "public " + ClassName + "():base(\"" + TableName + "\") {}"); plus.AppendLine(); plus.AppendLine(BuilderModel()); plus.AppendLine(BuilderMethod()); plus.AppendSpaceLine(1, "}"); plus.AppendLine("}"); plus.AppendLine(""); return plus.ToString(); }
/// <summary> /// �õ�Add()�Ĵ��� /// </summary> public string CreatAdd() { if (ModelSpace == "") { //ModelSpace = "ModelClassName"; ; } StringPlus strclass = new StringPlus(); strclass.AppendLine(""); strclass.AppendSpaceLine(2, "/// <summary>"); strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryadd"].ToString()); strclass.AppendSpaceLine(2, "/// </summary>"); string strretu = "bool"; if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005" || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012" || dbobj.DbType == "SQLite") && (IsHasIdentity)) { strretu = "int"; if (_IdentityKeyType != "int") { strretu = _IdentityKeyType; } } //if (dbobj.DbType == "OleDb" && IsHasIdentity) //{ // strretu = "bool"; //} //��������ͷ string strFun = CodeCommon.Space(2) + "public " + strretu + " Add(" + ModelSpace + " model)"; strclass.AppendLine(strFun); strclass.AppendSpaceLine(2, "{"); strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();"); strclass.AppendSpaceLine(3, "StringBuilder strSql1=new StringBuilder();"); strclass.AppendSpaceLine(3, "StringBuilder strSql2=new StringBuilder();"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; bool IsIdentity = field.IsIdentity; if (IsIdentity) { continue; } strclass.AppendSpaceLine(3, "if (model." + columnName + " != null)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "strSql1.Append(\"" + columnName + ",\");"); if ((dbobj.DbType == "Oracle") && (columnType.ToLower() == "date" || columnType.ToLower() == "datetime")) { strclass.AppendSpaceLine(4, "strSql2.Append(\"to_date('\" + model." + columnName + ".ToString() + \"','YYYY-MM-DD HH24:MI:SS'),\");"); } else if (columnType.ToLower() == "bit") { strclass.AppendSpaceLine(4, "strSql2.Append(\"\"+(model." + columnName + "? 1 : 0) +\",\");"); } else if ("uniqueidentifier" == columnType.ToLower()) { strclass.AppendSpaceLine(4, "strSql2.Append(\"'\"+ Guid.NewGuid().ToString() +\"',\");"); } else if (CodeCommon.IsAddMark(columnType.Trim())) { strclass.AppendSpaceLine(4, "strSql2.Append(\"'\"+model." + columnName + "+\"',\");"); } else { strclass.AppendSpaceLine(4, "strSql2.Append(\"\"+model." + columnName + "+\",\");"); } strclass.AppendSpaceLine(3, "}"); } strclass.AppendSpaceLine(3, "strSql.Append(\"insert into " + TableName + "(\");"); strclass.AppendSpaceLine(3, "strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));"); strclass.AppendSpaceLine(3, "strSql.Append(\")\");"); strclass.AppendSpaceLine(3, "strSql.Append(\" values (\");"); strclass.AppendSpaceLine(3, "strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));"); strclass.AppendSpaceLine(3, "strSql.Append(\")\");"); if (strretu == "void") { strclass.AppendSpaceLine(3, "" + DbHelperName + ".ExecuteSql(strSql.ToString());"); } else if (strretu == "bool") { strclass.AppendSpaceLine(3, "int rows=" + DbHelperName + ".ExecuteSql(strSql.ToString());"); strclass.AppendSpaceLine(3, "if (rows > 0)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return true;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return false;"); strclass.AppendSpaceLine(3, "}"); } else//�����Զ�������ֵ { if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005" || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012") && (IsHasIdentity)) { strclass.AppendSpaceLine(3, "strSql.Append(\";select @@IDENTITY\");"); } if ((dbobj.DbType == "SQLite") && (IsHasIdentity)) { strclass.AppendSpaceLine(3, "strSql.Append(\";select LAST_INSERT_ROWID()\");"); } strclass.AppendSpaceLine(3, "object obj = " + DbHelperName + ".GetSingle(strSql.ToString());"); strclass.AppendSpaceLine(3, "if (obj == null)"); strclass.AppendSpaceLine(3, "{"); strclass.AppendSpaceLine(4, "return 0;"); strclass.AppendSpaceLine(3, "}"); strclass.AppendSpaceLine(3, "else"); strclass.AppendSpaceLine(3, "{"); switch (strretu) { case "int": strclass.AppendSpaceLine(4, "return Convert.ToInt32(obj);"); break; case "long": strclass.AppendSpaceLine(4, "return Convert.ToInt64(obj);"); break; case "decimal": strclass.AppendSpaceLine(4, "return Convert.ToDecimal(obj);"); break; } strclass.AppendSpaceLine(3, "}"); } strclass.AppendSpace(2, "}"); return strclass.ToString(); }