A1:

1. enetity-data model mapping:

2. database design

2.1  sql

create table A_manufacturer_info(
manu_id int primary key identity(1,1) not null,
manu_code char(8) not null,--manufacturer code
manu_name nvarchar(50) not null,--manufacturer name
manu_logo varchar(100)--manufacturer logo URL
);
insert into A_manufacturer_info values('mfc00000','mfc000en','http://0');
insert into A_manufacturer_info values('mfc00001','mfc001en','http://1');
insert into A_manufacturer_info values('mfc00002','mfc002en','http://2');

create table A_product_category(
category_id smallint primary key not null,
category_name varchar(20) not null,
category_code varchar(10) not null,
parent_id smallint default 0 not null,
category_level tinyint default 1 not null--level/ optional field,default three grade classifications
);
insert into A_product_category values(1,'products','0000','',0);
insert into A_product_category values(2,'books','0001',1,1);
insert into A_product_category values(3,'software ','0002',1,1);
insert into A_product_category values(4,'philosophy','0003',2,2);
insert into A_product_category values(5,'literature ','0004',2,2);
insert into A_product_category values(6,'utilities','0005',3,2)
insert into A_product_category values(7,'confucianism','0006',4,3)

create table A_product_info(
pro_id int primary key identity(1,1) not null,
pro_code char(16) not null,
pro_name nvarchar(30),--en
price decimal(18,3),
description nvarchar(50),
manu_id int not null foreign key references A_manufacturer_info(manu_id),
one_category_id smallint not null,--one level category id / optional field
two_category_id smallint not null,-- optional field
thr_category_id smallint not null-- optional field
);
insert into A_product_info values('pro0','metaphysics',45.97,'metaphysics',1,2,4,0);
insert into A_product_info values('pro1','mencius',45.47,'mencius',1,2,4,7);
insert into A_product_info values('pro2','lin_yutang',65.9,'lin yutang',2,2,5,0);
insert into A_product_info values('pro3','file_management',542.5,'file management',3,3,6,0);

2.2 table view

A_product_category:

A_product_info:

A_manufacturer_info

3.retrieve all n-level category products recursively

3.1 sql

WITH TEST_CTE
AS
(
select category_name , parent_id ,category_id,Cast(category_id as nvarchar(4000)) as route, Cast(category_name as nvarchar(4000)) as path from A_product_category where A_product_category.parent_id=1
union all
select t.category_name ,t.parent_id , t.category_id ,CTE.route+'-'+Cast(t.category_id as nvarchar(4000)) ROUTE,CTE.path+'-'+Cast(t.category_name as nvarchar(4000)) PATH
from A_product_category t join TEST_CTE CTE on t.parent_id = CTE.category_id

)
SELECT t.path ,p.pro_name FROM TEST_CTE t join A_product_info p on p.two_category_id=category_id where p.one_category_id=2 and p.thr_category_id=0 --two level category
union SELECT t.path ,p.pro_name FROM TEST_CTE t join A_product_info p on p.thr_category_id=category_id --three level category
union SELECT t.path ,p.pro_name FROM TEST_CTE t join A_product_info p on p.two_category_id=category_id where p.one_category_id=3 and p.thr_category_id=0
--order by t.parent_id desc,t.category_id
OPTION(MAXRECURSION 10)

3.2 result view

A2:

1. demo:

<form id="form1" runat="server">
<div>
<br />
User: <asp:TextBox ID="TextBox1" value="johnsmith" style="width: 192px" runat="server"></asp:TextBox>
<br />
<br />
Message: <textarea id="TextArea1" runat="server"></textarea>
<asp:Button ID="Button3" runat="server" Text="contact us" OnClick="Button3_Click" />
</div>
</form>

 2.code-behind implementation:

public class MailInput
{
public MailInput()
{
}
public string MailFrom;
public string MailTo;
public string MailName;
public string MailCc;
public string MailSubject;//邮件主题
public string MailBody;//邮件内容
public string Link;
public string MailAppId;
public string MailBCC;
// public string lang;
// public string MailToName;

}

