private void reset() { hdType.Value = "0"; optClear(optprefill); txtsearch.Text = String.Empty; txtVTname.Text = String.Empty; txtvtype.Text = String.Empty; txtAbbr.Text = String.Empty; ddlvno.SelectedIndex = 0; Label1.Visible = false; Label2.Visible = false; Label3.Visible = false; txtno.Visible = false; txtwidth.Visible = false; optprefill.Visible = false; txtno.Text = String.Empty; txtwidth.Text = String.Empty; Voucher.Clear(); VoucherTable.Clear(); txtprefix.Text = ""; chkPrint.Checked = false; chkNarr.Checked = false; }
public void Insert(ChitSubscriberDueModel chitSubscriberDueModel) { var voucherModel = new VoucherTable { KeyId = Guid.NewGuid(), VoucherDate = System.DateTime.Now }; _unitOfWork.GetRepository <VoucherTable>().Add(voucherModel); string st = Reflection.GetPropFullName(new ChitSubscriberDueTable(), "DueAmountInfoKeyId"); if (st != "") { AccountBookFieldMapTable row = _unitOfWork.GetRepository <AccountBookFieldMapTable>().Single(x => x.FieldNameKey == st); var CashBook = _unitOfWork.GetRepository <AccountBookTable>().Single(x => x.ProgId == AccountBookProgs.CashBook); if (row != null && CashBook != null) { string AccessId = int.Parse(chitSubscriberDueModel.AccessId).ToString(); var voucherInfoModelCr = new VoucherInfoTable { KeyId = Guid.NewGuid(), VoucherKeyId = voucherModel.KeyId, AccountBookKeyId = row.AccountBookKeyId, Amount = chitSubscriberDueModel.Amount, IsCredit = true }; var voucherInfoModelDr = new VoucherInfoTable { KeyId = Guid.NewGuid(), VoucherKeyId = voucherModel.KeyId, AccountBookKeyId = CashBook.KeyId, Amount = chitSubscriberDueModel.Amount, IsCredit = false }; _unitOfWork.GetRepository <VoucherInfoTable>().Add(voucherInfoModelCr); _unitOfWork.GetRepository <VoucherInfoTable>().Add(voucherInfoModelDr); _unitOfWork.GetRepository <ChitSubscriberDueTable>().Add(new ChitSubscriberDueTable { KeyId = Guid.NewGuid(), AccessId = chitSubscriberDueModel.AccessId, ChitSubscriberKeyId = chitSubscriberDueModel.ChitSubscriberKeyId, DueAmountInfoKeyId = voucherInfoModelCr.KeyId }); _unitOfWork.SaveChanges(); } } else { throw new Exception("Account Book not Configured"); } }
/// <summary> /// add voucher master /// </summary> public bool AddVoucherMaster(VoucherModel voucherViewModel) { try { #region Get Campaign Category Prefix var couponPrefix = (from cc in _dbContext.CouponCategories join vc in _dbContext.VoucherCampaigns on cc.Id equals vc.CategoryId where vc.Id == voucherViewModel.CampaignId select cc.CouponPrefix).FirstOrDefault(); #endregion #region Coupon Prefix for Code String newPrefix = couponPrefix.Trim(); #endregion #region Pad Campaign Id with zero Int32 Length = Convert.ToInt32(voucherViewModel.CampaignId.ToString().Length); Int32 DigitToAppend = 5; String PCampId; if (Length != 0) { PCampId = voucherViewModel.CampaignId.ToString(); } else { PCampId = "00000"; } while (Length < DigitToAppend) { PCampId = "0" + PCampId; Length++; } #endregion #region checklists String newVoucherCode = ""; // check for the voucher code and set new voucher code while (newVoucherCode == "") { // check for repeated code in db string generatedVoucher = CreateVoucher(newPrefix); // check for unique token in DB if (!_dbContext.VoucherTables.Where(x => x.VoucherCode == generatedVoucher).Any()) { newVoucherCode = generatedVoucher; VoucherTable voucherTable = new VoucherTable { VoucherCode = newVoucherCode }; _dbContext.VoucherTables.Add(voucherTable); _dbContext.SaveChanges(); } } #endregion VoucherMaster voucherMaster = new VoucherMaster() { CampaignId = voucherViewModel.CampaignId, VoucherId = newVoucherCode, FirstName = voucherViewModel.FirstName, LastName = voucherViewModel.LastName, VoucherAmount = voucherViewModel.VoucherAmount, IssueDate = DateTime.Now, Expirydate = voucherViewModel.Expirydate, Status = voucherViewModel.Status, Created = DateTime.Now, Updated = DateTime.Now, VoucherValue = voucherViewModel.VoucherValue, FullName = voucherViewModel.FirstName + voucherViewModel.LastName }; _dbContext.VoucherMasters.Add(voucherMaster); _dbContext.SaveChanges(); // add the added values and return back voucherViewModel.Id = voucherMaster.Id; voucherViewModel.VoucherId = voucherMaster.VoucherId; voucherViewModel.IssueDate = voucherMaster.IssueDate; voucherViewModel.FullName = voucherMaster.FullName; return(true); } catch (Exception ex) { return(false); } }