首页 > 代码库 > 添加多条的代码

添加多条的代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductPropertyAdd.aspx.cs" Inherits="AmazonERP.Web.Product.ProductPropertyAdd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>添加产品属性信息</title>
<link rel="stylesheet" href="http://www.mamicode.com/css/common.css" type="text/css" />
<link href="http://www.mamicode.com/css/skin/qq/ymPrompt.css" rel="stylesheet" type="text/css" />
<script src="http://www.mamicode.com/js/ymPrompt.js" type="text/javascript"></script>
<script type="text/javascript">
//--------去掉空格-----------------
String.prototype.Trim = function () {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function () {
return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function () {
return this.replace(/(\s*$)/g, "");
}
//----------------------------------
// Example: obj = findObj("image1");
function findObj(theObj, theDoc) {
var p, i, foundObj;
if (!theDoc) theDoc = document;
if ((p = theObj.indexOf("?")) > 0 && parent.frames.length) {
theDoc = parent.frames[theObj.substring(p + 1)].document;
theObj = theObj.substring(0, p);
}
if (!(foundObj = theDoc[theObj]) && theDoc.all)
foundObj = theDoc.all[theObj];
for (i = 0; !foundObj && i < theDoc.forms.length; i++)
foundObj = theDoc.forms[i][theObj];
for (i = 0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
foundObj = findObj(theObj, theDoc.layers[i].document);
if (!foundObj && document.getElementById)
foundObj = document.getElementById(theObj);
return foundObj;
}

//----填充下拉框----
function FillCbo(objName, Data) {
var Obj = document.getElementById(objName);
var text, value;
Obj.options.length = 0;

for (var i = 0; i < Data.length; i = i + 2) {
value = http://www.mamicode.com/Data[i];
text = Data[i + 1];
Obj.options.add(new Option(text, value));
}
}
//给下拉框赋值
function InitSelectValue(currName, SelValue) {
if (SelValue != "0") {
var options = document.getElementById(currName).options;
for (var i = 0; i < options.length; i = i + 1) {
if (options[i].value =http://www.mamicode.com/= SelValue) {
document.getElementById(currName).options[i].selected = true;
}
}
}
}

//----复制----
function copyPrevSelectValue(prevName, currName) {
var pLen = document.getElementById(prevName).selectedIndex;
if (pLen != -1) {
document.getElementById(currName).options[pLen].selected = true;
}
}

//----添加一个填写行----
function AddSignRow() {
//读取最后一行的行号,存放在txtTRLastIndex文本框中
var txtTRLastIndex = findObj("txtTRLastIndex", document);
var rowID = parseInt(txtTRLastIndex.value);
var signFrame = findObj("SignFrame", document);
if (signFrame.rows.length == 11) {
ymPrompt.alert({ message: ‘一次最多允许录入10条记录!‘, title: ‘信息提示‘, showMask: false });
return;
}
//添加行
var newTR = signFrame.insertRow(signFrame.rows.length);
newTR.id = "SignItem" + rowID;

//添加列:序号
var newIndexTD = newTR.insertCell(0);
//添加列内容
newIndexTD.innerHTML = newTR.rowIndex.toString();

//添加列:属性英文名称
var newPropertyNameTD = newTR.insertCell(1);
//添加列内容
newPropertyNameTD.innerHTML = "<input name=‘txtProductPropertyName" + rowID + "‘ id=‘txtProductPropertyName" + rowID + "‘ type=‘text‘ size=‘10‘ style=‘width: 90%‘ />";

//添加列:属性中文名称
var newPropertyCNNameTD = newTR.insertCell(2);
//添加列内容
newPropertyCNNameTD.innerHTML = "<input name=‘txtProductPropertyCNName" + rowID + "‘ id=‘txtProductPropertyCNName" + rowID + "‘ type=‘text‘ size=‘10‘ style=‘width: 90%‘ />";


//添加列:参考价格
var newPrePriceTD = newTR.insertCell(3);
//添加列内容
newPrePriceTD.innerHTML = "<input name=‘txtPrePrice" + rowID + "‘ id=‘txtPrePrice" + rowID + "‘ onkeypress=\"return onlyNumber(event)\" type=‘text‘ style=‘width: 80px‘ value=http://www.mamicode.com/‘‘ />";

//添加列:参考重量
var newPreWeightTD = newTR.insertCell(4);
//添加列内容
newPreWeightTD.innerHTML = "<input name=‘txtPreWeight" + rowID + "‘ id=‘txtPreWeight" + rowID + "‘ onkeypress=\"return onlyNumber(event)\" type=‘text‘ style=‘width: 80px‘ value=http://www.mamicode.com/‘‘ />";

//添加列:删除按钮
var newDeleteTD = newTR.insertCell(5);
//添加列内容
newDeleteTD.innerHTML = "<div align=‘center‘> <input type=\"image\" alt=\"删除该行\" src=http://www.mamicode.com/"../images/icon/001_05.gif\" title=\"删除该行\" onclick=\"DeleteSignRow(‘SignItem" + rowID + "‘)\" /></div>";

//将行号推进下一行
txtTRLastIndex.value = http://www.mamicode.com/(rowID + 1).toString();
}

//----删除指定行-------
function DeleteSignRow(rowid) {
var signFrame = findObj("SignFrame", document);
var signItem = findObj(rowid, document);

//获取将要删除的行的Index
var rowIndex = signItem.rowIndex;

//删除指定Index的行
signFrame.deleteRow(rowIndex);

//重新排列序号,如果没有序号,这一步省略
for (i = rowIndex; i < signFrame.rows.length; i++) {
signFrame.rows[i].cells[0].innerHTML = i.toString();
}
}
//----清空列表----
function ClearAllSign() {
ymPrompt.confirmInfo({ message: ‘确定要清空准备添加的所有行吗?‘, title: ‘信息提示‘, handler: clearHandler, showMask: false });
}
//----清空列表出来函数-----
function clearHandler(tp) {
if (tp == ‘ok‘) {
var signFrame = findObj("SignFrame", document);
var rowscount = signFrame.rows.length;

//循环删除行,从最后一行往前删除
for (i = rowscount - 1; i > 0; i--) {
signFrame.deleteRow(i);
}

//重置最后行号为1
var txtTRLastIndex = findObj("txtTRLastIndex", document);
txtTRLastIndex.valuehttp://www.mamicode.com/= "http://www.mamicode.com/0";

//预添加一行
AddSignRow();
}
}

//----填充内容----
function FillContent() {
var TxtContent = document.getElementById("HrowContent");
var txtTRLastIndex = document.getElementById("txtTRLastIndex");
var signFrame = findObj("SignFrame", document);
var rowscount = signFrame.rows.length - 1;
var controlSplitStr = "^#^";
TxtContent.valuehttp://www.mamicode.com/= "";
if (txtTRLastIndex.value =http://www.mamicode.com/= 0 || rowscount == 0) {
//没有数据信息
ymPrompt.alert({ message: ‘请填写内容!‘, title: ‘信息提示‘, showMask: false });
return false;
}

 

var Index = 0;
var dataIndex = 0;

while (Index < txtTRLastIndex.value) {
var rowItem = "";
var txtProductPropertyName = document.getElementById("txtProductPropertyName" + Index);
var txtProductPropertyCNName = document.getElementById("txtProductPropertyCNName" + Index);
var txtPrePrice = document.getElementById("txtPrePrice" + Index);
var txtPreWeight = document.getElementById("txtPreWeight" + Index);


//验证
if (txtProductPropertyName.value.indexOf("/") > 0 || txtProductPropertyCNName.value.indexOf("/") > 0) {
//属性名称含有非法字符
ymPrompt.alert({ message: ‘属性名称含有非法字符/‘, title: ‘信息提示‘, showMask: false });
return false;
}

if (txtProductPropertyName == undefined || txtProductPropertyName.value.Trim() == "") {
//英文名称不能为空
ymPrompt.alert({ message: ‘英文名称不能为空‘, title: ‘信息提示‘, showMask: false });
return false;
}

if (txtProductPropertyCNName == undefined || txtProductPropertyCNName.value.Trim() == "") {
//中文名称不能为空
ymPrompt.alert({ message: ‘中文名称不能为空‘, title: ‘信息提示‘, showMask: false });
return false;
}

if (txtPrePrice == undefined || txtPrePrice.value.Trim() == "") {
//参考价格不能为空
ymPrompt.alert({ message: ‘参考价格不能为空‘, title: ‘信息提示‘, showMask: false });
return false;
}

if (txtPreWeight == undefined || txtPreWeight.value.Trim() == "") {
//参考重量不能为空
ymPrompt.alert({ message: ‘参考重量不能为空‘, title: ‘信息提示‘, showMask: false });
return false;
}
//----------------------------- 产品属性名称---
rowItem += controlSplitStr + txtProductPropertyName.value;
rowItem += controlSplitStr + txtProductPropertyCNName.value;
rowItem += controlSplitStr + (txtPrePrice.value.Trim() == "" ? " " : txtPrePrice.value);
rowItem += controlSplitStr + (txtPreWeight.value.Trim() == "" ? " " : txtPreWeight.value);

//----------------------------- 该行结束--------
TxtContent.value += rowItem + "\n\f";
dataIndex++;
//递增量
Index++;
}

if (dataIndex == 0) {
//没有数据信息
ymPrompt.alert({ message: ‘请填写内容!‘, title: ‘信息提示‘, showMask: false });
return false;
}
return true;
}
//保存数据
function SaveData() {
if (FillContent()) {
document.getElementById("btnAddSignRow").disabled = true;
document.getElementById("btnClearAllSign").disabled = true;
document.getElementById("btnSaveData").disabled = true;
document.getElementById("SaveMsg").style.display = "";
document.getElementById("SaveMsg").innerHTML = ‘<img src="http://www.mamicode.com/images/loading5.gif" />数据保存中......‘;

var HproductID = document.getElementById("HproductID")
var TxtContent = document.getElementById("HrowContent");
ProductPropertyAdd.AjaxSaveOrUpdate(HproductID.value, TxtContent.value, SaveOrUpdate_Callback);
}
}
//Ajax保存数据回调函数
function SaveOrUpdate_Callback(respone) {
var resultCode = respone.value;
if (resultCode == "0") {
//保存成功
parent.ymPrompt.doHandler(resultCode, true);
}
else {
document.getElementById("btnAddSignRow").disabled = false;
document.getElementById("btnClearAllSign").disabled = false;
document.getElementById("btnSaveData").disabled = false;
document.getElementById("SaveMsg").innerHTML = "";
if (resultCode == "2") {
//属性重复
ymPrompt.alert({ message: ‘属性名称已存在,请核查!‘, title: ‘警告‘, showMask: false });
} else {
//保存失败
ymPrompt.errorInfo({ message: ‘保存信息失败,请重试!‘, title: ‘失败‘, showMask: false });
}
}
}


var isIE = false;
var isFF = false;
var isSa = false;

if ((navigator.userAgent.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) isIE = true;
if (navigator.userAgent.indexOf("Firefox") > 0) isFF = true;
if (navigator.userAgent.indexOf("Safari") > 0) isSa = true;
function onlyNumber(e) {
var key;
iKeyCode = window.event ? e.keyCode : e.which;
if (!(((iKeyCode >= 48) && (iKeyCode <= 57)) || (iKeyCode == 13) || (iKeyCode == 46) || (iKeyCode == 45) || (iKeyCode == 37) || (iKeyCode == 39) || (iKeyCode == 8))) {
if (isIE) {
return e.returnValue = http://www.mamicode.com/false;
}
else {
return e.preventDefault();
}
}
}
</script>
</head>
<body onl oad="AddSignRow();">
<form id="form1" runat="server">
<div id="man_zone">
<table width="100%" border="0" cellpadding="1" cellspacing="1" id="SignFrame" style="text-align: center">
<tr id="trHeader">
<td width="50px" class="ListHead">序号</td>
<td class="ListHead">属性英文名称(必填,如:white或XL)</td>
<td class="ListHead">属性中文名称(可选,如:白色或大号)</td>
<td width="120px" class="ListHead">参考价格(可选,元)</td>
<td width="120px" class="ListHead">参考重量(可选,克)</td>
<td width="120px" class="ListHead">删除操作</td>
</tr>
</table>
<br />
<input type="button" id="btnAddSignRow" name="Submit" value="http://www.mamicode.com/新增一条" onclick="AddSignRow()" style="color: Red;" />
<input type="button" id="btnClearAllSign" name="Submit2" value="http://www.mamicode.com/清空" onclick="ClearAllSign()" />
<input type="button" id="btnSaveData" value="http://www.mamicode.com/确认提交" onclick="SaveData()" />
<span id="SaveMsg" style="display: none; color: #ffa501; font-weight: bold"></span>
<input name=‘txtTRLastIndex‘ type=‘hidden‘ id=‘txtTRLastIndex‘ value="http://www.mamicode.com/0" />
<!--用于存储每行的内容信息-->
<input id="HrowContent" type="hidden" style="width: 16px" runat="server" />
<input id="HproductID" type="hidden" runat="server" />
</div>
</form>
</body>
</html>