Skip to content

Commit

Permalink
Изменения для работы с бэком
Browse files Browse the repository at this point in the history
  • Loading branch information
Horoshev36 committed May 24, 2023
1 parent f840fef commit 761ecf2
Show file tree
Hide file tree
Showing 128 changed files with 285,457 additions and 229 deletions.
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="sqlserver://srv-intermech;initialCatalog=sample;integratedSecurity=true;username=prisma;password=aBcD1234;trustServerCertificate=true;"
37 changes: 18 additions & 19 deletions lib/app/presentation/screens/table/bloc/table_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,19 @@ class TableBloc extends Bloc<TableEvent, TableState> {
_Init event,
Emitter<TableState> emit,
) async {
emit(state.copyWith(loading: true));
List<Sell> sells = [];
Set<String> persons = {};
List<Person> personsList = [];
sells.addAll(Sells.fromJson(testData).sells);

for (var item in state.persons) {
persons.add(item.fullName);
}

for (var item in Sells.fromJson(testData).sells) {
persons.add(item.fullName);
}

personsList.addAll(await RemoteRepository.getPersons());
//for (var item in persons) {
// personsList.add(Person(fullname: item));
//}
emit(state.copyWith(sells: sells, persons: personsList));
sells.addAll(await RemoteRepository.getSells());

emit(state.copyWith(sells: sells, persons: personsList, loading: false));
}

FutureOr<void> _switchCurrentStateWindow(_SwitchCurrentStateWindow event, Emitter<TableState> emit) {
Expand Down Expand Up @@ -94,17 +89,18 @@ class TableBloc extends Bloc<TableEvent, TableState> {
emit(state.copyWith(selectedPerson: event.person));
}

FutureOr<void> _addNew(_AddNew event, Emitter<TableState> emit) {
FutureOr<void> _addNew(_AddNew event, Emitter<TableState> emit) async {
emit(state.copyWith(loading: true));
await RemoteRepository.addSell(event.sell);
List<Sell> sells = [];
sells.addAll(state.sells);
sells.add(event.sell);
emit(state.copyWith(sells: sells, selectedPerson: null));
sells.addAll(await RemoteRepository.getSells());
emit(state.copyWith(sells: sells, selectedPerson: null, loading: false));
add(const TableEvent.switchCurrentStateWindow());
}

Future<FutureOr<void>> _statementPressed(_StatementPressed event, Emitter<TableState> emit) async {
String path = "/xls/r.xlsx";
ExcelHelper.createExcelFromSells(sells: Sells(sells: state.sells), path: path);
ExcelHelper.createExcelFromSells(sells: state.sells, path: path);
print('file create');
emit(state.copyWith(action: ShowStatementDone()));
}
Expand All @@ -117,11 +113,14 @@ class TableBloc extends Bloc<TableEvent, TableState> {
emit(state.copyWith(action: ShowEditingModal(event.index)));
}

FutureOr<void> _onEditRowDone(_EditRowDone event, Emitter<TableState> emit) {
Future<FutureOr<void>> _onEditRowDone(_EditRowDone event, Emitter<TableState> emit) async {
emit(state.copyWith(loading: true));
List<Sell> sells = [];
sells.addAll(state.sells);
sells.removeAt(event.index);
sells.insert(event.index, event.sell);
emit(state.copyWith(sells: sells, selectedPerson: null));
try {
await RemoteRepository.updateSell(event.sell);
sells.addAll(await RemoteRepository.getSells());
} catch (e) {}

emit(state.copyWith(sells: sells, selectedPerson: null, loading: false));
}
}
Loading

0 comments on commit 761ecf2

Please sign in to comment.