<!--#include file="conn.asp"-->
<script src="js/jquery.min.js"></script>


<% 
if session("login")<>"1" then
response.write("<script>alert('未登录或者登陆超时，请重新登陆！');window.location.href='login.asp';</script>")   
response.end() 
end if

 %>

<% 

conn.open Str
sql = "select * from articulo where articuloid='"&request.Form("ArticuloID")&"'"
set rs = conn.execute(sql)

  If not(rs.bof and rs.eof) then
response.write("<script>alert('此条形码已有记录!\nCodigo barra repetido!');window.location.href='index.asp?get=good';</script>")   
    rs.close
    set rs=nothing
    response.End()
   End If
  rs.close
  conn.close
  set rs=nothing  



if request.QueryString("ac")="anadir" and request.QueryString("ArticuloID")<>"" then
 %> 


<form id="form1" name="form1" method="post" action="?ac=add">
  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td height="40" colspan="4" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;"><div align="center"><span class="Menu1">添加商品</span><br /><span class="Menu2">NUEVO PRODUCTO </div>
    </div></td>
    </tr>
    <tr>
      <td width="25%" height="34"><div align="right">商品编码：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">PRODUCTO ID</div>
        </div></td>
      <td height="34" colspan="2"><label>
        <input name="articuloid" type="text" id="ArticuloID" style="width:130px;height:25px;" value="<%= request.QueryString("ArticuloID")  %>" autocomplete="off"/>
      *</label>        </td>
      <td width="25%" rowspan="2"><div align="center">
        <label><input type="submit" name="Submit" value="OK保存" style="background-color:<%= bgcolor %>;opacity:<%= opacity %>;" class="Menu1" /></label>
      </div></td>
    </tr>
    <tr>
      <td width="25%" height="34"><div align="right">商品条码：<br />
            </div>        <div align="center" class="STYLE15">
          <div align="right">CODIGO BARRA</div>
        </div></td>
      <td height="34" colspan="2"><label>
        <input name="Codigobarra" type="text" id="articuloid" style="width:130px;height:25px;" autocomplete="off"/>
      </label></td>
    </tr>
    <tr>
      <td width="25%" height="34"><div align="right">西文名称：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">NOMBRE ES</div>
        </div></td>
      <td height="34" colspan="2"><input name="NombreES" type="text" id="nombrees" style=" width:130px;height:25px;" autofocus="autofocus" autocomplete="off"/>
      *</td>
      <td width="25%" height="34"><div align="center">
	  <% if autoprint="1" then %>
          <input name="print" type="checkbox" id="print" value="1" checked="checked" />
		<% else %>  
		<input name="print" type="checkbox" id="print" value="1" />
		<% end if %>
		打印价签
        </div></td>
    </tr>
    <tr>
      <td width="25%" height="34" ><div align="right">中文名称：<br />
            </div>        <div align="center" class="STYLE15">
          <div align="right">NOMBRE CHI</div>
      </div></td>
      <td height="34" colspan="2" ><input name="NombreCN" type="text" id="nombrecn" style=" width:130px;height:25px;" autocomplete="off" /></td>
      <td width="25%" height="34">&nbsp;</td>
    </tr>
    <tr>
      <td width="25%" height="34" >
            <div align="right">零售价：<br />
            </div>        <div align="center" class="STYLE15">
              <div align="right">PRE. VENTA</div>
      </div></td><td width="25%" height="34" ><input name="PrecioDetalle" type="number" step="0.001"id="preciodetalle" style=" width:60px;height:25px;" autocomplete="off" /></td>
      <td width="25%" height="34"><div align="right">始库存：<br />
            </div>        <div align="center" class="STYLE15">
          <div align="right">STOCK INICIAL</div>
      </div></td>
      <td width="25%" height="34" ><input name="stock" type="number" step="0.001"id="stock" style=" width:60px;height:25px;" value="1" autocomplete="off" /></td>
    </tr>
	    <tr>
      <td width="25%" height="34"><div align="right">类别：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">CATEGORIA</div>
        </div></td>
      <td width="25%" height="34">
	   <%
	  conn.open Str
 sql = "select * from articuloclase "
set rs = conn.execute(sql)
   %>
    <label>
        <select name="ClaseID" id="ClaseID" style=" width:80px;height:25px;">
		<%
       while not rs.eof
   %>
          <option value="<%= rs("ClaseID") %>" ><%= left(rs("NombreES"),20) %></option>
<% 
  rs.movenext
  wend
  rs.close
  conn.close
  set rs=nothing 

%>
        </select>
      </label>	  </td>
      <td width="25%" height="34"><div align="right">供应商：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">PROVEEDOR</div>
        </div></td>
	  <td width="25%" height="34">
	  <%
	  conn.open Str
 sql = "select * from proveedor "
set rs = conn.execute(sql)
   %>
    <label>
        <select name="proveedorid" id="proveedorid" style=" width:80px;height:25px;">
 <option value="" selected="selected">Normal</option>

		<%
       while not rs.eof
   %>
          <option value="<%= rs("proveedorID") %>" ><%= left(rs("NombreES"),20) %><%= left(rs("Nombrecn"),20) %></option>
<% 
  rs.movenext
  wend
  rs.close
  conn.close
  set rs=nothing 

%>
        </select>
      </label></td>
    </tr>
    <tr>
      <td width="25%" height="34">
            <div align="right">折扣%：<br />
            </div>        <div align="center" class="STYLE15">
              <div align="right">DESCUENDO</div>
      </div></td><td width="25%" height="34"><input name="Descuento"  type="number" step="0.001"id="Descuento" style=" width:60px;height:25px;" value="0" autocomplete="off" /></td>
      <td width="25%" height="34"><div align="right">进货价：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">PRE. ENTRADA</div>
      </div></td>
      <td width="25%" height="34"><input name="PrecioCoste"  type="number" step="0.001"id="PrecioCoste" style=" width:60px;height:25px;" autocomplete="off" /></td>
    </tr>

    <tr>
      <td width="25%" height="34"><div align="right">批发价：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">PRE.AL MAYOR</div>
        </div></td>
      <td width="25%" height="34"><input name="PrecioMayor"  type="number" step="0.001"id="PrecioMayor" style=" width:60px;height:25px;" autocomplete="off" /></td>
      <td width="25%" height="34"><div align="right">特别价：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">PRE. ESPECIAL</div>
      </div></td>
      <td width="25%" height="34"><input name="PrecioEspecial"  type="number" step="0.001"id="PrecioEspecial" style=" width:60px;height:25px;" autocomplete="off" /></td>
    </tr>
    <tr>
      <td width="25%" height="34"><div align="right">发票价：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">PRE.FACTURA</div>
      </div></td>
      <td width="25%" height="34"><input name="PrecioFactura"  type="number" step="0.001"id="PrecioFactura" style=" width:60px;height:25px;" autocomplete="off" /></td>
      <td width="25%" height="34"><div align="right">会员价：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">PRE.SOCIO</div>
      </div></td>
      <td width="25%" height="34"><input name="PrecioSocio"  type="number" step="0.001"id="PrecioSocio" style=" width:60px;height:25px;" autocomplete="off" /></td>
    </tr>
    <tr>
      <td width="25%" height="34"><div align="right">整包数：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">CANT.PAQUETE</div>
        </div></td>
      <td width="25%" height="34"><input name="CantidadPorUnidad"  type="number" step="0.001"id="CantidadPorUnidad" style=" width:60px;height:25px;" value="1" autocomplete="off" /></td>
      <td width="25%" height="34"><div align="right">整箱数：<br />
      </div>        <div align="center" class="STYLE15">
          <div align="right">CANT.CAJA</div>
      </div></td>
      <td width="25%" height="34"><input name="CantidadPorUnidad2"  type="number" step="0.001"id="CantidadPorUnidad2" style=" width:60px;height:25px;" value="1" autocomplete="off"/></td>
    </tr>
    <tr>
      <td height="34"><div align="right">整包销售：<br />
      </div>
        <div align="center" class="STYLE15">
          <div align="right"> POR PAQUETE</div>
      </div></td>
      <td height="34"><label>
        <input name="SoloPorUnidad" type="checkbox" id="SoloPorUnidad" value="-1" />
      </label></td>
      <td height="34"><div align="right">发票%：<br />
      </div>
        <div align="center" class="STYLE15">
          <div align="right">FACTURA%</div>
      </div></td>
      <td height="34"><input name="FacturaPorcentaje"  type="number" step="0.001"id="FacturaPorcentaje" style=" width:60px;height:25px;" value="100" autocomplete="off"/></td>
    </tr>
    <tr>
      <td height="34"><div align="right">库存下限：<br />
            </div>        <div align="center" class="STYLE15">
          <div align="right">STOCK.MINI</div>
      </div></td>
      <td height="34"><input name="ministock"  type="number" step="0.001"id="ministock" style=" width:60px;height:25px;" autocomplete="off" /></td>
      <td width="25%" height="34">
            <div align="right">库存上限：<br />
            </div>            <div align="center" class="STYLE15">
              <div align="right">STOCK.MAX</div>
      </div></td>
      <td height="34"><input name="maxistock"  type="number"id="maxistock" style=" width:60px;height:25px;" pattern="\d*" autocomplete="off" /></td>
    </tr>
    <tr>
      <td width="25%" height="34"><div align="right">仓库位置：<br />
              </div>        <div align="center" class="STYLE15">
          <div align="right">SITIO.ALMACEN</div>
        </div></td>
      <td height="34"><input name="sitioenalmacen" type="text" id="NombreCN" style=" width:100px;height:25px;" autocomplete="off" /></td>
      <td height="34">
            <div align="right">发票%：<br />
            </div>            <div align="center" class="STYLE15">
              <div align="right">FACTURA%</div>
      </div></td>
      <td height="34"><input name="FacturaPorcentaje"  type="number"id="FacturaPorcentaje" style=" width:60px;height:25px;" value="100" pattern="\d*" autocomplete="off" /></td>
    </tr>
	<tr>
      <td width="25%" height="34"><div align="right">单位名称：<br />
              </div>        <div align="center" class="STYLE15">
          <div align="right">UNIDAD NOMBRE </div>
        </div></td>
      <td height="34"><select name="UnidadNombre" id="UnidadNombre" style=" width:100px;height:20px;">
        <option value="" selected="selected"></option>
		<option value="El Kilo">El Kilo</option>
        <option value="El Litro">El Litro</option>
               </select></td>
      <td height="34">
      <div align="right">
        <div align="right">重量容量：<br />
        </div>
        <div align="center" class="STYLE15">
          <div align="right">VOLUMEN PESO </div>
        </div>
      </div>      </td>
      <td height="34"><input name="VolumenPeso" type="text" id="VolumenPeso" style=" width:60px;height:20px;" autocomplete="off" /></td>
	    </tr>
    <tr>
      <td height="34">
            <div align="right">禁止修改折扣：<br />
            </div>        <div align="center" class="STYLE15">
              <div align="right">No Cambiar.DES</div>
        </div></td><td height="34"><label>
      <input name="DescuentoCambioProhibido" type="checkbox" id="DescuentoCambioProhibido" value="-1" />
      </label></td>
      <td height="34">
            <div align="right">禁用：<br />
            </div>            <div align="center" class="STYLE15">
              <div align="right">Bloqueado</div>
      </div></td>
      <td height="34"><label>
      <input name="Bloqueado" type="checkbox" id="Bloqueado" value="-1" />
      </label></td>
    </tr>
    <tr>
      <td height="40"><div align="right">产品图片：<br />
      </div>
        <div align="center" class="STYLE15">
          <div align="right">Photo</div>
      </div></td>
      <td height="40" colspan="3"><input name="photo" type="text" id="photo" style=" width:220px;height:25px;" autocomplete="off" readonly="readonly" />
  <input name="file1" id="file1" type="file" capture="camera" size="20" accept="image/*"></td>
    </tr>
    <tr>
      <td height="40" colspan="4" align="center">&nbsp;</td>
    </tr>
  </table>
</form>
<script type="text/javascript">
//提醒：一定要设置iis那边上传文件大小，默认是200k，一定要改大！！！！！！！！！！！！
$("#file1").change(function(){
	/////////////////////浏览器端预检查文件类型和大小////////////////////////
	//解释：增强用户体验，以下情况可早发现早提示不用麻烦服务端：
	//1.误选择超过规定大小的文件。js判断立马就能给出提示，如果直接扔给服务器会等N秒包post完毕后才报错，浪费资源和时间，另外也避免了误选择大文件导致卡死，比如点错选择了个几百兆的压缩包，js秒判断，保证网页不会被卡死
	//2.误选择非期望的文件类型。 js可秒判断，服务端要等N秒接收到post包后才能给出提示。
	////////////////////////////////////////////////////////////////////////////
	var tmpFiles=document.all.file1.files;
	for(var i=0; i< tmpFiles.length; i++){
		if(!/.(gif|jpg|jpeg|png)$/i.test(tmpFiles[i].name)){//方法一：通过文件名后缀判断
		// if(!/^image\//.test(tmpFiles[i].type)){ //方法二：通过type属性判断是否是image/开头的
			alert("不是图片类型！ 您上传的类型是：" + tmpFiles[i].type);
			$(this).val("");
			return false;
		}else if(tmpFiles[i].size>30*1024*1024){//限制文件大小30M，可根据需要修改
			alert("文件太大了！建议不超过30M，您上传的大小是：" + parseInt(tmpFiles[i].size/1024/1024) + "M");
			$(this).val("");
			return false;
		}
	}
	//==========================第一波骚操作 前端检查结束====================================

	/////////////////////////使用ajax方法提交数据///////////////////////////////
	$.ajax({
        url: "ajax_upload.asp",
        type: 'POST',
        cache: false,
        data: new FormData($("#form1")[0]),
        processData: false,
        contentType: false,
        xhr:function(){ 
        	myXhr = $.ajaxSettings.xhr(); 
       		if(myXhr.upload){ // check if upload property exists 
           	myXhr.upload.addEventListener('progress',function(e){ 
                 var loaded = e.loaded;//已经上传大小情况
                 var tot = e.total;//附件总大小
                 var per = Math.floor(100*loaded/tot).toFixed(0); 

                 $("#progress").html( per +"%" );//设置进度显示百分比
                 $("#progress").css("width" , per +"%"); //设置完成的进度条宽度
                
             }, false); // for handling the progress of the upload
        	}	  
     	 return myXhr;  
  		},
        success: function (backdata) {
			$("#result").html("" + backdata.replace(/\r\n/img))
			$("#result").after("<img src=" + backdata.replace(/\r\n/img,"><br><img src=") + ">")
			$("#photo").attr("value",""+ backdata.replace(/\r\n/img));

		},
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $("#result").html(XMLHttpRequest.status + errorThrown + " 发生意外错误，请检查并排除问题后重试。建议检查iis端“最大请求实体主体限制”，错误详情：" + XMLHttpRequest.responseText);
        }
    });
    //==========================第二波骚操作 上传处理结束================================
});
</script>


