private void employeeModelAddButton_Click(object sender, EventArgs e) { ServiceResult <Employee> result = employeeService.validate(this.employeeModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.insert(employeeService .initialize(this.employeeModel).model, typeof(Employee)); if (dbResult.isOk()) { Employee employee = this.employeeModel; BindingList <EmployeeModel> newList = (BindingList <EmployeeModel>) this.employeesSet.DataSource; newList.Add(new EmployeeModel(employee.id, employee.fullname, employee.dob, employee.address, employee.phone, employee.title.name)); this.employeesSet.DataSource = newList; this.employeeModel = new Employee(); this.renderModel(); } }
private void customerModelAddButton_Click(object sender, EventArgs e) { ServiceResult <Customer> result = customerService.validate(this.customerModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.insert(customerService .initialize(this.customerModel).model, customerType); if (dbResult.isOk()) { BindingList <CustomerModel> list = (BindingList <CustomerModel>) this.customerSet.DataSource; Customer customer = this.customerModel; list.Add(new CustomerModel(customer.id, customer.fullname, customer.dob, customer.address, customer.email, customer.expiredDate, customer.debt)); this.customerSet.DataSource = list; this.customerModel = new Customer(); this.renderModel(); } }
private void bookModelAddButton_Click(object sender, EventArgs e) { ServiceResult <Book> result = bookService.validate(this.bookModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.insert(bookService .initialize(this.bookModel).model, type); if (dbResult.isOk()) { BindingList <Book> list = (BindingList <Book>) this.bookSet.DataSource; list.Add(this.bookModel); this.bookSet.DataSource = list; this.bookModel = new Book(); this.renderModel(); } }
private void bookModelRemoveButton_Click(object sender, EventArgs e) { DatabaseOperationResult dbResult = dao.delete(this.bookModel, type); if (dbResult.isOk()) { BindingList <Book> list = (BindingList <Book>) this.bookSet.DataSource; list.Remove(this.bookSet.CurrentRow.DataBoundItem as Book); this.bookSet.DataSource = list; this.bookModel = new Book(); this.bookModel.price = 1; this.renderModel(); } }
private void customerModelRemoveButton_Click(object sender, EventArgs e) { if (this.customerSet.SelectedRows.Count == 0) { return; } DatabaseOperationResult dbResult = dao.delete(this.customerModel, customerType); if (dbResult.isOk()) { BindingList <CustomerModel> list = (BindingList <CustomerModel>) this.customerSet.DataSource; list.Remove(this.customerSet.CurrentRow.DataBoundItem as CustomerModel); this.customerSet.DataSource = list; this.customerModel = new Customer(); this.renderModel(); } }
private void employeeModelRemoveButton_Click(object sender, EventArgs e) { if (this.employeesSet.SelectedRows.Count == 0) { return; } DataGridViewRow row = this.employeesSet.SelectedRows[0]; EmployeeModel model = row.DataBoundItem as EmployeeModel; this.employeesSet.Rows.Remove(row); DatabaseOperationResult dbResult = dao.delete(this.employeeModel, typeof(Employee)); if (dbResult.isOk()) { this.employeeModel = new Employee(); this.renderModel(); } }
public DatabaseOperationResult insert(PaymentReceipt receipt) { using (TransactionScope transactionScope = new TransactionScope()) { DatabaseOperationResult result = new DatabaseOperationResult(); DatabaseOperationResult lendingReceiptInsertionResult = dao.insert(receipt.lendingReceipt, typeof(LendingReceipt)); if (!lendingReceiptInsertionResult.isOk()) { result.status = ServiceStatus.INVALID; result.message = "Operation failed when trying to insert Lending Receipt"; return(result); } DatabaseOperationResult paymentReceiptInsertionResult = dao.insert(receipt, typeof(PaymentReceipt)); if (!paymentReceiptInsertionResult.isOk()) { result.status = ServiceStatus.INVALID; result.message = "Operation failed when trying to insert Payment Receipt"; return(result); } DatabaseOperationResult lendingDetailsInsertionResult; foreach (LendingReceiptDetail detail in receipt.lendingReceipt.details) { lendingDetailsInsertionResult = dao.insert(detail, typeof(LendingReceiptDetail)); if (!lendingDetailsInsertionResult.isOk()) { result.status = ServiceStatus.INVALID; result.message = "Operation failed when trying to insert Lending details"; return(result); } } transactionScope.Complete(); return(result); } }
private void customerModelEditButton_Click(object sender, EventArgs e) { if (this.customerSet.SelectedRows.Count == 0) { return; } ServiceResult <Customer> result = customerService.validate(this.customerModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.update(this.customerModel, customerType); if (dbResult.isOk()) { DataGridViewRow row = this.customerSet.CurrentRow; row.Cells["ID"].Value = this.customerModel.id; row.Cells["Fullname"].Value = this.customerModel.fullname; row.Cells["Birthdate"].Value = this.customerModel.dob; row.Cells["Address"].Value = this.customerModel.address; row.Cells["Email"].Value = this.customerModel.email; row.Cells["Expiry date"].Value = this.customerModel.expiredDate; row.Cells["Debt amount"].Value = this.customerModel.debt; this.customerModel = new Customer(); this.renderModel(); } }
private void employeeModelEditButton_Click(object sender, EventArgs e) { if (this.employeesSet.SelectedRows.Count == 0) { return; } ServiceResult <Employee> result = employeeService.validate(this.employeeModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.update(this.employeeModel, typeof(Employee)); if (dbResult.isOk()) { Employee employee = this.employeeModel; DataGridViewRow row = this.employeesSet.CurrentRow; row.Cells["ID"].Value = employee.id; row.Cells["Fullname"].Value = employee.fullname; row.Cells["Birthdate"].Value = employee.dob; row.Cells["Address"].Value = employee.address; row.Cells["Phone"].Value = employee.phone; row.Cells["Title"].Value = employee.title.name; this.employeeModel = new Employee(); this.renderModel(); } }
private void submitLendingButton_Click(object sender, EventArgs e) { this.paymentReceipt.lendingReceipt.details = this.lendingDetails; ServiceResult <PaymentReceipt> result = paymentReceiptService.initialize(this.paymentReceipt); if (!result.isOk()) { this.renderErrors(result.messages); return; } this.paymentReceipt = result.model; result = paymentReceiptService.validate(this.paymentReceipt); if (!result.isOk()) { this.renderErrors(result.messages); return; } DatabaseOperationResult insertResult = paymentReceiptService.insert(this.paymentReceipt); if (!insertResult.isOk()) { return; } this.paymentReceipt = new PaymentReceipt(); this.renderBookSet(); this.customerModel = new Customer(); this.renderCustomerModel(); this.itemSetClearButton_Click(sender, e); this.employeeSet_SelectedIndexChanged(this.employeeSet, e); }
private void bookModelEditButton_Click(object sender, EventArgs e) { ServiceResult <Book> result = bookService.validate(this.bookModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.update(this.bookModel, type); if (dbResult.isOk()) { DataGridViewRow row = this.bookSet.CurrentRow; row.Cells["ID"].Value = this.bookModel.id; row.Cells["Name"].Value = this.bookModel.name; row.Cells["Author"].Value = this.bookModel.author; row.Cells["Publisher"].Value = this.bookModel.publisher; row.Cells["Published date"].Value = this.bookModel.publishDate; row.Cells["Price"].Value = this.bookModel.price; row.Cells["Stocked date"].Value = this.bookModel.stockedDate; this.bookModel = new Book(); this.bookModel.price = 1; this.renderModel(); } }