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. Python os.tcgetpgrp() 方法

    概述 os.tcgetpgrp() 方法用于回与终端fd(一个由os.open()返回的打开的文件描述符)关联的进程组.高佣联盟 www.cgewang.com 语法 tcgetpgrp()方法语法格 ...

  2. PHP MySQL Delete删除数据库中的数据

    PHP MySQL Delete DELETE 语句用于从数据库表中删除行. 删除数据库中的数据 DELETE FROM 语句用于从数据库表中删除记录. 语法 DELETE FROM table_na ...

  3. PHP array_multisort() 函数

    实例 返回一个升序排列的数组: <?php$a=array("Dog","Cat","Horse","Bear", ...

  4. PHP mt_rand() 函数

    实例 生成随机数: <?phpecho(mt_rand() . "<br>");echo(mt_rand() . "<br>"); ...

  5. luogu P3645 [APIO2015]雅加达的摩天楼 分块 根号分治

    LINK:雅加达的摩天楼 容易想到设\(f_{i,j}\)表示第i个\(doge\)在第j层楼的最小步数. 转移显然是bfs.值得一提的是把初始某层的\(doge\)加入队列 然后转移边权全为1不需要 ...

  6. AGC 043 C - Giant Graph SG函数 dp 贪心

    LINK:Giant Graph 神仙题目. 容易发现在图中选择某个点的贡献为\(10^{18\cdot(x+y+z)}\) 这等价于多选一个点多大一点就多乘了一个\(10^{18}\) 所以显然是贪 ...

  7. idea安装testng插件后,无法使用调用testng里面的类

    1.已经安装好idea的testng插件,并且应用上相关的两个插件. 2.已经导入maven仓库的testng.jar,并且重启过idea后:发现不能调用. 本人在百度很多相关资料,始终没有找到解决方 ...

  8. CI4框架应用二 - 项目目录

    我们之前搭建好了CI4的开发环境,下面我们来看一下CI4的目录结构. Administrator@PC- MINGW64 /c/wamp64/www/ci4 $ ls -l total drwxr-x ...

  9. JVM系列之:从汇编角度分析Volatile

    目录 简介 重排序 写的内存屏障 非lock和LazySet 读的性能 总结 简介 Volatile关键字对熟悉java多线程的朋友来说,应该很熟悉了.Volatile是JMM(Java Memory ...

  10. Java中增强一个类的几种方法

    今天有人问我怎么增强一个类的功能.博客刚好没东西,今天就讲讲增强类. 增强的手段有三种类型: 1.继承或者实现接口:特点是被增强对象不能变,增强的内容不能变. 2.装饰着模式:特点是被增强对象可变,但 ...