Compare commits
No commits in common. 'master' and 'main' have entirely different histories.
@ -1,38 +0,0 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
@ -1,8 +0,0 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CodeReadingNote">
|
||||
<topics />
|
||||
<state lastExportDir="" lastImportDir="" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="product@localhost" uuid="75250724-1f0c-48e7-b2ec-693f5b79a97a">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://localhost:3306/product</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,71 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="AliAccessStaticViaInstance" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AliArrayNamingShouldHaveBracket" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AliControlFlowStatementWithoutBraces" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AliDeprecation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AliEqualsAvoidNull" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AliLongLiteralsEndingWithLowercaseL" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AliMissingOverrideAnnotation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AliWrapperTypeEquality" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAbstractClassShouldStartWithAbstractNaming" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAbstractMethodOrInterfaceMethodMustUseJavadoc" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidApacheBeanUtilsCopy" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidCallStaticSimpleDateFormat" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidCommentBehindStatement" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidComplexCondition" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidConcurrentCompetitionRandom" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidDoubleOrFloatEqualCompare" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidManuallyCreateThread" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidMissUseOfMathRandom" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidNegationOperator" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidNewDateGetTime" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidPatternCompileInMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidReturnInFinally" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidStartWithDollarAndUnderLineNaming" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaAvoidUseTimer" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaBigDecimalAvoidDoubleConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaBooleanPropertyShouldNotStartWithIs" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaClassCastExceptionWithSubListToArrayList" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaClassCastExceptionWithToArray" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaClassMustHaveAuthor" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaClassNamingShouldBeCamel" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaCollectionInitShouldAssignCapacity" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaCommentsMustBeJavadocFormat" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaConcurrentExceptionWithModifyOriginSubList" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaConstantFieldShouldBeUpperCase" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaCountDownShouldInFinally" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaDontModifyInForeachCircle" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaEnumConstantsMustHaveComment" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaExceptionClassShouldEndWithException" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaIbatisMethodQueryForList" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaLockShouldWithTryFinally" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaLowerCamelCaseVariableNaming" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaMethodReturnWrapperType" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaMethodTooLong" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaPackageNaming" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaPojoMustOverrideToString" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaPojoMustUsePrimitiveField" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaPojoNoDefaultValue" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaRemoveCommentedCode" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaServiceOrDaoClassShouldEndWithImpl" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaSneakyThrowsWithoutExceptionType" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaStringConcat" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaSwitchExpression" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaSwitchStatement" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaTestClassShouldEndWithTestNaming" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaThreadLocalShouldRemove" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaThreadPoolCreation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaThreadShouldSetName" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaTransactionMustHaveRollback" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaUndefineMagicConstant" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaUnsupportedExceptionWithModifyAsList" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaUseQuietReferenceNotation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AlibabaUseRightCaseForDateFormat" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.lang.foreign.Arena,ofAuto,java.lang.foreign.Arena,global,java.lang.Class,getResourceAsStream" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="MapOrSetKeyShouldOverrideHashCodeEquals" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="2">
|
||||
<item index="0" class="java.lang.String" itemvalue="Test" />
|
||||
<item index="1" class="java.lang.String" itemvalue="lombok.Data" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21_PREVIEW" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources/db_product.sql" dialect="MySQL" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
<component name="VcsProjectSettings">
|
||||
<option name="detectVcsMappingsAutomatically" value="false" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
@ -0,0 +1,33 @@
|
||||
GCC RUNTIME LIBRARY EXCEPTION
|
||||
|
||||
Version 3.1, 31 March 2009
|
||||
|
||||
General information: http://www.gnu.org/licenses/gcc-exception.html
|
||||
Copyright (C) 2009 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
This GCC Runtime Library Exception ("Exception") is an additional permission under section 7 of the GNU General Public License, version 3 ("GPLv3"). It applies to a given file (the "Runtime Library") that bears a notice placed by the copyright holder of the file stating that the file is governed by GPLv3 along with this Exception.
|
||||
|
||||
When you use GCC to compile a program, GCC may combine portions of certain GCC header files and runtime libraries with the compiled program. The purpose of this Exception is to allow compilation of non-GPL (including proprietary) programs to use, in this way, the header files and runtime libraries covered by this Exception.
|
||||
|
||||
0. Definitions.
|
||||
|
||||
A file is an "Independent Module" if it either requires the Runtime Library for execution after a Compilation Process, or makes use of an interface provided by the Runtime Library, but is not otherwise based on the Runtime Library.
|
||||
|
||||
"GCC" means a version of the GNU Compiler Collection, with or without modifications, governed by version 3 (or a specified later version) of the GNU General Public License (GPL) with the option of using any subsequent versions published by the FSF.
|
||||
|
||||
"GPL-compatible Software" is software whose conditions of propagation, modification and use would permit combination with GCC in accord with the license of GCC.
|
||||
|
||||
"Target Code" refers to output from any compiler for a real or virtual target processor architecture, in executable form or suitable for input to an assembler, loader, linker and/or execution phase. Notwithstanding that, Target Code does not include data in any format that is used as a compiler intermediate representation, or used for producing a compiler intermediate representation.
|
||||
|
||||
The "Compilation Process" transforms code entirely represented in non-intermediate languages designed for human-written code, and/or in Java Virtual Machine byte code, into Target Code. Thus, for example, use of source code generators and preprocessors need not be considered part of the Compilation Process, since the Compilation Process can be understood as starting with the output of the generators or preprocessors.
|
||||
|
||||
A Compilation Process is "Eligible" if it is done using GCC, alone or with other GPL-compatible software, or if it is done without using any work based on GCC. For example, using non-GPL-compatible Software to optimize any GCC intermediate representations would not qualify as an Eligible Compilation Process.
|
||||
|
||||
1. Grant of Additional Permission.
|
||||
|
||||
You have permission to propagate a work of Target Code formed by combining the Runtime Library with Independent Modules, even if such propagation would otherwise violate the terms of GPLv3, provided that all Target Code was generated by Eligible Compilation Processes. You may then convey such a combination under terms of your choice, consistent with the licensing of the Independent Modules.
|
||||
|
||||
2. No Weakening of GCC Copyleft.
|
||||
|
||||
The availability of this Exception does not imply any general presumption that third-party software is unaffected by the copyleft requirements of the license of GCC.
|
||||
|
Before Width: | Height: | Size: 256 KiB |
|
Before Width: | Height: | Size: 238 KiB |
@ -1,47 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.xky</groupId>
|
||||
<artifactId>Practical</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Practical</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- mysql驱动坐标-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.33</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.38</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>21</source>
|
||||
<target>21</target>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@ -1,28 +0,0 @@
|
||||
package com.xky;
|
||||
|
||||
import com.xky.pojo.User;
|
||||
import com.xky.ui.module.login.Autoregister;
|
||||
import com.xky.ui.module.login.Login;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Application
|
||||
{
|
||||
// 主方法,启动登录界面
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SwingUtilities.invokeLater(Login::new); // 在事件调度线程中创建登录界面
|
||||
|
||||
//自动注册管理员账号
|
||||
try {
|
||||
Autoregister.adminRegister();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package com.xky.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 客户实体类
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Customers {
|
||||
private Integer customerId;//客户ID
|
||||
private String customerCode;//客户编码
|
||||
private String customerName;//客户名称
|
||||
private String contactPerson;//联系人
|
||||
private String phone;//联系电话
|
||||
private String email;//电子邮箱
|
||||
private String address;//联系地址
|
||||
private String creditLimit;//信用额度
|
||||
private Boolean isActive;//是否有效(1:是,0:否)
|
||||
private LocalDateTime createdTime;//创建时间
|
||||
private LocalDateTime updatedTime;//更新时间
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package com.xky.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 库存实体类
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Inventory {
|
||||
private Integer inventoryId;//库存记录ID
|
||||
private Integer productId ;//商品ID
|
||||
private Integer warehouseId;//仓库ID
|
||||
private Integer quantity;//当前库存数量
|
||||
private Integer allocatedQuantity;//已分配数量
|
||||
private String locationCode;//库位编码
|
||||
private String batchNumber;//批次号
|
||||
private LocalDateTime expiryDate;//过期日期
|
||||
private LocalDateTime lastStockUpdate;//最后库存更新时间
|
||||
private LocalDateTime createdTime;//创建时间
|
||||
private LocalDateTime updatedTime;//更新时间
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
package com.xky.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 商品分类实体类
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ProductCategories {
|
||||
private Integer categoryId ;//分类ID
|
||||
private String categoryName;//分类名称
|
||||
private Integer parentId;//父分类ID
|
||||
private String isActive;//是否启用(1:启用,0:禁用)
|
||||
private LocalDateTime createdTime;//创建时间
|
||||
private LocalDateTime updatedTime;//更新时间
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package com.xky.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 商品实体类
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Products {
|
||||
private Integer productId;//商品ID
|
||||
private String productCode;//商品编码
|
||||
private String productName;//商品名称
|
||||
private Integer categoryId ;//所属分类ID
|
||||
private String unitOfMeasure;//计量单位
|
||||
private Integer minStockLevel;//最低库存水平
|
||||
private String isActive;//是否启用(1:启用,0:禁用)
|
||||
private LocalDateTime createdTime;//创建时间
|
||||
private LocalDateTime updatedTime;//更新时间
|
||||
private Integer supplierId; // 供应商ID
|
||||
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
package com.xky.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 销售订单实体类
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SalesOrders {
|
||||
private Integer orderId; // 订单ID
|
||||
private String orderNumber; // 订单编号
|
||||
private Integer customerId; // 客户ID
|
||||
private LocalDateTime orderDate; // 下单时间
|
||||
private LocalDate expectedShipDate; // 预计发货日期
|
||||
private LocalDate actualShipDate; // 实际发货日期
|
||||
private Integer warehouseId; // 发货仓库ID
|
||||
private String orderStatus; // 订单状态
|
||||
private String paymentStatus; // 支付状态
|
||||
private String paymentMethod; // 支付方式
|
||||
private BigDecimal subtotal; // 商品总额
|
||||
private BigDecimal taxAmount; // 税额
|
||||
private BigDecimal discountAmount; // 折扣金额
|
||||
private BigDecimal shippingFee; // 运费
|
||||
private BigDecimal totalAmount; // 订单总金额
|
||||
private BigDecimal paidAmount; // 已付金额
|
||||
private String notes; // 订单备注
|
||||
private Integer createdBy; // 创建人ID
|
||||
private LocalDateTime createdTime; // 创建时间
|
||||
private LocalDateTime updatedTime; // 更新时间
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package com.xky.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 销售发货单实体类
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SalesShipments {
|
||||
private Integer shipmentId; // 发货单ID
|
||||
private String shipmentNumber; // 发货单号
|
||||
private Integer orderId; // 关联订单ID
|
||||
private Integer warehouseId; // 发货仓库ID
|
||||
private LocalDate shipmentDate; // 发货日期
|
||||
private String carrier; // 承运商
|
||||
private String trackingNumber; // 物流单号
|
||||
private String shippingMethod; // 运输方式
|
||||
private String status; // 状态
|
||||
private String notes; // 备注
|
||||
private LocalDateTime createdTime; // 创建时间
|
||||
private LocalDateTime updatedTime; // 更新时间
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package com.xky.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 供应商实体类
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Supplier {
|
||||
private Integer supplierId; // 供应商ID
|
||||
private String supplierCode;//供应商编码
|
||||
private String supplierName; // 供应商名称
|
||||
private String contactName; // 联系人姓名
|
||||
private String contactPhone; // 联系人电话
|
||||
private String contactEmail; // 联系人邮箱
|
||||
private String address; // 地址
|
||||
private Boolean isActive; // 是否激活
|
||||
private LocalDateTime createdTime = LocalDateTime.now(); // 创建时间
|
||||
private LocalDateTime updatedTime = LocalDateTime.now(); // 更新时间
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return supplierName;
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package com.xky.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户实体类
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class User implements Serializable {
|
||||
private String username;
|
||||
private String password;
|
||||
private String email;
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
package com.xky.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 仓库实体类
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Warehouses {
|
||||
private Integer warehouseId ;//仓库ID
|
||||
private String warehouseCode;//仓库编码
|
||||
private String warehouseName;//仓库名称
|
||||
private String location ;//仓库位置
|
||||
private Boolean isActive;//是否启用
|
||||
private LocalDateTime createdTime;//创建时间
|
||||
private LocalDateTime updatedTime;//更新时间
|
||||
}
|
||||
@ -1,154 +0,0 @@
|
||||
package com.xky.ui.module.customersManagement;
|
||||
|
||||
import com.xky.pojo.Customers;
|
||||
import com.xky.ui.main.MainView;
|
||||
import com.xky.ui.module.customersManagement.select.SelectCustomers;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* 客户信息管理类
|
||||
* 负责显示和刷新客户信息
|
||||
*/
|
||||
public class CustomersInfo {
|
||||
private static JTable customersTable;
|
||||
private static final String MODULE_NAME = "客户信息";
|
||||
|
||||
/**
|
||||
* 显示客户信息页面
|
||||
*/
|
||||
public static void showCustomersPage() {
|
||||
try {
|
||||
// 创建客户信息面板
|
||||
JPanel customersInfoPanel = CustomersMassage.createCustomersPanel(CustomersInfo::refreshCustomersData);
|
||||
|
||||
// 获取表格组件
|
||||
initializeTable(customersInfoPanel);
|
||||
|
||||
// 更新右侧面板
|
||||
updateMainPanel(customersInfoPanel);
|
||||
|
||||
// 立即刷新一次
|
||||
refreshCustomersData();
|
||||
|
||||
// 更新状态消息
|
||||
MainView.updateStatusMessage(MODULE_NAME + "页面已加载");
|
||||
} catch (Exception e) {
|
||||
handleException(e, "加载" + MODULE_NAME + "页面失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化表格组件
|
||||
* @param panel 包含表格的面板
|
||||
* @throws IllegalStateException 如果无法找到表格组件
|
||||
*/
|
||||
private static void initializeTable(JPanel panel) throws IllegalStateException {
|
||||
// 尝试通过索引获取JScrollPane
|
||||
try {
|
||||
if (panel.getComponentCount() >= 5) {
|
||||
Component comp = panel.getComponent(4);
|
||||
if (comp instanceof JScrollPane) {
|
||||
JScrollPane scrollPane = (JScrollPane) comp;
|
||||
Component viewComponent = scrollPane.getViewport().getView();
|
||||
if (viewComponent instanceof JTable) {
|
||||
customersTable = (JTable) viewComponent;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果上面的方法失败,尝试遍历所有组件查找表格
|
||||
for (Component comp : panel.getComponents()) {
|
||||
if (comp instanceof JScrollPane) {
|
||||
JScrollPane scrollPane = (JScrollPane) comp;
|
||||
Component viewComponent = scrollPane.getViewport().getView();
|
||||
if (viewComponent instanceof JTable) {
|
||||
customersTable = (JTable) viewComponent;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException("无法找到表格组件");
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("初始化表格失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新主面板
|
||||
* @param panel 要显示的面板
|
||||
*/
|
||||
private static void updateMainPanel(JPanel panel) {
|
||||
MainView.rightPanel.removeAll();
|
||||
MainView.rightPanel.add(panel, BorderLayout.CENTER);
|
||||
MainView.rightPanel.revalidate();
|
||||
MainView.rightPanel.repaint();
|
||||
|
||||
// 注册刷新操作
|
||||
MainView.registerRefreshAction(MODULE_NAME, CustomersInfo::refreshCustomersData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新客户数据
|
||||
*/
|
||||
static void refreshCustomersData() {
|
||||
// 显示加载指示器
|
||||
MainView.updateStatusMessage("正在加载" + MODULE_NAME + "数据...");
|
||||
|
||||
new SwingWorker<List<Customers>, Void>() {
|
||||
@Override
|
||||
protected List<Customers> doInBackground() {
|
||||
validateTable();
|
||||
|
||||
DefaultTableModel model = (DefaultTableModel) customersTable.getModel();
|
||||
model.setRowCount(0);
|
||||
|
||||
// 获取所有客户数据
|
||||
return SelectCustomers.selectAllCustomers();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
List<Customers> customersList = get();
|
||||
if (customersTable != null) {
|
||||
CustomersMassage.updateTableData(customersTable, customersList);
|
||||
MainView.rightPanel.repaint();
|
||||
MainView.updateStatusMessage("已加载 " + customersList.size() + " 条" + MODULE_NAME + "数据");
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
handleException(e, "刷新失败");
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证表格是否已初始化
|
||||
* @throws IllegalStateException 如果表格未初始化
|
||||
*/
|
||||
private static void validateTable() throws IllegalStateException {
|
||||
if (customersTable == null) {
|
||||
throw new IllegalStateException("表格未初始化");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理异常
|
||||
* @param e 异常
|
||||
* @param message 错误消息前缀
|
||||
*/
|
||||
private static void handleException(Exception e, String message) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null,
|
||||
message + ": " + e.getMessage(),
|
||||
"错误", JOptionPane.ERROR_MESSAGE);
|
||||
MainView.updateStatusMessage(MODULE_NAME + "数据加载失败");
|
||||
}
|
||||
}
|
||||
@ -1,451 +0,0 @@
|
||||
package com.xky.ui.module.customersManagement;
|
||||
import com.xky.pojo.Customers;
|
||||
import com.xky.ui.module.customersManagement.select.SelectCustomers;
|
||||
import com.xky.ui.module.customersManagement.add.AddCustomers;
|
||||
import com.xky.ui.module.customersManagement.delete.DeleteCustomer;
|
||||
import com.xky.ui.module.customersManagement.update.UpdateCustomer;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
import java.awt.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.xky.ui.main.MainView.*;
|
||||
|
||||
/**
|
||||
* 客户信息管理UI类
|
||||
* 负责创建和管理客户信息界面
|
||||
*/
|
||||
public class CustomersMassage {
|
||||
private static JTable table;
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
// 定义颜色常量
|
||||
private static final Color PRIMARY_COLOR = new Color(70, 130, 180);
|
||||
private static final Color SECONDARY_COLOR = new Color(240, 248, 255);
|
||||
private static final Color BUTTON_COLOR = new Color(100, 149, 237);
|
||||
private static final Color SEARCH_BUTTON_COLOR = new Color(46, 204, 113);
|
||||
private static final Color SEPARATOR_COLOR = new Color(0, 191, 255);
|
||||
|
||||
// 定义字体常量
|
||||
private static final Font TITLE_FONT = new Font("微软雅黑", Font.BOLD, 24);
|
||||
private static final Font BUTTON_FONT = new Font("微软雅黑", Font.BOLD, 16);
|
||||
private static final Font TABLE_HEADER_FONT = new Font("微软雅黑", Font.BOLD, 15);
|
||||
private static final Font TABLE_CELL_FONT = new Font("微软雅黑", Font.PLAIN, 14);
|
||||
|
||||
/**
|
||||
* 创建客户信息面板
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 客户信息面板
|
||||
*/
|
||||
public static JPanel createCustomersPanel(Runnable refreshAction) {
|
||||
JPanel panel = new JPanel(new BorderLayout(10, 10));
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
|
||||
// 创建顶部面板(标题和按钮)
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
|
||||
// 标题面板
|
||||
JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JLabel titleLabel = new JLabel("客户基本信息");
|
||||
titleLabel.setFont(TITLE_FONT);
|
||||
titleLabel.setForeground(PRIMARY_COLOR);
|
||||
titlePanel.add(titleLabel);
|
||||
|
||||
// 分割线
|
||||
JSeparator separator = new JSeparator();
|
||||
separator.setPreferredSize(new Dimension(1200, 2));
|
||||
separator.setBackground(SEPARATOR_COLOR);
|
||||
|
||||
// 操作按钮面板
|
||||
JPanel buttonPanel = createButtonPanel(refreshAction);
|
||||
|
||||
// 添加到顶部面板
|
||||
topPanel.add(titlePanel, BorderLayout.NORTH);
|
||||
topPanel.add(separator, BorderLayout.CENTER);
|
||||
topPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 表格
|
||||
JScrollPane scrollPane = createCustomersTable();
|
||||
|
||||
// 添加到主面板
|
||||
panel.add(topPanel, BorderLayout.NORTH);
|
||||
panel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建按钮面板
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 按钮面板
|
||||
*/
|
||||
private static JPanel createButtonPanel(Runnable refreshAction) {
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
|
||||
buttonPanel.setBackground(SECONDARY_COLOR);
|
||||
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
|
||||
|
||||
// 创建按钮
|
||||
JButton addButton = createStyledButton("添加", BUTTON_COLOR);
|
||||
JButton deleteButton = createStyledButton("删除", BUTTON_COLOR);
|
||||
JButton updateButton = createStyledButton("修改", BUTTON_COLOR);
|
||||
JButton queryButton = createStyledButton("查询", SEARCH_BUTTON_COLOR);
|
||||
JButton refreshButton = createStyledButton("刷新", BUTTON_COLOR);
|
||||
|
||||
// 添加事件监听器
|
||||
addButton.addActionListener(e -> {
|
||||
new AddCustomers();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
deleteButton.addActionListener(e -> {
|
||||
new DeleteCustomer();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
updateButton.addActionListener(e -> {
|
||||
new UpdateCustomer();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
queryButton.addActionListener(e -> {
|
||||
// 显示查询对话框
|
||||
showSearchDialog();
|
||||
});
|
||||
|
||||
refreshButton.addActionListener(e -> {
|
||||
DefaultTableModel model = (DefaultTableModel) table.getModel();
|
||||
model.setRowCount(0);
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
// 重新注册刷新操作
|
||||
registerRefreshAction("客户信息", refreshAction);
|
||||
updateStatusMessage("客户数据已刷新");
|
||||
|
||||
// 启动自动刷新
|
||||
if (autoRefreshTimer != null && !autoRefreshTimer.isRunning()) {
|
||||
autoRefreshTimer.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 添加按钮到面板
|
||||
buttonPanel.add(addButton);
|
||||
buttonPanel.add(deleteButton);
|
||||
buttonPanel.add(updateButton);
|
||||
buttonPanel.add(queryButton);
|
||||
buttonPanel.add(refreshButton);
|
||||
|
||||
return buttonPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建统一风格的按钮
|
||||
* @param text 按钮文本
|
||||
* @param bgColor 背景颜色
|
||||
* @return 样式化的按钮
|
||||
*/
|
||||
private static JButton createStyledButton(String text, Color bgColor) {
|
||||
JButton button = new JButton(text);
|
||||
button.setFont(BUTTON_FONT);
|
||||
button.setBackground(bgColor);
|
||||
button.setForeground(Color.WHITE);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorderPainted(false);
|
||||
button.setPreferredSize(new Dimension(100, 35));
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建客户表格
|
||||
* @return 表格滚动面板
|
||||
*/
|
||||
public static JScrollPane createCustomersTable() {
|
||||
String[] title = {"客户ID", "客户编码", "客户名称", "联系人", "联系电话", "电子邮箱", "联系地址", "信用额度", "是否有效","创建时间", "更新时间"};
|
||||
DefaultTableModel model = new DefaultTableModel(title, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false; // 设置表格不可编辑
|
||||
}
|
||||
};
|
||||
|
||||
table = new JTable(model);
|
||||
table.setRowHeight(30);
|
||||
table.setFont(TABLE_CELL_FONT);
|
||||
table.getTableHeader().setFont(TABLE_HEADER_FONT);
|
||||
table.getTableHeader().setBackground(PRIMARY_COLOR);
|
||||
table.getTableHeader().setForeground(Color.BLACK);
|
||||
// 确保表头文本可见
|
||||
table.getTableHeader().setOpaque(true);
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setShowGrid(true);
|
||||
table.setOpaque(false);
|
||||
table.setGridColor(new Color(230, 230, 230));
|
||||
|
||||
// 设置表格排序
|
||||
TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<>(model);
|
||||
table.setRowSorter(sorter);
|
||||
|
||||
// 设置表格列宽
|
||||
int[] columnWidths = {60, 80, 80, 100, 100, 120, 100, 80, 60, 150, 150};
|
||||
for (int i = 0; i < columnWidths.length; i++) {
|
||||
table.getColumnModel().getColumn(i).setPreferredWidth(columnWidths[i]);
|
||||
}
|
||||
|
||||
// 创建美化的滚动面板
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
|
||||
scrollPane.getViewport().setBackground(Color.WHITE);
|
||||
|
||||
return scrollPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新表格数据
|
||||
* @param table 目标表格
|
||||
* @param customersList 客户数据列表
|
||||
*/
|
||||
public static void updateTableData(JTable table, List<Customers> customersList) {
|
||||
DefaultTableModel model = (DefaultTableModel) table.getModel();
|
||||
model.setRowCount(0); // 清空原有数据
|
||||
|
||||
if (customersList == null || customersList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Customers customers : customersList) {
|
||||
// 格式化日期时间
|
||||
String createdTime = customers.getCreatedTime() != null ? customers.getCreatedTime().format(FORMATTER) : "";
|
||||
String updatedTime = customers.getUpdatedTime() != null ? customers.getUpdatedTime().format(FORMATTER) : "";
|
||||
|
||||
String isActiveStr = customers.getIsActive() != null && customers.getIsActive() ? "是" : "否";
|
||||
|
||||
Object[] rowData = {
|
||||
customers.getCustomerId(),
|
||||
customers.getCustomerCode(),
|
||||
customers.getCustomerName(),
|
||||
customers.getContactPerson(),
|
||||
customers.getPhone(),
|
||||
customers.getEmail(),
|
||||
customers.getAddress(),
|
||||
customers.getCreditLimit(),
|
||||
isActiveStr,
|
||||
createdTime,
|
||||
updatedTime
|
||||
};
|
||||
model.addRow(rowData);
|
||||
}
|
||||
model.fireTableDataChanged(); // 触发表格刷新
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示查询对话框
|
||||
*/
|
||||
private static void showSearchDialog() {
|
||||
// 创建对话框
|
||||
JDialog searchDialog = new JDialog((Frame)null, "查询客户", true);
|
||||
searchDialog.setSize(830, 450);
|
||||
searchDialog.setLocationRelativeTo(null);
|
||||
searchDialog.setLayout(new BorderLayout());
|
||||
searchDialog.getContentPane().setBackground(SECONDARY_COLOR);
|
||||
|
||||
// 创建顶部面板
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 10, 15));
|
||||
topPanel.setBackground(SECONDARY_COLOR);
|
||||
|
||||
// 创建单选按钮组
|
||||
JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
radioPanel.setBackground(SECONDARY_COLOR);
|
||||
|
||||
ButtonGroup buttonGroup = new ButtonGroup();
|
||||
JRadioButton idRadio = new JRadioButton("按客户ID查询", true);
|
||||
JRadioButton keywordRadio = new JRadioButton("关键字查询");
|
||||
|
||||
idRadio.setFont(BUTTON_FONT);
|
||||
keywordRadio.setFont(BUTTON_FONT);
|
||||
idRadio.setBackground(SECONDARY_COLOR);
|
||||
keywordRadio.setBackground(SECONDARY_COLOR);
|
||||
|
||||
buttonGroup.add(idRadio);
|
||||
buttonGroup.add(keywordRadio);
|
||||
|
||||
radioPanel.add(idRadio);
|
||||
radioPanel.add(keywordRadio);
|
||||
|
||||
topPanel.add(radioPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建搜索条件面板
|
||||
JPanel searchPanel = new JPanel(new BorderLayout(10, 5));
|
||||
searchPanel.setBackground(SECONDARY_COLOR);
|
||||
|
||||
JLabel searchLabel = new JLabel("查询条件: ");
|
||||
searchLabel.setFont(BUTTON_FONT);
|
||||
searchLabel.setForeground(PRIMARY_COLOR);
|
||||
|
||||
JTextField searchField = new JTextField(20);
|
||||
searchField.setFont(TABLE_CELL_FONT);
|
||||
searchField.setPreferredSize(new Dimension(200, 30));
|
||||
|
||||
JButton searchButton = createStyledButton("搜索", BUTTON_COLOR);
|
||||
|
||||
JPanel searchFieldPanel = new JPanel(new BorderLayout(10, 0));
|
||||
searchFieldPanel.setBackground(SECONDARY_COLOR);
|
||||
searchFieldPanel.add(searchLabel, BorderLayout.WEST);
|
||||
searchFieldPanel.add(searchField, BorderLayout.CENTER);
|
||||
searchFieldPanel.add(searchButton, BorderLayout.EAST);
|
||||
searchPanel.add(searchFieldPanel, BorderLayout.NORTH);
|
||||
|
||||
// 添加提示信息
|
||||
JLabel tipLabel = new JLabel("提示: 关键字查询将搜索 客户编码/ 客户名称/ 联系人/ 联系电话/ 电子邮箱/ 联系地址/ 信用额度/ 是否有效");
|
||||
tipLabel.setFont(new Font("微软雅黑", Font.ITALIC, 12));
|
||||
tipLabel.setForeground(Color.GRAY);
|
||||
tipLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
|
||||
searchPanel.add(tipLabel, BorderLayout.CENTER);
|
||||
|
||||
topPanel.add(searchPanel, BorderLayout.CENTER);
|
||||
searchDialog.add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建表格
|
||||
String[] columnNames = {"客户ID", "客户编码", "客户名称", "联系人", "联系电话", "电子邮箱", "联系地址", "信用额度", "是否有效","创建时间", "更新时间"};
|
||||
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
JTable resultTable = new JTable(tableModel);
|
||||
resultTable.setRowHeight(30);
|
||||
resultTable.setFont(TABLE_CELL_FONT);
|
||||
resultTable.getTableHeader().setFont(TABLE_HEADER_FONT);
|
||||
resultTable.getTableHeader().setBackground(PRIMARY_COLOR);
|
||||
resultTable.getTableHeader().setForeground(Color.BLACK);
|
||||
// 确保表头文本可见
|
||||
resultTable.getTableHeader().setOpaque(true);
|
||||
resultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
resultTable.setShowGrid(true);
|
||||
resultTable.setGridColor(new Color(230, 230, 230));
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(resultTable);
|
||||
scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 15, 10, 15));
|
||||
scrollPane.getViewport().setBackground(Color.WHITE);
|
||||
searchDialog.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// 创建底部按钮面板
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
buttonPanel.setBackground(SECONDARY_COLOR);
|
||||
|
||||
JButton selectButton = createStyledButton("选择", BUTTON_COLOR);
|
||||
JButton cancelButton = createStyledButton("取消", BUTTON_COLOR);
|
||||
|
||||
buttonPanel.add(selectButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
searchDialog.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 设置按钮动作
|
||||
searchButton.addActionListener(e -> {
|
||||
String searchText = searchField.getText().trim();
|
||||
if (searchText.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "请输入查询条件", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Customers> resultList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
if (idRadio.isSelected()) {
|
||||
try {
|
||||
int id = Integer.parseInt(searchText);
|
||||
List<Customers> result = SelectCustomers.selectCustomersById(id);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
resultList.addAll(result);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "ID必须是数字", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else if (keywordRadio.isSelected()) {
|
||||
// 获取关键字搜索结果
|
||||
List<Customers> customers = SelectCustomers.searchCustomersByKeyword(searchText);
|
||||
if (customers != null && !customers.isEmpty()) {
|
||||
resultList.addAll(customers);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新表格数据
|
||||
tableModel.setRowCount(0);
|
||||
|
||||
if (!resultList.isEmpty()) {
|
||||
for (Customers customer : resultList) {
|
||||
String createdTimeStr = customer.getCreatedTime() != null ?
|
||||
customer.getCreatedTime().format(FORMATTER) : "";
|
||||
String updatedTimeStr = customer.getUpdatedTime() != null ?
|
||||
customer.getUpdatedTime().format(FORMATTER) : "";
|
||||
|
||||
String isActiveStr = customer.getIsActive() != null && customer.getIsActive() ? "是" : "否";
|
||||
|
||||
tableModel.addRow(new Object[]{
|
||||
customer.getCustomerId(),
|
||||
customer.getCustomerCode(),
|
||||
customer.getCustomerName(),
|
||||
customer.getContactPerson(),
|
||||
customer.getPhone(),
|
||||
customer.getEmail(),
|
||||
customer.getAddress(),
|
||||
customer.getCreditLimit(),
|
||||
isActiveStr,
|
||||
createdTimeStr,
|
||||
updatedTimeStr
|
||||
});
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(searchDialog, "未找到匹配的记录", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "查询发生错误: " + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(e -> searchDialog.dispose());
|
||||
|
||||
selectButton.addActionListener(e -> {
|
||||
int selectedRow = resultTable.getSelectedRow();
|
||||
if (selectedRow >= 0) {
|
||||
// 获取选中的行数据
|
||||
int customerId = (int) tableModel.getValueAt(selectedRow, 0);
|
||||
|
||||
// 获取选中的客户数据
|
||||
List<Customers> customersList = SelectCustomers.selectCustomersById(customerId);
|
||||
|
||||
if (customersList != null && !customersList.isEmpty()) {
|
||||
// 清空主表格并只显示选中的客户
|
||||
updateTableData(table, customersList);
|
||||
|
||||
// 更新状态消息
|
||||
updateStatusMessage("已选择客户: " + customersList.get(0).getCustomerName());
|
||||
}
|
||||
|
||||
searchDialog.dispose();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(searchDialog, "请选择一条记录", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
// 设置回车键触发搜索按钮
|
||||
searchDialog.getRootPane().setDefaultButton(searchButton);
|
||||
|
||||
// 显示对话框
|
||||
searchDialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
@ -1,471 +0,0 @@
|
||||
package com.xky.ui.module.customersManagement.update;
|
||||
|
||||
import com.xky.pojo.Customers;
|
||||
import com.xky.utils.DBUtils;
|
||||
import com.xky.ui.module.customersManagement.select.SelectCustomers;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 修改客户信息的窗口类
|
||||
*/
|
||||
public class UpdateCustomer extends JFrame {
|
||||
private JPanel mainPanel, formPanel, buttonPanel;
|
||||
private JTextField idField, codeField, nameField, contactPersonField,
|
||||
phoneField, emailField, addressField, creditLimitField;
|
||||
private JCheckBox isActiveCheckBox;
|
||||
private JButton searchButton, updateButton, cancelButton;
|
||||
|
||||
// 定义颜色常量
|
||||
private static final Color PRIMARY_COLOR = new Color(70, 130, 180);
|
||||
private static final Color SECONDARY_COLOR = new Color(240, 248, 255);
|
||||
private static final Color BUTTON_COLOR = new Color(100, 149, 237);
|
||||
private static final Color QUERY_BUTTON_COLOR = new Color(46, 204, 113);
|
||||
private static final Color CANCEL_BUTTON_COLOR = new Color(231, 76, 60);
|
||||
|
||||
// 邮箱验证正则表达式
|
||||
private static final String EMAIL_REGEX =
|
||||
"^(?![._-])(?!.*[._-]$)(?!.*\\.\\.)[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@(?![-])(?!.*-$)[a-zA-Z0-9-]+\\.[a-zA-Z]{2,}(?:\\.[a-zA-Z]{2,})?$";
|
||||
|
||||
public UpdateCustomer() {
|
||||
setTitle("修改客户信息");
|
||||
setSize(550, 800);
|
||||
setLocationRelativeTo(null);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
init();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
// 创建主面板并设置背景渐变
|
||||
mainPanel = new JPanel() {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
GradientPaint gp = new GradientPaint(0, 0, SECONDARY_COLOR, 0, h, new Color(230, 240, 250));
|
||||
g2d.setPaint(gp);
|
||||
g2d.fillRect(0, 0, w, h);
|
||||
}
|
||||
};
|
||||
mainPanel.setLayout(new BorderLayout(10, 10));
|
||||
mainPanel.setBorder(new EmptyBorder(20, 20, 20, 20));
|
||||
|
||||
// 顶部标题面板
|
||||
JPanel headerPanel = new JPanel(new BorderLayout());
|
||||
headerPanel.setOpaque(false);
|
||||
|
||||
JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
titlePanel.setOpaque(false);
|
||||
|
||||
JLabel titleLabel = new JLabel("修改客户信息");
|
||||
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 28));
|
||||
titleLabel.setForeground(PRIMARY_COLOR);
|
||||
titlePanel.add(titleLabel);
|
||||
|
||||
JPanel hintPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
hintPanel.setOpaque(false);
|
||||
|
||||
JLabel hintLabel = new JLabel("请输入客户ID查询后再修改");
|
||||
hintLabel.setFont(new Font("微软雅黑", Font.ITALIC, 14));
|
||||
hintLabel.setForeground(Color.GRAY);
|
||||
hintPanel.setPreferredSize(new Dimension(100,30));
|
||||
hintPanel.add(hintLabel);
|
||||
|
||||
// 添加分隔线
|
||||
JSeparator separator = new JSeparator();
|
||||
separator.setForeground(PRIMARY_COLOR);
|
||||
separator.setPreferredSize(new Dimension(450, 2));
|
||||
|
||||
headerPanel.add(titlePanel, BorderLayout.NORTH);
|
||||
headerPanel.add(hintPanel, BorderLayout.CENTER);
|
||||
headerPanel.add(separator, BorderLayout.SOUTH);
|
||||
headerPanel.setBorder(new EmptyBorder(0, 0, 20, 0));
|
||||
|
||||
mainPanel.add(headerPanel, BorderLayout.NORTH);
|
||||
|
||||
// 中部搜索和表单面板
|
||||
JPanel centerPanel = new JPanel(new BorderLayout(0, 15));
|
||||
centerPanel.setOpaque(false);
|
||||
|
||||
// 搜索面板
|
||||
JPanel searchCard = createRoundedPanel();
|
||||
searchCard.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 15));
|
||||
|
||||
JLabel idLabel = new JLabel("客户ID");
|
||||
idLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
idLabel.setForeground(PRIMARY_COLOR);
|
||||
searchCard.add(idLabel);
|
||||
|
||||
idField = new JTextField(15);
|
||||
idField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
||||
idField.setPreferredSize(new Dimension(200, 35));
|
||||
searchCard.add(idField);
|
||||
|
||||
searchButton = new JButton("查询");
|
||||
styleButton(searchButton, QUERY_BUTTON_COLOR);
|
||||
searchButton.setPreferredSize(new Dimension(100, 35));
|
||||
searchCard.add(searchButton);
|
||||
|
||||
centerPanel.add(searchCard, BorderLayout.NORTH);
|
||||
|
||||
// 表单面板
|
||||
JPanel formCard = createRoundedPanel();
|
||||
formCard.setLayout(new BorderLayout());
|
||||
|
||||
formPanel = new JPanel(new GridBagLayout());
|
||||
formPanel.setOpaque(false);
|
||||
|
||||
// 创建表单字段
|
||||
createFormFields(formPanel);
|
||||
|
||||
formCard.add(formPanel, BorderLayout.CENTER);
|
||||
formCard.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
|
||||
centerPanel.add(formCard, BorderLayout.CENTER);
|
||||
mainPanel.add(centerPanel, BorderLayout.CENTER);
|
||||
|
||||
// 底部按钮面板
|
||||
buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
buttonPanel.setOpaque(false);
|
||||
|
||||
updateButton = new JButton("更新");
|
||||
styleButton(updateButton, BUTTON_COLOR);
|
||||
|
||||
cancelButton = new JButton("取消");
|
||||
styleButton(cancelButton, CANCEL_BUTTON_COLOR);
|
||||
|
||||
buttonPanel.add(updateButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
|
||||
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
add(mainPanel);
|
||||
|
||||
// 禁用表单字段,直到用户搜索到客户
|
||||
setFormFieldsEnabled(false);
|
||||
|
||||
// 添加事件监听器
|
||||
addEventListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建带圆角和阴影的面板
|
||||
*/
|
||||
private JPanel createRoundedPanel() {
|
||||
JPanel panel = new JPanel() {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.fillRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 15, 15);
|
||||
}
|
||||
};
|
||||
panel.setOpaque(false);
|
||||
|
||||
// 添加阴影边框
|
||||
panel.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createEmptyBorder(5, 5, 5, 5),
|
||||
BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createLineBorder(new Color(230, 230, 230), 1),
|
||||
BorderFactory.createEmptyBorder(10, 10, 10, 10)
|
||||
)
|
||||
));
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void styleButton(JButton button, Color bgColor) {
|
||||
button.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
button.setPreferredSize(new Dimension(120, 40));
|
||||
button.setBackground(bgColor);
|
||||
button.setForeground(Color.WHITE);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorderPainted(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建表单字段
|
||||
*/
|
||||
private void createFormFields(JPanel panel) {
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.insets = new Insets(10, 10, 10, 10);
|
||||
|
||||
Font labelFont = new Font("微软雅黑", Font.BOLD, 16);
|
||||
Font fieldFont = new Font("微软雅黑", Font.PLAIN, 16);
|
||||
|
||||
JLabel[] labels = new JLabel[]{
|
||||
new JLabel("客户编码 *"),
|
||||
new JLabel("客户名称 *"),
|
||||
new JLabel("联系人 *"),
|
||||
new JLabel("联系电话 *"),
|
||||
new JLabel("电子邮箱 *"),
|
||||
new JLabel("联系地址 *"),
|
||||
new JLabel("信用额度 *"),
|
||||
new JLabel("是否有效")
|
||||
};
|
||||
|
||||
// 创建文本字段
|
||||
codeField = new JTextField(20);
|
||||
nameField = new JTextField(20);
|
||||
contactPersonField = new JTextField(20);
|
||||
phoneField = new JTextField(20);
|
||||
emailField = new JTextField(20);
|
||||
addressField = new JTextField(20);
|
||||
creditLimitField = new JTextField(20);
|
||||
isActiveCheckBox = new JCheckBox();
|
||||
isActiveCheckBox.setOpaque(false);
|
||||
|
||||
JTextField[] fields = {codeField, nameField, contactPersonField, phoneField, emailField, addressField, creditLimitField};
|
||||
|
||||
for (int i = 0; i < labels.length; i++) {
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = i;
|
||||
gbc.weightx = 0.3;
|
||||
labels[i].setFont(labelFont);
|
||||
labels[i].setForeground(PRIMARY_COLOR);
|
||||
panel.add(labels[i], gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 0.7;
|
||||
|
||||
if (i < 7) {
|
||||
fields[i].setFont(fieldFont);
|
||||
fields[i].setPreferredSize(new Dimension(250, 35));
|
||||
panel.add(fields[i], gbc);
|
||||
} else {
|
||||
panel.add(isActiveCheckBox, gbc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用或禁用表单字段
|
||||
*/
|
||||
private void setFormFieldsEnabled(boolean enabled) {
|
||||
codeField.setEnabled(enabled);
|
||||
nameField.setEnabled(enabled);
|
||||
contactPersonField.setEnabled(enabled);
|
||||
phoneField.setEnabled(enabled);
|
||||
emailField.setEnabled(enabled);
|
||||
addressField.setEnabled(enabled);
|
||||
creditLimitField.setEnabled(enabled);
|
||||
isActiveCheckBox.setEnabled(enabled);
|
||||
updateButton.setEnabled(enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加事件监听器
|
||||
*/
|
||||
private void addEventListeners() {
|
||||
// 查询按钮事件
|
||||
searchButton.addActionListener(e -> {
|
||||
try {
|
||||
String idText = idField.getText().trim();
|
||||
if (idText.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "请输入客户ID", "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
int customerId = Integer.parseInt(idText);
|
||||
List<Customers> customersList = SelectCustomers.selectCustomersById(customerId);
|
||||
|
||||
if (customersList != null && !customersList.isEmpty()) {
|
||||
Customers customer = customersList.get(0);
|
||||
// 填充表单字段
|
||||
codeField.setText(customer.getCustomerCode());
|
||||
nameField.setText(customer.getCustomerName());
|
||||
contactPersonField.setText(customer.getContactPerson());
|
||||
phoneField.setText(customer.getPhone());
|
||||
emailField.setText(customer.getEmail());
|
||||
addressField.setText(customer.getAddress());
|
||||
creditLimitField.setText(customer.getCreditLimit());
|
||||
isActiveCheckBox.setSelected(customer.getIsActive());
|
||||
|
||||
// 启用表单字段
|
||||
setFormFieldsEnabled(true);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "未找到ID为 " + customerId + " 的客户记录",
|
||||
"查找失败", JOptionPane.ERROR_MESSAGE);
|
||||
// 清空并禁用表单字段
|
||||
clearFormFields();
|
||||
setFormFieldsEnabled(false);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this, "请输入有效的数字ID", "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
// 更新按钮事件
|
||||
updateButton.addActionListener(e -> {
|
||||
try {
|
||||
int customerId = Integer.parseInt(idField.getText().trim());
|
||||
String customerCode = codeField.getText().trim();
|
||||
String customerName = nameField.getText().trim();
|
||||
String contactPerson = contactPersonField.getText().trim();
|
||||
String phone = phoneField.getText().trim();
|
||||
String email = emailField.getText().trim();
|
||||
String address = addressField.getText().trim();
|
||||
String creditLimit = creditLimitField.getText().trim();
|
||||
boolean isActive = isActiveCheckBox.isSelected();
|
||||
|
||||
// 验证输入
|
||||
if (!validateInputs(customerCode, customerName, contactPerson, phone, email, address, creditLimit)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新客户信息
|
||||
if (updateCustomer(customerId, customerCode, customerName, contactPerson, phone, email, address, creditLimit, isActive)) {
|
||||
JOptionPane.showMessageDialog(this, "客户信息更新成功", "更新成功", JOptionPane.INFORMATION_MESSAGE);
|
||||
dispose();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "客户信息更新失败", "更新失败", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this, "客户ID格式错误", "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
// 取消按钮事件
|
||||
cancelButton.addActionListener(e -> {
|
||||
dispose();
|
||||
});
|
||||
|
||||
// 为ID文本框添加回车键事件
|
||||
idField.addActionListener(e -> searchButton.doClick());
|
||||
}
|
||||
|
||||
private void clearFormFields() {
|
||||
codeField.setText("");
|
||||
nameField.setText("");
|
||||
contactPersonField.setText("");
|
||||
phoneField.setText("");
|
||||
emailField.setText("");
|
||||
addressField.setText("");
|
||||
creditLimitField.setText("");
|
||||
isActiveCheckBox.setSelected(false);
|
||||
}
|
||||
|
||||
private boolean validateInputs(String customerCode, String customerName, String contactPerson,
|
||||
String phone, String email, String address, String creditLimit) {
|
||||
// 1. 校验客户编码
|
||||
if (customerCode.isEmpty()) {
|
||||
showValidationError("客户编码不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 校验客户名称
|
||||
if (customerName.isEmpty()) {
|
||||
showValidationError("客户名称不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. 校验联系人
|
||||
if (contactPerson.isEmpty()) {
|
||||
showValidationError("联系人不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4. 校验联系电话
|
||||
if (phone.isEmpty()) {
|
||||
showValidationError("联系电话不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 5. 校验电子邮箱
|
||||
if (email.isEmpty()) {
|
||||
showValidationError("电子邮箱不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证邮箱格式
|
||||
if (email.matches(EMAIL_REGEX)) {
|
||||
showValidationError("电子邮箱格式不正确");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 6. 校验联系地址
|
||||
if (address.isEmpty()) {
|
||||
showValidationError("联系地址不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 7. 校验信用额度
|
||||
if (creditLimit.isEmpty()) {
|
||||
showValidationError("信用额度不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
double limit = Double.parseDouble(creditLimit);
|
||||
if (limit < 0) {
|
||||
showValidationError("信用额度不能为负数");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
showValidationError("信用额度必须是数字");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showValidationError(String message) {
|
||||
JOptionPane.showMessageDialog(this, message, "输入错误", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
|
||||
private boolean updateCustomer(int customerId, String customerCode, String customerName,
|
||||
String contactPerson, String phone, String email,
|
||||
String address, String creditLimit, boolean isActive) {
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try {
|
||||
connection = DBUtils.getConnection();
|
||||
String sql = "UPDATE customers SET customer_code=?, customer_name=?, contact_person=?, " +
|
||||
"phone=?, email=?, address=?, credit_limit=?, is_active=?, updated_time=NOW() " +
|
||||
"WHERE customer_id=?";
|
||||
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
preparedStatement.setString(1, customerCode);
|
||||
preparedStatement.setString(2, customerName);
|
||||
preparedStatement.setString(3, contactPerson);
|
||||
preparedStatement.setString(4, phone);
|
||||
preparedStatement.setString(5, email);
|
||||
preparedStatement.setString(6, address);
|
||||
preparedStatement.setString(7, creditLimit);
|
||||
preparedStatement.setBoolean(8, isActive);
|
||||
preparedStatement.setInt(9, customerId);
|
||||
|
||||
int rowsAffected = preparedStatement.executeUpdate();
|
||||
return rowsAffected > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
DBUtils.closeAll(connection, preparedStatement, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(UpdateCustomer::new);
|
||||
}
|
||||
}
|
||||
@ -1,74 +0,0 @@
|
||||
package com.xky.ui.module.inventorManagement;
|
||||
|
||||
import com.xky.pojo.Inventory;
|
||||
import com.xky.ui.main.MainView;
|
||||
import com.xky.ui.module.inventorManagement.select.SelectInvenTory;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class InvenToryInfo {
|
||||
|
||||
private static JTable inventoryTable;
|
||||
|
||||
/**
|
||||
* 显示库存信息页面
|
||||
*/
|
||||
public static void showInventoryInfoPage() {
|
||||
// 创建库存信息面板
|
||||
JPanel inventoryInfoPanel = InvenToryMassage.createInvenToryPanel(InvenToryInfo::refreshInventoryData);
|
||||
|
||||
// 获取表格组件
|
||||
Component[] components = ((JScrollPane)inventoryInfoPanel.getComponent(1)).getViewport().getComponents();
|
||||
if (components.length > 0 && components[0] instanceof JTable) {
|
||||
inventoryTable = (JTable) components[0];
|
||||
}
|
||||
|
||||
// 更新右侧面板
|
||||
MainView.rightPanel.removeAll();
|
||||
MainView.rightPanel.add(inventoryInfoPanel, BorderLayout.CENTER);
|
||||
MainView.rightPanel.revalidate();
|
||||
MainView.rightPanel.repaint();
|
||||
|
||||
// 注册刷新操作
|
||||
MainView.registerRefreshAction("库存信息", InvenToryInfo::refreshInventoryData);
|
||||
|
||||
// 立即刷新一次
|
||||
refreshInventoryData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新库存数据
|
||||
*/
|
||||
static void refreshInventoryData() {
|
||||
new SwingWorker<List<Inventory>, Void>() {
|
||||
@Override
|
||||
protected List<Inventory> doInBackground() {
|
||||
DefaultTableModel model = (DefaultTableModel) inventoryTable.getModel();
|
||||
model.setRowCount(0);
|
||||
|
||||
// 获取所有库存数据
|
||||
return SelectInvenTory.selectAllInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
List<Inventory> inventory = get();
|
||||
if (inventoryTable != null) {
|
||||
InvenToryMassage.updateTableData(inventoryTable, inventory);
|
||||
MainView.rightPanel.repaint();
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"刷新失败:" + e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
package com.xky.ui.module.productManagement;
|
||||
|
||||
import com.xky.pojo.ProductCategories;
|
||||
import com.xky.ui.module.productManagement.select.SelectCateGory;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static com.xky.ui.main.MainView.*;
|
||||
@Data
|
||||
public class ProductCategoryInfo {
|
||||
private static JTable categoryTable;
|
||||
private static JPanel homePanel;
|
||||
|
||||
/**
|
||||
* 显示商品分类信息页面
|
||||
*/
|
||||
public static void showCategoryInfoPage() {
|
||||
// 创建商品分类信息面板
|
||||
JPanel categoryInfoPanel = ProductCategoryMassage.createCategoryPanel(com.xky.ui.module.productManagement.ProductCategoryInfo::refreshCategoryData);
|
||||
|
||||
// 获取表格组件
|
||||
Component[] components = ((JScrollPane)categoryInfoPanel.getComponent(1)).getViewport().getComponents();
|
||||
if (components.length > 0 && components[0] instanceof JTable) {
|
||||
categoryTable = (JTable) components[0];
|
||||
}
|
||||
|
||||
// 更新右侧面板
|
||||
rightPanel.removeAll();
|
||||
rightPanel.add(categoryInfoPanel, BorderLayout.CENTER);
|
||||
rightPanel.revalidate();
|
||||
rightPanel.repaint();
|
||||
|
||||
// 注册刷新操作
|
||||
registerRefreshAction("商品分类", ProductCategoryInfo::refreshCategoryData);
|
||||
|
||||
// 立即刷新一次
|
||||
refreshCategoryData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新商品分类数据
|
||||
*/
|
||||
static void refreshCategoryData() {
|
||||
new SwingWorker<List<ProductCategories>, Void>() {
|
||||
@Override
|
||||
protected List<ProductCategories> doInBackground() {
|
||||
DefaultTableModel model = (DefaultTableModel) categoryTable.getModel();
|
||||
model.setRowCount(0);
|
||||
return SelectCateGory.selectAllCateGory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
List<ProductCategories> categoryList = get();
|
||||
if (categoryTable != null) {
|
||||
ProductCategoryMassage.updateTableData(categoryTable, categoryList);
|
||||
rightPanel.repaint();
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"刷新失败:" + e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
@ -1,157 +0,0 @@
|
||||
package com.xky.ui.module.productManagement.select;
|
||||
|
||||
import com.xky.pojo.ProductCategories;
|
||||
import com.xky.utils.DBUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@Setter
|
||||
@Getter
|
||||
public class SelectCateGory {
|
||||
|
||||
public static List<ProductCategories> selectAllCateGory(){
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<ProductCategories> productCategoriesList = new ArrayList<>();
|
||||
|
||||
connection = DBUtils.getConnection();
|
||||
try {
|
||||
preparedStatement = connection.prepareStatement("select * from product_categories");
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
// 直接使用while循环处理结果集
|
||||
while (resultSet.next()){
|
||||
ProductCategories productCategories = new ProductCategories();
|
||||
productCategories.setCategoryId(resultSet.getInt("category_id"));
|
||||
productCategories.setCategoryName(resultSet.getString("category_name"));
|
||||
productCategories.setParentId(resultSet.getInt("parent_id"));
|
||||
productCategories.setIsActive(resultSet.getString("is_active"));
|
||||
|
||||
// 获取创建时间和更新时间
|
||||
if (resultSet.getTimestamp("created_time") != null) {
|
||||
productCategories.setCreatedTime(resultSet.getTimestamp("created_time").toLocalDateTime());
|
||||
}
|
||||
if (resultSet.getTimestamp("updated_time") != null) {
|
||||
productCategories.setUpdatedTime(resultSet.getTimestamp("updated_time").toLocalDateTime());
|
||||
}
|
||||
|
||||
productCategoriesList.add(productCategories);
|
||||
}
|
||||
return productCategoriesList;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
DBUtils.closeAll(connection,preparedStatement,resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean selectAllCateGoryById(Integer id){
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
connection = DBUtils.getConnection();
|
||||
try {
|
||||
preparedStatement = connection.prepareStatement("select * from product_categories where category_id = ?");
|
||||
preparedStatement.setInt(1,id);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()){
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<ProductCategories> selectCateGoryById(Integer id){
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<ProductCategories> productCategoriesList = new ArrayList<>();
|
||||
|
||||
connection = DBUtils.getConnection();
|
||||
try {
|
||||
preparedStatement = connection.prepareStatement("select * from product_categories where category_id = ?");
|
||||
preparedStatement.setInt(1,id);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next()){
|
||||
ProductCategories productCategories = new ProductCategories();
|
||||
|
||||
productCategories.setCategoryId(resultSet.getInt("category_id"));
|
||||
productCategories.setCategoryName(resultSet.getString("category_name"));
|
||||
productCategories.setParentId(resultSet.getInt("parent_id"));
|
||||
productCategories.setIsActive(resultSet.getString("is_active"));
|
||||
|
||||
// 获取创建时间和更新时间
|
||||
if (resultSet.getTimestamp("created_time") != null) {
|
||||
productCategories.setCreatedTime(resultSet.getTimestamp("created_time").toLocalDateTime());
|
||||
}
|
||||
if (resultSet.getTimestamp("updated_time") != null) {
|
||||
productCategories.setUpdatedTime(resultSet.getTimestamp("updated_time").toLocalDateTime());
|
||||
}
|
||||
|
||||
productCategoriesList.add(productCategories);
|
||||
}
|
||||
return productCategoriesList;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
DBUtils.closeAll(connection,preparedStatement,resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类名称进行模糊查询
|
||||
* @param keyword 关键词
|
||||
* @return 分类列表
|
||||
*/
|
||||
public static List<ProductCategories> searchCategoriesByKeyword(String keyword) {
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<ProductCategories> categoriesList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
connection = DBUtils.getConnection();
|
||||
// 使用LIKE进行模糊查询
|
||||
preparedStatement = connection.prepareStatement(
|
||||
"SELECT * FROM product_categories WHERE category_name LIKE ?"
|
||||
);
|
||||
String searchPattern = "%" + keyword + "%";
|
||||
preparedStatement.setString(1, searchPattern);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
ProductCategories category = new ProductCategories();
|
||||
category.setCategoryId(resultSet.getInt("category_id"));
|
||||
category.setCategoryName(resultSet.getString("category_name"));
|
||||
category.setParentId(resultSet.getInt("parent_id"));
|
||||
category.setIsActive(resultSet.getString("is_active"));
|
||||
|
||||
// 获取创建时间和更新时间
|
||||
if (resultSet.getTimestamp("created_time") != null) {
|
||||
category.setCreatedTime(resultSet.getTimestamp("created_time").toLocalDateTime());
|
||||
}
|
||||
if (resultSet.getTimestamp("updated_time") != null) {
|
||||
category.setUpdatedTime(resultSet.getTimestamp("updated_time").toLocalDateTime());
|
||||
}
|
||||
|
||||
categoriesList.add(category);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
DBUtils.closeAll(connection, preparedStatement, resultSet);
|
||||
}
|
||||
return categoriesList;
|
||||
}
|
||||
}
|
||||
@ -1,312 +0,0 @@
|
||||
package com.xky.ui.module.productManagement.select;
|
||||
|
||||
import com.xky.pojo.Products;
|
||||
import lombok.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
@Setter
|
||||
public class SelectProduct extends JFrame {
|
||||
|
||||
@Getter
|
||||
private static Integer Id;
|
||||
private final ProductService productService;
|
||||
private JTextField searchField;
|
||||
private JRadioButton idSearchRadio;
|
||||
private JRadioButton nameSearchRadio;
|
||||
private JTable resultTable;
|
||||
private DefaultTableModel tableModel;
|
||||
private JScrollPane scrollPane;
|
||||
private boolean showingResults = false;
|
||||
|
||||
public SelectProduct(){
|
||||
setTitle("查询商品");
|
||||
setSize(600, 400);
|
||||
setLocationRelativeTo(null);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
productService = new ProductService();
|
||||
init();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
void init(){
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// 创建主面板
|
||||
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
|
||||
mainPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||
|
||||
// 创建搜索面板
|
||||
JPanel searchPanel = createSearchPanel();
|
||||
mainPanel.add(searchPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建结果表格
|
||||
createResultTable();
|
||||
mainPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// 创建底部按钮面板
|
||||
JPanel buttonPanel = createButtonPanel();
|
||||
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
add(mainPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private JPanel createSearchPanel() {
|
||||
JPanel panel = new JPanel(new BorderLayout(5, 5));
|
||||
panel.setBorder(new EmptyBorder(0, 0, 10, 0));
|
||||
|
||||
// 创建搜索类型选择面板
|
||||
JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
|
||||
idSearchRadio = new JRadioButton("按ID查询");
|
||||
idSearchRadio.setSelected(true);
|
||||
nameSearchRadio = new JRadioButton("按名称/编码查询");
|
||||
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(idSearchRadio);
|
||||
group.add(nameSearchRadio);
|
||||
|
||||
radioPanel.add(idSearchRadio);
|
||||
radioPanel.add(nameSearchRadio);
|
||||
|
||||
panel.add(radioPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建搜索框面板
|
||||
JPanel searchBoxPanel = new JPanel(new BorderLayout(5, 0));
|
||||
|
||||
JLabel searchLabel = new JLabel("查询条件:");
|
||||
searchLabel.setFont(new Font("黑体", Font.BOLD, 14));
|
||||
searchBoxPanel.add(searchLabel, BorderLayout.WEST);
|
||||
|
||||
searchField = new JTextField();
|
||||
searchField.setFont(new Font("宋体", Font.PLAIN, 14));
|
||||
searchBoxPanel.add(searchField, BorderLayout.CENTER);
|
||||
|
||||
JButton searchButton = new JButton("搜索");
|
||||
searchButton.setBackground(Color.PINK);
|
||||
searchButton.addActionListener(e -> performSearch());
|
||||
searchBoxPanel.add(searchButton, BorderLayout.EAST);
|
||||
|
||||
panel.add(searchBoxPanel, BorderLayout.CENTER);
|
||||
|
||||
// 添加提示标签
|
||||
JLabel tipLabel = new JLabel("提示: 模糊查询支持部分商品名称或编码");
|
||||
tipLabel.setFont(new Font("宋体", Font.ITALIC, 12));
|
||||
tipLabel.setForeground(Color.GRAY);
|
||||
panel.add(tipLabel, BorderLayout.SOUTH);
|
||||
|
||||
// 添加搜索框输入监听器,按回车时执行搜索
|
||||
searchField.addActionListener(e -> performSearch());
|
||||
|
||||
// 添加搜索模式切换时的监听器
|
||||
ActionListener radioListener = e -> {
|
||||
if (idSearchRadio.isSelected()) {
|
||||
tipLabel.setText("提示: 请输入商品ID");
|
||||
searchField.getDocument().removeDocumentListener(documentListener);
|
||||
} else {
|
||||
tipLabel.setText("提示: 模糊查询支持部分商品名称或编码");
|
||||
searchField.getDocument().addDocumentListener(documentListener);
|
||||
}
|
||||
};
|
||||
|
||||
idSearchRadio.addActionListener(radioListener);
|
||||
nameSearchRadio.addActionListener(radioListener);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void createResultTable() {
|
||||
// 创建表格模型
|
||||
String[] columnNames = {"商品ID", "商品编码", "商品名称", "分类ID", "计量单位", "最小库存", "是否激活"};
|
||||
tableModel = new DefaultTableModel(columnNames, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false; // 设置表格不可编辑
|
||||
}
|
||||
};
|
||||
|
||||
resultTable = new JTable(tableModel);
|
||||
resultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
resultTable.setRowHeight(25);
|
||||
resultTable.getTableHeader().setFont(new Font("宋体", Font.BOLD, 14));
|
||||
|
||||
// 设置列宽
|
||||
resultTable.getColumnModel().getColumn(0).setPreferredWidth(100); // 商品ID
|
||||
resultTable.getColumnModel().getColumn(1).setPreferredWidth(100); // 商品编码
|
||||
resultTable.getColumnModel().getColumn(2).setPreferredWidth(100); // 商品名称
|
||||
resultTable.getColumnModel().getColumn(3).setPreferredWidth(100); // 分类ID
|
||||
resultTable.getColumnModel().getColumn(4).setPreferredWidth(100); // 计量单位
|
||||
resultTable.getColumnModel().getColumn(5).setPreferredWidth(100); // 最小库存
|
||||
resultTable.getColumnModel().getColumn(6).setPreferredWidth(100); // 是否激活
|
||||
|
||||
// 添加表格点击事件
|
||||
resultTable.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2) { // 双击
|
||||
int selectedRow = resultTable.getSelectedRow();
|
||||
if (selectedRow >= 0) {
|
||||
Id = (Integer) tableModel.getValueAt(selectedRow, 0);
|
||||
JOptionPane.showMessageDialog(SelectProduct.this,
|
||||
"已选择ID为 " + Id + " 的商品: " + tableModel.getValueAt(selectedRow, 2),
|
||||
"已选择", JOptionPane.INFORMATION_MESSAGE);
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
scrollPane = new JScrollPane(resultTable);
|
||||
scrollPane.setPreferredSize(new Dimension(580, 250));
|
||||
}
|
||||
|
||||
private JPanel createButtonPanel() {
|
||||
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
JButton selectButton = new JButton("选择");
|
||||
selectButton.setFont(new Font("黑体", Font.BOLD, 14));
|
||||
selectButton.setBackground(Color.PINK);
|
||||
selectButton.setPreferredSize(new Dimension(100, 30));
|
||||
selectButton.addActionListener(e -> {
|
||||
int selectedRow = resultTable.getSelectedRow();
|
||||
if (selectedRow >= 0) {
|
||||
Id = (Integer) tableModel.getValueAt(selectedRow, 0);
|
||||
JOptionPane.showMessageDialog(SelectProduct.this,
|
||||
"已选择ID为 " + Id + " 的商品: " + tableModel.getValueAt(selectedRow, 2),
|
||||
"已选择", JOptionPane.INFORMATION_MESSAGE);
|
||||
dispose();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(SelectProduct.this,
|
||||
"请先选择一个商品",
|
||||
"提示", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
JButton cancelButton = new JButton("取消");
|
||||
cancelButton.setFont(new Font("黑体", Font.BOLD, 14));
|
||||
cancelButton.setBackground(Color.PINK);
|
||||
cancelButton.setPreferredSize(new Dimension(100, 30));
|
||||
cancelButton.addActionListener(e -> {
|
||||
Id = null;
|
||||
dispose();
|
||||
});
|
||||
|
||||
panel.add(selectButton);
|
||||
panel.add(Box.createHorizontalStrut(20));
|
||||
panel.add(cancelButton);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
// 文档监听器,用于实时搜索
|
||||
private DocumentListener documentListener = new DocumentListener() {
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
if (nameSearchRadio.isSelected() && showingResults) {
|
||||
performSearch();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
if (nameSearchRadio.isSelected() && showingResults) {
|
||||
performSearch();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
if (nameSearchRadio.isSelected() && showingResults) {
|
||||
performSearch();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 执行搜索
|
||||
private void performSearch() {
|
||||
String searchText = searchField.getText().trim();
|
||||
|
||||
if (searchText.isEmpty()) {
|
||||
if (idSearchRadio.isSelected()) {
|
||||
JOptionPane.showMessageDialog(this, "请输入商品ID", "提示", JOptionPane.WARNING_MESSAGE);
|
||||
} else {
|
||||
// 如果是模糊查询且输入为空,显示所有商品
|
||||
displayAllProducts();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (idSearchRadio.isSelected()) {
|
||||
// ID查询
|
||||
try {
|
||||
Integer id = Integer.valueOf(searchText);
|
||||
if (id <= 0) {
|
||||
JOptionPane.showMessageDialog(this, "商品ID必须为正整数", "输入错误", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Products> productList = ProductService.selectProductById(id);
|
||||
updateTableWithResults(productList);
|
||||
|
||||
if (productList.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "未查找到ID为 " + id + " 的商品", "查找结果", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this, "请输入有效的数字ID", "输入错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} else {
|
||||
// 模糊查询
|
||||
List<Products> productList = ProductService.searchProductsByKeyword(searchText);
|
||||
updateTableWithResults(productList);
|
||||
|
||||
if (productList.isEmpty() && !showingResults) {
|
||||
JOptionPane.showMessageDialog(this, "未找到匹配的商品", "查找结果", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
showingResults = true;
|
||||
}
|
||||
|
||||
// 显示所有商品
|
||||
private void displayAllProducts() {
|
||||
List<Products> productList = ProductService.selectAllProducts();
|
||||
updateTableWithResults(productList);
|
||||
}
|
||||
|
||||
// 更新表格数据
|
||||
private void updateTableWithResults(List<Products> productList) {
|
||||
// 清空表格
|
||||
tableModel.setRowCount(0);
|
||||
|
||||
// 添加结果到表格
|
||||
for (Products product : productList) {
|
||||
Object[] rowData = {
|
||||
product.getProductId(),
|
||||
product.getProductCode(),
|
||||
product.getProductName(),
|
||||
product.getCategoryId(),
|
||||
product.getUnitOfMeasure(),
|
||||
product.getMinStockLevel(),
|
||||
product.getIsActive()
|
||||
};
|
||||
tableModel.addRow(rowData);
|
||||
}
|
||||
|
||||
// 刷新表格
|
||||
tableModel.fireTableDataChanged();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(SelectProduct::new);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,229 +0,0 @@
|
||||
package com.xky.ui.module.register;
|
||||
|
||||
import com.xky.ui.module.login.Login;
|
||||
import com.xky.utils.DBUtils;
|
||||
import com.xky.utils.MD5Utils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Register extends JFrame {
|
||||
|
||||
public Register() {
|
||||
setTitle("注册界面");
|
||||
setSize(450, 450);
|
||||
setLocationRelativeTo(null);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
initComponents();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
void initComponents() {
|
||||
setLayout(new BorderLayout());
|
||||
JLabel label1 = new JLabel("用户注册",SwingConstants.CENTER);
|
||||
label1.setBounds(100, 20, 200, 30);
|
||||
label1.setFont(new java.awt.Font("华文行楷", Font.PLAIN, 30));
|
||||
add(label1, BorderLayout.NORTH);
|
||||
|
||||
|
||||
//表单面板
|
||||
JPanel jPanel = new JPanel(new GridBagLayout());
|
||||
jPanel.setBackground(new Color(147, 206, 141));
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.insets = new Insets(5,5,5,5);
|
||||
|
||||
jPanel.setOpaque(false); // 设置主面板为透明
|
||||
|
||||
|
||||
Font font = new Font("微软雅黑", Font.PLAIN, 20);
|
||||
|
||||
JLabel label2 = new JLabel("用户名:");
|
||||
label2.setFont(font);
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.weighty = 0;
|
||||
gbc.insets = new Insets(10,50,10,10);
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
jPanel.add(label2,gbc);
|
||||
|
||||
|
||||
JTextField usernameField = new JTextField(20);
|
||||
usernameField.setPreferredSize(new Dimension(400,35));
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1;
|
||||
gbc.weighty = 0;
|
||||
gbc.gridwidth = 2;
|
||||
gbc.insets = new Insets(10,0,10,50);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
jPanel.add(usernameField,gbc);
|
||||
|
||||
JLabel jLabel1 = new JLabel("密码:");
|
||||
jLabel1.setFont(font);
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.insets = new Insets(10,70,10,10);
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
jPanel.add(jLabel1,gbc);
|
||||
|
||||
|
||||
JPasswordField passwordField = new JPasswordField(20);
|
||||
passwordField.setPreferredSize(new Dimension(400,35));
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 1;
|
||||
gbc.weighty = 0;
|
||||
gbc.gridwidth = 2; // 输入框占据一个网格单元
|
||||
gbc.insets = new Insets(10,0,10,50);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
jPanel.add(passwordField,gbc);
|
||||
|
||||
|
||||
JLabel jLabel2 = new JLabel("确认密码:");
|
||||
jLabel2.setFont(font);
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 2;
|
||||
gbc.insets = new Insets(10,30,10,10);
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
jPanel.add(jLabel2,gbc);
|
||||
|
||||
|
||||
JPasswordField password1Field = new JPasswordField(20);
|
||||
password1Field.setPreferredSize(new Dimension(400,35));
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 2;
|
||||
gbc.weightx = 1;
|
||||
gbc.weighty = 0;
|
||||
gbc.gridwidth = 2; // 输入框占据一个网格单元
|
||||
gbc.insets = new Insets(10,0,10,50);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
jPanel.add(password1Field,gbc);
|
||||
|
||||
JLabel jLabel3 = new JLabel("邮箱:");
|
||||
jLabel3.setFont(font);
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 3;
|
||||
gbc.insets = new Insets(10,70,10,10);
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
jPanel.add(jLabel3,gbc);
|
||||
|
||||
JTextField emailField = new JTextField(20);
|
||||
emailField.setPreferredSize(new Dimension(400,35));
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1;
|
||||
gbc.weighty = 0;
|
||||
gbc.gridwidth = 2; // 输入框占据一个网格单元
|
||||
gbc.insets = new Insets(10,0,10,50);
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
jPanel.add(emailField,gbc);
|
||||
|
||||
//角色提示
|
||||
JLabel jLabel = new JLabel("你当前注册的角色是管理员");
|
||||
jLabel.setFont(new Font("华文行楷",Font.PLAIN,15));
|
||||
jLabel.setForeground(Color.LIGHT_GRAY);
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 4;
|
||||
gbc.insets = new Insets(5,30,10,10);
|
||||
jPanel.add(jLabel,gbc);
|
||||
|
||||
//按钮
|
||||
JButton jButton = new JButton("注册");
|
||||
jButton.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
||||
jButton.setForeground(Color.WHITE);
|
||||
jButton.setBackground(new Color(255, 182, 193)); // 柔和的粉色
|
||||
jButton.setPreferredSize(new Dimension(100, 35));
|
||||
jButton.setFocusPainted(false);
|
||||
jButton.setBorderPainted(false); // 禁用默认边框
|
||||
jButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 5;
|
||||
gbc.insets = new Insets(40,120,10,10);
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
String EMAIL = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$";
|
||||
jButton.addActionListener(e->{
|
||||
String username = usernameField.getText().trim();
|
||||
String password = new String(passwordField.getPassword()).trim();
|
||||
String password1 = new String(password1Field.getPassword()).trim();
|
||||
String email = emailField.getText().trim();
|
||||
|
||||
if (username.isEmpty() || password.isEmpty() || password1.isEmpty() || email.isEmpty()){
|
||||
JOptionPane.showMessageDialog(Register.this,"注册信息不能为空,请输入:","注册提示",JOptionPane.WARNING_MESSAGE);
|
||||
}else if (!password.equals(password1)){
|
||||
JOptionPane.showMessageDialog(Register.this,"你填写的密码不一致,请重新输入,","错误提示",JOptionPane.WARNING_MESSAGE);
|
||||
passwordField.setText("");
|
||||
password1Field.setText("");
|
||||
}else if (!email.matches(EMAIL)){
|
||||
JOptionPane.showMessageDialog(Register.this,"邮箱格式不对,请重新输入","错误提示",JOptionPane.ERROR_MESSAGE);
|
||||
emailField.setText("");
|
||||
}else if (addUser(username,password,email)){
|
||||
JOptionPane.showMessageDialog(Register.this,"恭喜你,注册成功!","成功提示",JOptionPane.INFORMATION_MESSAGE);
|
||||
dispose();
|
||||
new Login();
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(Register.this,"注册失败?","失败提示",JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
jPanel.add(jButton,gbc);
|
||||
|
||||
//按钮
|
||||
JButton jButton1 = new JButton("返回");
|
||||
jButton1.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
||||
jButton1.setForeground(Color.WHITE);
|
||||
jButton1.setBackground(new Color(135, 206, 250)); // 淡蓝色
|
||||
jButton1.setPreferredSize(new Dimension(100, 35));
|
||||
jButton1.setFocusPainted(false);
|
||||
jButton1.setBorderPainted(false); // 禁用默认边框
|
||||
jButton1.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 5;
|
||||
gbc.insets = new Insets(40,120,10,10);
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
|
||||
jButton1.addActionListener(e->{
|
||||
dispose();
|
||||
new Login();
|
||||
});
|
||||
|
||||
jPanel.add(jButton1,gbc);
|
||||
add(jPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
//添加用户信息
|
||||
public boolean addUser(String username, String password, String email){
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
connection = DBUtils.getConnection();
|
||||
String mdpassword = MD5Utils.md5Encrypt(password);
|
||||
try {
|
||||
preparedStatement = connection.prepareStatement("insert into login(username, password, email) values (?,?,?)");
|
||||
preparedStatement.setString(1,username);
|
||||
preparedStatement.setString(2,mdpassword);
|
||||
preparedStatement.setString(3,email);
|
||||
int i = preparedStatement.executeUpdate();
|
||||
|
||||
if (i>0){
|
||||
System.out.println("受影响的行数为"+i+",添加成功!");
|
||||
}else {
|
||||
System.out.println("受影响的行数为"+i+",添加失败!");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}finally {
|
||||
DBUtils.closeAll(connection,preparedStatement,null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
SwingUtilities.invokeLater(Register::new);
|
||||
}
|
||||
}
|
||||
@ -1,578 +0,0 @@
|
||||
package com.xky.ui.module.salesManagement;
|
||||
|
||||
import com.xky.pojo.SalesOrders;
|
||||
import com.xky.ui.module.salesManagement.select.SelectSalesOrder;
|
||||
import com.xky.ui.module.salesManagement.add.AddSalesOrder;
|
||||
import com.xky.ui.module.salesManagement.delete.DeleteSalesOrder;
|
||||
import com.xky.ui.module.salesManagement.update.UpdateSalesOrder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xky.ui.main.MainView.autoRefreshTimer;
|
||||
import static com.xky.ui.main.MainView.updateStatusMessage;
|
||||
|
||||
/**
|
||||
* 销售订单信息管理界面类
|
||||
*/
|
||||
public class SalesMassage {
|
||||
|
||||
// 表格组件
|
||||
private static JTable table;
|
||||
|
||||
// 定义颜色常量
|
||||
private static final Color PRIMARY_COLOR = new Color(70, 130, 180);
|
||||
private static final Color SECONDARY_COLOR = new Color(240, 248, 255);
|
||||
private static final Color BUTTON_COLOR = new Color(100, 149, 237);
|
||||
private static final Color ADD_BUTTON_COLOR = new Color(46, 204, 113);
|
||||
private static final Color UPDATE_BUTTON_COLOR = new Color(52, 152, 219);
|
||||
private static final Color DELETE_BUTTON_COLOR = new Color(231, 76, 60);
|
||||
private static final Color SEARCH_BUTTON_COLOR = new Color(46, 204, 113);
|
||||
private static final Color REFRESH_BUTTON_COLOR = new Color(142, 68, 173);
|
||||
private static final Color SEPARATOR_COLOR = new Color(0, 191, 255);
|
||||
private static final Color HIGHLIGHT_ROW_COLOR = new Color(235, 245, 251);
|
||||
private static final Color ALTERNATE_ROW_COLOR = new Color(248, 251, 255);
|
||||
|
||||
// 定义字体常量
|
||||
private static final Font TITLE_FONT = new Font("微软雅黑", Font.BOLD, 26);
|
||||
private static final Font SUBTITLE_FONT = new Font("微软雅黑", Font.PLAIN, 14);
|
||||
private static final Font BUTTON_FONT = new Font("微软雅黑", Font.BOLD, 14);
|
||||
private static final Font TABLE_HEADER_FONT = new Font("微软雅黑", Font.BOLD, 15);
|
||||
private static final Font TABLE_CELL_FONT = new Font("微软雅黑", Font.PLAIN, 14);
|
||||
|
||||
// 订单状态颜色映射
|
||||
private static final Map<String, Color> STATUS_COLORS = new HashMap<>();
|
||||
static {
|
||||
STATUS_COLORS.put("待处理", new Color(230, 126, 34));
|
||||
STATUS_COLORS.put("已确认", new Color(41, 128, 185));
|
||||
STATUS_COLORS.put("已发货", new Color(46, 204, 113));
|
||||
STATUS_COLORS.put("已完成", new Color(39, 174, 96));
|
||||
STATUS_COLORS.put("已取消", new Color(231, 76, 60));
|
||||
}
|
||||
|
||||
// 支付状态颜色映射
|
||||
private static final Map<String, Color> PAYMENT_COLORS = new HashMap<>();
|
||||
static {
|
||||
PAYMENT_COLORS.put("未支付", new Color(192, 57, 43));
|
||||
PAYMENT_COLORS.put("部分支付", new Color(243, 156, 18));
|
||||
PAYMENT_COLORS.put("已支付", new Color(39, 174, 96));
|
||||
PAYMENT_COLORS.put("已退款", new Color(142, 68, 173));
|
||||
}
|
||||
|
||||
// 状态代码到显示文本的映射
|
||||
private static final Map<String, String> STATUS_MAP = new HashMap<>();
|
||||
static {
|
||||
STATUS_MAP.put("pending", "待处理");
|
||||
STATUS_MAP.put("confirmed", "已确认");
|
||||
STATUS_MAP.put("shipped", "已发货");
|
||||
STATUS_MAP.put("completed", "已完成");
|
||||
STATUS_MAP.put("cancelled", "已取消");
|
||||
}
|
||||
|
||||
private static final Map<String, String> PAYMENT_STATUS_MAP = new HashMap<>();
|
||||
static {
|
||||
PAYMENT_STATUS_MAP.put("unpaid", "未支付");
|
||||
PAYMENT_STATUS_MAP.put("partial", "部分支付");
|
||||
PAYMENT_STATUS_MAP.put("paid", "已支付");
|
||||
PAYMENT_STATUS_MAP.put("refunded", "已退款");
|
||||
}
|
||||
|
||||
// 日期时间格式化器
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
private static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
/**
|
||||
* 创建销售订单信息面板
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 销售订单信息面板
|
||||
*/
|
||||
public static JPanel createSalesInfoPanel(Runnable refreshAction) {
|
||||
JPanel panel = new JPanel(new BorderLayout(10, 10));
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
|
||||
// 创建顶部面板(标题和按钮)
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
|
||||
// 标题面板
|
||||
JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JLabel titleLabel = new JLabel("销售订单基本信息");
|
||||
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
|
||||
titleLabel.setForeground(PRIMARY_COLOR);
|
||||
titlePanel.add(titleLabel);
|
||||
|
||||
// 分割线
|
||||
JSeparator separator = new JSeparator();
|
||||
separator.setPreferredSize(new Dimension(1200, 2));
|
||||
separator.setBackground(SEPARATOR_COLOR);
|
||||
|
||||
// 操作按钮面板
|
||||
JPanel buttonPanel = createButtonPanel(refreshAction);
|
||||
|
||||
// 添加到顶部面板
|
||||
topPanel.add(titlePanel, BorderLayout.NORTH);
|
||||
topPanel.add(separator, BorderLayout.CENTER);
|
||||
topPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 表格
|
||||
JScrollPane scrollPane = createSalesTable();
|
||||
|
||||
// 添加到主面板
|
||||
panel.add(topPanel, BorderLayout.NORTH);
|
||||
panel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建按钮面板
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 按钮面板
|
||||
*/
|
||||
private static JPanel createButtonPanel(Runnable refreshAction) {
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
|
||||
buttonPanel.setBackground(SECONDARY_COLOR);
|
||||
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
|
||||
|
||||
// 创建按钮
|
||||
JButton addButton = createStyledButton("添加", BUTTON_COLOR);
|
||||
JButton deleteButton = createStyledButton("删除", BUTTON_COLOR);
|
||||
JButton updateButton = createStyledButton("修改", BUTTON_COLOR);
|
||||
JButton queryButton = createStyledButton("查询", SEARCH_BUTTON_COLOR);
|
||||
JButton refreshButton = createStyledButton("刷新", BUTTON_COLOR);
|
||||
|
||||
// 添加事件监听器
|
||||
addButton.addActionListener(e -> {
|
||||
new AddSalesOrder();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
deleteButton.addActionListener(e -> {
|
||||
if (table.getSelectedRow() != -1) {
|
||||
int selectedRow = table.getSelectedRow();
|
||||
int orderId = (int) table.getModel().getValueAt(selectedRow, 0);
|
||||
new DeleteSalesOrder(orderId);
|
||||
} else {
|
||||
new DeleteSalesOrder();
|
||||
}
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
updateButton.addActionListener(e -> {
|
||||
if (table.getSelectedRow() != -1) {
|
||||
int selectedRow = table.getSelectedRow();
|
||||
int orderId = (int) table.getModel().getValueAt(selectedRow, 0);
|
||||
new UpdateSalesOrder(orderId);
|
||||
} else {
|
||||
new UpdateSalesOrder();
|
||||
}
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
queryButton.addActionListener(e -> showSearchDialog());
|
||||
|
||||
refreshButton.addActionListener(e -> {
|
||||
SelectSalesOrder.resetSearchStatus();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
updateStatusMessage("销售订单数据已刷新");
|
||||
|
||||
// 启动自动刷新
|
||||
if (autoRefreshTimer != null && !autoRefreshTimer.isRunning()) {
|
||||
autoRefreshTimer.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 添加按钮到面板
|
||||
buttonPanel.add(addButton);
|
||||
buttonPanel.add(deleteButton);
|
||||
buttonPanel.add(updateButton);
|
||||
buttonPanel.add(queryButton);
|
||||
buttonPanel.add(refreshButton);
|
||||
|
||||
return buttonPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建统一风格的按钮
|
||||
* @param text 按钮文本
|
||||
* @param bgColor 背景颜色
|
||||
* @return 按钮对象
|
||||
*/
|
||||
private static JButton createStyledButton(String text, Color bgColor) {
|
||||
JButton button = new JButton(text);
|
||||
button.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
button.setPreferredSize(new Dimension(100, 35));
|
||||
button.setBackground(bgColor);
|
||||
button.setForeground(Color.WHITE);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorderPainted(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建销售订单表格
|
||||
* @return 包含表格的滚动面板
|
||||
*/
|
||||
public static JScrollPane createSalesTable() {
|
||||
// 表格列名
|
||||
String[] columnNames = {"订单ID", "订单编号", "客户ID", "下单时间", "预计发货日期", "实际发货日期",
|
||||
"仓库ID", "商品总额", "税额",
|
||||
"折扣金额", "订单总金额", "已付金额", "备注", "创建时间", "更新时间"};
|
||||
|
||||
// 创建表格模型
|
||||
DefaultTableModel model = new DefaultTableModel(columnNames, 0);
|
||||
|
||||
// 创建表格
|
||||
table = new JTable(model);
|
||||
table.setRowHeight(30);
|
||||
table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
table.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 15));
|
||||
table.getTableHeader().setBackground(PRIMARY_COLOR);
|
||||
table.getTableHeader().setForeground(Color.BLACK);
|
||||
// 确保表头文本可见
|
||||
table.getTableHeader().setOpaque(true);
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setAutoCreateRowSorter(true);
|
||||
table.setShowGrid(true);
|
||||
table.setGridColor(new Color(230, 230, 230));
|
||||
|
||||
// 设置表格列宽
|
||||
table.getColumnModel().getColumn(0).setPreferredWidth(70);
|
||||
table.getColumnModel().getColumn(1).setPreferredWidth(100);
|
||||
table.getColumnModel().getColumn(2).setPreferredWidth(70);
|
||||
table.getColumnModel().getColumn(3).setPreferredWidth(100);
|
||||
table.getColumnModel().getColumn(4).setPreferredWidth(120);
|
||||
table.getColumnModel().getColumn(5).setPreferredWidth(120);
|
||||
table.getColumnModel().getColumn(6).setPreferredWidth(70);
|
||||
table.getColumnModel().getColumn(7).setPreferredWidth(100);
|
||||
table.getColumnModel().getColumn(8).setPreferredWidth(70);
|
||||
table.getColumnModel().getColumn(9).setPreferredWidth(100);
|
||||
table.getColumnModel().getColumn(10).setPreferredWidth(130);
|
||||
table.getColumnModel().getColumn(11).setPreferredWidth(100);
|
||||
table.getColumnModel().getColumn(12).setPreferredWidth(60);
|
||||
table.getColumnModel().getColumn(13).setPreferredWidth(120);
|
||||
table.getColumnModel().getColumn(14).setPreferredWidth(120);
|
||||
|
||||
// 设置单元格渲染器
|
||||
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
|
||||
centerRenderer.setHorizontalAlignment(JLabel.CENTER);
|
||||
|
||||
// 对所有列应用居中渲染器,除了备注列
|
||||
for (int i = 0; i < columnNames.length; i++) {
|
||||
if (i != 14) { // 备注列除外
|
||||
table.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加双击打开编辑功能
|
||||
table.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(java.awt.event.MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
int selectedRow = table.getSelectedRow();
|
||||
if (selectedRow != -1) {
|
||||
int orderId = (int) table.getModel().getValueAt(selectedRow, 0);
|
||||
new UpdateSalesOrder(orderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 创建滚动面板
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
|
||||
scrollPane.getViewport().setBackground(Color.WHITE);
|
||||
|
||||
return scrollPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新表格数据
|
||||
* @param table 表格
|
||||
* @param orderList 销售订单列表
|
||||
*/
|
||||
public static void updateTableData(JTable table, List<SalesOrders> orderList) {
|
||||
if (table == null || orderList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DefaultTableModel model = (DefaultTableModel) table.getModel();
|
||||
|
||||
// 清空表格中现有的数据
|
||||
model.setRowCount(0);
|
||||
|
||||
for (SalesOrders order : orderList) {
|
||||
String orderDateStr = order.getOrderDate() != null ?
|
||||
order.getOrderDate().format(DATETIME_FORMATTER) : "";
|
||||
String expectedShipDateStr = order.getExpectedShipDate() != null ?
|
||||
order.getExpectedShipDate().format(DATE_FORMATTER) : "";
|
||||
String actualShipDateStr = order.getActualShipDate() != null ?
|
||||
order.getActualShipDate().format(DATE_FORMATTER) : "";
|
||||
String createdTimeStr = order.getCreatedTime() != null ?
|
||||
order.getCreatedTime().format(DATETIME_FORMATTER) : "";
|
||||
String updatedTimeStr = order.getUpdatedTime() != null ?
|
||||
order.getUpdatedTime().format(DATETIME_FORMATTER) : "";
|
||||
|
||||
model.addRow(new Object[]{
|
||||
order.getOrderId(),
|
||||
order.getOrderNumber(),
|
||||
order.getCustomerId(),
|
||||
orderDateStr,
|
||||
expectedShipDateStr,
|
||||
actualShipDateStr,
|
||||
order.getWarehouseId(),
|
||||
order.getSubtotal(),
|
||||
order.getTaxAmount(),
|
||||
order.getDiscountAmount(),
|
||||
order.getTotalAmount(),
|
||||
order.getPaidAmount(),
|
||||
order.getNotes(),
|
||||
createdTimeStr,
|
||||
updatedTimeStr
|
||||
});
|
||||
}
|
||||
|
||||
// 触发表格数据刷新
|
||||
model.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示查询对话框
|
||||
*/
|
||||
private static void showSearchDialog() {
|
||||
// 创建对话框
|
||||
JDialog searchDialog = new JDialog((Frame)null, "查询销售订单", true);
|
||||
searchDialog.setSize(900, 550);
|
||||
searchDialog.setLocationRelativeTo(null);
|
||||
searchDialog.setLayout(new BorderLayout());
|
||||
|
||||
// 创建顶部面板
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 10, 15));
|
||||
topPanel.setBackground(SECONDARY_COLOR);
|
||||
|
||||
// 创建单选按钮组
|
||||
JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
radioPanel.setOpaque(false);
|
||||
|
||||
ButtonGroup buttonGroup = new ButtonGroup();
|
||||
JRadioButton idRadio = new JRadioButton("按订单ID查询", true);
|
||||
JRadioButton numberRadio = new JRadioButton("按订单编号查询");
|
||||
JRadioButton customerRadio = new JRadioButton("按客户ID查询");
|
||||
JRadioButton keywordRadio = new JRadioButton("关键字查询");
|
||||
|
||||
idRadio.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
numberRadio.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
customerRadio.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
keywordRadio.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
|
||||
idRadio.setOpaque(false);
|
||||
numberRadio.setOpaque(false);
|
||||
customerRadio.setOpaque(false);
|
||||
keywordRadio.setOpaque(false);
|
||||
|
||||
buttonGroup.add(idRadio);
|
||||
buttonGroup.add(numberRadio);
|
||||
buttonGroup.add(customerRadio);
|
||||
buttonGroup.add(keywordRadio);
|
||||
|
||||
radioPanel.add(idRadio);
|
||||
radioPanel.add(numberRadio);
|
||||
radioPanel.add(customerRadio);
|
||||
radioPanel.add(keywordRadio);
|
||||
|
||||
topPanel.add(radioPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建搜索条件面板
|
||||
JPanel searchPanel = new JPanel(new BorderLayout(10, 5));
|
||||
searchPanel.setOpaque(false);
|
||||
|
||||
JLabel searchLabel = new JLabel("查询条件: ");
|
||||
searchLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
||||
|
||||
JTextField searchField = new JTextField(20);
|
||||
searchField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
searchField.setPreferredSize(new Dimension(200, 30));
|
||||
|
||||
JButton searchButton = createStyledButton("搜索", SEARCH_BUTTON_COLOR);
|
||||
|
||||
JPanel searchFieldPanel = new JPanel(new BorderLayout(10, 0));
|
||||
searchFieldPanel.setOpaque(false);
|
||||
searchFieldPanel.add(searchLabel, BorderLayout.WEST);
|
||||
searchFieldPanel.add(searchField, BorderLayout.CENTER);
|
||||
searchFieldPanel.add(searchButton, BorderLayout.EAST);
|
||||
searchPanel.add(searchFieldPanel, BorderLayout.NORTH);
|
||||
|
||||
// 添加提示信息
|
||||
JLabel tipLabel = new JLabel("提示: 关键字查询将搜索 订单编号/ 客户ID/ 订单状态/ 支付状态/ 备注");
|
||||
tipLabel.setFont(new Font("微软雅黑", Font.ITALIC, 12));
|
||||
tipLabel.setForeground(Color.GRAY);
|
||||
tipLabel.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0));
|
||||
searchPanel.add(tipLabel, BorderLayout.CENTER);
|
||||
|
||||
topPanel.add(searchPanel, BorderLayout.CENTER);
|
||||
searchDialog.add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建表格
|
||||
String[] columnNames = {"订单ID", "订单编号", "客户ID", "下单时间", "订单状态", "支付状态", "订单总金额"};
|
||||
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
JTable resultTable = new JTable(tableModel);
|
||||
resultTable.setRowHeight(30);
|
||||
resultTable.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
resultTable.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 15));
|
||||
resultTable.getTableHeader().setBackground(PRIMARY_COLOR);
|
||||
resultTable.getTableHeader().setForeground(Color.BLACK);
|
||||
// 确保表头文本可见
|
||||
resultTable.getTableHeader().setOpaque(true);
|
||||
resultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
resultTable.setShowGrid(true);
|
||||
resultTable.setGridColor(new Color(230, 230, 230));
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(resultTable);
|
||||
scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 15, 10, 15));
|
||||
scrollPane.getViewport().setBackground(Color.WHITE);
|
||||
searchDialog.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// 创建底部按钮面板
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 15));
|
||||
buttonPanel.setBackground(SECONDARY_COLOR);
|
||||
|
||||
JButton selectButton = createStyledButton("选择", BUTTON_COLOR);
|
||||
JButton cancelButton = createStyledButton("取消", BUTTON_COLOR);
|
||||
|
||||
buttonPanel.add(selectButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
searchDialog.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 设置按钮动作
|
||||
searchButton.addActionListener(e -> {
|
||||
String searchText = searchField.getText().trim();
|
||||
if (searchText.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "请输入查询条件", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
List<SalesOrders> resultList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
if (idRadio.isSelected()) {
|
||||
try {
|
||||
int id = Integer.parseInt(searchText);
|
||||
List<SalesOrders> orders = SelectSalesOrder.selectById(id);
|
||||
if (orders != null && !orders.isEmpty()) {
|
||||
resultList.addAll(orders);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "ID必须是数字", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else if (numberRadio.isSelected()) {
|
||||
// 按订单编号查询
|
||||
List<SalesOrders> orders = SelectSalesOrder.selectByOrderNumber(searchText);
|
||||
if (orders != null && !orders.isEmpty()) {
|
||||
resultList.addAll(orders);
|
||||
}
|
||||
} else if (customerRadio.isSelected()) {
|
||||
// 按客户ID查询
|
||||
try {
|
||||
int customerId = Integer.parseInt(searchText);
|
||||
List<SalesOrders> orders = SelectSalesOrder.selectByCustomerId(customerId);
|
||||
if (orders != null && !orders.isEmpty()) {
|
||||
resultList.addAll(orders);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "客户ID必须是数字", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else if (keywordRadio.isSelected()) {
|
||||
// 关键字查询
|
||||
List<SalesOrders> orders = SelectSalesOrder.searchByKeyword(searchText);
|
||||
if (orders != null && !orders.isEmpty()) {
|
||||
resultList.addAll(orders);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新表格数据
|
||||
tableModel.setRowCount(0);
|
||||
|
||||
if (!resultList.isEmpty()) {
|
||||
for (SalesOrders order : resultList) {
|
||||
String orderDateStr = order.getOrderDate() != null ?
|
||||
order.getOrderDate().format(DATETIME_FORMATTER) : "";
|
||||
|
||||
tableModel.addRow(new Object[]{
|
||||
order.getOrderId(),
|
||||
order.getOrderNumber(),
|
||||
order.getCustomerId(),
|
||||
orderDateStr,
|
||||
STATUS_MAP.get(order.getOrderStatus()),
|
||||
PAYMENT_STATUS_MAP.get(order.getPaymentStatus()),
|
||||
order.getTotalAmount()
|
||||
});
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(searchDialog, "未找到匹配的记录", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "查询发生错误: " + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(e -> searchDialog.dispose());
|
||||
|
||||
selectButton.addActionListener(e -> {
|
||||
int selectedRow = resultTable.getSelectedRow();
|
||||
if (selectedRow >= 0) {
|
||||
// 获取选中的行数据
|
||||
int orderId = (int) tableModel.getValueAt(selectedRow, 0);
|
||||
|
||||
// 获取选中的订单数据
|
||||
List<SalesOrders> orderList = SelectSalesOrder.selectById(orderId);
|
||||
|
||||
if (!orderList.isEmpty()) {
|
||||
// 清空主表格并只显示选中的订单
|
||||
updateTableData(table, orderList);
|
||||
|
||||
// 停止自动刷新
|
||||
if (autoRefreshTimer != null && autoRefreshTimer.isRunning()) {
|
||||
autoRefreshTimer.stop();
|
||||
}
|
||||
|
||||
// 更新状态消息
|
||||
updateStatusMessage("已选择订单ID: " + orderId);
|
||||
}
|
||||
|
||||
searchDialog.dispose();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(searchDialog, "请选择一条记录", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
// 设置回车键触发搜索按钮
|
||||
searchDialog.getRootPane().setDefaultButton(searchButton);
|
||||
|
||||
// 显示对话框
|
||||
searchDialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
@ -1,498 +0,0 @@
|
||||
package com.xky.ui.module.salesManagement;
|
||||
|
||||
import com.xky.pojo.SalesShipments;
|
||||
import com.xky.ui.module.salesManagement.select.SelectSalesShipment;
|
||||
import com.xky.ui.module.salesManagement.add.AddSalesShipment;
|
||||
import com.xky.ui.module.salesManagement.delete.DeleteSalesShipment;
|
||||
import com.xky.ui.module.salesManagement.select.AdvancedSearchSalesShipmentDialog;
|
||||
import com.xky.ui.module.salesManagement.update.UpdateSalesShipment;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
import java.awt.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xky.ui.main.MainView.autoRefreshTimer;
|
||||
import static com.xky.ui.main.MainView.updateStatusMessage;
|
||||
|
||||
/**
|
||||
* 销售发货管理界面类
|
||||
*/
|
||||
public class SalesShipmentsManagement {
|
||||
|
||||
// 表格组件
|
||||
private static JTable table;
|
||||
|
||||
// 定义颜色常量
|
||||
private static final Color PRIMARY_COLOR = new Color(70, 130, 180);
|
||||
private static final Color SECONDARY_COLOR = new Color(240, 248, 255);
|
||||
private static final Color ADD_BUTTON_COLOR = new Color(46, 204, 113);
|
||||
private static final Color UPDATE_BUTTON_COLOR = new Color(52, 152, 219);
|
||||
private static final Color DELETE_BUTTON_COLOR = new Color(231, 76, 60);
|
||||
private static final Color SEARCH_BUTTON_COLOR = new Color(52, 73, 94);
|
||||
private static final Color REFRESH_BUTTON_COLOR = new Color(142, 68, 173);
|
||||
private static final Color SEPARATOR_COLOR = new Color(0, 191, 255);
|
||||
private static final Color HIGHLIGHT_ROW_COLOR = new Color(235, 245, 251);
|
||||
private static final Color ALTERNATE_ROW_COLOR = new Color(248, 251, 255);
|
||||
|
||||
// 定义字体常量
|
||||
private static final Font TITLE_FONT = new Font("微软雅黑", Font.BOLD, 26);
|
||||
private static final Font SUBTITLE_FONT = new Font("微软雅黑", Font.PLAIN, 14);
|
||||
private static final Font BUTTON_FONT = new Font("微软雅黑", Font.BOLD, 14);
|
||||
private static final Font TABLE_HEADER_FONT = new Font("微软雅黑", Font.BOLD, 15);
|
||||
private static final Font TABLE_CELL_FONT = new Font("微软雅黑", Font.PLAIN, 14);
|
||||
|
||||
// 状态颜色映射
|
||||
private static final Map<String, Color> STATUS_COLORS = new HashMap<>();
|
||||
|
||||
static {
|
||||
STATUS_COLORS.put("待发货", new Color(230, 126, 34));
|
||||
STATUS_COLORS.put("已发货", new Color(41, 128, 185));
|
||||
STATUS_COLORS.put("运输中", new Color(46, 204, 113));
|
||||
STATUS_COLORS.put("已签收", new Color(39, 174, 96));
|
||||
STATUS_COLORS.put("已取消", new Color(231, 76, 60));
|
||||
}
|
||||
|
||||
// 状态代码到显示文本的映射
|
||||
private static final Map<String, String> STATUS_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
STATUS_MAP.put("pending", "待发货");
|
||||
STATUS_MAP.put("shipped", "已发货");
|
||||
STATUS_MAP.put("in_transit", "运输中");
|
||||
STATUS_MAP.put("delivered", "已签收");
|
||||
STATUS_MAP.put("cancelled", "已取消");
|
||||
}
|
||||
|
||||
// 日期时间格式化器
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
private static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
/**
|
||||
* 创建销售发货信息面板
|
||||
*
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 销售发货信息面板
|
||||
*/
|
||||
public static JPanel createShipmentsPanel(Runnable refreshAction) {
|
||||
JPanel panel = new JPanel(new BorderLayout(10, 10)) {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
// 创建渐变背景 - 从浅蓝色到白色
|
||||
GradientPaint gp = new GradientPaint(0, 0, SECONDARY_COLOR, 0, h, new Color(255, 255, 255));
|
||||
g2d.setPaint(gp);
|
||||
g2d.fillRect(0, 0, w, h);
|
||||
}
|
||||
};
|
||||
panel.setBorder(new EmptyBorder(15, 15, 15, 15));
|
||||
|
||||
// 创建顶部面板(标题和按钮)
|
||||
JPanel topPanel = new JPanel(new BorderLayout(0, 10));
|
||||
topPanel.setOpaque(false);
|
||||
|
||||
// 标题面板
|
||||
JPanel titlePanel = new JPanel(new BorderLayout());
|
||||
titlePanel.setOpaque(false);
|
||||
|
||||
JLabel titleLabel = new JLabel("销售发货管理");
|
||||
titleLabel.setFont(TITLE_FONT);
|
||||
titleLabel.setForeground(PRIMARY_COLOR);
|
||||
titleLabel.setBorder(new EmptyBorder(0, 10, 0, 0));
|
||||
|
||||
JLabel subtitleLabel = new JLabel("管理和查询所有销售发货信息");
|
||||
subtitleLabel.setFont(SUBTITLE_FONT);
|
||||
subtitleLabel.setForeground(Color.GRAY);
|
||||
subtitleLabel.setBorder(new EmptyBorder(0, 12, 5, 0));
|
||||
|
||||
JPanel labelsPanel = new JPanel(new BorderLayout());
|
||||
labelsPanel.setOpaque(false);
|
||||
labelsPanel.add(titleLabel, BorderLayout.NORTH);
|
||||
labelsPanel.add(subtitleLabel, BorderLayout.CENTER);
|
||||
|
||||
titlePanel.add(labelsPanel, BorderLayout.WEST);
|
||||
|
||||
// 分割线
|
||||
JSeparator separator = new JSeparator();
|
||||
separator.setForeground(SEPARATOR_COLOR);
|
||||
separator.setBackground(SEPARATOR_COLOR);
|
||||
|
||||
// 操作按钮面板
|
||||
JPanel buttonPanel = createButtonPanel(refreshAction);
|
||||
|
||||
// 添加到顶部面板
|
||||
topPanel.add(titlePanel, BorderLayout.NORTH);
|
||||
topPanel.add(separator, BorderLayout.CENTER);
|
||||
topPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 创建表格和滚动面板
|
||||
JScrollPane scrollPane = createShipmentsTable();
|
||||
|
||||
// 给表格添加圆角边框
|
||||
scrollPane.setBorder(BorderFactory.createCompoundBorder(
|
||||
new EmptyBorder(5, 0, 5, 0),
|
||||
BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createLineBorder(SEPARATOR_COLOR, 1, true),
|
||||
BorderFactory.createEmptyBorder(8, 8, 8, 8)
|
||||
)
|
||||
));
|
||||
|
||||
// 状态面板
|
||||
JPanel statusPanel = new JPanel(new BorderLayout());
|
||||
statusPanel.setOpaque(false);
|
||||
statusPanel.setBorder(new EmptyBorder(5, 0, 0, 0));
|
||||
|
||||
// 添加到主面板
|
||||
panel.add(topPanel, BorderLayout.NORTH);
|
||||
panel.add(scrollPane, BorderLayout.CENTER);
|
||||
panel.add(statusPanel, BorderLayout.SOUTH);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建按钮面板
|
||||
*
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 按钮面板
|
||||
*/
|
||||
private static JPanel createButtonPanel(Runnable refreshAction) {
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 10));
|
||||
buttonPanel.setOpaque(false);
|
||||
|
||||
// 创建按钮
|
||||
JButton addButton = createStyledButton("添加发货", ADD_BUTTON_COLOR);
|
||||
JButton updateButton = createStyledButton("修改发货", UPDATE_BUTTON_COLOR);
|
||||
JButton deleteButton = createStyledButton("删除发货", DELETE_BUTTON_COLOR);
|
||||
JButton queryButton = createStyledButton("高级查询", SEARCH_BUTTON_COLOR);
|
||||
JButton refreshButton = createStyledButton("刷新数据", REFRESH_BUTTON_COLOR);
|
||||
|
||||
// 设置按钮大小更一致
|
||||
Dimension buttonSize = new Dimension(110, 35);
|
||||
addButton.setPreferredSize(buttonSize);
|
||||
updateButton.setPreferredSize(buttonSize);
|
||||
deleteButton.setPreferredSize(buttonSize);
|
||||
queryButton.setPreferredSize(buttonSize);
|
||||
refreshButton.setPreferredSize(buttonSize);
|
||||
|
||||
// 按钮事件
|
||||
addButton.addActionListener(e -> {
|
||||
new AddSalesShipment();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
updateButton.addActionListener(e -> {
|
||||
if (table.getSelectedRow() != -1) {
|
||||
int selectedRow = table.getSelectedRow();
|
||||
if (table.getRowSorter() != null) {
|
||||
selectedRow = table.getRowSorter().convertRowIndexToModel(selectedRow);
|
||||
}
|
||||
int shipmentId = (int) table.getModel().getValueAt(selectedRow, 0);
|
||||
new UpdateSalesShipment(shipmentId);
|
||||
} else {
|
||||
new UpdateSalesShipment();
|
||||
}
|
||||
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
deleteButton.addActionListener(e -> {
|
||||
if (table.getSelectedRow() != -1) {
|
||||
int selectedRow = table.getSelectedRow();
|
||||
if (table.getRowSorter() != null) {
|
||||
selectedRow = table.getRowSorter().convertRowIndexToModel(selectedRow);
|
||||
}
|
||||
int shipmentId = (int) table.getModel().getValueAt(selectedRow, 0);
|
||||
new DeleteSalesShipment(shipmentId);
|
||||
} else {
|
||||
new DeleteSalesShipment();
|
||||
}
|
||||
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
queryButton.addActionListener(e -> {
|
||||
Window window = SwingUtilities.getWindowAncestor((Component) e.getSource());
|
||||
AdvancedSearchSalesShipmentDialog dialog = new AdvancedSearchSalesShipmentDialog(window, table);
|
||||
dialog.setVisible(true);
|
||||
|
||||
if (dialog.isConfirmed() && refreshAction != null) {
|
||||
refreshAction.run();
|
||||
updateStatusMessage("已执行高级查询");
|
||||
}
|
||||
});
|
||||
|
||||
refreshButton.addActionListener(e -> {
|
||||
SelectSalesShipment.resetSearchStatus();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
updateStatusMessage("销售发货数据已刷新");
|
||||
|
||||
// 启动自动刷新
|
||||
if (autoRefreshTimer != null && !autoRefreshTimer.isRunning()) {
|
||||
autoRefreshTimer.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 添加按钮到面板
|
||||
buttonPanel.add(addButton);
|
||||
buttonPanel.add(updateButton);
|
||||
buttonPanel.add(deleteButton);
|
||||
buttonPanel.add(queryButton);
|
||||
buttonPanel.add(refreshButton);
|
||||
|
||||
return buttonPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建样式化按钮
|
||||
*
|
||||
* @param text 按钮文本
|
||||
* @param bgColor 背景颜色
|
||||
* @return 按钮对象
|
||||
*/
|
||||
private static JButton createStyledButton(String text, Color bgColor) {
|
||||
JButton button = new JButton(text);
|
||||
button.setFont(BUTTON_FONT);
|
||||
button.setBackground(bgColor);
|
||||
button.setForeground(Color.WHITE);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorderPainted(false);
|
||||
|
||||
// 设置按钮圆角
|
||||
button.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
|
||||
button.setMargin(new Insets(5, 10, 5, 10));
|
||||
|
||||
// 添加鼠标悬停效果
|
||||
button.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(java.awt.event.MouseEvent evt) {
|
||||
button.setBackground(brightenColor(bgColor, 0.1f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(java.awt.event.MouseEvent evt) {
|
||||
button.setBackground(bgColor);
|
||||
}
|
||||
});
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调亮颜色
|
||||
*
|
||||
* @param color 原始颜色
|
||||
* @param factor 调亮因子
|
||||
* @return 调亮后的颜色
|
||||
*/
|
||||
private static Color brightenColor(Color color, float factor) {
|
||||
int r = Math.min(255, (int) (color.getRed() * (1 + factor)));
|
||||
int g = Math.min(255, (int) (color.getGreen() * (1 + factor)));
|
||||
int b = Math.min(255, (int) (color.getBlue() * (1 + factor)));
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建销售发货表格
|
||||
*
|
||||
* @return 包含表格的滚动面板
|
||||
*/
|
||||
public static JScrollPane createShipmentsTable() {
|
||||
// 表格列名
|
||||
String[] columnNames = {"发货单ID", "发货单号", "关联订单ID", "仓库ID", "发货日期",
|
||||
"承运商", "物流单号", "运输方式", "状态", "备注",
|
||||
"创建时间", "更新时间"};
|
||||
|
||||
// 创建表格模型
|
||||
DefaultTableModel model = new DefaultTableModel(columnNames, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false; // 设置表格不可编辑
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int columnIndex) {
|
||||
if (columnIndex == 0 || columnIndex == 2 || columnIndex == 3) {
|
||||
return Integer.class; // ID列使用整数类型
|
||||
}
|
||||
return String.class;
|
||||
}
|
||||
};
|
||||
|
||||
// 创建表格
|
||||
table = new JTable(model);
|
||||
table.setRowHeight(35);
|
||||
table.setFont(TABLE_CELL_FONT);
|
||||
table.getTableHeader().setFont(TABLE_HEADER_FONT);
|
||||
table.getTableHeader().setBackground(PRIMARY_COLOR);
|
||||
table.getTableHeader().setForeground(Color.BLACK);
|
||||
table.getTableHeader().setOpaque(true);
|
||||
table.getTableHeader().setReorderingAllowed(false); // 禁止拖动列
|
||||
table.getTableHeader().setResizingAllowed(true); // 允许调整列宽
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setShowGrid(true);
|
||||
table.setGridColor(new Color(230, 230, 230));
|
||||
table.setFillsViewportHeight(true);
|
||||
|
||||
// 设置表格自动调整大小模式
|
||||
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
|
||||
// 设置交替行颜色
|
||||
table.setDefaultRenderer(Object.class, new TableCellRenderer() {
|
||||
private final DefaultTableCellRenderer DEFAULT_RENDERER = new DefaultTableCellRenderer();
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||
boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
Component c = DEFAULT_RENDERER.getTableCellRendererComponent(
|
||||
table, value, isSelected, hasFocus, row, column);
|
||||
|
||||
if (c instanceof JLabel) {
|
||||
JLabel label = (JLabel) c;
|
||||
label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
|
||||
|
||||
// 居中显示
|
||||
if (column != 9) { // 备注列除外
|
||||
label.setHorizontalAlignment(JLabel.CENTER);
|
||||
}
|
||||
|
||||
// 设置行背景颜色
|
||||
if (isSelected) {
|
||||
c.setBackground(HIGHLIGHT_ROW_COLOR);
|
||||
c.setForeground(PRIMARY_COLOR);
|
||||
} else {
|
||||
c.setBackground(row % 2 == 0 ? Color.WHITE : ALTERNATE_ROW_COLOR);
|
||||
c.setForeground(Color.BLACK);
|
||||
}
|
||||
|
||||
// 设置状态的显示样式
|
||||
if (column == 8 && value != null) { // 状态列
|
||||
String status = value.toString();
|
||||
if (STATUS_COLORS.containsKey(status)) {
|
||||
label.setForeground(Color.WHITE);
|
||||
label.setBackground(STATUS_COLORS.get(status));
|
||||
label.setOpaque(true);
|
||||
label.setBorder(BorderFactory.createEmptyBorder(2, 8, 2, 8));
|
||||
label.setHorizontalAlignment(JLabel.CENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
});
|
||||
|
||||
// 设置表格列宽
|
||||
int[] columnWidths = {70, 100, 70, 70, 100, 100, 100, 100, 100, 200, 150, 150};
|
||||
for (int i = 0; i < Math.min(columnWidths.length, table.getColumnModel().getColumnCount()); i++) {
|
||||
table.getColumnModel().getColumn(i).setPreferredWidth(columnWidths[i]);
|
||||
}
|
||||
|
||||
// 添加双击打开编辑功能
|
||||
table.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(java.awt.event.MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
int selectedRow = table.getSelectedRow();
|
||||
if (selectedRow != -1) {
|
||||
if (table.getRowSorter() != null) {
|
||||
selectedRow = table.getRowSorter().convertRowIndexToModel(selectedRow);
|
||||
}
|
||||
int shipmentId = (int) table.getModel().getValueAt(selectedRow, 0);
|
||||
new UpdateSalesShipment(shipmentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 设置表格排序
|
||||
TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<>(model);
|
||||
table.setRowSorter(sorter);
|
||||
|
||||
// 创建滚动面板
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
scrollPane.setOpaque(false);
|
||||
scrollPane.getViewport().setOpaque(false);
|
||||
|
||||
return scrollPane;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新表格数据
|
||||
*
|
||||
* @param table 表格组件
|
||||
* @param shipmentsList 销售发货列表
|
||||
*/
|
||||
public static void updateTableData(JTable table, List<SalesShipments> shipmentsList) {
|
||||
if (table == null) return;
|
||||
|
||||
DefaultTableModel model = (DefaultTableModel) table.getModel();
|
||||
model.setRowCount(0);
|
||||
|
||||
for (SalesShipments shipment : shipmentsList) {
|
||||
// 获取状态的显示文本
|
||||
String statusDisplay = STATUS_MAP.getOrDefault(shipment.getStatus(), shipment.getStatus());
|
||||
|
||||
Object[] rowData = {
|
||||
shipment.getShipmentId(),
|
||||
shipment.getShipmentNumber(),
|
||||
shipment.getOrderId(),
|
||||
shipment.getWarehouseId(),
|
||||
shipment.getShipmentDate() != null ? shipment.getShipmentDate().format(DATE_FORMATTER) : "",
|
||||
shipment.getCarrier(),
|
||||
shipment.getTrackingNumber(),
|
||||
shipment.getShippingMethod(),
|
||||
statusDisplay,
|
||||
shipment.getNotes(),
|
||||
shipment.getCreatedTime() != null ? shipment.getCreatedTime().format(DATETIME_FORMATTER) : "",
|
||||
shipment.getUpdatedTime() != null ? shipment.getUpdatedTime().format(DATETIME_FORMATTER) : ""
|
||||
};
|
||||
model.addRow(rowData);
|
||||
}
|
||||
|
||||
// 更新状态栏信息
|
||||
Component parent = table.getParent();
|
||||
while (parent != null && !(parent instanceof JPanel)) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
if (parent != null) {
|
||||
Component[] components = parent.getParent().getComponents();
|
||||
for (Component component : components) {
|
||||
if (component instanceof JPanel && ((JPanel) component).getComponentCount() > 0) {
|
||||
Component c = ((JPanel) component).getComponent(0);
|
||||
if (c instanceof JLabel) {
|
||||
JLabel statusLabel = (JLabel) c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,454 +0,0 @@
|
||||
package com.xky.ui.module.supplierManagement;
|
||||
|
||||
import com.xky.pojo.Supplier;
|
||||
import com.xky.ui.module.supplierManagement.select.SelectSupplier;
|
||||
import com.xky.ui.module.supplierManagement.add.AddSuppliers;
|
||||
import com.xky.ui.module.supplierManagement.delete.DeleteSupplier;
|
||||
import com.xky.ui.module.supplierManagement.update.UpdateSupplier;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.xky.ui.main.MainView.autoRefreshTimer;
|
||||
import static com.xky.ui.main.MainView.updateStatusMessage;
|
||||
|
||||
/**
|
||||
* 供应商信息管理界面类
|
||||
*/
|
||||
public class SupplierMassage {
|
||||
|
||||
// 表格组件
|
||||
private static JTable table;
|
||||
|
||||
// 定义颜色常量
|
||||
private static final Color PRIMARY_COLOR = new Color(70, 130, 180);
|
||||
private static final Color SECONDARY_COLOR = new Color(240, 248, 255);
|
||||
private static final Color BUTTON_COLOR = new Color(100, 149, 237);
|
||||
private static final Color SEPARATOR_COLOR = new Color(0, 191, 255);
|
||||
private static final Color SEARCH_BUTTON_COLOR = new Color(46, 204, 113);
|
||||
|
||||
// 日期时间格式化器
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
/**
|
||||
* 创建供应商信息面板
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 供应商信息面板
|
||||
*/
|
||||
public static JPanel createWarehouseInfoPanel(Runnable refreshAction) {
|
||||
JPanel panel = new JPanel(new BorderLayout(10, 10));
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
|
||||
// 创建顶部面板(标题和按钮)
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
|
||||
// 标题面板
|
||||
JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JLabel titleLabel = new JLabel("供应商基本信息");
|
||||
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
|
||||
titleLabel.setForeground(PRIMARY_COLOR);
|
||||
titlePanel.add(titleLabel);
|
||||
|
||||
// 分割线
|
||||
JSeparator separator = new JSeparator();
|
||||
separator.setPreferredSize(new Dimension(1200, 2));
|
||||
separator.setBackground(SEPARATOR_COLOR);
|
||||
|
||||
// 操作按钮面板
|
||||
JPanel buttonPanel = createButtonPanel(refreshAction);
|
||||
|
||||
// 添加到顶部面板
|
||||
topPanel.add(titlePanel, BorderLayout.NORTH);
|
||||
topPanel.add(separator, BorderLayout.CENTER);
|
||||
topPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 表格
|
||||
JScrollPane scrollPane = createSupplierTable();
|
||||
|
||||
// 添加到主面板
|
||||
panel.add(topPanel, BorderLayout.NORTH);
|
||||
panel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建按钮面板
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 按钮面板
|
||||
*/
|
||||
private static JPanel createButtonPanel(Runnable refreshAction) {
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
|
||||
buttonPanel.setBackground(SECONDARY_COLOR);
|
||||
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
|
||||
|
||||
// 创建按钮
|
||||
JButton addButton = createStyledButton("添加", BUTTON_COLOR);
|
||||
JButton deleteButton = createStyledButton("删除", BUTTON_COLOR);
|
||||
JButton updateButton = createStyledButton("修改", BUTTON_COLOR);
|
||||
JButton queryButton = createStyledButton("查询", SEARCH_BUTTON_COLOR);
|
||||
JButton refreshButton = createStyledButton("刷新", BUTTON_COLOR);
|
||||
|
||||
// 添加事件监听器
|
||||
addButton.addActionListener(e -> {
|
||||
new AddSuppliers();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
deleteButton.addActionListener(e -> {
|
||||
new DeleteSupplier();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
updateButton.addActionListener(e -> {
|
||||
new UpdateSupplier();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
});
|
||||
|
||||
queryButton.addActionListener(e -> showSearchDialog());
|
||||
|
||||
refreshButton.addActionListener(e -> {
|
||||
SelectSupplier.resetSearchStatus();
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
updateStatusMessage("供应商数据已刷新");
|
||||
|
||||
// 启动自动刷新
|
||||
if (autoRefreshTimer != null && !autoRefreshTimer.isRunning()) {
|
||||
autoRefreshTimer.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 添加按钮到面板
|
||||
buttonPanel.add(addButton);
|
||||
buttonPanel.add(deleteButton);
|
||||
buttonPanel.add(updateButton);
|
||||
buttonPanel.add(queryButton);
|
||||
buttonPanel.add(refreshButton);
|
||||
|
||||
return buttonPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建统一风格的按钮
|
||||
* @param text 按钮文本
|
||||
* @param bgColor 背景颜色
|
||||
* @return 按钮对象
|
||||
*/
|
||||
private static JButton createStyledButton(String text, Color bgColor) {
|
||||
JButton button = new JButton(text);
|
||||
button.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
button.setPreferredSize(new Dimension(100, 35));
|
||||
button.setBackground(bgColor);
|
||||
button.setForeground(Color.WHITE);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorderPainted(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建供应商表格
|
||||
* @return 包含表格的滚动面板
|
||||
*/
|
||||
public static JScrollPane createSupplierTable() {
|
||||
// 表格列名
|
||||
String[] columnNames = {"供应商ID", "供应商编码", "供应商名称", "联系人姓名", "联系人电话", "联系人邮箱", "地址", "是否合作", "创建时间", "更新时间"};
|
||||
|
||||
// 创建表格模型
|
||||
DefaultTableModel model = new DefaultTableModel(columnNames, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false; // 设置表格不可编辑
|
||||
}
|
||||
};
|
||||
|
||||
// 创建表格
|
||||
table = new JTable(model);
|
||||
table.setRowHeight(30);
|
||||
table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
table.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 15));
|
||||
table.getTableHeader().setBackground(PRIMARY_COLOR);
|
||||
table.getTableHeader().setForeground(Color.BLACK);
|
||||
// 确保表头文本可见
|
||||
table.getTableHeader().setOpaque(true);
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setAutoCreateRowSorter(true);
|
||||
table.setShowGrid(true);
|
||||
table.setGridColor(new Color(230, 230, 230));
|
||||
|
||||
// 设置表格列宽
|
||||
table.getColumnModel().getColumn(0).setPreferredWidth(80);
|
||||
table.getColumnModel().getColumn(1).setPreferredWidth(100);
|
||||
table.getColumnModel().getColumn(2).setPreferredWidth(120);
|
||||
table.getColumnModel().getColumn(3).setPreferredWidth(100);
|
||||
table.getColumnModel().getColumn(4).setPreferredWidth(120);
|
||||
table.getColumnModel().getColumn(5).setPreferredWidth(150);
|
||||
table.getColumnModel().getColumn(6).setPreferredWidth(150);
|
||||
table.getColumnModel().getColumn(7).setPreferredWidth(80);
|
||||
table.getColumnModel().getColumn(8).setPreferredWidth(150);
|
||||
table.getColumnModel().getColumn(9).setPreferredWidth(150);
|
||||
|
||||
// 创建滚动面板
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
|
||||
scrollPane.getViewport().setBackground(Color.WHITE);
|
||||
|
||||
return scrollPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新表格数据
|
||||
* @param table 表格
|
||||
* @param supplierList 供应商列表
|
||||
*/
|
||||
public static void updateTableData(JTable table, List<Supplier> supplierList) {
|
||||
if (table == null || supplierList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DefaultTableModel model = (DefaultTableModel) table.getModel();
|
||||
|
||||
// 清空表格中现有的数据
|
||||
model.setRowCount(0);
|
||||
|
||||
for (Supplier supplier : supplierList) {
|
||||
String createdTimeStr = supplier.getCreatedTime() != null ?
|
||||
supplier.getCreatedTime().format(DATE_FORMATTER) : "";
|
||||
String updatedTimeStr = supplier.getUpdatedTime() != null ?
|
||||
supplier.getUpdatedTime().format(DATE_FORMATTER) : "";
|
||||
|
||||
model.addRow(new Object[]{
|
||||
supplier.getSupplierId(),
|
||||
supplier.getSupplierCode(),
|
||||
supplier.getSupplierName(),
|
||||
supplier.getContactName(),
|
||||
supplier.getContactPhone(),
|
||||
supplier.getContactEmail(),
|
||||
supplier.getAddress(),
|
||||
supplier.getIsActive() ? "是" : "否",
|
||||
createdTimeStr,
|
||||
updatedTimeStr
|
||||
});
|
||||
}
|
||||
|
||||
// 触发表格数据刷新
|
||||
model.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示查询对话框
|
||||
*/
|
||||
private static void showSearchDialog() {
|
||||
// 创建对话框
|
||||
JDialog searchDialog = new JDialog((Frame)null, "查询供应商", true);
|
||||
searchDialog.setSize(900, 550);
|
||||
searchDialog.setLocationRelativeTo(null);
|
||||
searchDialog.setLayout(new BorderLayout());
|
||||
|
||||
// 创建顶部面板
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 10, 15));
|
||||
topPanel.setBackground(SECONDARY_COLOR);
|
||||
|
||||
// 创建单选按钮组
|
||||
JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
radioPanel.setOpaque(false);
|
||||
|
||||
ButtonGroup buttonGroup = new ButtonGroup();
|
||||
JRadioButton idRadio = new JRadioButton("按供应商ID查询", true);
|
||||
JRadioButton keywordRadio = new JRadioButton("关键字查询");
|
||||
|
||||
idRadio.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
keywordRadio.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
idRadio.setOpaque(false);
|
||||
keywordRadio.setOpaque(false);
|
||||
|
||||
buttonGroup.add(idRadio);
|
||||
buttonGroup.add(keywordRadio);
|
||||
|
||||
radioPanel.add(idRadio);
|
||||
radioPanel.add(keywordRadio);
|
||||
|
||||
topPanel.add(radioPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建搜索条件面板
|
||||
JPanel searchPanel = new JPanel(new BorderLayout(10, 5));
|
||||
searchPanel.setOpaque(false);
|
||||
|
||||
JLabel searchLabel = new JLabel("查询条件: ");
|
||||
searchLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
||||
|
||||
JTextField searchField = new JTextField(20);
|
||||
searchField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
searchField.setPreferredSize(new Dimension(200, 30));
|
||||
|
||||
JButton searchButton = createStyledButton("搜索", SEARCH_BUTTON_COLOR);
|
||||
|
||||
JPanel searchFieldPanel = new JPanel(new BorderLayout(10, 0));
|
||||
searchFieldPanel.setOpaque(false);
|
||||
searchFieldPanel.add(searchLabel, BorderLayout.WEST);
|
||||
searchFieldPanel.add(searchField, BorderLayout.CENTER);
|
||||
searchFieldPanel.add(searchButton, BorderLayout.EAST);
|
||||
searchPanel.add(searchFieldPanel, BorderLayout.NORTH);
|
||||
|
||||
// 添加提示信息
|
||||
JLabel tipLabel = new JLabel("提示: 关键字查询将搜索 供应商编码/ 供应商名称/ 联系人姓名/ 联系人电话/ 联系人邮箱/ 地址/ 是否合作");
|
||||
tipLabel.setFont(new Font("微软雅黑", Font.ITALIC, 12));
|
||||
tipLabel.setForeground(Color.GRAY);
|
||||
tipLabel.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0));
|
||||
searchPanel.add(tipLabel, BorderLayout.CENTER);
|
||||
|
||||
topPanel.add(searchPanel, BorderLayout.CENTER);
|
||||
searchDialog.add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建表格
|
||||
String[] columnNames = {"供应商ID", "供应商编码", "供应商名称", "联系人姓名", "联系人电话", "联系人邮箱", "地址", "是否合作", "创建时间", "更新时间"};
|
||||
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
JTable resultTable = new JTable(tableModel);
|
||||
resultTable.setRowHeight(30);
|
||||
resultTable.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
resultTable.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 15));
|
||||
resultTable.getTableHeader().setBackground(Color.lightGray);
|
||||
resultTable.getTableHeader().setForeground(Color.BLACK);
|
||||
// 确保表头文本可见
|
||||
resultTable.getTableHeader().setOpaque(true);
|
||||
resultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
resultTable.setShowGrid(true);
|
||||
resultTable.setGridColor(new Color(230, 230, 230));
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(resultTable);
|
||||
scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 15, 10, 15));
|
||||
scrollPane.getViewport().setBackground(Color.WHITE);
|
||||
searchDialog.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// 创建底部按钮面板
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 15));
|
||||
buttonPanel.setBackground(SECONDARY_COLOR);
|
||||
|
||||
JButton selectButton = createStyledButton("选择", BUTTON_COLOR);
|
||||
JButton cancelButton = createStyledButton("取消", new Color(231, 76, 60));
|
||||
|
||||
buttonPanel.add(selectButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
searchDialog.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 设置按钮动作
|
||||
searchButton.addActionListener(_ -> {
|
||||
String searchText = searchField.getText().trim();
|
||||
if (searchText.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "请输入查询条件", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Supplier> resultList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
if (idRadio.isSelected()) {
|
||||
try {
|
||||
int id = Integer.parseInt(searchText);
|
||||
Supplier result = SelectSupplier.selectWarehousesById(id);
|
||||
if (result != null) {
|
||||
resultList.add(result);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "ID必须是数字", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else if (keywordRadio.isSelected()) {
|
||||
// 获取关键字搜索结果
|
||||
List<Supplier> suppliers = SelectSupplier.searchSupplierByKeyword(searchText);
|
||||
if (suppliers != null && !suppliers.isEmpty()) {
|
||||
resultList.addAll(suppliers);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新表格数据
|
||||
tableModel.setRowCount(0);
|
||||
|
||||
if (!resultList.isEmpty()) {
|
||||
for (Supplier supplier : resultList) {
|
||||
String createdTimeStr = supplier.getCreatedTime() != null ?
|
||||
supplier.getCreatedTime().format(DATE_FORMATTER) : "";
|
||||
String updatedTimeStr = supplier.getUpdatedTime() != null ?
|
||||
supplier.getUpdatedTime().format(DATE_FORMATTER) : "";
|
||||
|
||||
tableModel.addRow(new Object[]{
|
||||
supplier.getSupplierId(),
|
||||
supplier.getSupplierCode(),
|
||||
supplier.getSupplierName(),
|
||||
supplier.getContactName(),
|
||||
supplier.getContactPhone(),
|
||||
supplier.getContactEmail(),
|
||||
supplier.getAddress(),
|
||||
supplier.getIsActive() ? "是" : "否",
|
||||
createdTimeStr,
|
||||
updatedTimeStr
|
||||
});
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(searchDialog, "未找到匹配的记录", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "查询发生错误: " + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(e -> searchDialog.dispose());
|
||||
|
||||
selectButton.addActionListener(e -> {
|
||||
int selectedRow = resultTable.getSelectedRow();
|
||||
if (selectedRow >= 0) {
|
||||
// 获取选中的行数据
|
||||
int supplierId = (int) tableModel.getValueAt(selectedRow, 0);
|
||||
|
||||
// 获取选中的供应商数据
|
||||
Supplier supplier = SelectSupplier.selectWarehousesById(supplierId);
|
||||
List<Supplier> supplierList = new ArrayList<>();
|
||||
if (supplier != null) {
|
||||
supplierList.add(supplier);
|
||||
}
|
||||
|
||||
if (!supplierList.isEmpty()) {
|
||||
// 清空主表格并只显示选中的供应商
|
||||
updateTableData(table, supplierList);
|
||||
|
||||
// 停止自动刷新
|
||||
if (autoRefreshTimer != null && autoRefreshTimer.isRunning()) {
|
||||
autoRefreshTimer.stop();
|
||||
}
|
||||
|
||||
// 更新状态消息
|
||||
updateStatusMessage("已选择供应商: " + supplierList.get(0).getSupplierName());
|
||||
}
|
||||
|
||||
searchDialog.dispose();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(searchDialog, "请选择一条记录", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
// 设置回车键触发搜索按钮
|
||||
searchDialog.getRootPane().setDefaultButton(searchButton);
|
||||
|
||||
// 显示对话框
|
||||
searchDialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
@ -1,133 +0,0 @@
|
||||
package com.xky.ui.module.supplierManagement.select;
|
||||
|
||||
import com.xky.pojo.Supplier;
|
||||
import com.xky.pojo.Warehouses;
|
||||
import com.xky.utils.DBUtils;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SelectSupplier {
|
||||
|
||||
@Getter
|
||||
private static Integer Id;
|
||||
|
||||
// 标记查询是否成功
|
||||
@Getter
|
||||
private static boolean searchSuccessful = false;
|
||||
|
||||
// 存储查询结果
|
||||
@Getter
|
||||
private static List<Warehouses> searchResults;
|
||||
|
||||
public static List<Supplier> searchSupplierByKeyword(String keyword){
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<Supplier> supplierList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
connection = DBUtils.getConnection();
|
||||
// 使用LIKE进行模糊查询
|
||||
preparedStatement = connection.prepareStatement(
|
||||
"SELECT * FROM suppliers WHERE supplier_code LIKE ? OR supplier_name LIKE ? OR contact_name LIKE ? OR contact_Phone LIKE ? OR contact_email LIKE ? OR address LIKE ? OR is_active LIKE ? ORDER BY supplier_id"
|
||||
);
|
||||
String searchPattern = "%" + keyword + "%";
|
||||
preparedStatement.setString(1, searchPattern);
|
||||
preparedStatement.setString(2, searchPattern);
|
||||
preparedStatement.setString(3, searchPattern);
|
||||
preparedStatement.setString(4, searchPattern);
|
||||
preparedStatement.setString(5, searchPattern);
|
||||
preparedStatement.setString(6, searchPattern);
|
||||
preparedStatement.setString(7, searchPattern);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next()){
|
||||
supplierList.add(createSupplierFromResultSet(resultSet));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
DBUtils.closeAll(connection, preparedStatement, resultSet);
|
||||
}
|
||||
return supplierList;
|
||||
}
|
||||
|
||||
//查询所有的供应商信息
|
||||
public static List<Supplier> selectAll(){
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<Supplier> supplierList = new ArrayList<>();
|
||||
|
||||
connection = DBUtils.getConnection();
|
||||
try {
|
||||
preparedStatement = connection.prepareStatement("SELECT * FROM suppliers");
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next()){
|
||||
supplierList.add(createSupplierFromResultSet(resultSet));
|
||||
}
|
||||
return supplierList;
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
DBUtils.closeAll(connection, preparedStatement, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
public static Supplier selectWarehousesById(int supplierId) {
|
||||
Connection connection;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
connection = DBUtils.getConnection();
|
||||
try {
|
||||
preparedStatement = connection.prepareStatement("SELECT * FROM suppliers WHERE supplier_id = ?");
|
||||
preparedStatement.setInt(1, supplierId);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()){
|
||||
return createSupplierFromResultSet(resultSet);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
DBUtils.closeAll(connection, preparedStatement, resultSet);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Supplier createSupplierFromResultSet(ResultSet resultSet) throws SQLException {
|
||||
Supplier supplier = new Supplier();
|
||||
supplier.setSupplierId(resultSet.getInt("supplier_id"));
|
||||
supplier.setSupplierCode(resultSet.getString("supplier_code"));
|
||||
supplier.setSupplierName(resultSet.getString("supplier_name"));
|
||||
supplier.setContactName(resultSet.getString("contact_name"));
|
||||
supplier.setContactPhone(resultSet.getString("contact_phone"));
|
||||
supplier.setContactEmail(resultSet.getString("contact_email"));
|
||||
supplier.setAddress(resultSet.getString("address"));
|
||||
supplier.setIsActive(resultSet.getBoolean("is_active"));
|
||||
|
||||
// 获取创建时间和更新时间
|
||||
if (resultSet.getTimestamp("created_time") != null) {
|
||||
supplier.setCreatedTime(resultSet.getTimestamp("created_time").toLocalDateTime());
|
||||
}
|
||||
if (resultSet.getTimestamp("updated_time") != null) {
|
||||
supplier.setUpdatedTime(resultSet.getTimestamp("updated_time").toLocalDateTime());
|
||||
}
|
||||
|
||||
return supplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置查询状态
|
||||
*/
|
||||
public static void resetSearchStatus() {
|
||||
searchSuccessful = false;
|
||||
searchResults = null;
|
||||
Id = null;
|
||||
}
|
||||
}
|
||||
@ -1,71 +0,0 @@
|
||||
package com.xky.ui.module.warehouseManagement;
|
||||
|
||||
import com.xky.pojo.Warehouses;
|
||||
import com.xky.ui.module.warehouseManagement.select.WarehouseService;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static com.xky.ui.main.MainView.*;
|
||||
|
||||
public class WarehouseInfo {
|
||||
|
||||
private static JTable warehouseTable;
|
||||
|
||||
/**
|
||||
* 显示仓库信息页面
|
||||
*/
|
||||
public static void showWarehouseInfoPage() {
|
||||
// 创建仓库信息面板
|
||||
JPanel warehouseInfoPanel = WarehouseManage.createWarehouseInfoPanel(WarehouseInfo::refreshWarehouseData);
|
||||
|
||||
// 获取表格组件
|
||||
Component[] components = ((JScrollPane)warehouseInfoPanel.getComponent(1)).getViewport().getComponents();
|
||||
if (components.length > 0 && components[0] instanceof JTable) {
|
||||
warehouseTable = (JTable) components[0];
|
||||
}
|
||||
|
||||
// 更新右侧面板
|
||||
rightPanel.removeAll();
|
||||
rightPanel.add(warehouseInfoPanel, BorderLayout.CENTER);
|
||||
rightPanel.revalidate();
|
||||
rightPanel.repaint();
|
||||
|
||||
// 注册刷新操作
|
||||
registerRefreshAction("仓库信息", WarehouseInfo::refreshWarehouseData);
|
||||
|
||||
// 立即刷新一次
|
||||
refreshWarehouseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新仓库数据
|
||||
*/
|
||||
static void refreshWarehouseData() {
|
||||
new SwingWorker<List<Warehouses>, Void>() {
|
||||
@Override
|
||||
protected List<Warehouses> doInBackground() {
|
||||
return WarehouseService.selectAllWarehouses();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
List<Warehouses> warehouses = get();
|
||||
if (warehouseTable != null) {
|
||||
// updateTableData方法会清空并更新表格数据
|
||||
WarehouseManage.updateTableData(warehouseTable, warehouses);
|
||||
rightPanel.revalidate();
|
||||
rightPanel.repaint();
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"刷新失败:" + e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
@ -1,438 +0,0 @@
|
||||
package com.xky.ui.module.warehouseManagement;
|
||||
|
||||
import com.xky.pojo.Warehouses;
|
||||
import com.xky.ui.module.warehouseManagement.select.WarehouseService;
|
||||
import com.xky.ui.module.warehouseManagement.add.AddWarehouse;
|
||||
import com.xky.ui.module.warehouseManagement.delete.DeleteWarehouse;
|
||||
import com.xky.ui.module.warehouseManagement.select.SelectWarehouse;
|
||||
import com.xky.ui.module.warehouseManagement.update.UpdateWarehouse;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
import static com.xky.ui.main.MainView.autoRefreshTimer;
|
||||
import static com.xky.ui.main.MainView.updateStatusMessage;
|
||||
|
||||
/**
|
||||
* 仓库管理界面类
|
||||
*/
|
||||
public class WarehouseManage {
|
||||
|
||||
static JTable table;
|
||||
|
||||
// 定义颜色常量
|
||||
private static final Color PRIMARY_COLOR = new Color(70, 130, 180);
|
||||
private static final Color SECONDARY_COLOR = new Color(240, 248, 255);
|
||||
private static final Color BUTTON_COLOR = new Color(100, 149, 237);
|
||||
private static final Color SEPARATOR_COLOR = new Color(0, 191, 255);
|
||||
private static final Color SEARCH_BUTTON_COLOR = new Color(46, 204, 113);
|
||||
|
||||
/**
|
||||
* 创建仓库信息面板
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 仓库信息面板
|
||||
*/
|
||||
public static JPanel createWarehouseInfoPanel(Runnable refreshAction) {
|
||||
JPanel panel = new JPanel(new BorderLayout(10, 10));
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
|
||||
// 创建顶部面板(标题和按钮)
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
|
||||
// 标题面板
|
||||
JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JLabel titleLabel = new JLabel("仓库基本信息");
|
||||
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
|
||||
titleLabel.setForeground(PRIMARY_COLOR);
|
||||
titlePanel.add(titleLabel);
|
||||
|
||||
// 分割线
|
||||
JSeparator separator = new JSeparator();
|
||||
separator.setPreferredSize(new Dimension(1200, 2));
|
||||
separator.setBackground(SEPARATOR_COLOR);
|
||||
|
||||
// 操作按钮面板
|
||||
JPanel buttonPanel = createButtonPanel(refreshAction);
|
||||
|
||||
// 添加到顶部面板
|
||||
topPanel.add(titlePanel, BorderLayout.NORTH);
|
||||
topPanel.add(separator, BorderLayout.CENTER);
|
||||
topPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 表格
|
||||
JScrollPane scrollPane = createWarehouseTable();
|
||||
|
||||
// 添加到主面板
|
||||
panel.add(topPanel, BorderLayout.NORTH);
|
||||
panel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建按钮面板
|
||||
* @param refreshAction 刷新操作
|
||||
* @return 按钮面板
|
||||
*/
|
||||
private static JPanel createButtonPanel(Runnable refreshAction) {
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
|
||||
buttonPanel.setBackground(SECONDARY_COLOR);
|
||||
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
|
||||
|
||||
// 创建按钮
|
||||
JButton addButton = createStyledButton("添加", BUTTON_COLOR);
|
||||
JButton deleteButton = createStyledButton("删除", BUTTON_COLOR);
|
||||
JButton updateButton = createStyledButton("修改", BUTTON_COLOR);
|
||||
JButton queryButton = createStyledButton("查询", SEARCH_BUTTON_COLOR);
|
||||
JButton refreshButton = createStyledButton("刷新", BUTTON_COLOR);
|
||||
|
||||
// 添加事件监听器
|
||||
addButton.addActionListener(e -> {
|
||||
AddWarehouse addWarehouse = new AddWarehouse();
|
||||
addWarehouse.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
deleteButton.addActionListener(e -> {
|
||||
DeleteWarehouse deleteWarehouse = new DeleteWarehouse();
|
||||
deleteWarehouse.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
updateButton.addActionListener(e -> {
|
||||
UpdateWarehouse updateWarehouse = new UpdateWarehouse();
|
||||
updateWarehouse.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
queryButton.addActionListener(e -> {
|
||||
showSearchDialog();
|
||||
});
|
||||
|
||||
refreshButton.addActionListener(e -> {
|
||||
SelectWarehouse.resetSearchStatus();
|
||||
|
||||
if (refreshAction != null) {
|
||||
refreshAction.run();
|
||||
|
||||
// 更新状态消息
|
||||
updateStatusMessage("仓库数据已刷新");
|
||||
|
||||
// 启动自动刷新
|
||||
if (autoRefreshTimer != null && !autoRefreshTimer.isRunning()) {
|
||||
autoRefreshTimer.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 添加按钮到面板
|
||||
buttonPanel.add(addButton);
|
||||
buttonPanel.add(deleteButton);
|
||||
buttonPanel.add(updateButton);
|
||||
buttonPanel.add(queryButton);
|
||||
buttonPanel.add(refreshButton);
|
||||
|
||||
return buttonPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建统一风格的按钮
|
||||
* @param text 按钮文本
|
||||
* @param bgColor 背景颜色
|
||||
* @return 按钮对象
|
||||
*/
|
||||
private static JButton createStyledButton(String text, Color bgColor) {
|
||||
JButton button = new JButton(text);
|
||||
button.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
button.setPreferredSize(new Dimension(100, 35));
|
||||
button.setBackground(bgColor);
|
||||
button.setForeground(Color.WHITE);
|
||||
button.setFocusPainted(false);
|
||||
button.setBorderPainted(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建仓库表格
|
||||
* @return 包含表格的滚动面板
|
||||
*/
|
||||
public static JScrollPane createWarehouseTable() {
|
||||
// 表格列名
|
||||
String[] columnNames = {"仓库ID", "仓库编码", "仓库名称", "仓库位置", "是否启用", "创建时间", "更新时间"};
|
||||
|
||||
// 创建表格模型
|
||||
DefaultTableModel model = new DefaultTableModel(columnNames, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false; // 设置表格不可编辑
|
||||
}
|
||||
};
|
||||
|
||||
// 创建表格
|
||||
table = new JTable(model);
|
||||
table.setRowHeight(30);
|
||||
table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
||||
table.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 15));
|
||||
table.getTableHeader().setBackground(PRIMARY_COLOR);
|
||||
table.getTableHeader().setForeground(Color.BLACK);
|
||||
// 确保表头文本可见
|
||||
table.getTableHeader().setOpaque(true);
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setAutoCreateRowSorter(true);
|
||||
table.setShowGrid(true);
|
||||
table.setGridColor(new Color(230, 230, 230));
|
||||
|
||||
// 设置表格列宽
|
||||
table.getColumnModel().getColumn(0).setPreferredWidth(70); // 仓库ID
|
||||
table.getColumnModel().getColumn(1).setPreferredWidth(100); // 仓库编码
|
||||
table.getColumnModel().getColumn(2).setPreferredWidth(150); // 仓库名称
|
||||
table.getColumnModel().getColumn(3).setPreferredWidth(200); // 仓库位置
|
||||
table.getColumnModel().getColumn(4).setPreferredWidth(70); // 是否启用
|
||||
table.getColumnModel().getColumn(5).setPreferredWidth(150); // 创建时间
|
||||
table.getColumnModel().getColumn(6).setPreferredWidth(150); // 更新时间
|
||||
|
||||
// 创建滚动面板
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
|
||||
scrollPane.getViewport().setBackground(Color.WHITE);
|
||||
|
||||
return scrollPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新表格数据
|
||||
* @param table 表格
|
||||
* @param warehouseList 仓库列表
|
||||
*/
|
||||
public static void updateTableData(JTable table, List<Warehouses> warehouseList) {
|
||||
DefaultTableModel model = (DefaultTableModel) table.getModel();
|
||||
|
||||
// 清空表格中现有的数据
|
||||
model.setRowCount(0);
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
for (Warehouses warehouse : warehouseList) {
|
||||
model.addRow(new Object[]{
|
||||
warehouse.getWarehouseId(),
|
||||
warehouse.getWarehouseCode(),
|
||||
warehouse.getWarehouseName(),
|
||||
warehouse.getLocation(),
|
||||
warehouse.getIsActive() ? "是" : "否",
|
||||
warehouse.getCreatedTime().format(formatter),
|
||||
warehouse.getUpdatedTime().format(formatter)
|
||||
});
|
||||
}
|
||||
|
||||
// 触发表格数据刷新
|
||||
model.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示查询对话框
|
||||
*/
|
||||
private static void showSearchDialog() {
|
||||
// 创建对话框
|
||||
JDialog searchDialog = new JDialog((Frame)null, "查询仓库", true);
|
||||
searchDialog.setSize(550, 450);
|
||||
searchDialog.setLocationRelativeTo(null);
|
||||
searchDialog.setLayout(new BorderLayout());
|
||||
|
||||
// 创建顶部面板
|
||||
JPanel topPanel = new JPanel(new BorderLayout());
|
||||
topPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 5, 10));
|
||||
|
||||
// 创建单选按钮组
|
||||
JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
ButtonGroup buttonGroup = new ButtonGroup();
|
||||
JRadioButton idRadio = new JRadioButton("按ID查询", true);
|
||||
JRadioButton nameRadio = new JRadioButton("按名称查询");
|
||||
JRadioButton codeRadio = new JRadioButton("按编码查询");
|
||||
JRadioButton locationRadio = new JRadioButton("按位置查询");
|
||||
JRadioButton keywordRadio = new JRadioButton("关键字查询");
|
||||
|
||||
buttonGroup.add(idRadio);
|
||||
buttonGroup.add(nameRadio);
|
||||
buttonGroup.add(codeRadio);
|
||||
buttonGroup.add(locationRadio);
|
||||
buttonGroup.add(keywordRadio);
|
||||
|
||||
radioPanel.add(idRadio);
|
||||
radioPanel.add(nameRadio);
|
||||
radioPanel.add(codeRadio);
|
||||
radioPanel.add(locationRadio);
|
||||
radioPanel.add(keywordRadio);
|
||||
|
||||
topPanel.add(radioPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建搜索条件面板
|
||||
JPanel searchPanel = new JPanel(new BorderLayout());
|
||||
JLabel searchLabel = new JLabel("查询条件: ");
|
||||
JTextField searchField = new JTextField(20);
|
||||
JButton searchButton = new JButton("搜索");
|
||||
searchButton.setBackground(new Color(255, 175, 175)); // 浅粉色
|
||||
|
||||
JPanel searchFieldPanel = new JPanel(new BorderLayout());
|
||||
searchFieldPanel.add(searchLabel, BorderLayout.WEST);
|
||||
searchFieldPanel.add(searchField, BorderLayout.CENTER);
|
||||
searchFieldPanel.add(searchButton, BorderLayout.EAST);
|
||||
searchPanel.add(searchFieldPanel, BorderLayout.NORTH);
|
||||
|
||||
// 添加提示信息
|
||||
JLabel tipLabel = new JLabel("提示: 关键字查询将搜索名称/编码/位置");
|
||||
tipLabel.setForeground(Color.GRAY);
|
||||
tipLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
|
||||
searchPanel.add(tipLabel, BorderLayout.CENTER);
|
||||
|
||||
topPanel.add(searchPanel, BorderLayout.CENTER);
|
||||
searchDialog.add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
// 创建表格
|
||||
String[] columnNames = {"仓库ID", "仓库编码", "仓库名称", "仓库位置", "是否启用", "创建时间", "更新时间"};
|
||||
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false; // 设置表格不可编辑
|
||||
}
|
||||
};
|
||||
|
||||
JTable resultTable = new JTable(tableModel);
|
||||
resultTable.setRowHeight(25);
|
||||
resultTable.getTableHeader().setFont(new Font("宋体", Font.BOLD, 14));
|
||||
resultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(resultTable);
|
||||
scrollPane.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
|
||||
searchDialog.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// 创建底部按钮面板
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
||||
JButton selectButton = new JButton("选择");
|
||||
JButton cancelButton = new JButton("取消");
|
||||
selectButton.setBackground(new Color(255, 175, 175)); // 浅粉色
|
||||
cancelButton.setBackground(new Color(255, 175, 175)); // 浅粉色
|
||||
|
||||
selectButton.setPreferredSize(new Dimension(100, 30));
|
||||
cancelButton.setPreferredSize(new Dimension(100, 30));
|
||||
|
||||
buttonPanel.add(selectButton);
|
||||
buttonPanel.add(cancelButton);
|
||||
searchDialog.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// 设置按钮动作
|
||||
searchButton.addActionListener(e -> {
|
||||
String searchText = searchField.getText().trim();
|
||||
if (searchText.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "请输入查询条件", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Warehouses> results = null;
|
||||
|
||||
try {
|
||||
if (idRadio.isSelected()) {
|
||||
try {
|
||||
int id = Integer.parseInt(searchText);
|
||||
results = WarehouseService.selectWarehousesById(id);
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "ID必须是数字", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else if (nameRadio.isSelected()) {
|
||||
results = WarehouseService.searchWarehousesByName(searchText);
|
||||
} else if (codeRadio.isSelected()) {
|
||||
results = WarehouseService.searchWarehousesByCode(searchText);
|
||||
} else if (locationRadio.isSelected()) {
|
||||
results = WarehouseService.searchWarehousesByLocation(searchText);
|
||||
} else if (keywordRadio.isSelected()) {
|
||||
results = WarehouseService.searchWarehousesByKeyword(searchText);
|
||||
}
|
||||
|
||||
// 更新表格数据
|
||||
tableModel.setRowCount(0);
|
||||
|
||||
if (results != null && !results.isEmpty()) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
for (Warehouses warehouse : results) {
|
||||
tableModel.addRow(new Object[]{
|
||||
warehouse.getWarehouseId(),
|
||||
warehouse.getWarehouseCode(),
|
||||
warehouse.getWarehouseName(),
|
||||
warehouse.getLocation(),
|
||||
warehouse.getIsActive() ? "是" : "否",
|
||||
warehouse.getCreatedTime().format(formatter),
|
||||
warehouse.getUpdatedTime().format(formatter)
|
||||
});
|
||||
}
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(searchDialog, "未找到匹配的记录", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(searchDialog, "查询发生错误: " + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addActionListener(e -> searchDialog.dispose());
|
||||
|
||||
selectButton.addActionListener(e -> {
|
||||
int selectedRow = resultTable.getSelectedRow();
|
||||
if (selectedRow >= 0) {
|
||||
// 获取选中的行数据
|
||||
int warehouseId = (int) tableModel.getValueAt(selectedRow, 0);
|
||||
|
||||
// 获取选中的仓库数据
|
||||
List<Warehouses> selectedWarehouse = WarehouseService.selectWarehousesById(warehouseId);
|
||||
|
||||
if (selectedWarehouse != null && !selectedWarehouse.isEmpty()) {
|
||||
// 清空主表格并只显示选中的仓库
|
||||
updateTableData(table, selectedWarehouse);
|
||||
|
||||
// 停止自动刷新
|
||||
if (autoRefreshTimer != null && autoRefreshTimer.isRunning()) {
|
||||
System.out.println("停止自动刷新");
|
||||
autoRefreshTimer.stop();
|
||||
}
|
||||
|
||||
// 更新状态消息
|
||||
updateStatusMessage("已选择仓库: " + selectedWarehouse.get(0).getWarehouseName());
|
||||
}
|
||||
|
||||
searchDialog.dispose();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(searchDialog, "请选择一条记录", "提示", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
// 设置回车键触发搜索按钮
|
||||
searchDialog.getRootPane().setDefaultButton(searchButton);
|
||||
|
||||
// 显示对话框
|
||||
searchDialog.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
|
||||
driver=com.mysql.cj.jdbc.Driver
|
||||
url=jdbc:mysql://localhost:3306/product?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
|
||||
username=root
|
||||
password=123456
|
||||
Loading…
Reference in new issue