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

Answers for Q1 and Q2的更多相关文章

  1. CS231n -Assignments 1 Q1 and Q2

    前言 最近在youtube 上学习CS231n的课程,并尝试完成Assgnments,收获很多,这里记录下过程和结果以及过程中遇到的问题,我并不是只是完成需要补充的代码段,对于自己不熟悉的没用过的库函 ...

  2. Black Box 分类: POJ 栈和队列 2015-08-05 14:07 2人阅读 评论(0) 收藏

    Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8754 Accepted: 3599 Description ...

  3. 2014北邮新生归来赛解题报告d-e

    D: 399. Who Is Joyful 时间限制 3000 ms 内存限制 65536 KB 题目描述 There are several little buddies standing in a ...

  4. hdu3713 Double Maze

    Problem Description Unlike single maze, double maze requires a common sequence of commands to solve ...

  5. POJ2104 K-th Number [整体二分]

    题目传送门 K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 69053   Accepted: 24 ...

  6. HDU4261 Estimation

    题意 Estimation Time Limit: 40000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  7. POJ 1984 Navigation Nightmare 【经典带权并查集】

    任意门:http://poj.org/problem?id=1984 Navigation Nightmare Time Limit: 2000MS   Memory Limit: 30000K To ...

  8. POJ2104 K-th Number —— 区间第k小 整体二分

    题目链接:https://vjudge.net/problem/POJ-2104 K-th Number Time Limit: 20000MS   Memory Limit: 65536K Tota ...

  9. Spark MLlib LDA 源代码解析

    1.Spark MLlib LDA源代码解析 http://blog.csdn.net/sunbow0 Spark MLlib LDA 应该算是比較难理解的,当中涉及到大量的概率与统计的相关知识,并且 ...

随机推荐

  1. c++输出左右对齐设置

    #include<iostream> int main(){ using std::cout; cout.setf(std::ios::left); int w = cout.width( ...

  2. 使用Esxi虚拟化部署OpenWrt/HomeLede+扩容硬盘 保姆级教程

    本文介绍使用VMware虚拟化平台部署OpenWrt/HomeLede,并扩容固件硬盘的方法. 推荐使用虚拟化方式部署软路由,理由如下: 部署.升级.回退.扩容等操作非常方便,特别适合折腾 可以方便的 ...

  3. C#后台实现在Grid标签中动态新增CheckBox标签(WPF中)

    页面代码 <Grid Margin="45,0,10,0" > <Grid.RowDefinitions> <RowDefinition Height ...

  4. 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用

    一.什么是 RestTemplate? RestTemplate是执行HTTP请求的同步阻塞式的客户端,它在HTTP客户端库(例如JDK HttpURLConnection,Apache HttpCo ...

  5. 【BZOJ4318】OSU! 题解(期望)

    题目链接 题目大意:给定$n$个操作的成功率$p[i]$.连续成功操作$m$次可以贡献$m^3$的分数.问期望分数. 对于$(x+1)^3$ $=x^3+3x^2+3x+1$ 每多连续成功一次,对答案 ...

  6. linux下的node版本管理利器:nvm

    nvm是一款node版本管理工具,简单来说,如果你想在一个环境下安装多个node版本,并向自由地切换相关版本,那你就需要使用nvm进行版本管理,有点类似pyenv,也是一款python版本管理工具. ...

  7. c语言学习笔记之结构体存储

    今天讲讲结构体存储问题 首先,结构体简单说是对不同类型的封装,一开始我们可能会想结构体在内存中的存储的大小是直接元素的和 例如 我们可能会觉得是 结构体大小=int(4个字节)+ short(2个字节 ...

  8. QT下UDP套接字通信——QUdpSocket 简单使用

    QT下UDP套接字通信--QUdpSocket QUdpSocket类提供一个UDP套接字. UDP(用户数据报协议)是一种轻量级.不可靠.面向数据报.无连接的协议.它可以在可靠性不重要的情况下使用. ...

  9. CSS变化、过渡与动画

    CSS变换用于在空间中移动物体,而CSS过渡和CSS关键帧动画用于控制元素随时间推移的变化. 变换.过渡和关键帧动画的规范仍然在制定中.尽管如此,其中大多数特性已经在常用浏览器中实现了. 1.二维变换 ...

  10. JDBC工具类—如何封装JDBC

    “获得数据库连接”操作,将在以后的增删改查所有功能中都存在,可以封装工具类JDBCUtils.提供获取连接对象的方法,从而达到代码的重复利用. 该工具类提供方法:public static Conne ...