protected void Button3_Click(object sender, EventArgs e)
{
MailInput mailInput = new MailInput();
mailInput.MailTo = "wh.lu@asmpt.com";
mailInput.MailName = "Dear HR";
mailInput.MailFrom = TextBox1.Text.ToLower().ToString().Trim()+"@reasonables.com";
bool flag = false;
mailInput.MailSubject = "Test for Net.Mail";
mailInput.MailBody = "<font face=Arial size=2><br>" + mailInput.MailName + ":<br><br>"
+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + TextArea1.InnerText + "<br><br>" + "Best Regards," + "<br><br>"
+ TextBox1.Text.ToString();
SendEmailWS.SendEmailWS s= new SendEmailWS.SendEmailWS();
List<string[]> header = new List<string[]> { new string[] { "h1", "any_header"} };
s.Send_Email_Header(header, mailInput.MailFrom, mailInput.MailTo, mailInput.MailCc, mailInput.MailBCC, mailInput.MailSubject, mailInput.MailBody, 1, true, "10008499", "ReworkOperationSystem");

}

public string[] Send_Email_Header(List<String[]> mail_header, string mail_from, string mail_to, string mail_cc, string mail_bcc, string mail_subj, string mail_body, int priority, bool IsLogBody, string strRequester, string strAppName)
{
IDictionary<string, string> header = null;
if (mail_header != null)
{
header = new Dictionary<string, string>();
foreach (string[] temp in mail_header)
{
header.Add(temp[0], temp[1]);
}
}
return SendEmail(header, mail_from, mail_to, mail_cc, mail_bcc, mail_subj, mail_body, priority, IsLogBody, null, strRequester, strAppName);

}

private string[] SendEmail(IDictionary<string, string> mail_header, string mail_from, string mail_to, string mail_cc, string mail_bcc, string mail_subj, string mail_body, int priority, bool IsLogBody, ISet<string> att_path, string strRequester, string strAppName)
{
string[] ret_msg = new string[2];
ret_msg[0] = "S";
IsEmailTest(ref mail_from, ref mail_to, ref mail_cc, ref mail_bcc, ref mail_body);
if (string.IsNullOrWhiteSpace(strRequester))
{
ret_msg[0] = "E";
ret_msg[1] = "Requester is required";
return ret_msg;
}
if (string.IsNullOrWhiteSpace(strAppName))
{
ret_msg[0] = "E";
ret_msg[1] = "Application name is required";
return ret_msg;
}
/*
if (!WebService1.SecurityHandler.IsAuthRight(GetHostName(Context.Request.UserHostName), strAppName.Trim()))
{
ret_msg[0] = "E";
ret_msg[1] = "Access denied: " + GetHostName(Context.Request.UserHostName) + " app:" + strAppName;
WriteLog(mail_from, mail_to, mail_subj, mail_body, strRequester, strAppName, IsLogBody, ret_msg[1].ToString());
SendAdmin(strAppName);
//return ret_msg;
}*/
try
{

System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
if (string.IsNullOrWhiteSpace(mail_from))
{
mail_from = ConfigurationManager.AppSettings["mailFrom"];
}
else
{
mail_from = mail_from.Trim(new char[] { ',', ' ', ';' });
}
string fromnames = "Jhon Smith";
MailAddress from = new MailAddress(mail_from, fromnames);//邮件来源地址。
mailMessage.From = from;
if (mail_to == null)
{
ret_msg[0] = "E";
ret_msg[1] = "Mail to is required";
return ret_msg;
}
else
{
mail_to = mail_to.Replace(';', ',').Trim(new char[] { ',', ' ' });
if (string.IsNullOrEmpty(mail_to))
{
ret_msg[0] = "E";
ret_msg[1] = "Mail to is required";
return ret_msg;
}
}
mailMessage.To.Add(mail_to);
if (mail_header != null)
{
foreach (KeyValuePair<string, string> temp in mail_header)
{
mailMessage.Headers.Add(temp.Key, temp.Value);
}
}
if (mail_cc != null)
{
mail_cc = mail_cc.Replace(';', ',').Trim(new char[] { ',', ' ' });
if (!string.IsNullOrEmpty(mail_cc))
{
mailMessage.CC.Add(mail_cc);
}
}
if (mail_bcc != null)
{
mail_bcc = mail_bcc.Replace(';', ',').Trim(new char[] { ',', ' ' });
if (!string.IsNullOrEmpty(mail_bcc))
{
mailMessage.Bcc.Add(mail_bcc);
}
}
mailMessage.Subject = mail_subj;
mailMessage.Body = mail_body;
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
switch (priority)
{
case 0: mailMessage.Priority = System.Net.Mail.MailPriority.Low;
break;
case 1: mailMessage.Priority = System.Net.Mail.MailPriority.Normal;
break;
case 2: mailMessage.Priority = System.Net.Mail.MailPriority.High;
break;
default: mailMessage.Priority = System.Net.Mail.MailPriority.Normal;
break;
}
if (att_path != null)
{
foreach (string temp in att_path)
{
mailMessage.Attachments.Add(new System.Net.Mail.Attachment(temp));
}

}
mailMessage.Sender = new MailAddress("web@reasonables.com");
//初始化 SmtpClient 类的新实例。
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
mailClient.Host = "127.0.0.1";//ConfigurationManager.AppSettings["mailSvr"];
mailClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis;
mailClient.Send(mailMessage);
//mailMessage.Attachments.Dispose(); //一定要释放该对象,否则无法删除附件
//WriteLog(mail_from, mail_to, mail_subj, mail_body, strRequester, strAppName, IsLogBody);

#region

//alternative way

//System.Web.Mail.MailMessage mailmsg = new System.Web.Mail.MailMessage();
//mailmsg.Subject = "Test for Web.Mail"; mailmsg.From = ConfigurationManager.AppSettings["mailFrom"];
//mailmsg.To = "wh.lu@asmpt.com";
//mailmsg.BodyFormat = System.Web.Mail.MailFormat.Html;
//mailmsg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
//mailmsg.Body = "anybody";
//System.Web.Mail.SmtpMail.SmtpServer = "127.0.0.1";
//System.Web.Mail.SmtpMail.Send(mailmsg);

#endregion
}
catch (Exception ex)
{
ret_msg[0] = "E";
ret_msg[1] = ex.ToString();
//WriteExceptionLog(ex, mail_from, mail_to, mail_subj, mail_body, strRequester, strAppName, IsLogBody);
}
return ret_msg;
}

