⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autocreatecode.cs

📁 一款自动编码工具
💻 CS
📖 第 1 页 / 共 4 页
字号:
			for(int i=1;i<dt.Rows.Count;i++)
			{
				if(i	==	dt.Rows.Count-1)
				{
					sw.WriteLine("			sbInsert.Append(\" @" + dt.Rows[i]["column_name"].ToString() + "\");");
				}
				else
				{
					sw.WriteLine("			sbInsert.Append(\" @" + dt.Rows[i]["column_name"].ToString() + ",\");");
				}
			}
			sw.WriteLine("			sbInsert.Append(\")\");");
			sw.Write("\n");
			sw.WriteLine("			return sbInsert.ToString();");
			sw.Write("\n");
			sw.WriteLine("	    }");
			sw.Write("\n");


			//设置添加参数
			sw.WriteLine("\t\t/// <summary> ");
			sw.WriteLine("\t\t///  设置添加信息表的参数");
			sw.WriteLine("\t\t/// </summary>");
			sw.WriteLine("\t\t/// <param name=\"sqlParmeterCollection\">参数集合</param>");
			sw.WriteLine("		public override void setInsertParameter(SqlParameterCollection sqlParmeterCollection)");
			sw.WriteLine("		{");

			for(int i2=1;i2<dt.Rows.Count;i2++)
			{
				int err = 0;
				SqlDbType sqlType = new SqlDbType();
				err = Getparam(dt.Rows[i2]["type_name"].ToString().ToUpper(),out sqlType);
				if( err == -1)
				{
					MessageBox.Show("发生类型转换错误","错误",MessageBoxButtons.OK);
				}
				else
				{
					type = ChangeToCSharpType(sqlType.ToString().ToLower());
				}

				if( type == "string")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2},{3}).Value									= this.{4}{5};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),dt.Rows[i2]["length"].ToString(),"_s",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "int")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2}).Value										= this.{3}{4};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),"_n",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "DateTime")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2}).Value										= this.{3}{4};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),"_dt",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "decimal")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2},{3}).Value									= this.{4}{5};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),dt.Rows[i2]["length"].ToString(),"_d",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "bool")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2}).Value										= this.{3}{4};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),"_b",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "text")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}).Value										= this.{2}{3};",dt.Rows[i2]["column_name"].ToString(),
						"Text","_s",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "strings")
				{
					type = "NVarChar";
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2},{3}).Value									= this.{4}{5};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),dt.Rows[i2]["Plength"].ToString(),"_s",
						dt.Rows[i2]["column_name"].ToString());
				}
				else
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2},{3}).Value									= this.{4}{5};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),dt.Rows[i2]["length"].ToString(),"_",
						dt.Rows[i2]["column_name"].ToString());
				}
			}
			sw.WriteLine("		}");
			sw.Write("\n");



			//在Table中修改一条信息
			sw.WriteLine("\t\t/// <summary> ");
			sw.WriteLine("\t\t///  修改基本信息表链接");
			sw.WriteLine("\t\t/// </summary>");
			sw.WriteLine("\t\t///  <returns>返回修改Sql语句</returns>");

			sw.WriteLine("		public override string GetUpdateString()");
			sw.WriteLine("		{");
			sw.WriteLine("			StringBuilder sbUpdate = new StringBuilder(\"update {0} set \");",tableName);
			sw.Write("\n");

			for(int i3=1;i3<dt.Rows.Count;i3++)
			{
				if(i3	==	dt.Rows.Count-1)
				{
					sw.WriteLine("			sbUpdate.Append(\" {0} 			= @{1}\");",dt.Rows[i3]["column_name"].ToString(),dt.Rows[i3]["column_name"].ToString());
				}
				else
				{
					sw.WriteLine("			sbUpdate.Append(\" {0} 			= @{1},\");",dt.Rows[i3]["column_name"].ToString(),dt.Rows[i3]["column_name"].ToString());
				}
			}

			sw.Write("\n");
			sw.WriteLine("			sbUpdate.Append(\" where\");");
			sw.Write("\n");
			sw.WriteLine("			sbUpdate.Append(\" " + dt.Rows[0]["column_name"].ToString() +"=@" + dt.Rows[0]["column_name"].ToString() + "\");");
			sw.Write("\n");
			sw.WriteLine("			return sbUpdate.ToString();");
			sw.WriteLine("		}");
			sw.Write("\n");

			
			//设置修改参数
			sw.WriteLine("\t\t/// <summary> ");
			sw.WriteLine("\t\t///  设置修改基本信息表的参数");
			sw.WriteLine("\t\t/// </summary>");
			sw.WriteLine("\t\t/// <param name=\"sqlParmeterCollection\">参数集合</param>");
			sw.WriteLine("		public override void setUpdateParameter(SqlParameterCollection sqlParmeterCollection)");
			sw.WriteLine("		{");
			for(int i2=0;i2<dt.Rows.Count;i2++)
			{
				int err = 0;
				SqlDbType sqlType = new SqlDbType();
				err = Getparam(dt.Rows[i2]["type_name"].ToString().ToUpper(),out sqlType);
				if( err == -1)
				{
					MessageBox.Show("发生类型转换错误","错误",MessageBoxButtons.OK);
				}
				else
				{
					type = ChangeToCSharpType(sqlType.ToString().ToLower());
				}

				if( type == "string")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2},{3}).Value									= this.{4}{5};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),dt.Rows[i2]["length"].ToString(),"_s",	
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "int")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2}).Value										= this.{3}{4};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),"_n",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "DateTime")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2}).Value										= this.{3}{4};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),"_dt",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "decimal")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2},{3}).Value										= this.{4}{5};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),dt.Rows[i2]["length"].ToString(),"_d",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "bool")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2}).Value										= this.{3}{4};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),"_b",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "text")
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}).Value										= this.{2}{3};",dt.Rows[i2]["column_name"].ToString(),
						"Text","_s",
						dt.Rows[i2]["column_name"].ToString());
				}
				else if( type == "strings")
				{
					type = "NVarChar";
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2},{3}).Value									= this.{4}{5};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),dt.Rows[i2]["Plength"].ToString(),"_s",
						dt.Rows[i2]["column_name"].ToString());
				}
				else
				{
					sw.WriteLine("			sqlParmeterCollection.Add(\"@{0}\", SqlDbType.{1}{2},{3}).Value									= this.{4}{5};",dt.Rows[i2]["column_name"].ToString(),
						type.ToString().Substring(0,1).ToUpper(),type.Substring(1,type.Length-1),dt.Rows[i2]["length"].ToString(),"_",
						dt.Rows[i2]["column_name"].ToString());
				}
			}
			sw.WriteLine("		}");
			sw.Write("\n");


			//在Table中删除一条信息
			sw.WriteLine("\t\t/// <summary> ");
			sw.WriteLine("\t\t///  删除基本信息表链接");
			sw.WriteLine("\t\t/// </summary>");
			sw.WriteLine("\t\t/// <returns>返回添加Sql语句</returns>");

			sw.WriteLine("		public override string GetDeleteString()");
			sw.WriteLine("		{");
			sw.WriteLine("			StringBuilder sbDelete = new StringBuilder(\"delete "+ tableName +"\");");
			sw.Write("\n");
			sw.WriteLine("			sbDelete.Append(\" where\");");
			sw.Write("\n");
			sw.WriteLine("			sbDelete.Append(\" "+ dt.Rows[0]["column_name"].ToString() +" = @" + dt.Rows[0]["column_name"].ToString() +"\");");
			sw.WriteLine("			return sbDelete.ToString();");
			sw.WriteLine("		}");
			sw.Write("\n");
			
			//设置删除参数
			sw.WriteLine("\t\t/// <summary> ");
			sw.WriteLine("\t\t///  设置删除基本信息表的参数");
			sw.WriteLine("\t\t/// </summary>");
			sw.WriteLine("\t\t/// <param name=\"sqlParmeterCollection\">参数集合</param>");

			sw.WriteLine("		public override void setDeleteParameter(SqlParameterCollection sqlParmeterCollection)");
			sw.WriteLine("		{");

			int err1 = 0;
			SqlDbType sqlType1 = new SqlDbType();
			err1 = Getparam(dt.Rows[0]["type_name"].ToString().ToUpper(),out sqlType1);
			if( err1 == -1)
			{
				MessageBox.Show("发生类型转换错误","错误",MessageBoxButtons.OK);
			}
			else
			{
				type = ChangeToCSharpType(sqlType1.ToString().ToLower());
			}

			if( type == "string" || type == "strings")
			{
				sw.WriteLine("				sqlParmeterCollection.Add(\"@{0}\", SqlDbType.Int).Value		=this.{1}{2};",dt.Rows[0]["column_name"].ToString(),"_s",dt.Rows[0]["column_name"].ToString());

			}
			else
			{
				sw.WriteLine("				sqlParmeterCollection.Add(\"@{0}\", SqlDbType.Int).Value		=this.{1}{2};",dt.Rows[0]["column_name"].ToString(),"_n",dt.Rows[0]["column_name"].ToString());
			}
			sw.WriteLine("		}");
			sw.Write("\n");



			//得到一条数据库记录
			sw.WriteLine("\t\t/// <summary> ");
			sw.WriteLine("\t\t///  得到一条数据库记录");
			sw.WriteLine("\t\t/// </summary>");
			sw.WriteLine("\t\t/// <param name=\"dataRowCollection\">行集合</param>");
			sw.WriteLine("\t\t/// <param name=\"i\">行号</param>");

			sw.WriteLine("		public override void SetSelectResult(DataRowCollection dataRowCollection, int i)");
			sw.WriteLine("		{");
			
			for(int i4=0;i4<dt.Rows.Count;i4++)
			{
				int err = 0;
				SqlDbType sqlType = new SqlDbType();
				err = Getparam(dt.Rows[i4]["type_name"].ToString().ToUpper(),out sqlType);
				if( err == -1)
				{
					MessageBox.Show("发生类型转换错误","错误",MessageBoxButtons.OK);
				}
				else
				{
					type = ChangeToCSharpType(sqlType.ToString().ToLower());
				}

				if( type == "string" || type == "text" || type == "strings")
				{
					type	= "GetDBString";
				}
				else if( type == "int" )
				{
					type	= "GetDBInt";
				}
				else if( type == "DateTime")
				{
					type	=	"GetDBDateTime";
				}
				else if( type == "decimal")
				{
					type	=	"GetDBDecimal";
				}
//				else if(dt.Rows[i4]["type_name"].ToString().ToUpper() == "INT IDENTITY")
//				{
//					type	=	"GetDBInt";
//				}
				else
				{
					type	=	"手动修改";
				}
				if( type == "GetDBString" )
				{
					sw.WriteLine("			this.{0}{1}\t\t= this." + type + "(dataRowCollection[i], \"{2}\");","_s",dt.Rows[i4]["column_name"].ToString(),dt.Rows[i4]["column_name"].ToString());
				}
				else if( type == "GetDBInt" )
				{
					sw.WriteLine("			this.{0}{1}\t\t= this." + type + "(dataRowCollection[i], \"{2}\");","_n",dt.Rows[i4]["column_name"].ToString(),dt.Rows[i4]["column_name"].ToString());
				}
				else if( type == "GetDBDateTime" )
				{
					sw.WriteLine("			this.{0}{1}\t\t= this." + type + "(dataRowCollection[i], \"{2}\");","_dt",dt.Rows[i4]["column_name"].ToString(),dt.Rows[i4]["column_name"].ToString());
				}
				else if( type == "GetDBDecimal" )
				{
					sw.WriteLine("			this.{0}{1}\t\t= this." + type + "(dataRowCollection[i], \"{2}\");","_d",dt.Rows[i4]["column_name"].ToString(),dt.Rows[i4]["column_name"].ToString());
				}
				else
				{
					sw.WriteLine("			this.{0}{1}\t\t= this." + type + "(dataRowCollection[i], \"{2}\");","_",dt.Rows[i4]["column_name"].ToString(),dt.Rows[i4]["column_name"].ToString());
				}
			}
			sw.WriteLine("		}");
			sw.Write("\n");
			sw.WriteLine("\t\t#endregion");

			//			sw.WriteLine("			///btnSave_Click");
			//			sw.WriteLine("			{");
			//			for(int i5=0;i5<dt.Rows.Count;i5++)
			//			{
			//				if(dt.Rows[i5]["type_name"].ToString() == "NVARCHAR")
			//				{
			//					type	= "string";
			//				}
			//				else
			//				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -