📄 changeplan.java
字号:
package src.wuyang;
import src.com.*;
import java.sql.*;
import java.io.*;
public class ChangePlan extends ShangObject
{
/**
部门编码
*/
private String deptId;
/**
产品编码
*/
private String productId;
/**
序号
*/
private int sequence;
/**
计划数量
*/
private float quantity;
/**
完成数量
*/
private float quantityFinish;
public ChangePlan()
{
viewName = "DeptInventory";
}
public int loadAttr(){
try {
quantity = rs.getFloat("remain");
sequence = rs.getInt("sequence");
} catch(SQLException e) {
e.printStackTrace();
System.out.println("query failed!");
return -1;
}
return 1;
}
public int query1(){
String whereClause = "productId='"+productId+"' and deptId='"+deptId+"' and remain!=0";
int rowCount = query(whereClause,"sequence");
if (rowCount > 0) {
next();
if (quantity >= quantityFinish) {
quantity = quantity - quantityFinish;
update();
return 1;
} else {
quantityFinish = quantityFinish - quantity;
quantity = 0;
update();
return 0;
}
} else {
return -1;
}
}
public int query2(){
String whereClause = "productId='"+productId+"' and deptId='"+deptId+"'";
int rowCount = query(whereClause,"sequence");
if (rowCount > 0) {
last();
quantity = quantity - quantityFinish;
update();
return 1;
} else {
quantity = quantity - quantityFinish;
insert();
return 1;
}
}
public int process(){
for (int i=0;i==0;) {
i = query1();
if (i == -1) {
i = query2();
}
}
return 0;
}
public int update(){
String sql = "update DeptInventory set remain=? where sequence=" + sequence;
try{
PreparedStatement updStmt = conn.prepareStatement(sql);
updStmt.setFloat(1,quantity);
updStmt.executeUpdate();
updStmt.close();
return 0;
}catch(SQLException e){
System.out.println(e.getMessage());
e.printStackTrace();
return -1;
}
}
public int insert(){
String sql = "insert DeptInventory (deptId,productId,remain) values (?,?,?)";
try{
PreparedStatement updStmt = conn.prepareStatement(sql);
setStmtString(updStmt,1,deptId);
setStmtString(updStmt,2,productId);
updStmt.setFloat(3,quantity);
updStmt.executeUpdate();
updStmt.close();
return 0;
}catch(SQLException e){
System.out.println(e.getMessage());
e.printStackTrace();
return -1;
}
}
/**
* Access method for the deptId property.
*
* @return the current value of the deptId property
*/
public String getDeptId() {
return deptId;}
/**
* Sets the value of the deptId property.
*
* @param aDeptId the new value of the deptId property
*/
public void setDeptId(String aDeptId) {
deptId = setChnString(aDeptId);}
/**
* Access method for the productId property.
*
* @return the current value of the productId property
*/
public String getProductId() {
return productId;}
/**
* Sets the value of the productId property.
*
* @param aProductId the new value of the productId property
*/
public void setProductId(String aProductId) {
productId = setChnString(aProductId);}
/**
* Access method for the sequence property.
*
* @return the current value of the sequence property
*/
public int getSequence() {
return sequence;}
/**
* Sets the value of the sequence property.
*
* @param aSequence the new value of the sequence property
*/
public void setSequence(int aSequence) {
sequence = aSequence;}
/**
* Access method for the quantity property.
*
* @return the current value of the quantity property
*/
public float getQuantity() {
return quantity;}
/**
* Sets the value of the quantity property.
*
* @param aQuantity the new value of the quantity property
*/
public void setQuantity(float aQuantity) {
quantity = aQuantity;}
/**
* Access method for the quantityFinish property.
*
* @return the current value of the quantityFinish property
*/
public float getQuantityFinish() {
return quantityFinish;}
/**
* Sets the value of the quantityFinish property.
*
* @param aQuantityFinish the new value of the quantityFinish property
*/
public void setQuantityFinish(float aQuantityFinish) {
quantityFinish = aQuantityFinish;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -