protected void grdDetailEntry_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e) { ASPxGridView grid = sender as ASPxGridView; Guid voucherAllocationId = (Guid)grid.GetMasterRowKeyValue(); Guid accountId = (Guid)e.NewValues["AccountId!Key"]; VoucherAllocationBookingAccount vaba = session.FindObject <VoucherAllocationBookingAccount>( CriteriaOperator.And( new BinaryOperator("AccountId!Key", accountId, BinaryOperatorType.Equal), new BinaryOperator("VoucherAllocationId!Key", voucherAllocationId, BinaryOperatorType.Equal) )); //Validate duuplicate account in transaction //Insert mode if (grid.IsNewRowEditing) { if (vaba != null) { Helpers.AddErrorToGridViewColumn(e.Errors, grid.Columns["AccountId!Key"], String.Format("Tài khoản này đã được chọn")); } } //Edit mode else { Guid oldAccountId = (Guid)e.OldValues["AccountId!Key"]; if (!oldAccountId.Equals(accountId)) { if (vaba != null) { Helpers.AddErrorToGridViewColumn(e.Errors, grid.Columns["AccountId!Key"], String.Format("Tài khoản này đã được chọn")); } } } //Check negative if (e.NewValues["Credit"] != null && (double)e.NewValues["Credit"] < 0) { Utility.Helpers.AddErrorToGridViewColumn(e.Errors, grid.Columns["Credit"], "Không thể nhập số âm"); } if (e.NewValues["Debit"] != null && (double)e.NewValues["Debit"] < 0) { Utility.Helpers.AddErrorToGridViewColumn(e.Errors, grid.Columns["Debit"], "Không thể nhập số âm"); } //Check input both credit and debit if ((e.NewValues["Credit"] != null && ((double)e.NewValues["Credit"]) > 0) && (e.NewValues["Debit"] != null && ((double)e.NewValues["Debit"]) > 0)) { Utility.Helpers.AddErrorToGridViewColumn(e.Errors, grid.Columns["Credit"], "Chỉ cho phép nhập Nợ hoặc nhập Có"); Utility.Helpers.AddErrorToGridViewColumn(e.Errors, grid.Columns["Debit"], "Chỉ cho phép nhập Nợ hoặc nhập Có"); } //Check leave blank both credit and debit else if ((e.NewValues["Credit"] == null || ((double)e.NewValues["Credit"]) == 0) && (e.NewValues["Debit"] == null || ((double)e.NewValues["Debit"]) == 0)) { Utility.Helpers.AddErrorToGridViewColumn(e.Errors, grid.Columns["Credit"], "Chưa nhập Nợ hoặc nhập Có"); Utility.Helpers.AddErrorToGridViewColumn(e.Errors, grid.Columns["Debit"], "Chưa nhập Nợ hoặc nhập Có"); } }
public bool GenerateTemplateVoucherForBookingEntry(Guid VouchesId) { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { try { NAS.DAL.Vouches.Vouches voucher = uow.GetObjectByKey <NAS.DAL.Vouches.Vouches>(VouchesId); if (voucher == null) { throw new Exception("The Vouches is not exist in db"); } string AllocationTypeCode = string.Empty; if (voucher is NAS.DAL.Vouches.PaymentVouches) { AllocationTypeCode = "VOUCHER_PAYMENT"; } if (voucher is NAS.DAL.Vouches.ReceiptVouches) { AllocationTypeCode = "VOUCHER_RECEIPT"; } XPCollection <VoucherAllocation> voucherAllocationLst = new XPCollection <VoucherAllocation>(uow, new BinaryOperator("VouchesId", voucher, BinaryOperatorType.Equal)); XPCollection <Allocation> allocationsTemplate = new XPCollection <Allocation>(uow, new BinaryOperator("AllocationTypeId.Code", AllocationTypeCode, BinaryOperatorType.Equal)); if (voucherAllocationLst != null && voucherAllocationLst.Count > 0) { foreach (VoucherAllocation va in voucherAllocationLst) { IEnumerable <Allocation> allocations = allocationsTemplate.Where(t => t == va.AllocationId); if (allocations != null && allocations.Count <Allocation>() <= 0) { continue; } if (va.VoucherAllocationBookingAccounts != null && va.VoucherAllocationBookingAccounts.Count > 0) { continue; } foreach (AllocationAccountTemplate aat in va.AllocationId.AllocationTemplates) { VoucherAllocationBookingAccount vaba = new VoucherAllocationBookingAccount(uow); vaba.AccountId = aat.AccountId; vaba.VoucherAllocationId = va; } } } uow.CommitChanges(); return(true); } catch { //uow.ExplicitRollbackTransaction(); throw; } } }