Answers for Q1 and Q2
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>"
+ " " + 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的更多相关文章
- CS231n -Assignments 1 Q1 and Q2
前言 最近在youtube 上学习CS231n的课程,并尝试完成Assgnments,收获很多,这里记录下过程和结果以及过程中遇到的问题,我并不是只是完成需要补充的代码段,对于自己不熟悉的没用过的库函 ...
- Black Box 分类: POJ 栈和队列 2015-08-05 14:07 2人阅读 评论(0) 收藏
Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8754 Accepted: 3599 Description ...
- 2014北邮新生归来赛解题报告d-e
D: 399. Who Is Joyful 时间限制 3000 ms 内存限制 65536 KB 题目描述 There are several little buddies standing in a ...
- hdu3713 Double Maze
Problem Description Unlike single maze, double maze requires a common sequence of commands to solve ...
- POJ2104 K-th Number [整体二分]
题目传送门 K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 69053 Accepted: 24 ...
- HDU4261 Estimation
题意 Estimation Time Limit: 40000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- POJ 1984 Navigation Nightmare 【经典带权并查集】
任意门:http://poj.org/problem?id=1984 Navigation Nightmare Time Limit: 2000MS Memory Limit: 30000K To ...
- POJ2104 K-th Number —— 区间第k小 整体二分
题目链接:https://vjudge.net/problem/POJ-2104 K-th Number Time Limit: 20000MS Memory Limit: 65536K Tota ...
- Spark MLlib LDA 源代码解析
1.Spark MLlib LDA源代码解析 http://blog.csdn.net/sunbow0 Spark MLlib LDA 应该算是比較难理解的,当中涉及到大量的概率与统计的相关知识,并且 ...
随机推荐
- == 和 is 的区别
import copy a = ['a','b','c'] b = a #b和a引用自同一块地址空间 print("a==b :",a==b) print("a is b ...
- PHP 函数实例讲解
PHP 函数 PHP 的真正威力源自于它的函数. 在 PHP 中,提供了超过 1000 个内建的函数. PHP 内建函数 如需查看所有数组函数的完整参考手册和实例,请访问我们的 PHP 参考手册. P ...
- Python File close() 方法
概述 close() 方法用于关闭一个已打开的文件.高佣联盟 www.cgewang.com 关闭后的文件不能再进行读写操作, 否则会触发 ValueError 错误. close() 方法允许调用多 ...
- 一些Tips
https://www.cnblogs.com/yeungchie/ 1. 快捷键e,有个EnableDimming选项,勾选后只会高亮你所选中的器件连线等等,其他器件亮度会下降,和mark不同,有利 ...
- CF R 635 div2 1337D Xenia and Colorful Gems 贪心 二分 双指针
LINK:Xenia and Colorful Gems 考试的时候没想到一个很好的做法. 赛后也有一个想法. 可以考虑答案的样子 x,y,z 可以发现 一共有 x<=y<=z,z< ...
- 【问题记录】springMVC @Valid使用不生效问题
问题描述 在网上找到如何使用@Valid注解后,就把用到的配置和jar包加上,然后测试发现一直不生效.下面是配置及解决方法 配置 1.引入依赖 2.添加相应的配置(springmvc配置文件) < ...
- PV与UV你的网站也可以
个人博客网站分析 阅读前面的文章,有助于理解本文. 1.是时候来一个个人博客网站了 2.什么?你还没有自己的域名? 3.你的个人博客网站该上线了! 为什么需要流量分析? 各位小伙伴,请看下图,你们发现 ...
- LeetCode(1)---检查括号出现的合法性
题目: 检查字符串中"( )","[ ]","{ }" 的合法性,即是否成对出现 eg,如出现"[()]", ...
- Nginx的基本使用和配置
2.1什么是Nginx Nginx 是一款高性能的 http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师伊戈尔·西索夫(Igor Sysoev)所开发,官方 ...
- “随手记”开发记录day20
练习软件的展示,尽量将软件全方面的展示给大众,希望不要像上次一样有许多遗漏的地方,让其他团队以为我们的软件没有完善的功能.