📄 orderviewcontrolor.java
字号:
this.ShowCheckDetailForm();
t.start();
} else if(cmd == Check_BackCMD){
this.createMainList();
} else if(cmd == CheckDetail_OkCMD){ //查询的 结果 显示
this.createMainList();
} else if(cmd == CheckDetail__BackCMD){
this.CheckForm();
} else if(cmd == Order_OkCMD){ //订购
actionFlag = "Order";
Thread t = new Thread(this);
int m = groups[0].getSelectedIndex();
strProName = groups[0].getString(m);
strProNumber = tf_ProNumber.getString();
if (strProNumber.length() == 0) {
Alert a = new Alert("Error", "请输入订购数量", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, OrderForm);
return;
}
strUserNm = tf_UserName.getString();
if (strUserNm.length() == 0) {
Alert a = new Alert("Error", "请输入客户姓名", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, OrderForm);
return;
}
strAddress = tf_Address.getString();
if (strAddress.length() == 0) {
Alert a = new Alert("Error", "请输入联系地址", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, OrderForm);
return;
}
strTell = tf_Tell.getString();
if (strTell.length() == 0) {
Alert a = new Alert("Error", "请输入联系电话", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, OrderForm);
return;
}
t.start();
} else if(cmd == Order_BackCMD){
this.createMainList();
} else if(cmd == Add_CMD){ //添加
actionFlag = "Add";
Thread t = new Thread(this);
strProNm = tf_ProductNm.getString();
if (strProNm.length() == 0) {
Alert a = new Alert("Error", "请输入产品型号", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, AddForm);
return;
}
strPrice = tf_Price.getString();
if (strPrice.length() == 0) {
Alert a = new Alert("Error", "请输入产品单价", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, AddForm);
return;
}
strNumber = tf_Number.getString();
if (strNumber.length() == 0) {
Alert a = new Alert("Error", "请输入产品数量", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, AddForm);
return;
}
strCompany = tf_Company.getString();
if (strCompany.length() == 0) {
Alert a = new Alert("Error", "请输入生产厂家", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, AddForm);
return;
}
strPhone = tf_Phone.getString();
if (strPhone.length() == 0) {
Alert a = new Alert("Error", "请输入联系电话", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, AddForm);
return;
}
t.start();
} else if(cmd == Add_BackCMD){
this.createAdmainList();
} else if(cmd == Update_OkCMD){ //修改
actionFlag = "Update";
Thread t = new Thread(this);
strProUpdNm = tf_Update_Name.getString();
if (strProUpdNm.length() == 0) {
Alert a = new Alert("Error", "请输入产品型号", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, UpdateForm);
return;
}
this.UpdateListForm();
t.start();
} else if(cmd == Update_BackCMD){
this.createAdmainList();
} else if(cmd == UpdateList_OkCMD){ //修改 详细
actionFlag = "UpdateList";
Thread t = new Thread(this);
strUpdateListName = tf_UpdateList_Price.getString();
if (strUpdateListName.length() == 0) {
Alert a = new Alert("Error", "请输入修改后的单价", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, UpdateListForm);
return;
}
strUpdateListNum = tf_UpdateList_Num.getString();
if (strUpdateListNum.length() == 0) {
Alert a = new Alert("Error", "请输入修改后的数量", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, UpdateListForm);
return;
}
t.start();
} else if(cmd == UpdateList_BackCMD){
this.createAdmainList();
} else if(cmd == Delete_OkCMD){ //删除
actionFlag = "Delete";
Thread t = new Thread(this);
strDeleteName = tf_Delete_Name.getString();
if (strDeleteName.length() == 0) {
Alert a = new Alert("Error", "请输入要删除的产品型号", null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, DeleteForm);
return;
}
this.createAdmainList();
t.start();
} else if(cmd == Delete_BackCMD){
this.createAdmainList();
}
}
public void run() {
DataInputStream ds = null;
DataOutputStream dos = null;
HttpConnection conn = null;
String returnStr = "";
try {
String defaultURL = "http://localhost:8080/OrderServer/login";
conn = (HttpConnection) Connector.open(defaultURL,
Connector.READ_WRITE);
if (actionFlag == "login") {
dos = conn.openDataOutputStream();
dos.writeUTF("login");
dos.writeUTF(strUserName);
dos.writeUTF(strPassword);
ds = new DataInputStream(conn.openInputStream());
returnStr = ds.readUTF();
if (returnStr.equals("welcome")) {
this.createMainList();
} else {
Alert alert = new Alert("错误", "用户名或密码不正确.", null,
AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, LoginForm);
return;
}
} else if (actionFlag == "Admain") {
dos = conn.openDataOutputStream();
dos.writeUTF("Admain");
dos.writeUTF(strUserName);
dos.writeUTF(strPassword);
ds = new DataInputStream(conn.openInputStream());
returnStr = ds.readUTF();
if (returnStr.equals("welcome")) {
this.createAdmainList();
} else {
Alert alert = new Alert("错误", "用户名或密码不正确.", null,
AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, AddAdminLoginForm);
return;
}
}else if (actionFlag == "Check") {
dos = conn.openDataOutputStream();
dos.writeUTF("Check");
dos.writeUTF(strProName);
ds = new DataInputStream(conn.openInputStream());
tf_CheckDetail_Name.setString(ds.readUTF());
tf_CheckDetail_Price.setString(ds.readUTF());
tf_CheckDetail_Num.setString(ds.readUTF());
}else if (actionFlag == "Order") { //订购
dos = conn.openDataOutputStream();
dos.writeUTF("Order");
dos.writeUTF(strProName);
dos.writeUTF(strProNumber);
dos.writeUTF(strUserNm);
dos.writeUTF(strAddress);
dos.writeUTF(strTell);
ds = new DataInputStream(conn.openInputStream());
if(ds.readUTF().equals("1")){
Image err_img= null;
//create error image
try {
err_img=Image.createImage("/res/icons/go.png");
}catch(Exception e){
System.out.println("image is not created.");
}
Alert a = new Alert("Error",
"您已经订购成功.",
err_img,
AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, OrderForm);
return;
}
}else if (actionFlag == "Add") { //添加
dos = conn.openDataOutputStream();
dos.writeUTF("Add");
dos.writeUTF(strProNm);
dos.writeUTF(strPrice);
dos.writeUTF(strNumber);
dos.writeUTF(strCompany);
dos.writeUTF(strPhone);
ds = new DataInputStream(conn.openInputStream());
if(ds.readUTF().equals("1")){
Image err_img= null;
//create error image
try {
err_img=Image.createImage("/res/icons/go.png");
}catch(Exception e){
System.out.println("image is not created.");
}
Alert a = new Alert("Error",
"您已经订购成功.",
err_img,
AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, AddForm);
return;
}
}else if (actionFlag == "Update") { //修改
dos = conn.openDataOutputStream();
dos.writeUTF("Update");
dos.writeUTF(strProUpdNm);
ds = new DataInputStream(conn.openInputStream());
if(ds.readUTF().equals("0")){
Image err_img= null;
//create error image
try {
err_img=Image.createImage("/res/icons/go.png");
}catch(Exception e){
System.out.println("image is not created.");
}
Alert a = new Alert("Error",
"库中没有您输入的产品型号.",
err_img,
AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, UpdateForm);
return;
}
}else if (actionFlag == "UpdateList") { //修改 详细
dos = conn.openDataOutputStream();
dos.writeUTF("UpdateList");
dos.writeUTF(strProUpdNm);
dos.writeUTF(strUpdateListName);
dos.writeUTF(strUpdateListNum);
ds = new DataInputStream(conn.openInputStream());
if(ds.readUTF().equals("1")){
Image err_img= null;
//create error image
try {
err_img=Image.createImage("/res/icons/go.png");
}catch(Exception e){
System.out.println("image is not created.");
}
Alert a = new Alert("Error",
"已经修改成功.",
err_img,
AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, UpdateListForm);
return;
}
} else if (actionFlag == "Delete") { //删除
dos = conn.openDataOutputStream();
dos.writeUTF("Delete");
dos.writeUTF(strDeleteName);
ds = new DataInputStream(conn.openInputStream());
if(ds.readUTF().equals("1")){
Image err_img= null;
//create error image
try {
err_img=Image.createImage("/res/icons/go.png");
}catch(Exception e){
System.out.println("image is not created.");
}
Alert a = new Alert("Error",
"已经成功删除.",
err_img,
AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a, DeleteForm);
return;
}
}else if(actionFlag == "ProName"){ //库中 的 产品型号
dos = conn.openDataOutputStream();
dos.writeUTF("ProName");
ds = new DataInputStream(conn.openInputStream());
int strProductLen = 0;
int strProductLen_old = 0;
while(true)
{
try {
strProductLen ++;
String strProductName = ds.readUTF();
System.out.println("strProductName=========="+strProductName);
int ProductCount = ds.readInt();
int strLen_step = ProductCount;
if(strProductLen > strProductLen_old)
{
String[] stringArray_tmp = new String[strProductLen_old + strLen_step];
System.arraycopy(stringArray1, 0, stringArray_tmp, 0, stringArray1.length);
stringArray1 = new String[strProductLen_old + strLen_step];
stringArray1 = stringArray_tmp;
}
stringArray1[strProductLen-1] = strProductName;
}
catch (Exception e){
//System.out.println("StockProvider Test =========== OVER");
break;
}
}
groups[0] = new ChoiceGroup("请选择产品型号:", ChoiceGroup.POPUP, stringArray1, null);
}
actionFlag = "";
dos.close();
} catch (IOException ex) {
Alert alert = new Alert("I/O Error",
"An error occurred while communicating with the server.",
null, AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, LoginForm);
return;
} finally {
// Close open streams
try {
if (ds != null) {
ds.close();
ds = null;
}
} catch (IOException ex1) {
}
try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (IOException ex1) {
}
}
}
protected void startApp() throws MIDletStateChangeException {
if (display == null) {
initialize();
display.setCurrent(LoginForm);
}
}
protected void pauseApp() {
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -