From 78f102387639ed268444188e1a050327d28bd5df Mon Sep 17 00:00:00 2001 From: kkpalma <85182515+chanchobrujo@users.noreply.github.com> Date: Wed, 20 Sep 2023 10:28:06 -0500 Subject: [PATCH] REFACTOR: Modify date expired and price. --- bd/db.db | Bin 81920 -> 81920 bytes nbproject/private/private.xml | 4 +- src/Constans/Headers/HeadersTableSwing.java | 2 +- src/entities/Product.java | 3 +- src/model/ModelProduct.java | 2 + src/modules/ModuleProduct.java | 4 +- .../table/Entity/TableModelProduct.java | 5 +- src/repository/ProductRepository.java | 12 +- src/services/ProductService.java | 36 ++-- src/util/Mapper.java | 11 +- src/views/maintenance/products_views.form | 136 ++++++++------ src/views/maintenance/products_views.java | 173 +++++++++++------- 12 files changed, 219 insertions(+), 169 deletions(-) diff --git a/bd/db.db b/bd/db.db index f368ab456a3ed9544b869aecbfdaa77e5c259ca3..9ce264dc16319a6a81b1263bfbde7cc6877a73d9 100644 GIT binary patch delta 2837 zcmai0YiJ|a6~3d9WRG6gS6SEVwIz+#uQ*=W^U%|~VSOcyorz~OVk8-FmMxK`QMz;; zZ@hMCp{d-`A5Hrw=|T%BB+$}78|Wj3q(AzCmXMV8N4rZ&D1;=WwEeTCPzV$PJ$Gcu z>+Lo%T%(zL?m6Fg&Uen8g9G2ef$#YbP84!mIv0<3+I$DyiI*@CLDMR5#N;; zJ|FY=uKe_yx4nU{#m0xmCMLMAlbgQ||1~T+U%Y;G*J+D&ZL@y!ePR0WS^v_Ihl?Nn zD7@hr_TYCBzKh>I42}E=FGiwXloYC(z1lD}Tc;z$i)I8 z-#ZM6cd!`Ylicx%=mQ> z{vmF6=b9H>2Zj9`&Mrd3UVfBgKm8#OJJ{TFp4!>{QZyWBpjqJ+A@IXMQg|i!2Ihi6 z;p4zRggc>U@SVtWk#|BLMR4G9;CJCCL$8Iu6aITR7y5HJ@ta5oe>+qT{w;72N`}50 z`AP5x!Dl1o;C%2Bz807{Opd%i+!a1X%EAmMa6+;~jgnrpDq@A!sUfaX+obDOrPeSh zC5oh|DXEZB3Lyg(&(92TZ~{_fSgTrvmMpPm!BgPNXm)9WgFRHYsY%P0A!a0VZAmtb z4IRAdHGZ7TjR+{^#zfsg(6X49!183&xz7kF6JzMmnq`86nrJqRy3Tx=dZlbzRjo!# zXUW-90$Lh#1NRMAHQTm~#-<3%vg16Fuz>ET+Wlm%!Jh{$#YANQf+y%tGSrQiol#IC{i>VD-Uj>0_{o~OfNldeh zxcen-m4)84pk7Cm`DK!vfO;of1HijZSx#Vkpw66!gujYnb3Ixm5X+`!!11oAn=Yrh zDL{DtZhvz?7zaoq0n$8z3T~J*p}wv(?P~2DPw*TXopTM6E*FuSRcj#$?(ctT7_{3b zIWlxSVwB{JfaZH+q(oOK)W1kej4eEAFqQBSiIir}LKE~TLr$n+fyS5(H7%_Hy~oB^ z)Jv2}0i9ns&Wu~j4C_e-4C-${1TY1q(19}O|jX_A~BD5Qdl4|yb=Ry*(JeBUg3jqNVLf40p%1bQ zA?ut$38Q{8dj`aIROO;rv@I}(R#cenz;4V>rlYLCPc~4=f-=Dw#2ic$7^+pvrX?M2pcV9c_V-FL_&@mH`0iok;6p6N<366_VlnoAaxx4SzDOM5@8JuP zwMY^B$52Nw(lT6BI*bdr3~k!_T(fg+=b3%y=^bbLs7wv|@Fd-Ls=UVKEMl?rl8Rpgs5zWnI< zRxY20(AfQy{natczX*#s9n%cl=-BYX>Q<8R@&@Q0AC%lOe4 zf06sYIq}DN%Jqr;FE8KWtsg&e9m;$I;XmT<;~TF>M9#t86d#y}VLA*K7h<0+0JtC( z(yE&6f5foo<+Qr2W-naur#ufbS7a%3!d#J;rOf)eKgB)3JfBuG(1z|O(qszU=b8JA p4DNeMdXs%{{sq7JdPL%Wix>NV_$WWm9b;rcJ%pbZ2CrPl{{^HHZ7Bc% delta 941 zcmZuwPfXKb6#u@q8*N$pZNsrBtSh2H5|~}PuIr))1QHGeP!kS@M8B;aAr8898^Hr% zXHOC?28nX!pg@CgG|?FKs0O)t@!(NCdh+Y|qXfU^rG4-H-tYJNUcN>n&}al6U5LUZ z0Khq7QDPLai_3kgK%%L+J%N7@BEiMw`w2>Tx%Kc9v$ZKhZ!vhag#sb(xiCqwAPfNd ziN1QF@JE!gBP;`YxCz&;+U`8A&CEMOm;p(yf~&Qeav4{7qR_1Qg}!(p`7@GjK0^1v zQzdi~o)m<)l|3}o5n|~CEY_GdgwF@lhh(QQB zT*VeS*>5@^UDr;b(|TUln&{Mj&{{@6M0XyMr?q@W km!y+1zC$}`XIE6<8src/modules/ModuleProduct.java - 75 + 76 - file:/C:/Users/User/Documents/Ambientes%20de%20desarrollo/BOTICA-CAUTIVO/src/views/reports/ReportSales.java + file:/C:/Users/User/Documents/Ambientes%20de%20desarrollo/BOTICA-CAUTIVO/src/views/maintenance/products_views.java diff --git a/src/Constans/Headers/HeadersTableSwing.java b/src/Constans/Headers/HeadersTableSwing.java index 1bec040..3e6c12c 100644 --- a/src/Constans/Headers/HeadersTableSwing.java +++ b/src/Constans/Headers/HeadersTableSwing.java @@ -14,7 +14,7 @@ public class HeadersTableSwing { public static final String headres_product[] = new String[] {"ID", "NOMBRE", "MARCA", "PRECIO", "STOCK", "CATEGORIA" - , "ESTADO"}; + , "ESTADO", "FECHA DE VENC."}; public static final String headres_productstock[] = new String[] {"ID", "PRODUCTO", "PRECIO", "STOCK", "CATEGORIA"}; diff --git a/src/entities/Product.java b/src/entities/Product.java index de20725..7fcb48d 100644 --- a/src/entities/Product.java +++ b/src/entities/Product.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package entities; +package entities; import lombok.AllArgsConstructor; import lombok.Builder; @@ -31,6 +31,7 @@ public class Product { private Integer stock; private Category category; private Boolean state; + private String date; public Product(String name, String brand, Double price, Integer stock, Category category) { diff --git a/src/model/ModelProduct.java b/src/model/ModelProduct.java index d5e8b13..c67b644 100644 --- a/src/model/ModelProduct.java +++ b/src/model/ModelProduct.java @@ -5,6 +5,7 @@ */ package model; +import java.util.Date; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -29,6 +30,7 @@ public class ModelProduct { private Double price; private Integer stock; private String category; + private Date date; private Boolean state; } diff --git a/src/modules/ModuleProduct.java b/src/modules/ModuleProduct.java index 0efd6b8..5795ad3 100644 --- a/src/modules/ModuleProduct.java +++ b/src/modules/ModuleProduct.java @@ -70,11 +70,11 @@ public List findAll_Products_Active() { } public String saveProduct(Integer id, String name, String brand, - Double price, Integer Stock, String category) { + Double price, Integer Stock, String category, String date) { boolean verify = Commons.StringsIsEmpty(name, brand, category) || Commons.IntegerIsEmpty(Stock) || Commons.DoublesIsEmpty(price); - return verify ? messageError : this.productService.save(id, name, brand, price, Stock, category); + return verify ? messageError : this.productService.save(id, name, brand, price, Stock, category, date); } public String changeStateProduct(Integer id) { diff --git a/src/render/table/Entity/TableModelProduct.java b/src/render/table/Entity/TableModelProduct.java index 9e4f3e2..17e45e4 100644 --- a/src/render/table/Entity/TableModelProduct.java +++ b/src/render/table/Entity/TableModelProduct.java @@ -63,10 +63,9 @@ private void renderTable(JTable table, List array){ row.add(product.getStock()); row.add(product.getCategory().getName()); row.add(Commons.BooleanToString(product.getState())); + row.add(product.getDate()); return row; - }).forEachOrdered(row -> { - ((DefaultTableModel) table.getModel()).addRow(row); - }); + }).forEachOrdered(row -> ((DefaultTableModel) table.getModel()).addRow(row)); table.getColumnModel().getColumn(0).setMaxWidth(0); table.getColumnModel().getColumn(3).setMaxWidth(50); table.getColumnModel().getColumn(4).setMaxWidth(50); diff --git a/src/repository/ProductRepository.java b/src/repository/ProductRepository.java index 27c5d00..6816f0a 100644 --- a/src/repository/ProductRepository.java +++ b/src/repository/ProductRepository.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import java.util.stream.Stream; import util.Commons; import util.GestorBd; import util.Mapper; @@ -34,12 +35,12 @@ public ProductRepository(){ } public String insert(Product product) { - String sql = "INSERT INTO product (name, brand, price, stock, id_category, state) VALUES('" + String sql = "INSERT INTO product (name, brand, price, stock, id_category, state, expired) VALUES('" +product.getName()+"','"+product.getBrand()+"'," +product.getPrice()+","+product.getStock()+"," +product.getCategory().getId()+"," - +Commons.BooleanToInteger(product.getState()) +");"; - + +Commons.BooleanToInteger(product.getState()) +",'" + +product.getDate() + "');"; return GestorBd.execute(sql); } @@ -48,9 +49,9 @@ public String update(Product product) { + "brand = '"+product.getBrand()+"', " + "price = "+product.getPrice()+", " + "stock = "+product.getStock()+", " + + "expired = '"+product.getDate()+"', " + "id_category = "+product.getCategory().getId() + " WHERE id = "+product.getId(); - return GestorBd.execute(sql); } @@ -79,8 +80,7 @@ public String changeState(int id, Boolean state) { public List findAll() { List list = GestorBd.findAll(SCRIPT_FINDALL); - List findAll = new ArrayList<>(); - + List findAll = new ArrayList<>(); if (Commons.collectionNonEmptyOrNull(list)) list.stream() .map(mapper -> { diff --git a/src/services/ProductService.java b/src/services/ProductService.java index 483bc85..6bed5f4 100644 --- a/src/services/ProductService.java +++ b/src/services/ProductService.java @@ -6,7 +6,7 @@ package services; import entities.Category; -import entities.Product; +import entities.Product; import java.util.List; import java.util.Objects; @@ -38,15 +38,10 @@ private Optional findByName_Categories(String name){ .findFirst(); } - public String save(int id, String name, String brand, Double price, - Integer Stock, String category){ + public String save(Integer id, String name, String brand, Double price, + Integer Stock, String category, String date){ String message = Constans.Enums.ErrorMessage.REPETED_VALUES.getValue(); Optional _category = this.findByName_Categories(category); - - Boolean verify = this.verifyByNameOrBrand(name, brand).isPresent(); - - if (verify) return message; - Product product = Product.builder() .name(name) .brand(brand) @@ -54,16 +49,16 @@ public String save(int id, String name, String brand, Double price, .stock(Stock) .category(_category.get()) .state(Boolean.TRUE) + .date(date) .build(); - - switch(id){ - case 0: - message = this.productRepository.insert(product); - break; - default: - product.setId(id); - message = this.productRepository.update(product); - break; + if (id == null || id == 0) { + Boolean verify = this.verifyByNameOrBrand(name, brand).isPresent(); + if (verify) return message; + message = this.productRepository.insert(product); + } else { + product.setId(id); + product.setDate(date); + message = this.productRepository.update(product); } return message; } @@ -128,11 +123,8 @@ public List searchProduct(String value){ public List findAllByStockMin(){ return this.productRepository.findAll().stream() - .filter(predicate -> predicate.getStock() <= 10) - .map(mapper -> { - this.productRepository.changeState(mapper.getId(), Boolean.FALSE); - return mapper; - }) + .filter(predicate -> predicate.getStock() == 0) + .peek(mapper -> this.productRepository.changeState(mapper.getId(), false)) .collect(Collectors.toList()); } } \ No newline at end of file diff --git a/src/util/Mapper.java b/src/util/Mapper.java index 80d4146..dbcc3f1 100644 --- a/src/util/Mapper.java +++ b/src/util/Mapper.java @@ -13,6 +13,7 @@ import model.ModelSale; import Constans.Constan; +import java.util.Objects; /** * @@ -28,7 +29,6 @@ public static Rol mapperRol(Object object) { .id(id) .name(row[1].toString()) .build(); - } public static Category mapperCategory(Object obj) { @@ -60,7 +60,6 @@ public static User mapperUser(Object obj) { public static Product mapperProduct(Object obj) { Object[] row = (Object[]) obj; - Integer id = Integer.parseInt(row[0].toString()); String name = row[1].toString(); String brand = row[2].toString(); @@ -68,8 +67,7 @@ public static Product mapperProduct(Object obj) { Integer stock = Integer.parseInt(row[4].toString()); Boolean state = Commons.IntegerToBoolean(Integer.parseInt(row[6].toString())); - - return Product.builder() + Product prod = Product.builder() .id(id) .name(name) .brand(brand) @@ -77,7 +75,10 @@ public static Product mapperProduct(Object obj) { .stock(stock) .state(state) .build(); - + if (Objects.nonNull(row[7])) { + prod.setDate(row[7].toString()); + } + return prod; } public static ModelSale mapperSale(Object object) { diff --git a/src/views/maintenance/products_views.form b/src/views/maintenance/products_views.form index 670e0da..ba6038c 100644 --- a/src/views/maintenance/products_views.form +++ b/src/views/maintenance/products_views.form @@ -31,13 +31,13 @@ - - + + - + - + @@ -45,20 +45,21 @@ - + + - + + - - + @@ -202,25 +203,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - + + + + + + + + + @@ -232,39 +238,42 @@ - + - - - + + + + + + + + + + + - - - - + + + + + + - - - - + + + - - - - + - - - - + + + - - - + - + @@ -296,11 +305,6 @@ - - - - - @@ -392,7 +396,7 @@ - + @@ -478,7 +482,27 @@ - + + + + + + + + + + + + + + + + + + + + + diff --git a/src/views/maintenance/products_views.java b/src/views/maintenance/products_views.java index 7cca3ee..62e7400 100644 --- a/src/views/maintenance/products_views.java +++ b/src/views/maintenance/products_views.java @@ -6,13 +6,14 @@ package views.maintenance; import Constans.Constan; -import javax.swing.JSpinner; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Date; import model.ModelProduct; import modules.ModuleProduct; import render.ComboBox.Entity.ComboBoxCategories; import render.table.Entity.TableModelProduct; -import util.Commons; -import views.Administration; +import util.Commons; /** * @@ -38,7 +39,6 @@ public products_views() { initComponents(); this.clear(); this.recharge_data(); - this.SetModelSpinner(this.spnPrecio); } private void recharge_data(){ @@ -49,23 +49,18 @@ private void recharge_data(){ private void SetValueSelected(ModelProduct model) { txtName.setText(model.getName()); txtBrand.setText(model.getBrand()); - spnPrecio.setValue(model.getPrice()); + txtBrand1.setText(model.getPrice().toString()); cmbCategories.setSelectedItem(model.getCategory()); spnStock.setValue(model.getStock()); - } - - private void SetModelSpinner(JSpinner spinner) { - JSpinner.NumberEditor numberEditor = new JSpinner - .NumberEditor(spinner, "0.00"); - - spinner.setEditor(numberEditor); + jDateChooser1.setDate(model.getDate()); } private void clear() { + jDateChooser1.setDate(new Date()); txtName.setText(Constan.empty); txtBrand.setText(Constan.empty); - - spnPrecio.setValue(0); + txtBrand1.setText(Constan.empty); + spnStock.setValue(0); cmbCategories.setSelectedIndex(0); @@ -101,7 +96,6 @@ private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel5 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); - jSeparator2 = new javax.swing.JSeparator(); cmbCategories = new javax.swing.JComboBox<>(); txtName = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); @@ -114,7 +108,9 @@ private void initComponents() { jButton1 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); lblMessage = new javax.swing.JLabel(); - spnPrecio = new javax.swing.JSpinner(); + txtBrand1 = new javax.swing.JTextField(); + jDateChooser1 = new com.toedter.calendar.JDateChooser(); + jLabel15 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -200,8 +196,6 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { jLabel9.setText("Categoria:"); jLabel9.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL); - cmbCategories.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N cmbCategories.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); @@ -259,7 +253,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)) + .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( @@ -278,6 +272,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { lblMessage.setForeground(new java.awt.Color(255, 0, 0)); lblMessage.setBorder(javax.swing.BorderFactory.createEtchedBorder()); + txtBrand1.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N + + jLabel15.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N + jLabel15.setText("Fecha Venc:"); + jLabel15.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( @@ -288,22 +288,25 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(lblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE) - .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(2, 2, 2)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(cmbCategories, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(txtBrand) + .addComponent(txtName) + .addComponent(txtBrand1, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE) + .addComponent(spnStock) + .addComponent(jDateChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(cmbCategories, javax.swing.GroupLayout.Alignment.LEADING, 0, 134, Short.MAX_VALUE) - .addComponent(spnPrecio, javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(txtBrand, javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(txtName, javax.swing.GroupLayout.Alignment.LEADING)) - .addComponent(spnStock, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); @@ -311,32 +314,37 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(12, 12, 12) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE) + .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(txtBrand, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(txtBrand, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spnPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(txtBrand1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(cmbCategories, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(cmbCategories, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spnStock, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addComponent(jSeparator2) - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(spnStock) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(18, 18, 18) .addComponent(lblMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) ); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N @@ -354,10 +362,10 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 846, Short.MAX_VALUE) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); @@ -365,7 +373,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jSeparator4) .addGroup(layout.createSequentialGroup() .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) @@ -373,9 +382,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(jSeparator4)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE))) + .addContainerGap()) ); pack(); @@ -388,14 +397,24 @@ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS }//GEN-LAST:event_jButton2ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - String message = this.modulePorduct.saveProduct(modelproduct.getId(), txtName.getText(), - txtBrand.getText(), Double.parseDouble(spnPrecio.getValue().toString()), - Integer.parseInt(spnStock.getValue().toString()), - cmbCategories.getSelectedItem().toString()); - - lblMessage.setText(message); - + // TODO add your handling code here: + String msg = ""; + try { + Integer id = modelproduct.getId(); + String dateString = (new SimpleDateFormat(Constan.format_date)) + .format(jDateChooser1.getDate()); + String category = cmbCategories.getSelectedItem().toString(); + Integer stock = Integer.parseInt(spnStock.getValue().toString()); + Double price = (new BigDecimal(txtBrand1.getText())).doubleValue(); + if (jDateChooser1.getDate().after(new Date()) && price > 0.0) { + msg = this.modulePorduct.saveProduct(id, txtName.getText(), txtBrand.getText(), price, stock, category, dateString); + } else { + msg = "Error en fecha o precio"; + } + } catch (Exception e) { + msg = e.getMessage(); + } + lblMessage.setText(msg); this.clear(); }//GEN-LAST:event_jButton1ActionPerformed @@ -406,6 +425,9 @@ private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS private void tblProductMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblProductMouseClicked // TODO add your handling code here: + Date date; + SimpleDateFormat formatter = new SimpleDateFormat(Constan.format_date); + int row = tblProduct.getSelectedRow(); int id = Integer.parseInt(tblProduct.getValueAt(row, 0).toString()); String name = tblProduct.getValueAt(row, 1).toString(); @@ -414,6 +436,13 @@ private void tblProductMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST: int stock = Integer.parseInt(tblProduct.getValueAt(row, 4).toString()); String category = tblProduct.getValueAt(row, 5).toString(); Boolean state = Commons.StringStateToBoolean(tblProduct.getValueAt(row, 6).toString()); + + try { + date = formatter.parse(tblProduct.getValueAt(row, 7).toString()); + } catch (Exception e) { + date = null; + System.err.println(e.getMessage()); + } modelproduct = ModelProduct.builder() .id(id) @@ -423,6 +452,7 @@ private void tblProductMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST: .stock(stock) .category(category) .state(state) + .date(date) .build(); this.SetValueSelected(modelproduct); }//GEN-LAST:event_tblProductMouseClicked @@ -477,8 +507,10 @@ public void run() { private javax.swing.JButton jButton2; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; + private com.toedter.calendar.JDateChooser jDateChooser1; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; + private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; @@ -488,14 +520,13 @@ public void run() { private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel5; private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JSeparator jSeparator2; private javax.swing.JSeparator jSeparator3; private javax.swing.JSeparator jSeparator4; private javax.swing.JLabel lblMessage; - private javax.swing.JSpinner spnPrecio; private javax.swing.JSpinner spnStock; private javax.swing.JTable tblProduct; private javax.swing.JTextField txtBrand; + private javax.swing.JTextField txtBrand1; private javax.swing.JTextField txtBuscarProducto; private javax.swing.JTextField txtName; // End of variables declaration//GEN-END:variables