📄 wwindow.java
字号:
}
}
/**
* Report
*/
else if (p_cmd.equals("Report"))
{
/** @todo Report */
}
/**
* Print
*/
else if (p_cmd.equals("Print"))
{
/** @todo Print */
}
/**
* New
*/
else if (p_cmd.equals("New"))
{
if (!ws.curTab.dataNew(false))
ws.curTab.dataIgnore();
}
/**
* Delete
*/
else if (p_cmd.equals("Delete"))
{
ws.curTab.dataDelete();
}
/**
* Save - Check for changed values
*/
else if (p_cmd.equals("Save"))
{
executeSave (request, wsc, ws);
}
} // executeCommand
/**
* Execute Save
* @param request request
* @param ws
*/
private void executeSave (HttpServletRequest request, WebSessionCtx wsc, WWindowStatus ws)
{
log.info("");
boolean error = updateFields(request, wsc, ws);
// Check Mandatory
log.fine("Mandatory check");
int size = ws.curTab.getFieldCount();
for (int i = 0; i < size; i++)
{
MField field = ws.curTab.getField(i);
if (field.isMandatory(true)) // context check
{
Object value = field.getValue();
if (value == null || value.toString().length() == 0)
{
field.setInserting (true); // set editable otherwise deadlock
field.setError(true);
field.setErrorValue(value == null ? null : value.toString());
if (!error)
error = true;
log.info("Mandatory Error: " + field.getColumnName());
}
else
field.setError(false);
}
}
if (error)
return;
// save it - of errors ignore changes
if (!ws.curTab.dataSave(true))
ws.curTab.dataIgnore();
log.fine("done");
} // executeSave
/**
* Update Field Values from Parameter
* @param request request
* @param wsc session context
* @param ws window status
* @return true if error
*/
private boolean updateFields(HttpServletRequest request, WebSessionCtx wsc, WWindowStatus ws)
{
boolean error = false;
try
{
String enc = request.getCharacterEncoding();
if (enc == null)
request.setCharacterEncoding(WebEnv.ENCODING);
}
catch (Exception e)
{
log.log(Level.SEVERE, "Set CharacterEndocung=" + WebEnv.ENCODING, e);
}
// loop through parameters
Enumeration en = request.getParameterNames();
while (en.hasMoreElements())
{
String key = (String)en.nextElement();
// ignore hidden commands
if (key.equals(P_Command)
|| key.equals(P_ChangedColumn)
|| key.equals(P_MR_RowNo)
|| key.equals(P_Tab))
continue;
MField mField = ws.curTab.getField(key);
// log.fine("executeSave - Key=" + key + " - " + mField);
// we found a writable field
if (mField != null && mField.isEditable(true))
{
String value = WebUtil.getParameter(request, key);
Object dbValue = mField.getValue();
boolean fieldError = false;
String columnName = mField.getColumnName();
log.finest(columnName
+ ": " + (dbValue==null ? "null" : dbValue.toString())
+ " -> " + (value==null ? "null" : value.toString()));
// same = both null
if (dbValue == null && value == null)
continue;
// new value null
else if (dbValue != null && value == null)
ws.curTab.setValue (mField, null);
// from null to new value
else if (dbValue == null && value != null)
fieldError = !setFieldValue (wsc, ws, mField, value);
// same
else if (dbValue.equals(value))
continue;
else
fieldError = !setFieldValue (wsc, ws, mField, value);
//
if (!error && fieldError)
{
log.info("Error: " + mField.getColumnName());
error = true;
}
}
} // for all parameteres
// Re-Do Changed Column to overwrite
String columnName = WebUtil.getParameter (request, P_ChangedColumn);
if (columnName != null && columnName.length() > 0)
{
MField mField = ws.curTab.getField(columnName);
if (mField != null)
{
String value = WebUtil.getParameter(request, columnName);
Object newValue = getFieldValue (wsc, mField, value);
if (!ERROR.equals(newValue))
{
// De-Selected Check Boxes are null
if (newValue == null && mField.getDisplayType() == DisplayType.YesNo)
newValue = "N";
log.fine("ChangedColumn: " + columnName + "=" + newValue);
ws.curTab.setValue(mField, newValue);
}
}
}
return error;
} // updateFields
/**************************************************************************
* Set Field Value
* @param wsc web session
* @param ws window status
* @param mField field
* @param value as String
* @return true if correct
*/
private boolean setFieldValue (WebSessionCtx wsc, WWindowStatus ws,
MField mField, String value)
{
Object newValue = getFieldValue (wsc, mField, value);
if (ERROR.equals(newValue))
{
mField.setErrorValue(value);
return false;
}
Object dbValue = mField.getValue();
if ((newValue == null && dbValue != null)
|| (newValue != null && !newValue.equals(dbValue)))
ws.curTab.setValue(mField, newValue);
return true;
} // setFieldValue
/**
* Get Field value (convert value to datatype of MField)
* @param wsc session context
* @param mField field
* @param value String Value
* @return converted Field Value
*/
private Object getFieldValue (WebSessionCtx wsc, MField mField, String value)
{
if (value == null || value.length() == 0)
return null;
int dt = mField.getDisplayType();
String columnName = mField.getColumnName();
// BigDecimal
if (DisplayType.isNumeric(dt))
{
BigDecimal bd = null;
try
{
Number nn = null;
if (dt == DisplayType.Amount)
nn = wsc.amountFormat.parse(value);
else if (dt == DisplayType.Quantity)
nn = wsc.quantityFormat.parse(value);
else // DisplayType.CostPrice
nn = wsc.numberFormat.parse(value);
if (nn instanceof BigDecimal)
bd = (BigDecimal)nn;
else
bd = new BigDecimal(nn.toString());
}
catch (Exception e)
{
log.warning("BigDecimal: " + columnName + "=" + value + ERROR);
return ERROR;
}
log.fine("BigDecimal: " + columnName + "=" + value + " -> " + bd);
return bd;
}
// ID
else if (DisplayType.isID(dt))
{
Integer ii = null;
try
{
ii = new Integer (value);
}
catch (Exception e)
{
log.log(Level.WARNING, "ID: " + columnName + "=" + value, e);
ii = null;
}
// -1 indicates NULL
if (ii.intValue() == -1)
ii = null;
log.fine("ID: " + columnName + "=" + value + " -> " + ii);
return ii;
}
// Date/Time
else if (DisplayType.isDate(dt))
{
Timestamp ts = null;
try
{
java.util.Date d = null;
if (dt == DisplayType.Date)
d = wsc.dateFormat.parse(value);
else
d = wsc.dateTimeFormat.parse(value);
ts = new Timestamp(d.getTime());
}
catch (Exception e)
{
log.warning("Date: " + columnName + "=" + value + ERROR);
return ERROR;
}
log.fine("Date: " + columnName + "=" + value + " -> " + ts);
return ts;
}
// Checkbox
else if (dt == DisplayType.YesNo)
{
Boolean retValue = Boolean.FALSE;
if (value.equals("true"))
retValue = Boolean.TRUE;
log.fine("YesNo: " + columnName + "=" + value + " -> " + retValue);
return retValue;
}
// treat as string
log.fine(columnName + "=" + value);
return value;
} // getFieldValue
/**************************************************************************
* Return SingleRow Form details
* @param action action
* @param wsc web session context
* @param ws window status
* @return Form
*/
private WebDoc getSR_Form (String action, WebSessionCtx wsc, WWindowStatus ws)
{
log.fine("Tab=" + ws.curTab.getTabNo());
/**********************
* For all Fields
*/
table table = new table()
.setAlign(AlignType.CENTER);
// table.setBorder(1).setBorderColor("#00FF00"); // debug field lines
StringBuffer scriptSrc = new StringBuffer();
//
tr line = new tr();
if (ws.curTab.isDisplayed())
{
int noFields = ws.curTab.getFieldCount();
for (int i = 0; i < noFields; i++)
{
MField field = ws.curTab.getField(i);
String columnName = field.getColumnName();
/**
* Get Data and convert to String (singleRow)
*/
Object oData = ws.curTab.getValue(field);
/**
* Display field
*/
if (field.isDisplayed(true))
{
if (!field.isSameLine())
line = new tr();
//
boolean hasDependents = ws.curTab.hasDependants(columnName);
addField(wsc, line, field, oData, hasDependents);
table.addElement(line);
// Additional Values
String dispLogic = field.getDisplayLogic();
if (dispLogic != null && dispLogic.length() > 0)
{
dispLogic = dispLogic.replace('\'', '"'); // replace ' with "
scriptSrc.append("document.").append(FORM_NAME)
.append(".").append(columnName)
.append(".displayLogic='").append(dispLogic).append("';\n");
}
}
} // for all fields
} // displayed
if (scriptSrc.length() > 0)
table.addElement(new script(scriptSrc.toString()));
// Status Line
int rowNo = ws.curTab.getCurrentRow();
String statusDB = String.valueOf(rowNo+1) + " # " + ws.curTab.getRowCount();
//
return createLayout (action, table, wsc, ws, "", statusDB);
} // getSR_Form
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -