<!--#include file="userCheck.asp"-->
<!--#include file="conn.asp"-->
<!--#include file="inc/exportPinPai.asp"-->
<%
carId          = request.form("carId")				'不为空则表示修改，否则为添加
sell_name      = trim(request.form("sell_name"))
tel            = trim(request.form("tel"))
addr           = trim(request.form("addr"))
memberPrice    = trim(request.form("memberPrice"))
carYear        = trim(request.form("caryear"))
marketPrice    = request.form("marketPrice")
if marketPrice = "" then marketPrice = 0

dim img(4)
img(0) = trim(request.form("smallimg"))
img(1) = trim(request.form("smallimg2"))
img(2) = trim(request.form("smallimg3"))
img(3) = trim(request.form("smallimg4"))
img(4) = trim(request.form("smallimg5"))

'===============================================================================================
'检查必要字段
if sell_name = "" or tel = "" or addr = "" or caryear = "" or memberPrice = "" then call wrong("姓名、联系电话、地址、年限、出售价必须正确填写！")
if instr(memberPrice,",") > 0 or isnumeric(memberPrice) = false  then call wrong("您输入的出售价格有误，请检查！")
if isnumeric(memberPrice) = true and memberPrice < 100 then call wrong("您输入的价格过低，请检查！")

If instr(Request.Form("email"),".")=0 or instr(Request.Form("email"),"@")=0 or instr(Request.Form("email"),"@")=1 or instr(Request.Form("email"),"@")=len(email) then 
Response.Write "<script language=javascript>alert('电子信箱格式填写不正确！');javascript:history.back();</script>" 
Response.End 
End If


dim dates(4), idPath, ifXiuGai

ifXiuGai         = request.Form("ifXiuGai")				'是否修改
oldSortPath      = request.Form("oldSortPath")			'老的品牌路径
dates(0)         = request.Form("s1")					'国产还是进口
dates(1)         = request.Form("s2")					'厂家
dates(2)         = request.Form("s3")					'品牌
dates(3)         = request.Form("s4")					'型号

ifXiuGaiShengShi = request.Form("ifXiuGaiShengShi")	    '是否修改省市
oldSheng         = request.Form("oldSheng")				'老的省份
oldShi           = request.Form("oldShi")				'老的市
newSheng         = request.form("province")				'新的省份
newShi           = request.form("city")					'新的城市

if carId = "" then	   '如果是添加
	i = 0         '验证品牌型号
	for i = 0 to 3
		if dates(i) = "" then
			call wrong("请填写完整品牌和型号！")
		end if
	next
	idPath   = dates(0)&","&dates(1)&","&dates(2)&","&dates(3)
	
	'验证省份城市
	if newSheng = "" then call wrong("请选择省份名称！")
	if newShi   = "" then call wrong("请选择城市名称！")
	

else        '如果是修改

	if ifXiuGai = "1" then			'如果选中了修改按钮
		i = 0
		
		for i = 0 to 3
			if dates(i) = "" then
				call wrong("请填写完整品牌和型号！")
			end if
		next
		
			idPath   = dates(0)&","&dates(1)&","&dates(2)&","&dates(3)
	else							               '否则用旧的品牌路径
		idPath   = oldSortPath
	end if


	if ifXiuGaiShengShi = "1" then					'如果选中了修改按钮
		if newSheng = "" then call wrong("请选择省份名称！")
		if newShi   = "" then call wrong("请选择城市名称！")
	else											'否则用旧的省市
		newSheng    = oldSheng
		newShi      = oldShi
	end if

end if
'================================================================================================


dim sql
Set InsertCursor = Server.CreateObject("ADODB.Recordset")

if carId <> "" then		                            	'如果是修改
	InsertCursor.Open "SELECT top 1 * FROM product where id = "& carId &"",conn,1,3
else
	InsertCursor.Open "SELECT top 1 * FROM product order by id desc",conn,1,3
	InsertCursor.addnew
end if

InsertCursor("bianhao")     = getBianhao(now())
InsertCursor("productSort") = idPath			        '获得类别路径
InsertCursor("userId")      = session("userId23")
InsertCursor("sell_name")   = trim(request.form("sell_name"))
InsertCursor("tel")         = trim(request.form("tel"))
InsertCursor("addr")        = trim(request.form("addr"))
InsertCursor("email")       = trim(request.form("email"))
InsertCursor("caryear")     = carYear
InsertCursor("carmonth")    = trim(request.form("carmonth"))
InsertCursor("provice")     = newSheng
InsertCursor("provice_shi") = newShi
InsertCursor("bz")          = trim(request.form("peizhichk"))
InsertCursor("introduce")   = trim(request.form("introduce"))		'附加配置
InsertCursor("explain")     = toHTML(request.form("explain"))
InsertCursor("marketPrice") = marketPrice
InsertCursor("memberPrice") = request.form("memberPrice")

if img(0) <> ""  then  InsertCursor("smallimg")  = img(0)
if img(1) <> ""  then  InsertCursor("smallimg2") = img(1)
if img(2) <> ""  then  InsertCursor("smallimg3") = img(2)
if img(3) <> ""  then  InsertCursor("smallimg4") = img(3)
if img(4) <> ""  then  InsertCursor("smallimg5") = img(4)

InsertCursor("carcolor")    = request.form("carcolor")
InsertCursor("hitNum")      = 0
InsertCursor("recommend")   = 0
InsertCursor("fa_class")    = request.form("fa_class")
InsertCursor("fa_chuqiu")   = "出售"

if carId = "" then
	InsertCursor("chushou") = 0						'如果是添加则置为未出售
	InsertCursor("ifpg")    = 0						'如果是添加则默认为未评估
end if

InsertCursor("fa_time")     = now()
InsertCursor("fabu")        = 0						'添加或修改时都重置为未审核
InsertCursor("leibie")      = request.Form("chexing")
InsertCursor("yanglufei")   = "至" & trim(request.Form("yl2"))
InsertCursor("baoxian")     = "至" & trim(request.Form("bx2"))
InsertCursor("nianjian")    = "至" & trim(request.Form("nj2"))

InsertCursor("soukey")		= newSheng&"|"&newShi&"|"&carYear&"|"&getCarSortName(idPath)


InsertCursor.Update
InsertCursor.close
set InsertCursor=nothing

'检查是否五张汽车图片都提交，对易卡贝贝值进行计算
if img(0) <> "" and img(1) <> "" and img(2) <> "" and img(3) <> "" and img(4) <> "" then

	set rs_kak2 = server.CreateObject("adodb.recordset")
	rs_kak2.open "select * from userJiFen where userId="& session("userId23") &"",conn,1,3
	if not rs_kak2.bof and not rs_kak2.eof then
		rs_kak2("yikabeibei") = rs_kak2("yikabeibei") + 1
		rs_kak2("yikaxinyu")  = rs_kak2("yikaxinyu")  + 2
	end if
	rs_kak2.close
	set rs_kak2 = nothing

end if



if carId = "" then

	'检查发布车辆数是否到五，做相应操作
	set rs_jifen = server.CreateObject("adodb.recordset")
	rs_jifen.open "select * from userJiFen where userId = "& session("userId23") &" ",conn,1,3
	
	if not rs_jifen.eof then
		jifen_bb = rs_jifen("tmp_carNum")
		jifen_bb = jifen_bb + 1					'车辆数加1
		
		if jifen_bb >=5 then					'如果超过五辆
			rs_jifen("yikabeibei") = rs_jifen("yikabeibei") + 1
			rs_jifen("tmp_carNum") = 0
		else
			rs_jifen("tmp_carNum") = jifen_bb
		end if
		rs_jifen.update
	end if
	
	rs_jifen.close
	set rs_jifen = nothing

	response.write "<script>alert('添加成功！等待管理员在24小时内审批，审批通过可在页面上查看！');window.open('user_main.asp','_self')</script>"
	
else

	response.write "<script>alert('修改成功！等待管理员在24小时内审批，审批通过可在页面上查看！');window.open('user_main.asp','_self')</script>"
	
end if




'===============================================================================================
'获得编号
function getBianhao(hh)
	if hh = "" then
		getBianhao = ""
	else
		hh = replace(hh," ","")
		hh = replace(hh,"-","")
		hh = replace(hh,":","")
		hh = replace(hh,"上午","")
		hh = replace(hh,"下午","")
		hh = replace(hh,"AM","")
		hh = replace(hh,"PM","")
		getBianhao = hh
	end if
end function
%>