-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdateItemData.java
121 lines (89 loc) · 3.81 KB
/
UpdateItemData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package invertorymanagement;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
/**
*
* @author partha
*/
public class UpdateItemData {
static FileInputStream fis;
static File file;
static File f;
static HSSFWorkbook hssfw;
static Workbook wb;
static HSSFSheet hssfs;
static FormulaEvaluator formulaEvaluator;
static String Code,name;
static int Quantity;
static int RemainQuantity,q;
static double Price,TotalPrice;
static String cellid;
static Sheet s;
public UpdateItemData( String Item_Code,int item_Quantity,double Item_Price) throws FileNotFoundException, IOException, InvalidFormatException{
Code = Item_Code;
Quantity =item_Quantity;
Price = Item_Price;
//System.out.println("Id:"+this.Id+"\n Pass: "+this.Password);
f =new File("Items.xlsx");
fis = new FileInputStream(f);
file =new File("Items.xlsx");
if(file.exists() && f.exists()){
hssfw = new HSSFWorkbook(fis);
hssfs = hssfw.getSheetAt(0);
// s=hssfw.getSheetAt(0);
}
// formulaEvaluator= hssfw.getCreationHelper().createFormulaEvaluator();
// }
// public boolean matchdata() throws IOException{
for (int rowIndex = 0; rowIndex <= hssfs.getLastRowNum(); rowIndex++) {
Row row = hssfs.getRow(rowIndex);
if (row != null) {
Cell cell0 =row.getCell(0);
Cell cell = row.getCell(1);
Cell cell1 = row.getCell(2);
Cell cell2 = row.getCell(3);
Cell cell3 = row.getCell(4);
if (cell != null) {
// Found column and there is value in the cell.
cellid = cell.getStringCellValue();
if(cellid.equals(Code)){
name = cell0.getStringCellValue();
q = (int)cell1.getNumericCellValue();
RemainQuantity= q+Quantity;
TotalPrice = RemainQuantity*Price;
Row rowh = hssfs.getRow(rowIndex);
hssfs.removeRow(rowh);
row = hssfs.createRow(rowIndex);
row.createCell(0).setCellValue(this.name);
row.createCell(1).setCellValue(cellid);
row.createCell(2).setCellValue(this.RemainQuantity);
row.createCell(3).setCellValue(this.Price);
row.createCell(4).setCellValue(this.TotalPrice);
}
}
}
}
FileOutputStream fos = new FileOutputStream(file);
hssfw.write(fos);
hssfw.close();
fos.close();
// return false;
}
}