3. result 

3.1  email content format:

3.2  email header:

Received: from ******.com (*.1*.1.*0) by
*****.com (1*.1.*0) with Microsoft SMTP Server id
1*.3.*68.0; Mon, 24 Aug 2020 21:32:30 +0800
Received: from mail pickup service by *****.com with Microsoft
SMTPSVC; Mon, 24 Aug 2020 21:32:30 +0800
h1: any_header
MIME-Version: 1.0
Sender: <web@reasonables.com>
From: Jhon Smith <smith@reasonables.com>
To: <wh.lu@**.com>
Date: Mon, 24 Aug 2020 21:32:29 +0800
Subject: Test for Net.Mail
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
Message-ID: <****5t8NlqD000038df@*****.com>
X-OriginalArrivalTime: 24 Aug 2020 13:32:30.0078 (UTC) FILETIME=[**91E0:01D***B]
Return-Path: web@reasonables.com
X-MS-Exchange-Organization-AuthSource: ****.com
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 10
X-MS-Exchange-Organization-AVStamp-Mailbox: SMEX{~Ks;1618300;0;This mail has
been scanned by Trend Micro ScanMail for Microsoft Exchange;
X-MS-Exchange-Organization-SCL: 0

最新文章

  1. struts2中各个jar包作用
  2. 《The Elder Scrolls V: Skyrim》百般冷门却强力职业
  3. linux网络协议
  4. Android中的dispatchTouchEvent()、onInterceptTouchEvent()和onTouchEvent()
  5. AndroidStudio Lod.d在LogCat中不输出
  6. [新概念51单片机C语言教程&#183;郭天祥] 1、 基础知识必备
  7. [WinAPI] API 11 [创建目录]
  8. WPF ListView 选中问题
  9. linux useradd(adduser)命令参数及用法详解(linux创建新用户命令)
  10. dig out secrets beneath AirSig
  11. app打包流程
  12. 常用html演示模板
  13. fadein()
  14. ubuntu14.04下交叉编译器的安装
  15. Get RSA public key ASN.1 encode from a certificate in DER format
  16. 【收集】sql查询统计,周,月,年
  17. ngix_http_stub_status_module
  18. StackExchange.Redis .net core Timeout performing 超时问题
  19. Linux 下安装nodejs
  20. 内核里面writel(readl)是如何实现的

热门文章

  1. Python访问、修改、删除字典中的值
  2. Django学习路7_注册app到能够在页面上显示app网页内容
  3. Flutter中的绘图(Canvas&amp;CustomPaint)API
  4. PHP gmmktime() 函数
  5. PDOStatement::setFetchMode
  6. OKHttp 官方文档【一】
  7. Dynamics 2016 启用Bing Maps
  8. 面试题:JVM 堆内存溢出后,其他线程是否可继续工作?
  9. Spring学习总结(1)-注入方式
  10. 漫画 | 到底是什么让IT人如此苦逼???