<!-----------------------------此页代码参照user_csAdd_fun.asp页面--------------------------->
<!--#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"))
carcolor       = trim(request.form("carcolor"))
marketPrice    = request.form("marketPrice")
if marketPrice = "" then marketPrice = 0
qgprice        = request.form("qgprice")
peizhichk	   = trim(request.form("peizhichk"))
yl			   = trim(request.form("yl2"))
bx			   = trim(request.form("bx2"))
nj			   = trim(request.form("nj2"))


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 = "" then call wrong("姓名必须正确填写！")
if tel = "" then call wrong("电话必须正确填写！")
if addr = "" 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

if carcolor = "" then call wrong("汽车颜色必须正确填写！")
if peizhichk = "" then call wrong("汽车配置要求必须正确填写！")
if yl = "" then call wrong("养路费要求必须正确填写！")
if bx = "" then call wrong("保险要求必须正确填写！")
if nj = "" then call wrong("年检要求必须正确填写！")

if instr(qgprice,",") > 0 or isnumeric(qgprice) = false  then call wrong("您输入的欲购买价格有误，请检查！")
if isnumeric(qgprice) = true and qgprice < 100 then call wrong("您输入的欲购买价格过低，请检查！")



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") = getIdPath()			        '获得类别路径
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("qgnianxian")  = trim(request.form("qgnianxian"))
InsertCursor("carmonth")    = "1"
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("qgprice")     = request.form("qgprice")
InsertCursor("qgyongtu")    = request.form("qgyongtu")

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")   = "求购"
InsertCursor("chushou")     = 0			'是否已经出售
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("ifpg")        = "no"

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

InsertCursor.Update
InsertCursor.close
conn.close
set InsertCursor=nothing
set conn=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
	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
%>
<%
'================================================
'获取字符串中分隔符的数量
function countpg(str1,str2)
	dim i,counter
	counter=0
	if InStr(str2,str1) then
		for i=1 to len(str2)
			if mid(str2,i,len(str1))=str1 then
				counter=counter+1
			end if
		next 
	end if
	countpg=counter
 end function
%>