<% 
end if


if request.QueryString("ac")="add" and request.Form("ArticuloID")="" then
response.write("<script>alert('商品编码不能为空！\nCodigo barra no puede dejar en blanco!');window.location.href='index.asp?get=good';</script>")
response.End()
end if
if request.QueryString("ac")="add" and request.Form("NombreES")="" then
response.write("<script>alert('商品名称不能为空！\nNombre articulo no puede dejar en blanco!');window.location.href='index.asp?get=good';</script>")
response.End()
end if




if request.QueryString("ac")="add" and request.Form("ArticuloID")<>"" and request.Form("NombreES")<>"" then
conn.open Str
set addnewpro=conn.execute("insert into articulo(ArticuloID,Codigobarra,NombreES,NombreCN,PrecioDetalle,PrecioCoste,PrecioMayor,PrecioEspecial,PrecioFactura,PrecioSocio,CantidadPorUnidad,CantidadPorUnidad2,ClaseID,FechaPrecioCoste,Descuento,proveedorID,ministock,maxistock,sitioenalmacen,DescuentoCambioProhibido,Bloqueado,pinyin,consultaparcial,SoloPorUnidad,FacturaPorcentaje,UnidadNombre,VolumenPeso)values('"& request.Form("ArticuloID") &"','"& request.Form("Codigobarra") &"','"& request.Form("NombreES") &"','"& request.Form("NombreCN") &"','"& request.Form("PrecioDetalle") &"','"& request.Form("PrecioCoste") &"','"& request.Form("PrecioMayor") &"','"& request.Form("PrecioEspecial") &"','"& request.Form("PrecioFactura") &"','"& request.Form("PrecioSocio") &"','"& request.Form("CantidadPorUnidad") &"','"& request.Form("CantidadPorUnidad2") &"','"& request.Form("ClaseID") &"','"& date() &"','"& request.Form("Descuento") &"','"& request.Form("proveedorID") &"','"& request.Form("ministock") &"','"& request.Form("maxistock") &"','"& request.Form("sitioenalmacen") &"','"& request.Form("DescuentoCambioProhibido") &"','"& request.Form("Bloqueado") &"','"& request.Form("photo") &"','"& request.Form("ArticuloID") & request.Form("Codigobarra") & request.Form("NombreES") &request.Form("Nombrecn") &"','"& request.Form("SoloPorUnidad") &"','"& request.Form("FacturaPorcentaje") &"','"& request.Form("UnidadNombre") &"','"& request.Form("VolumenPeso") &"')")

