<% @ 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> Add Product Property Information </title>
<LINK rel = "stylesheet" href = "../CSS/common.css" type = "text/CSS"/>
<Link href = "../CSS/skin/QQ/ymprompt.css" rel = "stylesheet" type = "text/CSS"/>
<SCRIPT src = "../JS/ymprompt. js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
// -------- Remove space -----------------
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 + 12.16.doc ument;
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 =.doc ument );
If (! Foundobj & document. getelementbyid)
Foundobj = Document. getelementbyid (theobj );
Return foundobj;
}
// ---- Fill in the drop-down box ----
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 = data [I];
TEXT = data [I + 1];
OBJ. Options. Add (New Option (text, value ));
}
}
// Assign a value to the drop-down list
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 = selvalue ){
Document. getelementbyid (currname). Options [I]. Selected = true;
}
}
}
}
// ---- Copy ----
Function copyprevselectvalue (prevname, currname ){
VaR Plen = Document. getelementbyid (prevname). selectedindex;
If (Plen! =-1 ){
Document. getelementbyid (currname). Options [Plen]. Selected = true;
}
}
// ---- Add a field ----
Function addsignrow (){
// Read the row number of the last row and store it in the txttrlastindex text box.
VaR txttrlastindex = findobj ("txttrlastindex", document );
VaR rowid = parseint (txttrlastindex. value );
VaR signframe = findobj ("signframe", document );
If (signframe. Rows. Length = 11 ){
Ymprompt. Alert ({message: 'up to 10 records can be entered at a time! ', Title: 'infotip', showmask: false });
Return;
}
// Add rows
VaR newtr = signframe. insertrow (signframe. Rows. Length );
Newtr. ID = "signitem" + rowid;
// Add a column: Sequence Number
VaR newindextd = newtr. insertcell (0 );
// Add column content
Newindextd. innerhtml = newtr. rowindex. tostring ();
// Add a column: English name of the attribute
VaR newpropertynametd = newtr. insertcell (1 );
// Add column content
Newpropertynametd. innerhtml = "<input name = 'txtproductpropertyname" + rowid + "'id = 'txtproductpropertyname" + rowid + "'Type = 'text' size = '10' style = 'width: 90% '/> ";
// Add a column: Chinese name of the attribute
VaR newpropertycnnametd = newtr. insertcell (2 );
// Add column content
Newpropertycnnametd. innerhtml = "<input name = 'txtproductpropertycnname" + rowid + "'id = 'txtproductpropertycnname" + rowid + "'Type = 'text' size = '10' style = 'width: 90% '/> ";
// Add a column: reference price
VaR newprepricetd = newtr. insertcell (3 );
// Add column content
Newprepricetd. innerhtml = "<input name = 'txtpreprice" + rowid + "'id = 'txtpreprice" + rowid + "'onkeypress = \" Return onlynumber (Event) \ "type = 'text' style = 'width: 80px 'value =' <% = currentproduct. preprice %> '/> ";
// Add a column: reference weight
VaR newpreweighttd = newtr. insertcell (4 );
// Add column content
Newpreweighttd. innerhtml = "<input name = 'txtpreweight" + rowid + "'id = 'txtpreweight" + rowid + "'onkeypress = \" Return onlynumber (Event) \ "type = 'text' style = 'width: 80px 'value =' <% = currentproduct. preweight %> '/> ";
// Add column: delete button
VaR newdeletetd = newtr. insertcell (5 );
// Add column content
Newdeletetd. innerhtml = "<Div align = 'center'> <input type = \" image \ "alt = \" delete this row \ "src = \".. /images/icon/0020.05.gif \ "Title = \" delete this row \ "onclick = \" deletesignrow ('signitem "+ rowid + "') \ "/> </div> ";
// Push the row number to the next row
Txttrlastindex. value = (rowid + 1). tostring ();
}
// ---- Delete the specified row -------
Function deletesignrow (rowid ){
VaR signframe = findobj ("signframe", document );
VaR signitem = findobj (rowid, document );
// Obtain the index of the row to be deleted
VaR rowindex = signitem. rowindex;
// Delete the row of the specified index
Signframe. deleterow (rowindex );
// Rearrange the sequence number. If no sequence number exists, this step is omitted.
For (I = rowindex; I <signframe. Rows. length; I ++ ){
Signframe. Rows [I]. cells [0]. innerhtml = I. tostring ();
}
}
// ---- Clear the list ----
Function clearallsign (){
Ymprompt. confirminfo ({message: 'Are you sure you want to clear all rows to be added? ', Title: 'infotip', Handler: clearhandler, showmask: false });
}
// ---- Clear the list and function -----
Function clearhandler (TP ){
If (TP = 'OK '){
VaR signframe = findobj ("signframe", document );
VaR rowscount = signframe. Rows. length;
// Delete rows cyclically from the last row
For (I = rowscount-1; I> 0; I --){
Signframe. deleterow (I );
}
// Reset the last row number to 1
VaR txttrlastindex = findobj ("txttrlastindex", document );
Txttrlastindex. value = "0 ";
// Pre-Add a row
Addsignrow ();
}
}
// ---- Fill in content ----
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. value = "";
If (txttrlastindex. value = 0 | rowscount = 0 ){
// No data information
Ymprompt. Alert ({message: 'enter the content! ', Title: 'infotip', 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 );
// Verify
If (txtproductpropertyname. value. indexof ("/")> 0 | txtproductpropertycnname. value. indexof ("/")> 0 ){
// The attribute name contains invalid characters
Ymprompt. Alert ({message: 'The attribute name contains invalid characters/', Title: 'infotip ', showmask: false });
Return false;
}
If (txtproductpropertyname = undefined | txtproductpropertyname. value. Trim () = ""){
// The English name cannot be blank
Ymprompt. Alert ({message: 'English name cannot be blank ', Title: 'infotip', showmask: false });
Return false;
}
If (txtproductpropertycnname = undefined | txtproductpropertycnname. value. Trim () = ""){
// The Chinese name cannot be blank
Ymprompt. Alert ({message: 'Chinese name cannot be blank ', Title: 'infotip', showmask: false });
Return false;
}
If (txtpreprice = undefined | txtpreprice. value. Trim () = ""){
// The reference price cannot be blank
Ymprompt. Alert ({message: 'reference price cannot be blank ', Title: 'infotip', showmask: false });
Return false;
}
If (txtpreweight = undefined | txtpreweight. value. Trim () = ""){
// The reference weight cannot be blank.
Ymprompt. Alert ({message: 'reference weight cannot be blank ', Title: 'infotip', showmask: false });
Return false;
}
// ------------------------------- Product attribute name ---
Rowitem + = controlsplitstr + txtproductpropertyname. value;
Rowitem + = controlsplitstr + txtproductpropertycnname. value;
Rowitem + = controlsplitstr + (txtpreprice. value. Trim () = ""? "": Txtpreprice. value );
Rowitem + = controlsplitstr + (txtpreweight. value. Trim () = ""? "": Txtpreweight. value );
// ------------------------------- This row ends --------
Txtcontent. Value + = rowitem + "\ n \ f ";
Dataindex ++;
// Increment
Index ++;
}
If (dataindex = 0 ){
// No data information
Ymprompt. Alert ({message: 'enter the content! ', Title: 'infotip', showmask: false });
Return false;
}
Return true;
}
// Save data
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 = ' saving data ......';
VaR hproductid = Document. getelementbyid ("hproductid ")
VaR txtcontent = Document. getelementbyid ("hrowcontent ");
Productpropertyadd. ajaxsaveorupdate (hproductid. Value, txtcontent. Value, saveorupdate_callback );
}
}
// Ajax callback function for saving data
Function saveorupdate_callback (respone ){
VaR resultcode = respone. value;
If (resultcode = "0 "){
// Saved
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 "){
// Duplicate attributes
Ymprompt. Alert ({message: 'The property name already exists. Check it! ', Title: 'Warning', showmask: false });
} Else {
// Failed to save
Ymprompt. errorinfo ({message: 'failed to save the information. Please try again! ', Title: 'failed', 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 = false;
}
Else {
Return e. preventdefault ();
}
}
}
</SCRIPT>
</Head>
<Body onload = "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"> NO. </TD>
<TD class = "listhead"> English attribute name (required, for example, white or XL) </TD>
<TD class = "listhead"> Chinese attribute name (optional, for example, white or large) </TD>
<TD width = "120px" class = "listhead"> reference price (optional, RMB) </TD>
<TD width = "120px" class = "listhead"> reference weight (optional, grams) </TD>
<TD width = "120px" class = "listhead"> delete operation </TD>
</Tr>
</Table>
<Br/>
<Input type = "button" id = "btnaddsignrow" name = "Submit" value = "Add a new entry" onclick = "addsignrow ()" style = "color: red;"/>
<Input type = "button" id = "btnclearallsign" name = "submit2" value = "clear" onclick = "clearallsign ()"/>
<Input type = "button" id = "btnsavedata" value = "confirm to submit" onclick = "savedata ()"/>
<Span id = "savemsg" style = "display: none; color: # ffa501; font-weight: bold"> </span>
<Input name = 'txttrlastindex' type = 'den den 'Id = 'txttrlastindex' value = "0"/>
<! -- Used to store the content information of each row -->
<Input id = "hrowcontent" type = "hidden" style = "width: 16px" runat = "server"/>
<Input id = "hproductid" type = "hidden" runat = "server"/>
</Div>
</Form>
</Body>
</Html>