Skip to content
This repository was archived by the owner on Apr 6, 2022. It is now read-only.

Commit aa6349b

Browse files
committed
Init
1 parent 4133cc9 commit aa6349b

10 files changed

+2207
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

BuildWin32x64.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run build

InstallModules.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm install

Run.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run start

index.html

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<!-- Required meta tags -->
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
8+
<!-- Bootstrap CSS -->
9+
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
10+
<!-- Bootstrap Optional JavaScript -->
11+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
12+
<script>let $ = require('jquery');</script>
13+
<script>require('popper.js');</script>
14+
<script>require('bootstrap');</script>
15+
<script>
16+
window.$ = JQuery = require('jquery');
17+
require('bootstrap')
18+
</script>
19+
<style>
20+
.matrixContainer {
21+
border-radius: 10px/40px;
22+
border: 2px solid #555555;
23+
border-top-color: rgb(85, 85, 85);
24+
border-bottom-color: rgb(85, 85, 85);
25+
padding: 10px 5px;
26+
border-top-color: transparent;
27+
border-bottom-color: transparent;
28+
margin: 0em 0.1em;
29+
}
30+
.table {
31+
width: 100%;
32+
border: none;
33+
margin-bottom: 20px;
34+
}
35+
tbody, td, tfoot, th, thead, tr {
36+
border-color: inherit;
37+
border-style: solid;
38+
border-width: 1px;
39+
text-align: center;
40+
}
41+
.table thead th {
42+
font-weight: bold;
43+
text-align: left;
44+
border: none;
45+
padding: 10px 15px;
46+
background: #d8d8d8;
47+
font-size: 14px;
48+
border-left: 1px solid #ddd;
49+
border-right: 1px solid #ddd;
50+
51+
}
52+
53+
.table tbody td {
54+
text-align: left;
55+
border-left: 1px solid #ddd;
56+
border-right: 1px solid #ddd;
57+
padding: 10px 15px;
58+
font-size: 14px;
59+
vertical-align: top;
60+
}
61+
62+
.table thead tr th:first-child, .table tbody tr td:first-child {
63+
border-left: none;
64+
}
65+
66+
.table thead tr th:last-child, .table tbody tr td:last-child {
67+
border-right: none;
68+
}
69+
70+
.table tbody tr:nth-child(even){
71+
background: #f3f3f3;
72+
}
73+
</style>
74+
<title>Matrix calc</title>
75+
</head>
76+
<body class="user-select-none">
77+
<h4 class="text-center mt-1">Калькулятор умножения матриц чисел</h1>
78+
<hr>
79+
<div class="container" id="matrixSize">
80+
<div class="alert alert-warning alert-dismissible fade show" role="alert">
81+
<strong>Внимание!</strong> Для ввода значений матрицы c большим кол-вом столбцов, может потребоватся развернуть программу на полный экран
82+
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
83+
</div>
84+
<div class="row">
85+
<label class="form-label">Размер матрицы A:</label>
86+
87+
<div class="input-group mb-3">
88+
<input type="number" id="aW" value="1" step="1" class="form-control">
89+
<span class="input-group-text">x</span>
90+
<input type="number" id="aH" value="1" step="1" class="form-control">
91+
</div>
92+
</div>
93+
<div class="row">
94+
<label class="form-label">Размер матрицы B:</label>
95+
96+
<div class="input-group mb-3">
97+
<input type="number" id="bW" min="0" value="1" step="1" class="form-control">
98+
<span class="input-group-text">x</span>
99+
<input type="number" id="bH" min="0" value="1" step="1" class="form-control">
100+
</div>
101+
</div>
102+
<button id="setMatrixSize" class="btn btn-dark">Применить</button>
103+
</div>
104+
105+
<div class="container" style="display:none" id="matrixA"></div>
106+
<div class="container" style="display:none" id="matrixB"></div>
107+
<div class="container" style="display:none" id="result"></div>
108+
<!-- Option 2: Separate Popper and Bootstrap JS -->
109+
<!--
110+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-KsvD1yqQ1/1+IA7gi3P0tyJcT3vR+NdBTt13hSJ2lnve8agRGXTTyNaBYmCR/Nwi" crossorigin="anonymous"></script>
111+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-nsg8ua9HAw1y0W1btsyWgBklPnCUAFLuTMS2G72MMONqmOymq585AcH49TLBQObG" crossorigin="anonymous"></script>
112+
-->
113+
<script src="./renderer.js"></script>
114+
</body>
115+
</html>

