private void tspSaveAndNew_Click(object sender, EventArgs e) { this.isSaveAndNew = true; SaveAccount(); frmMain.LoadAccountByType(frmMain.CboFilterText); frmMain.DisableEditDelete(); frmMain.DrawChart(frmMain.CboChart); }
private void tspSaveAndClose_Click(object sender, EventArgs e) { if (cboAccount.Text == "") { MessageBox.Show("Pilih rekening terlebih dahulu", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (txtAmount.Text == "") { MessageBox.Show("Jumlah tidak boleh kosong", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.Focus(); } else if (decimal.Parse(txtAmount.Text.Replace(".", string.Empty)) > forBalance) { MessageBox.Show("Pembayaran tidak mencukupi. " + lblForBalance.Text, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.Focus(); } else { Model.Transaction transaction = new Model.Transaction(); transaction.Type = TransactionType.Payment.ToString(); transaction.Date = dtpDate.Value; transaction.Amount = decimal.Parse(txtAmount.Text.Replace(".", string.Empty)); transaction.Description = "Bayar " + this.accountName + " dengan " + cboAccount.Text; transaction.CategoryId = new Guid(lblCategoryId.Text); transaction.AccountId = new Guid(lblAccountId.Text); transaction.Notes = txtNotes.Text; transactionRepository.Save(transaction); frmMain.LoadAccountByType(frmMain.CboFilterText); frmMain.DisableEditDelete(); frmMain.DisableAction(); frmMain.DrawChart(frmMain.CboChart); this.Close(); } }
private void SaveTransaction() { if (ValidateEntry()) { Model.Transaction transaction = new Model.Transaction(); transaction.Date = dtpDate.Value; transaction.Type = transactionType.ToString(); transaction.CategoryId = new Guid(lblCategoryId.Text); transaction.AccountId = new Guid(lblAccountId.Text); transaction.Amount = decimal.Parse(txtAmount.Text.Replace(".", string.Empty)); transaction.Notes = txtNotes.Text; string errMsg = string.Empty; try { if (formMode == FormMode.AddNew) { errMsg = "Gagal menyimpan transaksi!"; if (transactionType == TransactionType.Income.ToString()) { transaction.Description = "Pendapatan dari " + cboCategory.Text + " disimpan di " + cboAccount.Text; } else if (transactionType == TransactionType.Expense.ToString()) { transaction.Description = "Pengeluaran untuk " + cboCategory.Text + " dibayar dengan " + cboAccount.Text; } if (transactionRepository.IsTransactionExist(dtpDate.Value, this.transactionType, new Guid(lblCategoryId.Text), new Guid(lblAccountId.Text))) { MessageBox.Show("Transaksi sudah ada", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { transactionRepository.Save(transaction); if (this.isSaveAndNew) { ClearForm(); } else { this.Close(); } } } else if (formMode == FormMode.Edit) { errMsg = "Gagal mengubah transaksi!"; transaction.ID = new Guid(lblID.Text); transactionRepository.Update(transaction); this.Close(); } frmMain.LoadTransactionByType(frmMain.CboFilterText); frmMain.DisableEditDelete(); frmMain.DrawChart(frmMain.CboChart); } catch (Exception ex) { MessageBox.Show(errMsg, "Info", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }