package com.example.xxxmes.models;
public class Material {
private int materialId; // 物料ID
private String name; // 物料名称
private String type; // 物料类型
private double unitPrice; // 单价
private int employeeId; // 员工ID
private int totalQuantity; // 总数
private int receivedQuantity; // 领取数量
// 构造方法
public Material(int materialId, String name, String type, double unitPrice, int employeeId, int totalQuantity, int receivedQuantity) {
this.materialId = materialId;
this.name = name;
this.type = type;
this.unitPrice = unitPrice;
this.employeeId = employeeId;
this.totalQuantity = totalQuantity;
this.receivedQuantity = receivedQuantity;
}
// Getter 和 Setter 方法
public int getMaterialId() {
return materialId;
}
public void setMaterialId(int materialId) {
this.materialId = materialId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(double unitPrice) {
this.unitPrice = unitPrice;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public int getTotalQuantity() {
return totalQuantity;
}
public void setTotalQuantity(int totalQuantity) {
this.totalQuantity = totalQuantity;
}
public int getReceivedQuantity() {
return receivedQuantity;
}
public void setReceivedQuantity(int receivedQuantity) {
this.receivedQuantity = receivedQuantity;
}
}
package com.example.xxxmes;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.example.xxxmes.R;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
// 默认选中主页
loadFragment(new HomeFragment());
bottomNavigationView.setOnItemSelectedListener(new BottomNavigationView.OnItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
if (item.getItemId() == R.id.navigation_home) {
selectedFragment = new HomeFragment();
} else if (item.getItemId() == R.id.navigation_work) {
selectedFragment = new WorkFragment();
} else if (item.getItemId() == R.id.navigation_mine) {
selectedFragment = new MineFragment();
}
return loadFragment(selectedFragment);
}
});
}
private boolean loadFragment(Fragment fragment) {
// 更换 Fragment
if (fragment != null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commit();
return true;
}
return false;
}
}
package com.example.xxxmes;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.xxxmes.utils.JDBCUtils;
import com.journeyapps.barcodescanner.CaptureActivity;
import android.widget.TextView;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class MaterialActivity extends AppCompatActivity {
private int taskId;
private int employeeId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_material);
Intent intent = getIntent();
taskId = intent.getIntExtra("TASK_ID", -1);
employeeId = intent.getIntExtra("EMPLOYEE_ID", -1); // 接收员工ID
TextView employeeIdTextView = findViewById(R.id.employeeIdTextView);
employeeIdTextView.setText("员工ID: " + employeeId); // 设置员工ID文本
ImageView scanQRCodeImageView = findViewById(R.id.scanQRCodeImageView);
scanQRCodeImageView.setOnClickListener(v -> {
Intent scanIntent = new Intent(this, CaptureActivity.class); // CaptureActivity 是扫描二维码的活动
startActivityForResult(scanIntent, 100); // 100 是请求码
});
EditText nameEditText = findViewById(R.id.nameEditText);
EditText typeEditText = findViewById(R.id.typeEditText);
EditText unitPriceEditText = findViewById(R.id.unitPriceEditText);
EditText totalQuantityEditText = findViewById(R.id.totalQuantityEditText);
EditText receivedQuantityEditText = findViewById(R.id.receivedQuantityEditText);
Button submitButton = findViewById(R.id.submitButton);
submitButton.setOnClickListener(v -> {
String name = nameEditText.getText().toString().trim();
String type = typeEditText.getText().toString().trim();
String unitPriceString = unitPriceEditText.getText().toString().trim();
String totalQuantityString = totalQuantityEditText.getText().toString().trim();
String receivedQuantityString = receivedQuantityEditText.getText().toString().trim();
if (name.isEmpty() || type.isEmpty() || unitPriceString.isEmpty() ||
totalQuantityString.isEmpty() || receivedQuantityString.isEmpty()) {
Toast.makeText(MaterialActivity.this, "请填写所有字段", Toast.LENGTH_SHORT).show();
} else {
double unitPrice = Double.parseDouble(unitPriceString);
int totalQuantity = Integer.parseInt(totalQuantityString);
int receivedQuantity = Integer.parseInt(receivedQuantityString);
insertMaterial(name, type, unitPrice, employeeId, totalQuantity, receivedQuantity);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK) {
String result = data.getStringExtra("SCAN_RESULT"); // 获取扫描结果
populateFields(result); // 填充数据
}
}
private void populateFields(String result) {
// 假设结果格式为 "name,type,unitPrice,totalQuantity"
String[] parts = result.split(",");
if (parts.length == 4) {
EditText nameEditText = findViewById(R.id.nameEditText);
EditText typeEditText = findViewById(R.id.typeEditText);
EditText unitPriceEditText = findViewById(R.id.unitPriceEditText);
EditText totalQuantityEditText = findViewById(R.id.totalQuantityEditText);
nameEditText.setText(parts[0]); // 物料名称
typeEditText.setText(parts[1]); // 物料类型
unitPriceEditText.setText(parts[2]); // 单价
totalQuantityEditText.setText(parts[3]); // 总数
} else {
Toast.makeText(this, "扫描结果格式错误", Toast.LENGTH_SHORT).show();
}
}
private void insertMaterial(String name, String type, double unitPrice, int employeeId, int totalQuantity, int receivedQuantity) {
new Thread(() -> {
String sql = "INSERT INTO material (Name, Type, UnitPrice, EmployeeID, TotalQuantity, ReceivedQuantity) VALUES (?, ?, ?, ?, ?, ?)";
try (Connection connection = JDBCUtils.getConn();
PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, name);
ps.setString(2, type);
ps.setDouble(3, unitPrice);
ps.setInt(4, employeeId);
ps.setInt(5, totalQuantity);
ps.setInt(6, receivedQuantity);
ps.executeUpdate();
runOnUiThread(() -> Toast.makeText(MaterialActivity.this, "物料添加成功", Toast.LENGTH_SHORT).show());
finish(); // 返回到上一个活动
} catch (SQLException e) {
e.printStackTrace();
runOnUiThread(() -> Toast.makeText(MaterialActivity.this, "添加物料失败: " + e.getMessage(), Toast.LENGTH_SHORT).show());
}
}).start();
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人