main.js

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// Modules to control application life and create native browser window
2+
const {app, BrowserWindow, Menu, ipcMain, dialog} = require('electron')
3+
const path = require('path');
4+
let fs = require('fs-extra');
5+
var xl = require('excel4node');
6+
let mainWindow;
7+
8+
function MultiplyMatrix(A, B){
9+
let rowsA = A.length,
10+
colsA = A[0].length,
11+
rowsB = B.length,
12+
colsB = B[0].length,
13+
C = [];
14+
if(colsA != rowsB) return false;
15+
for(let i = 0; i < rowsA; i++) C[i] = [];
16+
for(let k = 0; k < colsB; k++){
17+
for(let i = 0; i < rowsA; i++){
18+
let t = 0;
19+
for(let j = 0; j < rowsB; j++) t += A[i][j] * B[j][k];
20+
C[i][k] = t;
21+
}
22+
}
23+
return C;
24+
}
25+
26+
ipcMain.handle('export', async (event, {a, b, result}) => {
27+
let dir = dialog.showOpenDialogSync(mainWindow, {
28+
properties: ['openDirectory']
29+
});
30+
31+
if(dir !== undefined) {
32+
await fs.stat(dir[0]).then(async () => {
33+
34+
//Export A matrix
35+
const wbA = new xl.Workbook();
36+
const wsA = wbA.addWorksheet('Sheet');
37+
const styleCenterA = wbA.createStyle({
38+
alignment: { // §18.8.1
39+
horizontal: ['center'],
40+
},
41+
});
42+
let rowIndexA = 1;
43+
let colIndexA = 1;
44+
for(let row of a){
45+
for(let col of row){
46+
wsA.cell(rowIndexA, colIndexA)
47+
.number(Math.round((col + Number.EPSILON) * 1000) / 1000)
48+
.style(styleCenterA);
49+
colIndexA++;
50+
}
51+
colIndexA = 1;
52+
rowIndexA++;
53+
}
54+
55+
wbA.write(path.join(dir[0], 'MatrixA.xlsx'));
56+
57+
//Export B matrix
58+
const wbB = new xl.Workbook();
59+
const wsB = wbB.addWorksheet('Sheet');
60+
const styleCenterB = wbB.createStyle({
61+
alignment: { // §18.8.1
62+
horizontal: ['center'],
63+
},
64+
});
65+
let rowIndexB = 1;
66+
let colIndexB = 1;
67+
for(let row of b){
68+
for(let col of row){
69+
wsB.cell(rowIndexB, colIndexB)
70+
.number(Math.round((col + Number.EPSILON) * 1000) / 1000)
71+
.style(styleCenterB);
72+
colIndexB++;
73+
}
74+
colIndexB = 1;
75+
rowIndexB++;
76+
}
77+
78+
wbB.write(path.join(dir[0], 'MatrixB.xlsx'));
79+
80+
//Export result
81+
const wbResult = new xl.Workbook();
82+
const wsResult = wbResult.addWorksheet('Sheet');
83+
const styleCenterResult = wbResult.createStyle({
84+
alignment: { // §18.8.1
85+
horizontal: ['center'],
86+
},
87+
});
88+
89+
let rowIndexResult = 1;
90+
let colIndexResult = 1;
91+
for(let row of result){
92+
for(let col of row){
93+
wsResult.cell(rowIndexResult, colIndexResult)
94+
.number(Math.round((col + Number.EPSILON) * 1000) / 1000)
95+
.style(styleCenterResult);
96+
colIndexResult++;
97+
}
98+
colIndexResult = 1;
99+
rowIndexResult++;
100+
}
101+
102+
wbResult.write(path.join(dir[0], 'MatrixResult.xlsx'));
103+
104+
await new Promise((resolve) => {
105+
setTimeout(() => {
106+
dialog.showMessageBoxSync(mainWindow, {
107+
title: 'Успех!',
108+
type: 'info',
109+
message: 'Данные успешно экспортированы'
110+
});
111+
resolve();
112+
}, 500)
113+
})
114+
}).catch((error) => {
115+
dialog.showMessageBoxSync(mainWindow, {
116+
title: 'Ошибка!',
117+
type: 'error',
118+
message: 'Выбранная директория не существует, экспорт отменен',
119+
detail: 'Код ошибки: '+ error.code
120+
});
121+
});
122+
} else dialog.showMessageBoxSync(mainWindow, {
123+
title: 'Внимание!',
124+
type: 'warning',
125+
message: 'Экспорт отменен, папка небыла выбрана'
126+
});
127+
});
128+
129+
ipcMain.handle('calc', async (event, {a, b}) => {
130+
return MultiplyMatrix(a, b)
131+
});
132+
133+
function createWindow () {
134+
// Create the browser window.
135+
mainWindow = new BrowserWindow({
136+
width: 800,
137+
height: 600,
138+
webPreferences: {
139+
preload: path.join(__dirname, 'preload.js'),
140+
nodeIntegration: true,
141+
contextIsolation: false,
142+
enableRemoteModule: true
143+
}
144+
})
145+
146+
// and load the index.html of the app.
147+
mainWindow.loadFile('index.html')
148+
Menu.setApplicationMenu(null)
149+
// Open the DevTools
150+
// mainWindow.webContents.openDevTools()
151+
}
152+
153+
// This method will be called when Electron has finished
154+
// initialization and is ready to create browser windows.
155+
// Some APIs can only be used after this event occurs.
156+
app.whenReady().then(() => {
157+
createWindow()
158+
159+
app.on('activate', function () {
160+
// On macOS it's common to re-create a window in the app when the
161+
// dock icon is clicked and there are no other windows open.
162+
if (BrowserWindow.getAllWindows().length === 0) createWindow()
163+
})
164+
})
165+
166+
// Quit when all windows are closed, except on macOS. There, it's common
167+
// for applications and their menu bar to stay active until the user quits
168+
// explicitly with Cmd + Q.
169+
app.on('window-all-closed', function () {
170+
if (process.platform !== 'darwin') app.quit()
171+
})
172+
173+
// In this file you can include the rest of your app's specific main process
174+
// code. You can also put them in separate files and require them here.

0 commit comments

Comments
 (0)