请求前辈指点代码规范

sean_zhou 2010-03-03 09:59:25
using System;
using System.Collections.Generic;
using System.Text;
using Common;

//email用到的命名空间

using System.Collections;
using System.Net.Mail;
using System.Net;
using System.Net.Mime;
using System.Text.RegularExpressions;
using System.Diagnostics;



namespace SendMail
{
class SendMail
{
public SendMail()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public void DoSent(string AddressName, string email_s,string email_s_pass, StringBuilder sbLog, StringBuilder sbLogError, string total, string docu, string filepath)
{
string email_r = "";
email_r = conn.ExecSqlNonQuery("SELECT TOP 1 EMAIL FROM SYSUSER WHERE NAME = '" + AddressName + "'");
send(AddressName, email_r, email_s, email_s_pass, sbLogError, sbLog, total, docu, filepath);
}



private void send(string AddressName, string email_r, string email_s, string email_s_pass, StringBuilder sbLogError, StringBuilder sbLog, string total, string docu, string filepath)
{
string smtp_service = "****.*****.com"; //需要根据不同公司设定。发件人的smtp值。

if (IsEmail(email_r) == false)
{
sbLogError.Append("收件人" + AddressName + "邮件格式不对!");
return;
}

if (IsEmail(email_s) == false)
{
sbLogError.Append("发件人邮件格式不对!");
return;
}

CreateMessageWithAttachment(smtp_service, AddressName, email_r, email_s, email_s_pass, total, docu, filepath, sbLogError, sbLog);

}


//发邮件
private void CreateMessageWithAttachment(string server, string AddressName, string email_r, string email_s, string email_s_pass,string total, string docu, string filepath, StringBuilder sbLogError, StringBuilder sbLog)
{
// Specify the file to be attached and sent.
// This example assumes that a file named Data.xls exists in the
// current working directory.
Attachment data = new Attachment(filepath, MediaTypeNames.Application.Octet);
try
{
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
email_s,//发件人
email_r,//收件人
total,//主题
docu //内容
);

// Create the file attachment for this e-mail message.
message.Attachments.Add(data);

SmtpClient client = new SmtpClient(server);
// Add credentials if the SMTP server requires them.
client.Credentials = new System.Net.NetworkCredential(email_s, email_s_pass);//用户名和密码
client.Send(message);
sbLog.Append("发送邮件至" + AddressName + "成功" + "\r\n");
}
catch
{
sbLogError.Append("发送邮件至" + AddressName + "失败" + "\r\n");
}
finally
{
data.Dispose();
}
}




//判断输出邮件地址格式
private static bool IsEmail(string Str)
{
return Regex.IsMatch(Str, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
}
}
}


上面是我写的一段代码,发送email的,同事都很忙没空帮我看,我也写这个快一年了,没人指点我代码的规范,我自己总觉得自己写的代码没人家写的美,自己也不知道如何改,请大伙帮我看看,分数就剩这么多了,不好意思,
...全文
142 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sean_zhou 2010-03-04
  • 打赏
  • 举报
回复
谢谢这位兄弟,我会把这个都改为匈牙利命名法的。其他朋友有建议也帮忙多提提,谢谢。
引用 6 楼 wodegege10 的回复:
private void CreateMessageWithAttachment(string server, string AddressName, string email_r, string email_s, string email_s_pass,string total, string docu, string filepath, StringBuilder sbLogError, StringBuilder sbLog)
若是没弄错的话
使用了PASSCAL命名法,还有匈牙利命名法,还有linux下面的习惯。
LZ博采众长呀。。。
onlylove_meng 2010-03-03
  • 打赏
  • 举报
回复
初学时,对规范是很重要的
继续努力
wenbin 2010-03-03
  • 打赏
  • 举报
回复
private void CreateMessageWithAttachment(string server, string AddressName, string email_r, string email_s, string email_s_pass,string total, string docu, string filepath, StringBuilder sbLogError, StringBuilder sbLog)
若是没弄错的话
使用了PASSCAL命名法,还有匈牙利命名法,还有linux下面的习惯。

LZ博采众长呀。。。

cja03 2010-03-03
  • 打赏
  • 举报
回复
1.参考MSDN的《.net类库设计准则》
2.使用Microsoft FXCop工具或CodStyle(可能拼写错误)工具,前者针对项目,对dll,exe进行检则,后者是vs的一个插件,可随时对项目,类进行检则
sean_zhou 2010-03-03
  • 打赏
  • 举报
回复


using System;
using System.Collections.Generic;
using System.Text;
using Common;

//email用到的命名空间

using System.Collections;
using System.Net.Mail;
using System.Net;
using System.Net.Mime;
using System.Text.RegularExpressions;
using System.Diagnostics;


namespace SendMail
{
class SendMail
{
public SendMail()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public void DoSent(string AddressName, string email_s,string email_s_pass, StringBuilder sbLog, StringBuilder sbLogError, string total, string docu, string filepath)
{
string email_r = "";
email_r = conn.ExecSqlNonQuery("SELECT TOP 1 EMAIL FROM SYSUSER WHERE NAME = '" + AddressName + "'");
send(AddressName, email_r, email_s, email_s_pass, sbLogError, sbLog, total, docu, filepath);
}


private void send(string AddressName, string email_r, string email_s, string email_s_pass, StringBuilder sbLogError, StringBuilder sbLog, string total, string docu, string filepath)
{
string smtp_service = "****.*****.com"; //需要根据不同公司设定。发件人的smtp值。

if (IsEmail(email_r) == false)
{
sbLogError.Append("收件人" + AddressName + "邮件格式不对!");
return;
}

if (IsEmail(email_s) == false)
{
sbLogError.Append("发件人邮件格式不对!");
return;
}

CreateMessageWithAttachment(smtp_service, AddressName, email_r, email_s, email_s_pass, total, docu, filepath, sbLogError, sbLog);

}


//发邮件
private void CreateMessageWithAttachment(string server, string AddressName, string email_r, string email_s, string email_s_pass,string total, string docu, string filepath, StringBuilder sbLogError, StringBuilder sbLog)
{
// Specify the file to be attached and sent.
// This example assumes that a file named Data.xls exists in the
// current working directory.
Attachment data = new Attachment(filepath, MediaTypeNames.Application.Octet);
try
{
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
email_s,//发件人
email_r,//收件人
total,//主题
docu //内容
);

// Create the file attachment for this e-mail message.
message.Attachments.Add(data);

SmtpClient client = new SmtpClient(server);
// Add credentials if the SMTP server requires them.
client.Credentials = new System.Net.NetworkCredential(email_s, email_s_pass);//用户名和密码
client.Send(message);
sbLog.Append("发送邮件至" + AddressName + "成功" + "\r\n");
}
catch
{
sbLogError.Append("发送邮件至" + AddressName + "失败" + "\r\n");
}
finally
{
data.Dispose();
}
}


//判断输出邮件地址格式
private static bool IsEmail(string Str)
{
return Regex.IsMatch(Str, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
}
}
}


这样发出来,看的清晰点
sean_zhou 2010-03-03
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Text;
using Common;

//email用到的命名空间

using System.Collections;
using System.Net.Mail;
using System.Net;
using System.Net.Mime;
using System.Text.RegularExpressions;
using System.Diagnostics;


namespace SendMail
{
class SendMail
{
public SendMail()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public void DoSent(string AddressName, string email_s,string email_s_pass, StringBuilder sbLog, StringBuilder sbLogError, string total, string docu, string filepath)
{
string email_r = "";
email_r = conn.ExecSqlNonQuery("SELECT TOP 1 EMAIL FROM SYSUSER WHERE NAME = '" + AddressName + "'");
send(AddressName, email_r, email_s, email_s_pass, sbLogError, sbLog, total, docu, filepath);
}


private void send(string AddressName, string email_r, string email_s, string email_s_pass, StringBuilder sbLogError, StringBuilder sbLog, string total, string docu, string filepath)
{
string smtp_service = "****.*****.com"; //需要根据不同公司设定。发件人的smtp值。

if (IsEmail(email_r) == false)
{
sbLogError.Append("收件人" + AddressName + "邮件格式不对!");
return;
}

if (IsEmail(email_s) == false)
{
sbLogError.Append("发件人邮件格式不对!");
return;
}

CreateMessageWithAttachment(smtp_service, AddressName, email_r, email_s, email_s_pass, total, docu, filepath, sbLogError, sbLog);

}


//发邮件
private void CreateMessageWithAttachment(string server, string AddressName, string email_r, string email_s, string email_s_pass,string total, string docu, string filepath, StringBuilder sbLogError, StringBuilder sbLog)
{
// Specify the file to be attached and sent.
// This example assumes that a file named Data.xls exists in the
// current working directory.
Attachment data = new Attachment(filepath, MediaTypeNames.Application.Octet);
try
{
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
email_s,//发件人
email_r,//收件人
total,//主题
docu //内容
);

// Create the file attachment for this e-mail message.
message.Attachments.Add(data);

SmtpClient client = new SmtpClient(server);
// Add credentials if the SMTP server requires them.
client.Credentials = new System.Net.NetworkCredential(email_s, email_s_pass);//用户名和密码
client.Send(message);
sbLog.Append("发送邮件至" + AddressName + "成功" + "\r\n");
}
catch
{
sbLogError.Append("发送邮件至" + AddressName + "失败" + "\r\n");
}
finally
{
data.Dispose();
}
}


//判断输出邮件地址格式
private static bool IsEmail(string Str)
{
return Regex.IsMatch(Str, @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
}
}
}
PandaIT 2010-03-03
  • 打赏
  • 举报
回复
//code1
public string GetStr(string inputStr,string reutrnstr)
{
}
//code2
public string getStr(string inputStr,string reutrnStr)
{
}
cqq 2010-03-03
  • 打赏
  • 举报
回复
成长过程中的一个阶段, 典型特点就是看着自己的东西总是缺少什么,但是又说不上来,呵呵。

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