/// <summary> /// 得到表示层显示窗体的html代码 /// </summary> public string GetShowDesigner() { if (ModelSpace == "") { ModelSpace = "ModelClassName";; } 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 BuilderFrameS3(IDbObject idbobj, string dbName, string tableName, string modelName, string bllName, string dalName, List <ColumnInfo> fieldlist, List <ColumnInfo> keys, string nameSpace, string folder, string dbHelperName) { dbobj = idbobj; _dbtype = idbobj.DbType; DbName = dbName; TableName = tableName; ModelName = modelName; BLLName = bllName; DALName = dalName; NameSpace = nameSpace; DbHelperName = dbHelperName; Folder = folder; Fieldlist = fieldlist; Keys = keys; foreach (ColumnInfo key in keys) { _key = key.ColumnName; _keyType = key.TypeName; if (key.IsIdentity) { _key = key.ColumnName; _keyType = CodeCommon.DbTypeToCS(key.TypeName); break; } } //model = new BuilderModel(dbobj, DbName, TableName, ModelName, NameSpace, Folder, Modelpath, fieldlist); }
/// <summary> /// 得到主键的条件表达式 /// </summary> /// <param name="Keys"></param> /// <returns></returns> public string GetkeyWherelist(Hashtable Keys) { StringPlus strlist = new StringPlus(); int n = 0; foreach (DictionaryEntry key in Keys) { n++; if (CodeCommon.IsAddMark(key.Value.ToString())) { strlist.Append(key.Key.ToString() + "='\"+" + key.Key.ToString() + "+\"'\""); } else { strlist.Append(key.Key.ToString() + "=\"+" + key.Key.ToString() + "+\""); if (n == Keys.Count) { strlist.Append("\""); } } strlist.Append(" and "); } if (strlist.Value.IndexOf("and") > 0) { strlist.DelLastChar("and"); } return(strlist.Value); }
/// <summary> /// 得到表示层显示窗体的代码 /// </summary> public string GetShowAspxCs() { if (ModelSpace == "") { ModelSpace = "ModelClassName";; } StringBuilder strclass = new StringBuilder(); strclass.Append("\r\n"); string key = Key; strclass.Append("private void ShowInfo(" + LTP.CodeHelper.CodeCommon.GetInParameter(Keys) + ")" + "\r\n"); strclass.Append("{" + "\r\n"); strclass.Append(" "+ BLLSpace + " bll=new " + BLLSpace + "();" + "\r\n"); strclass.Append(" "+ ModelSpace + " model=bll.GetModel(" + LTP.CodeHelper.CodeCommon.GetFieldstrlist(Keys) + ");" + "\r\n"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.DeText; bool ispk = field.IsPK; bool IsIdentity = field.IsIdentity; if ((ispk) || (IsIdentity)) { continue; } switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower()) { case "int": case "smallint": case "float": case "numeric": case "decimal": case "datetime": case "smalldatetime": strclass.Append(" this.lbl"+ columnName + ".Text=model." + columnName + ".ToString();" + "\r\n"); break; case "bool": strclass.Append(" this.chk"+ columnName + ".Checked=model." + columnName + ";" + "\r\n"); break; case "byte[]": strclass.Append(" this.lbl"+ columnName + ".Text=model." + columnName + ".ToString();" + "\r\n"); break; default: strclass.Append(" this.lbl"+ columnName + ".Text=model." + columnName + ";" + "\r\n"); break; } } strclass.Append("\r\n"); strclass.Append("}"); return(strclass.ToString()); }
/// <summary> /// 得到主键条件字段参数定义列表 /// </summary> /// <param name="Keys"></param> /// <returns></returns> public string GetkeyParalist(Hashtable Keys) { StringPlus strlist = new StringPlus(); foreach (DictionaryEntry key in Keys) { strlist.Append(CodeCommon.DbTypeToCS(key.Value.ToString()) + " " + key.Key.ToString() + ","); } if (strlist.Value.IndexOf(",") > 0) { strlist.DelLastComma(); } return(strlist.Value); }
/// <summary> /// 得到表示层增加窗体的html代码 /// </summary> public string GetUpdateDesigner() { if (ModelSpace == "") { ModelSpace = "ModelClassName";; } StringPlus strclass = new StringPlus(); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string deText = field.DeText; bool ispk = field.IsPK; bool IsIdentity = field.IsIdentity; if (deText.Trim() == "") { deText = columnName; } if ((ispk) || (IsIdentity)) { 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 btnAdd;"); strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Button btnCancel;"); return(strclass.Value); }
public BuilderBLL(List <ColumnInfo> keys, string modelspace) { _modelspace = modelspace; Keys = keys; foreach (ColumnInfo key in _keys) { _key = key.ColumnName; _keyType = key.TypeName; if (key.IsIdentity) { _key = key.ColumnName; _keyType = CodeCommon.DbTypeToCS(key.TypeName); break; } } }
/// <summary> /// 生成实体类的属性 /// </summary> /// <returns></returns> public string CreatModelMethod() { StringPlus strclass = new StringPlus(); StringPlus strclass1 = new StringPlus(); StringPlus strclass2 = new StringPlus(); strclass.AppendSpaceLine(2, "#region Model"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; bool IsIdentity = field.IsIdentity; bool ispk = field.IsPK; bool cisnull = field.cisNull; string deText = field.DeText; columnType = CodeCommon.DbTypeToCS(columnType); string isnull = ""; if (CodeCommon.isValueType(columnType)) { if ((!IsIdentity) && (!ispk) && (cisnull)) { isnull = "?"; } } strclass1.AppendSpaceLine(2, "private " + columnType + isnull + " _" + columnName.ToLower() + ";");//私有变量 strclass2.AppendSpaceLine(2, "/// <summary>"); strclass2.AppendSpaceLine(2, "/// " + deText); strclass2.AppendSpaceLine(2, "/// </summary>"); strclass2.AppendSpaceLine(2, "public " + columnType + isnull + " " + columnName);//属性 strclass2.AppendSpaceLine(2, "{"); strclass2.AppendSpaceLine(3, "set{" + " _" + columnName.ToLower() + "=value;}"); strclass2.AppendSpaceLine(3, "get{return " + "_" + columnName.ToLower() + ";}"); strclass2.AppendSpaceLine(2, "}"); } strclass.Append(strclass1.Value); strclass.Append(strclass2.Value); strclass.AppendSpaceLine(2, "#endregion Model"); return(strclass.ToString()); }
public BuilderWeb(IDbObject idbobj, string dbName, string tableName, string modelName, List <ColumnInfo> fieldlist, List <ColumnInfo> keys, string nameSpace, string folder) { dbobj = idbobj; DbName = dbName; TableName = tableName; ModelName = modelName; Folder = folder; NameSpace = nameSpace; Fieldlist = fieldlist; Keys = keys; foreach (ColumnInfo key in keys) { _key = key.ColumnName; _keyType = key.TypeName; if (key.IsIdentity) { _key = key.ColumnName; _keyType = CodeCommon.DbTypeToCS(key.TypeName); break; } } }
/// <summary> /// 得到数据的xml /// </summary> /// <returns></returns> private XmlDocument GetXml2() { string xmlDoc = @"Template\temp.xml"; //临时数据文件temp.xml XmlTextWriter writer = new XmlTextWriter(xmlDoc, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(true); writer.WriteStartElement("Schema"); writer.WriteStartElement("TableName"); writer.WriteAttributeString("value", TableName); writer.WriteEndElement(); //字段属性 writer.WriteStartElement("FIELDS"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; string Length = field.Length; bool IsIdentity = field.IsIdentity; bool isPK = field.IsPK; string deText = field.DeText; string defaultVal = field.DefaultVal; writer.WriteStartElement("FIELD"); writer.WriteAttributeString("Name", columnName); writer.WriteAttributeString("Type", CodeCommon.DbTypeToCS(columnType)); writer.WriteAttributeString("Desc", deText); writer.WriteAttributeString("defaultVal", defaultVal); writer.WriteEndElement(); } writer.WriteEndElement(); //主键字段 writer.WriteStartElement("PrimaryKeys"); foreach (ColumnInfo field in Keys) { string columnName = field.ColumnName; string columnType = field.TypeName; string Length = field.Length; bool IsIdentity = field.IsIdentity; bool isPK = field.IsPK; string deText = field.DeText; string defaultVal = field.DefaultVal; writer.WriteStartElement("FIELD"); writer.WriteAttributeString("Name", columnName); writer.WriteAttributeString("Type", CodeCommon.DbTypeToCS(columnType)); writer.WriteAttributeString("Desc", deText); writer.WriteAttributeString("defaultVal", defaultVal); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); writer.Close(); XmlDocument xml = new XmlDocument(); xml.Load(xmlDoc); return(xml); }
/// <summary> /// 得到接口层代码 /// </summary> /// <param name="ID">主键</param> /// <param name="ModelName">类名</param> /// <returns></returns> public string GetIDALCode(bool Maxid, bool Exists, bool Add, bool Update, bool Delete, bool GetModel, bool List, bool ListProc) { StringBuilder strclass = new StringBuilder(); strclass.Append("using System;\r\n"); strclass.Append("using System.Data;\r\n"); strclass.Append("namespace " + IDALpath + "\r\n"); strclass.Append("{" + "\r\n"); strclass.Append(" /// <summary>"+ "\r\n"); strclass.Append(" /// 接口层"+ IClass + " 的摘要说明。" + "\r\n"); strclass.Append(" /// </summary>"+ "\r\n"); strclass.Append(" public interface "+ IClass + "\r\n"); strclass.Append(" {\r\n"); strclass.Append(Space(2) + "#region 成员方法" + "\r\n"); if (Maxid) { if (Keys.Count > 0) { foreach (ColumnInfo obj in Keys) { if (CodeCommon.DbTypeToCS(obj.TypeName) == "int") { if (obj.IsPK) { strclass.Append(Space(2) + "/// <summary>" + "\r\n"); strclass.Append(Space(2) + "/// 得到最大ID" + "\r\n"); strclass.Append(Space(2) + "/// </summary>" + "\r\n"); strclass.Append(" int GetMaxId();"+ "\r\n"); break; } } } } } if (Exists) { if (Keys.Count > 0) { strclass.Append(Space(2) + "/// <summary>" + "\r\n"); strclass.Append(Space(2) + "/// 是否存在该记录" + "\r\n"); strclass.Append(Space(2) + "/// </summary>" + "\r\n"); strclass.Append(Space(2) + "bool Exists(" + LTP.CodeHelper.CodeCommon.GetInParameter(Keys) + ");" + "\r\n"); } } if (Add) { strclass.Append(Space(2) + "/// <summary>" + "\r\n"); strclass.Append(Space(2) + "/// 增加一条数据" + "\r\n"); strclass.Append(Space(2) + "/// </summary>" + "\r\n"); string strretu = "void"; if (IsHasIdentity) { strretu = "int"; } strclass.Append(Space(2) + strretu + " Add(" + ModelSpace + " model);" + "\r\n"); } if (Update) { strclass.Append(Space(2) + "/// <summary>" + "\r\n"); strclass.Append(Space(2) + "/// 更新一条数据" + "\r\n"); strclass.Append(Space(2) + "/// </summary>" + "\r\n"); strclass.Append(Space(2) + "void Update(" + ModelSpace + " model);" + "\r\n"); } if (Delete) { strclass.Append(Space(2) + "/// <summary>" + "\r\n"); strclass.Append(Space(2) + "/// 删除一条数据" + "\r\n"); strclass.Append(Space(2) + "/// </summary>" + "\r\n"); strclass.Append(Space(2) + "void Delete(" + LTP.CodeHelper.CodeCommon.GetInParameter(Keys) + ");" + "\r\n"); } if (GetModel) { strclass.Append(Space(2) + "/// <summary>" + "\r\n"); strclass.Append(Space(2) + "/// 得到一个对象实体" + "\r\n"); strclass.Append(Space(2) + "/// </summary>" + "\r\n"); strclass.Append(Space(2) + ModelSpace + " GetModel(" + LTP.CodeHelper.CodeCommon.GetInParameter(Keys) + ");" + "\r\n"); } if (List) { strclass.Append(Space(2) + "/// <summary>" + "\r\n"); strclass.Append(Space(2) + "/// 获得数据列表" + "\r\n"); strclass.Append(Space(2) + "/// </summary>" + "\r\n"); strclass.Append(Space(2) + "DataSet GetList(string strWhere);" + "\r\n"); if ((dbobj.DbType == "SQL2000") || (dbobj.DbType == "SQL2005") || (dbobj.DbType == "SQL2008")) { strclass.Append(Space(2) + "/// <summary>" + "\r\n"); strclass.Append(Space(2) + "/// 获得前几行数据" + "\r\n"); strclass.Append(Space(2) + "/// </summary>" + "\r\n"); strclass.Append(Space(2) + "DataSet GetList(int Top,string strWhere,string filedOrder);" + "\r\n"); } } if (ListProc) { //strclass.Append(Space(2) + "/// <summary>" + "\r\n"); //strclass.Append(Space(2) + "/// 获得数据列表" + "\r\n"); //strclass.Append(Space(2) + "/// </summary>" + "\r\n"); //strclass.Append(" DataSet GetList();" + "\r\n"); strclass.Append(Space(2) + "/// <summary>" + "\r\n"); strclass.Append(Space(2) + "/// 根据分页获得数据列表" + "\r\n"); strclass.Append(Space(2) + "/// </summary>" + "\r\n"); strclass.Append(Space(2) + "//DataSet GetList(int PageSize,int PageIndex,string strWhere);" + "\r\n"); } strclass.Append(Space(2) + "#endregion 成员方法" + "\r\n"); strclass.Append(" }\r\n"); strclass.Append("}" + "\r\n"); return(strclass.ToString()); }
/// <summary> /// 得到修改窗体的代码 /// </summary> public string GetUpdateAspxCs() { if (ModelSpace == "") { ModelSpace = "ModelClassName";; } StringBuilder strclass = new StringBuilder(); StringBuilder strclass0 = new StringBuilder(); StringBuilder strclass1 = new StringBuilder(); StringBuilder strclass2 = new StringBuilder(); strclass.Append("\r\n"); strclass.Append(" string strErr=\"\";\r\n"); foreach (ColumnInfo field in Fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; bool ispk = field.IsPK; bool IsIdentity = field.IsIdentity; if ((ispk) || (IsIdentity)) { continue; } switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower()) { case "int": case "smallint": strclass0.Append(" int "+ columnName + "=int.Parse(this.txt" + columnName + ".Text);" + "\r\n"); strclass1.Append(" if(!PageValidate.IsNumber(txt"+ columnName + ".Text))" + "\r\n"); strclass1.Append(" {"+ "\r\n"); strclass1.Append(" strErr+=\""+ columnName + "不是数字!\\\\n\"; "+ "\r\n"); strclass1.Append(" }"+ "\r\n"); break; case "float": case "numeric": case "decimal": strclass0.Append(" decimal "+ columnName + "=decimal.Parse(this.txt" + columnName + ".Text);" + "\r\n"); strclass1.Append(" if(!PageValidate.IsDecimal(txt"+ columnName + ".Text))" + "\r\n"); strclass1.Append(" {"+ "\r\n"); strclass1.Append(" strErr+=\""+ columnName + "不是数字!\\\\n\"; "+ "\r\n"); strclass1.Append(" }"+ "\r\n"); break; case "datetime": case "smalldatetime": strclass0.Append(" DateTime "+ columnName + "=DateTime.Parse(this.txt" + columnName + ".Text);" + "\r\n"); strclass1.Append(" if(!PageValidate.IsDateTime(txt"+ columnName + ".Text))" + "\r\n"); strclass1.Append(" {"+ "\r\n"); strclass1.Append(" strErr+=\""+ columnName + "不是时间格式!\\\\n\"; "+ "\r\n"); strclass1.Append(" }"+ "\r\n"); break; case "bool": strclass0.Append(" bool "+ columnName + "=this.chk" + columnName + ".Checked;" + "\r\n"); break; case "byte[]": strclass0.Append(" byte[] "+ columnName + "= new UnicodeEncoding().GetBytes(this.txt" + columnName + ".Text);" + "\r\n"); break; default: strclass0.Append(" string "+ columnName + "=this.txt" + columnName + ".Text;" + "\r\n"); strclass1.Append(" if(this.txt"+ columnName + ".Text ==\"\")" + "\r\n"); strclass1.Append(" {"+ "\r\n"); strclass1.Append(" strErr+=\""+ columnName + "不能为空!\\\\n\"; "+ "\r\n"); strclass1.Append(" }"+ "\r\n"); break; } strclass2.Append(" model."+ columnName + "=" + columnName + ";" + "\r\n"); } strclass.Append(strclass1.ToString() + "\r\n"); strclass.Append(" if(strErr!=\"\")"+ "\r\n"); strclass.Append(" {"+ "\r\n"); strclass.Append(" MessageBox.Show(this,strErr);"+ "\r\n"); strclass.Append(" return;"+ "\r\n"); strclass.Append(" }"+ "\r\n"); strclass.Append(strclass0.ToString() + "\r\n"); strclass.Append("\r\n"); strclass.Append(" "+ ModelSpace + " model=new " + ModelSpace + "();" + "\r\n"); strclass.Append(strclass2.ToString()); strclass.Append(" "+ BLLSpace + " bll=new " + BLLSpace + "();" + "\r\n"); strclass.Append(" bll.Update(model);"); return(strclass.ToString()); }