被划航天工业学院计算机科学与工程系 B07513 班
{
string className = txtName.Text.Trim();//获取类名
string classRemarks = txtRemarks.Text.Trim();//获取类说明
if (className.Length == 0)
{
MessageBox.Show("类名不能为空!");
return;
}
sfdFile.FileName = className;
if (sfdFile.ShowDialog() == DialogResult.OK)
{
//写入内容
writeFile(className, classRemarks);
MessageBox.Show("实体类创建成功!");
}
}
/// <summary>
/// 创建相对应的.NET实体类
/// </summary>
/// <param name="className">类名</param>
/// <param name="classRemarks">类说明</param>
private void writeFile(string className, string classRemarks)
{
//创建文件流
FileStream fs = new FileStream(sfdFile.FileName, FileMode.Create,
FileAccess.Write);
//创建写入流
StreamWriter sw = new StreamWriter(fs, Encoding.Default);//用户编码设为默认
//写入内容
sw.WriteLine("/*");
sw.WriteLine(" * 作者:孙永刚");
sw.WriteLine(" * 创建时间:" + DateTime.Now.ToString());
if (classRemarks.Length != 0)
{
sw.WriteLine(" * 类说明:" + classRemarks);
}
sw.WriteLine(" */");
if (radYou.Checked && txtNameSpace.Text.Trim() != null&&radYou.Checked &&
txtNameSpace.Text.Trim() != "")
{
sw.WriteLine("namespace " + txtNameSpace.Text.Trim());
sw.WriteLine("{");
}
if (classRemarks.Length != 0)
{
sw.WriteLine(" /// <summary>");
sw.WriteLine(" ///" + classRemarks);
sw.WriteLine(" /// </summary>");
}
sw.WriteLine(" public class " + className);
sw.WriteLine(" {");
foreach (DataGridViewRow row in dgvContent.Rows)
{
if (row.Cells[0].Value != null && row.Cells[1].Value != null)
{
string propName = row.Cells[0].Value.ToString();//获取属性名
string functionName = getFullName(ref propName);
评论1