Skip to content

Commit 893eca8

Browse files
committed
Improve AddCarController.kt, fix bugs, optimization
1 parent 18d524e commit 893eca8

32 files changed

+1092
-1037
lines changed

.idea/encodings.xml

-6
This file was deleted.

.idea/gradle.xml

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

-6
This file was deleted.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

-10
This file was deleted.

.idea/workspace.xml

+34-232
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ tasks.jar {
7272
dependsOn(configurations.runtimeClasspath)
7373
manifest {
7474
exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "META-INF/*.MF")
75-
attributes(
75+
attributes("Main",
7676
"Implementation-Title" to "ServiceHelper",
7777
"Implementation-Version" to archiveVersion,
7878
"Main-Class" to "ldcapps.servicehelper.WindowsKt",
@@ -82,6 +82,6 @@ tasks.jar {
8282
from({
8383
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
8484
})
85-
86-
85+
86+
8787
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/kotlin/ldcapps/servicehelper/Dialogs.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class Dialogs {
5959
return false
6060
}
6161

62-
fun filter(type: Int, vararg els: String): Triple<Int, Int, MutableList<Int>> {
63-
val dialog = Dialog<String>()
62+
data class Filter(val topMargin: Int, val rightMargin: Int, val result: List<Int>)
6463

64+
fun filter(type: Int, vararg els: String): Filter {
65+
val dialog = Dialog<String>()
6566
dialog.title = "Фильтр"
66-
6767
dialog.dialogPane.buttonTypes.addAll(ButtonType.OK)
6868

6969
val excelTab = DataClasses.excelTabs[type]
@@ -76,6 +76,7 @@ class Dialogs {
7676
prefWidth = 60.0
7777
valueFactory = SpinnerValueFactory.IntegerSpinnerValueFactory(0, 100, excelTab.topMargin)
7878
}
79+
7980
val tabPane = TabPane().apply {
8081
tabDragPolicy = TabPane.TabDragPolicy.REORDER
8182
tabClosingPolicy = TabPane.TabClosingPolicy.UNAVAILABLE
@@ -123,7 +124,7 @@ class Dialogs {
123124
toJSON(".excelTabs", DataClasses.excelTabs)
124125
}
125126

126-
return Triple(topMargin.value, rightMargin.value, res)
127+
return Filter(topMargin.value, rightMargin.value, res)
127128
}
128129

129130
fun getAlert(type: Alert.AlertType, title: String, text: String): Alert {

src/main/kotlin/ldcapps/servicehelper/FXML.kt

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ldcapps.servicehelper
2+
3+
enum class FXMLInfo(val path: String, val minWidth: Double? = null, val minHeight: Double? = null) {
4+
Main("Main"),
5+
ToolSelector("Tools/Main"),
6+
Print("Print"),
7+
CreateAct("CreateAct"),
8+
Blank("Blank"),
9+
Login("Login"),
10+
CarData("CarData", 275.0, 335.0),
11+
OO("OO", 1100.0, 700.0),
12+
OOCollapsed("Tools/Add car", 600.0, 360.0),
13+
14+
TOOL_ADD_CAR("Tools/Add car", 650.0, 350.0),
15+
TOOL_CREATE_CONTRACT("Tools/Create contract", 1000.0, 350.0),
16+
TOOL_REDACT_DB("Tools/Redact DB", 800.0, 350.0),
17+
TOOL_GET_REPORT("Tools/Get report", 800.0, 350.0),
18+
TOOL_SING_UP("Tools/Signup", 750.0, 730.0),
19+
}

src/main/kotlin/ldcapps/servicehelper/Helper.kt

+22-18
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import javafx.scene.Node
99
import javafx.scene.control.ComboBox
1010
import javafx.scene.control.TableView
1111
import javafx.scene.control.TextField
12+
import javafx.stage.Stage
1213
import ldcapps.servicehelper.controllers.tools.CreateContract
13-
import ldcapps.servicehelper.controllers.tools.Panes
14-
import ldcapps.servicehelper.controllers.tools.ToolSelector
14+
import ldcapps.servicehelper.controllers.tools.ToolSelectorController
15+
import ldcapps.servicehelper.controllers.tools.Tools
1516
import ldcapps.servicehelper.db.DataClasses
1617
import org.apache.poi.ss.usermodel.Cell
1718
import org.apache.poi.ss.usermodel.CellType
@@ -73,30 +74,32 @@ fun getToken(): String? {
7374
return null
7475
}
7576

76-
fun open(path: String? = null) {
77+
fun open(path: String? = null, stage: Stage? = null) {
7778
if (!isOnline || DataClasses.db?.checkToken() == true) {
7879
val mainController = Windows.ooController
7980
val extension = path?.substringAfterLast(".")
8081
val controller =
81-
if (extension == "oab" || extension == "oo" || extension == null) ToolSelector() else Windows.tools()!!
82-
83-
if (path != null)
84-
when (extension) {
85-
"db" -> Panes.REDACT_DB.show(controller.redactDBTb)
86-
"report" -> Panes.GET_REPORT.show(controller.getReportTb)
87-
"settings" -> Panes.SETTINGS.show(controller.settingsTb)
88-
"contract" -> (Panes.CREATE_CONTRACT.show<CreateContract>(controller.createContractTb)).loadData(path)
89-
"act" -> Windows.act()?.fill(fromJSON(path), path)
90-
"oab", "oo" -> mainController?.fillOO(fromJSON(path), path)
91-
else -> Dialogs.warning("Ошибка инициализации файла")
92-
}
82+
if (extension == "oab" || extension == "oo" || extension == null) ToolSelectorController() else Windows.tools()!!
83+
84+
if (path == null || stage == null) return
85+
86+
when (extension) {
87+
"db" -> Tools.REDACT_DB.show(controller.redactDBTb, stage)
88+
"report" -> Tools.GET_REPORT.show(controller.getReportTb, stage)
89+
"settings" -> Tools.SETTINGS.show(controller.settingsTb, stage)
90+
"contract" -> (Tools.CREATE_CONTRACT.show<CreateContract>(controller.createContractTb, stage)).loadData(path)
91+
"act" -> Windows.act()?.fill(fromJSON(path), path)
92+
"oab", "oo" -> mainController?.fillOO(fromJSON(path), path)
93+
else -> Dialogs.warning("Ошибка инициализации файла")
94+
}
95+
9396
} else {
9497
DataClasses.delete()
9598
Windows.login()
9699
}
97100
}
98101

99-
fun <E> List<E>.toFXList(): ObservableList<E> = FXCollections.observableArrayList(this)
102+
fun <E> Iterable<E>.toFXList(): ObservableList<E> = FXCollections.observableArrayList(this.toList())
100103
fun fxList(vararg el: String): ObservableList<String> = FXCollections.observableArrayList(*el)
101104

102105
fun isNotNull(vararg nodes: Node, playAnim: Boolean = true): Boolean {
@@ -168,8 +171,9 @@ fun TableView<*>.initTableSize(vararg proportions: Int) {
168171
columns.forEachIndexed { i, tableColumn -> tableColumn.prefWidth = proportions[i] * w }
169172
}
170173

171-
fun <T> loadFXML(fxml: FXML): T = fxmlLoader(fxml).load()
172-
fun fxmlLoader(fxml: FXML) = FXMLLoader(Windows::class.java.classLoader.getResource("fxml/${fxml.path}.fxml"))
174+
fun <T> loadFXML(fxmlInfo: FXMLInfo): T = fxmlLoader(fxmlInfo).load()
175+
fun fxmlLoader(fxmlInfo: FXMLInfo) =
176+
FXMLLoader(Windows::class.java.classLoader.getResource("fxml/${fxmlInfo.path}.fxml"))
173177

174178
fun numToStr(n: Double): String {
175179
val text = RuleBasedNumberFormat(Locale.forLanguageTag("ru"), RuleBasedNumberFormat.SPELLOUT).format(n.toInt())

src/main/kotlin/ldcapps/servicehelper/Windows.kt

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import javafx.application.Platform
77
import javafx.stage.Stage
88
import javafx.stage.StageStyle
99
import ldcapps.servicehelper.controllers.*
10-
import ldcapps.servicehelper.controllers.tools.ToolSelector
10+
import ldcapps.servicehelper.controllers.tools.ToolSelectorController
1111
import kotlin.system.exitProcess
1212

1313
var isOnline = false
@@ -37,7 +37,7 @@ fun main(arguments: Array<String>) {
3737
class Windows : Application() {
3838

3939
override fun start(primaryStage: Stage) {
40-
val loader = fxmlLoader(FXML.Main)
40+
val loader = fxmlLoader(FXMLInfo.Main)
4141
val stage = loader.load<Stage>()
4242
ooController = loader.getController()
4343
stage.show()
@@ -49,15 +49,15 @@ class Windows : Application() {
4949
init<MainController>(FXML.Main)
5050
}*/
5151

52-
fun tools() = init<ToolSelector>(FXML.ToolSelector)
53-
fun print(stage: Stage) = init<Print>(FXML.Print, stage)
54-
fun act() = init<CreateAct>(FXML.CreateAct)
55-
fun blank() = init<Blank>(FXML.Blank)
56-
fun login() = init<Login>(FXML.Login)
52+
fun tools() = init<ToolSelectorController>(FXMLInfo.ToolSelector)
53+
fun print(stage: Stage) = init<Print>(FXMLInfo.Print, stage)
54+
fun act() = init<CreateAct>(FXMLInfo.CreateAct)
55+
fun blank() = init<Blank>(FXMLInfo.Blank)
56+
fun login() = init<Login>(FXMLInfo.Login)
5757

58-
private fun <T> init(FXML: FXML, primaryStage: Stage? = null): T? {
58+
private fun <T> init(FXMLInfo: FXMLInfo, primaryStage: Stage? = null): T? {
5959
try {
60-
val loader = fxmlLoader(FXML)
60+
val loader = fxmlLoader(FXMLInfo)
6161
loader.load<Stage>().apply {
6262
if (primaryStage != null) {
6363
initStyle(StageStyle.UTILITY)

src/main/kotlin/ldcapps/servicehelper/controllers/CarDataController.kt

+15-31
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import javafx.scene.control.Button
55
import javafx.scene.control.DatePicker
66
import javafx.scene.image.ImageView
77
import javafx.scene.text.Text
8+
import javafx.stage.Stage
89
import ldcapps.servicehelper.*
9-
import ldcapps.servicehelper.controllers.tools.AddCar
10-
import ldcapps.servicehelper.controllers.tools.Panes
10+
import ldcapps.servicehelper.controllers.tools.AddCarController
11+
import ldcapps.servicehelper.controllers.tools.Tools
1112
import ldcapps.servicehelper.db.DataClasses
1213
import ldcapps.servicehelper.db.DataClasses.Companion.cars
1314
import ldcapps.servicehelper.db.DataClasses.Companion.companies
14-
import ldcapps.servicehelper.db.DataClasses.Companion.individuals
1515
import ldcapps.servicehelper.db.DataClasses.Companion.owners
1616
import ldcapps.servicehelper.db.DataClasses.Companion.user
1717
import ldclibs.javafx.controls.AutoCompletedTextField
@@ -37,7 +37,8 @@ class CarDataController : Initializable {
3737
override fun initialize(url: URL?, resourceBundle: ResourceBundle?) {
3838
userTx.text = user.name
3939
userBtn.setOnMouseClicked {
40-
Panes.SETTINGS.show(Windows.tools()!!.settingsTb)
40+
val toolsController = Windows.tools()!!
41+
Tools.SETTINGS.show(toolsController.settingsTb, toolsController.stage)
4142
}
4243

4344
keyTf.items = cars.map { it.keyNum }.toFXList()
@@ -46,7 +47,7 @@ class CarDataController : Initializable {
4647
executionDp.value = LocalDate.now()
4748

4849
openBtn.setOnAction {
49-
open(Dialogs.getFile(MainController.stage, settings.oosLocate))
50+
open(Dialogs.getFile(MainController.stage, settings.oosLocate), confirmBtn.scene.window as Stage)
5051
}
5152

5253
toolsBtn.setOnAction { Windows.tools() }
@@ -61,7 +62,7 @@ class CarDataController : Initializable {
6162
val car = cars.find { it.keyNum == keyTf.text }
6263
if (car == null) {
6364
Dialogs.confirmation("Данного гос. номера авто нет в БД, но вы можите добавить его в меню \"Инструменты\"") {
64-
Panes.ADD_CAR.show<AddCar>(Windows.tools()!!.addCarTb).keyTf.text = keyTf.text
65+
Tools.ADD_CAR.show<AddCarController>(Windows.tools()!!.addCarTb, confirmBtn.scene.window).keyTf.text = keyTf.text
6566
}
6667
return@setOnAction
6768
}
@@ -71,33 +72,16 @@ class CarDataController : Initializable {
7172
executionDate = DataClasses.Date(executionDp.value),
7273
car = car,
7374
carMileage = carMileageTf.text.toIntOrNull(),
74-
customer = owners.find { o -> o.owner == car.owner }?.company ?: car.owner,
75-
vat = user.vat,
76-
hourNorm = user.hourNorm,
77-
companyName = user.executor,
78-
abbreviatedCompanyName = user.abbreviatedExecutor,
79-
companyAddress = user.address,
80-
companyPA = user.pa,
81-
companyBank = user.bank,
82-
companyBankAddress = user.bankAddress,
83-
companyBIK = user.bik,
84-
companyPRN = user.prn.toString(),
85-
companyPhone = user.phone
75+
executor = user.getExecutor()
8676
)
8777

88-
companies.find { c -> c.company == ooAndBill.customer }?.let { c ->
89-
ooAndBill.number = MainController.currentCashlessNumber++
90-
91-
ooAndBill.customerAddress = c.address
92-
ooAndBill.customerPA = c.pa
93-
ooAndBill.customerBank = c.bank
94-
ooAndBill.customerBIK = c.bik
95-
ooAndBill.customerPRN = c.prn
96-
ooAndBill.customerContractDate = c.contractDate
97-
} ?: individuals.find { i -> i.individual == ooAndBill.customer }?.let { i ->
98-
ooAndBill.number = MainController.currentCashNumber++
99-
100-
ooAndBill.customerAddress = i.address
78+
val company = owners.find { it.owner == car.owner }?.company ?: car.owner
79+
companies.find { it.company == company }?.let {
80+
ooAndBill.number = MainController.currentCashlessNumber
81+
MainController.currentCashlessNumber++
82+
} ?: let {
83+
ooAndBill.number = MainController.currentCashNumber
84+
MainController.currentCashNumber++
10185
}
10286

10387
if (ooNumberTf.text.isNotBlank())

src/main/kotlin/ldcapps/servicehelper/controllers/CreateAct.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class CreateAct : Initializable {
9999
act.ooNumber = ooAndBill.number
100100
workCb.items = ooAndBill.works.map { it.name }.toFXList()
101101
detailCb.items = (ooAndBill.dfcs.map { it.name } + ooAndBill.dpcs.map { it.name }).toFXList()
102-
act.abbreviatedFullName = abbreviatedCompanyName
102+
act.abbreviatedFullName = executor!!.abbreviatedExecutor
103103
act.executionDate = executionDate.toString()
104104
act.carNumber = car!!.number
105105
act.carModel = car!!.model

0 commit comments

Comments
 (0)