set addstock=conn.execute("insert into stock (ArticuloID,stock)values('"& request.Form("ArticuloID") &"','"& request.Form("stock") &"')")

conn.close


if request.Form("print")="1" then

	if ventamode="1" then
	precio=request.Form("preciodetalle")
	else
	precio=request.Form("preciomayor")
	end if

if precio="" then  
response.write("<script>alert('商品添加成功，产品价格为空，无法打印！\nProducto guardado!No se impremir articulo con precio vacio!');window.location.href='index.asp?get=good';</script>")  
response.End()
end if

	if billetecode="1" then
	precioxs=formatnumber(precio,2,-1,-1,0)
	else
	precioxs=precio
	end if

 if modelo="0" and style="1"  then
tipo="1"
papel="普通58MM连续纸"
papeles="Papel 58MM Continuo"
end if

 if modelo="0" and style="2"  then
tipo="9"
papel="普通58MM连续纸"
papeles="Papel 58MM Continuo"
end if

 if modelo="0" and style="3"  then
tipo="10"
papel="普通80MM连续纸"
papeles="Papel 80MM Continuo"
end if

if modelo="1" and style="13" then
tipo="6"
papel="58MM*40MM间隙贴纸"
papeles="58MM*40MM Pegatina Adhesivo"
end if

if modelo="1" and style="14" then
tipo="14"
papel="58MM*40MM间隙贴纸"
papeles="58MM*40MM Pegatina Adhesivo"
end if


if EName2IgualEName1="0" then
name1=left(request.Form("nombrees"),EName1MAX)
name2=left(request.Form("nombrecn"),EName2MAX)
else
name1=left(request.Form("nombrees"),EName1MAX)
name2=mid(request.Form("nombrees"),EName1MAX+1,EName2MAX)
end if

if request.Form("UnidadNombre")="" then
UnidadNombre="Litro/Kg"
else
UnidadNombre=request.Form("UnidadNombre")
end if

if request.Form("VolumenPeso")="" or request.Form("VolumenPeso")="0" then
nota1=nota
else
nota1=UnidadNombre&":"&formatnumber(1/formatnumber(request.Form("VolumenPeso"),2,-1,-1,0)*formatnumber(precio,2,-1,-1,0),2,-1,-1,0)&billete
end if

if notaxs="1" then
notaprint=nota
end if

if notaxs="2" then
notaprint=date()
end if

if notaxs="3" then
notaprint=nota1
end if

if notaxs="4" then
notaprint=request.Form("SITIOENALMACEN")
end if

if Printidocodigo="2" and request.Form("Codigobarra")<>"" then
code=request.Form("Codigobarra")
else
code=request.Form("ArticuloID")
end if

response.Redirect("impremir.asp?ac=imp&tipo="&tipo&"&articuloid="&code&"&preciodetalle="&precioxs&"&Url=index&nombrees="&Server.URLEncode(name1)&"&nota="& notaprint &"&name2="&Server.URLEncode(name2)&"&tiendaname="& Server.URLEncode(tiendaname)&"&billete="& billete &"&tiendanamesize="& tiendanamesize &"&tiendanamealign="& tiendanamealign &"&name1size="& name1size &"&name1align="& name1align &"&name2size="& name2size &"&name2align="& name2align &"&preciosize="& preciosize &"&precioalign="& precioalign &"&fxsize="& fxsize &"&fxalign="& fxalign &"&notasize="& notasize &"&notaalign="& notaalign &"&codesize="& codesize &"&codealign="& codealign &"&billetesize="& billetesize &"&billetealign="& billetealign &"&codebarwidth="& codebarwidth &"&codebarheight="& codebarheight &"&fx="& fx &"&BilleteAntes="& BilleteAntes &"&estado=商品添加成功\nProducto guardado!  ")

end if

response.write("<script>alert('商品添加成功\nProducto guardado!');window.location.href='index.asp?get=good';</script>")  
response.End()




end if
 %>
<div style="height:300px"/></div>
<!--#include file="fooder.asp"-->