public void AddHeader(VoucherHeader h) { m_HeadersCount++; m_vlistHead.Add(new XAttribute("StoreId", h.StoreId)); m_vlistHead.Add(new XAttribute("PremierStoreId", h.PremierStoreId)); m_vlistHead.Add(new XAttribute("StoreCountryCode", h.StoreCountryCode)); m_vlistHead.Add(new XAttribute("DocumentDate", h.DocumentDate)); }
/// <summary> /// 对凭证的各个ID进行处理:内码、序号、凭证号 /// 序号要求连续,出现重复,直接取新的填充 /// 凭证号,在同一会计年度、期间、凭证字下唯一,出现重复,报错 /// </summary> /// <param name="item">凭证主体</param> /// <param name="tran">事务对象</param> void GeneratorIds(VoucherHeader header, dynamic tran) { string exKey = string.Format("{0}_{1}_{2}", header.year, header.period, header.word); SerialNoService noGenerator = new SerialNoService(mContext, tran) { SerialKey = SerialNoKey.VoucherNo, Ex = exKey }; //var bExistNo = DBHelper.GetInstance(mContext).Exist( // string.Format("select 1 from _voucherheader where _year = {0} and _period={1} and _word ='{2}' and _no={3}", // header.year, header.period, header.word, header.no)); //if (bExistNo) // throw new FinanceException(FinanceResult.RECORD_EXIST, string.Format("{0}年度第{1}期间{2}字序号{3}", header.year, header.period, header.word, header.no)); SerialNoService idGenerator = new SerialNoService(mContext, tran) { SerialKey = SerialNoKey.System }; SerialNoService snGenerator = new SerialNoService(mContext, tran) { SerialKey = SerialNoKey.VoucherSn }; header.id = idGenerator.GetIncrease(); header.serialNo = snGenerator.GetIncrease(); header.no = noGenerator.GetIncrease(); while (DBHelper.GetInstance(mContext).Exist(string.Format("select 1 from _voucherheader where _id = {0}", header.id))) { header.id = idGenerator.GetIncrease(); } while (DBHelper.GetInstance(mContext).Exist(string.Format("select 1 from _voucherheader where _serialNo={0}", header.serialNo))) { header.serialNo = snGenerator.GetIncrease(); } while (DBHelper.GetInstance(mContext).Exist(string.Format("select 1 from _voucherheader where _year = {0} and _period={1} and _word ='{2}' and _no={3}", header.year, header.period, header.word, header.no))) { header.no = noGenerator.GetIncrease(); } }
void LoadVoucher(long id, LINKED linked = LINKED.CURRENT) { Voucher v = DataFactory.Instance.GetVoucherExecuter().Find(id, linked); VoucherHeader header = v.header; if (v.udefenties != null) { mUserDefineDataSource = v.udefenties; } mid = header.id; lblStatus.Visibility = Visibility.Hidden; UnLock(); txtBBillNo.Text = ""; txtAgent.Text = header.agent; txtCashier.Text = header.cashier; txtReference.Text = header.reference; lblCreater.Tag = header.creater; lblCreater.Content = DataFactory.Instance.GetUserExecuter().FindName(header.creater); dateBusinessDate.SelectedDate = header.businessDate; dateDate.SelectedDate = header.date; cmbWords.SelectedValue = header.word; intSn.Value = (int)header.serialNo; intNo.Value = (int)header.no; lblPeriod.Content = string.Format("{0}年第{1}期", header.date.Year, header.date.Month); List <VoucherGridItem> items = new List <VoucherGridItem>(); v.entries.ForEach(entry => { var item = new VoucherGridItem(); item.UniqueKey = entry.uniqueKey; item.AccountSubjectId = entry.accountSubjectId; item.Content = entry.explanation; if (entry.direction == 1) { item.DebitsAmount = entry.amount; } else { item.CreditAmount = entry.amount; } items.Add(item); }); voucherGrid.DataSource = items; logger.Debug("LoadVoucher:[{0}]", items.Count); voucherGrid.Refresh(); lblChecker.Tag = header.checker; lblChecker.Content = DataFactory.Instance.GetUserExecuter().FindName(header.checker); lblPoster.Tag = header.poster; lblPoster.Content = DataFactory.Instance.GetUserExecuter().FindName(header.poster); if (header.status > 0) { ShowStatusLable((VoucherStatus)(header.status)); Lock(); } }
Voucher ReadVoucher() { VoucherHeader header = new VoucherHeader(); header.agent = txtAgent.Text; header.businessDate = DateTime.Parse(dateBusinessDate.Text); header.cashier = txtCashier.Text; header.creater = DataFactory.Instance.GetCacheHashtable().Get(CacheHashkey.UserId); header.creatTime = DateTime.Now; header.date = DateTime.Parse(dateDate.Text);; header.word = cmbWords.Text; header.serialNo = int.Parse(intSn.Value.ToString()); header.reference = txtReference.Text; header.no = int.Parse(intNo.Value.ToString()); header.year = header.date.Year; header.period = header.date.Month; header.id = 0; var lst = voucherGrid.DataSource; int i = 1; List <VoucherEntry> entries = new List <VoucherEntry>(); Dictionary <string, Dictionary <string, object> > userDefineValues = new Dictionary <string, Dictionary <string, object> >(); foreach (var item in lst) { var entry = new VoucherEntry(); entry.index = i; entry.explanation = item.Content; entry.accountSubjectId = item.AccountSubjectId; entry.accountSubjectNo = item.AccountSubjectNo; if (item.DebitsAmount > 0) { entry.amount = item.DebitsAmount; entry.direction = 1; } else { entry.amount = item.CreditAmount; entry.direction = -1; } if (entry.accountSubjectId == 0 && entry.amount == 0) { continue; } entry.uniqueKey = item.UniqueKey; entries.Add(entry); if (mUserDefineDataSource.ContainsKey(item.UniqueKey)) { userDefineValues.Add(item.UniqueKey, mUserDefineDataSource[item.UniqueKey]); } i++; } Voucher v = new Voucher() { header = header, entries = entries, udefenties = userDefineValues }; return(v); }
private void btnOk_Click(object sender, EventArgs e) { if (dgv.Rows.Count > 0) { if (btnBess.Text != btnBeds.Text) { MessageBox.Show("کاربر گرامی مقادیر بدهکاری و بستانکاری بایستی برابر باشند"); return; } if (VoucherId != 0) { var voucherLines = (from DataGridViewRow row in dgv.Rows select new VoucherLine { Id = int.Parse(row.Cells["clnId"].Value.ToString()), VoucherHeaderId = VoucherId, EntityCode = int.Parse(row.Cells["clnCode"].Value.ToString()), Comment = row.Cells["clnDisc"].Value == null ? " " : row.Cells["clnDisc"].Value.ToString(), BedPrice = decimal.Parse(row.Cells["clnBed"].Value == null ? "0" : row.Cells["clnBed"].Value.ToString()), BesPrice = decimal.Parse(row.Cells["clnBes"].Value == null ? "0" : row.Cells["clnBes"].Value.ToString()), CurrencyId = int.Parse(row.Cells["clnIdCurrency"].Value.ToString()), RatePrice = decimal.Parse(row.Cells["clnRate"].Value.ToString()), BedTMIN = decimal.Parse(row.Cells["clnBedTMN"].Value == null ? "0" : row.Cells["clnBedTMN"].Value.ToString().ToString()), BesTMIN = decimal.Parse(row.Cells["clnBesTMN"].Value == null ? "0" : row.Cells["clnBesTMN"].Value.ToString().ToString()) }).ToList(); var voucherHeader = new VoucherHeader { Id = VoucherId, UserId = UtilityClass.UserId, Comment = txtDisc.Text, ManualDate = txtDate.Text, LogRecord = DateTime.Now //VoucherLines = voucherLines }; using (var dbContext = new UnitOfWork()) { dbContext.VoucherHeaderRepository.Update(voucherHeader); dbContext.VoucherLineRepository.UpdateLine(voucherLines); //foreach (VoucherLine line in voucherLines) //{ // var lines = new VoucherLine() // { // Id = line.Id, // VoucherHeaderId = VoucherId, // EntityCode = line.EntityCode, // Comment = line.Comment, // BedPrice = line.BedPrice, // BesPrice = line.BesPrice, // CurrencyId = line.CurrencyId, // RatePrice = line.RatePrice, // BedTMIN = line.BedTMIN, // BesTMIN = line.BesTMIN // }; //} dbContext.Save(); DialogResult = DialogResult.OK; } } else { var voucherLines = (from DataGridViewRow row in dgv.Rows select new VoucherLine { EntityCode = int.Parse(row.Cells["clnCode"].Value.ToString()), Comment = row.Cells["clnDisc"].Value == null ? " " : row.Cells["clnDisc"].Value.ToString(), BedPrice = decimal.Parse(row.Cells["clnBed"].Value == null ? "0" : row.Cells["clnBed"].Value.ToString()), BesPrice = decimal.Parse(row.Cells["clnBes"].Value == null ? "0" : row.Cells["clnBes"].Value.ToString()), CurrencyId = int.Parse(row.Cells["clnIdCurrency"].Value.ToString()), RatePrice = decimal.Parse(row.Cells["clnRate"].Value.ToString()), BedTMIN = decimal.Parse(row.Cells["clnBedTMN"].Value == null ? "0" : row.Cells["clnBedTMN"].Value.ToString().ToString()), BesTMIN = decimal.Parse(row.Cells["clnBesTMN"].Value == null ? "0" : row.Cells["clnBesTMN"].Value.ToString().ToString()) }).ToList(); var voucherHeader = new VoucherHeader { UserId = UtilityClass.UserId, Comment = txtDisc.Text, ManualDate = txtDate.Text, LogRecord = DateTime.Now, VoucherLines = voucherLines }; using (var dbContext = new UnitOfWork()) { dbContext.VoucherHeaderRepository.Insert(voucherHeader); //dbContext.VoucherLineRepository.Insert(line); dbContext.Save(); DialogResult = DialogResult.OK; } } } }
void ExecCarriedForward(string taskId, string procName, Dictionary <string, object> paramMap) { if (paramMap == null) { paramMap = new Dictionary <string, object>(); } RefreshTaskResult(taskId, ExecTaskType.CarriedForward.ToString(), 0, "开始执行", ""); Auxiliary auxFilter = new Auxiliary() { type = (int)AuxiliaryType.CarriedForward, no = procName }; var lst = DataManager.GetInstance(mContext).Query(auxFilter); if (lst == null || lst.Count == 0) { throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "结转方式不存在"); } var auxObj = lst.FirstOrDefault(); var templateList = TemplateSevice.GetInstance(mContext).ListCarriedForwardTemplate(auxObj.id); if (templateList == null || templateList.Count == 0) { throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "结转模板不存在"); } var year = SystemProfileService.GetInstance(mContext).GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentYear); var period = SystemProfileService.GetInstance(mContext).GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentPeriod); var dbHelper = DBHelper.GetInstance(mContext); //1、检查是否还有未过账 if (dbHelper.Exist(string.Format("select 1 from _VoucherHeader where _year = {0} and _period = {1} and _status < {2} and _status <> {3}" , year, period, (int)VoucherStatus.Posted, (int)VoucherStatus.Canceled))) { throw new FinanceException(FinanceResult.INCORRECT_STATE, "当前凭证没有全部过账"); } //2、生成凭证 var direction = 1; switch (auxObj.description) { case "income": break; case "cost": direction = -1; break; case "investment": break; case "profits": break; } var word = "转"; if (paramMap.ContainsKey("word")) { word = paramMap["word"].ToString(); } var explanation = auxObj.name; if (paramMap.ContainsKey("explanation")) { explanation = paramMap["explanation"].ToString(); } var lstAccountObject = AccountSubjectService.GetInstance(mContext).List(); var lstEntries = new List <VoucherEntry>(); var index = 0; foreach (var temp in templateList) { var srcActObj = lstAccountObject.FirstOrDefault(actObj => actObj.id == temp.src); var dstActObj = lstAccountObject.FirstOrDefault(actObj => actObj.id == temp.dst); if (srcActObj == null || dstActObj == null) { throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "结转模板数据错误"); } var amountObj = dbHelper.ExecuteScalar(string.Format(@"select sum(_amount * _direction) as _amount from _VoucherEntry where _accountSubjectId = {0} and _id in (select _id from _VoucherHeader where _year = {1} and _period = {2})", temp.src, year, period)); if (amountObj == null || amountObj == DBNull.Value) { continue; } var amount = (decimal)amountObj; if (amount < 0) { direction = -1 * direction; amount = -1 * amount; } var voucherEntrySrc = new VoucherEntry(); voucherEntrySrc.index = index++; voucherEntrySrc.accountSubjectId = temp.src; voucherEntrySrc.accountSubjectNo = srcActObj.no; voucherEntrySrc.amount = amount; voucherEntrySrc.direction = direction; voucherEntrySrc.explanation = explanation; lstEntries.Add(voucherEntrySrc); var voucherEntryDst = new VoucherEntry(); voucherEntryDst.index = index++; voucherEntryDst.accountSubjectId = temp.dst; voucherEntryDst.accountSubjectNo = dstActObj.no; voucherEntryDst.amount = amount; voucherEntryDst.direction = -1 * direction; voucherEntryDst.explanation = explanation; lstEntries.Add(voucherEntryDst); } if (lstEntries.Count == 0) { throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "没有需要结转的凭证"); } var voucherHeader = new VoucherHeader(); voucherHeader.word = word; voucherHeader.year = year; voucherHeader.period = period; voucherHeader.date = CommonUtils.CalcMaxPeriodDate(year, period); var now = DateTime.Now; voucherHeader.businessDate = now; voucherHeader.creatTime = now; voucherHeader.creater = 13594; Voucher voucher = new Voucher(); voucher.header = voucherHeader; voucher.entries = lstEntries; var id = VoucherService.GetInstance(mContext).Add(voucher); var h = VoucherService.GetInstance(mContext).FindHeader(id); var msg = string.Format("结转成功,凭证字号:{0} - {1};", h.word, h.no); RefreshTaskResult(taskId, ExecTaskType.CreateVoucher.ToString(), 100, "", msg, 1); }
private void dgvHeader_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (dgvHeader.CurrentCell.ColumnIndex == 5) { using (var page = new DocumentOperationPage()) { page.VoucherId = (int)dgvHeader.CurrentRow.Cells["clnId"].Value; page.ShowDialog(); } DocumentListPage_Load(null, null); } else if (dgvHeader.CurrentCell.ColumnIndex == 6) { var dr = MessageBox.Show("آیا مایل به حذف این سند می باشید؟", "سوال", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { var voucherLines = (from DataGridViewRow row in dgvLine.Rows select new VoucherLine { EntityCode = int.Parse(row.Cells["clnCode"].Value.ToString()), Comment = row.Cells["clnCommentLine"].Value == null ? " " : row.Cells["clnCommentLine"].Value.ToString(), BedPrice = decimal.Parse(row.Cells["clnBed"].Value == null ? "0" : row.Cells["clnBed"].Value.ToString()), BesPrice = decimal.Parse(row.Cells["clnBes"].Value == null ? "0" : row.Cells["clnBes"].Value.ToString()), CurrencyId = int.Parse(row.Cells["clnCurrency"].Value.ToString()), RatePrice = decimal.Parse(row.Cells["clnRate"].Value.ToString()), BedTMIN = decimal.Parse(row.Cells["clnSBed"].Value == null ? "0" : row.Cells["clnSBed"].Value.ToString().ToString()), BesTMIN = decimal.Parse(row.Cells["clnSBes"].Value == null ? "0" : row.Cells["clnSBed"].Value.ToString().ToString()) }).ToList(); var voucherHeader = new VoucherHeader { UserId = Convert.ToInt32(dgvHeader.CurrentRow.Cells["clnUser"].Value.ToString()), Comment = dgvHeader.CurrentRow.Cells["clnComment"].Value.ToString(), LogRecord = Convert.ToDateTime(dgvHeader.CurrentRow.Cells["clnDate"].Value.ToString()), VoucherLines = voucherLines }; using (var db = new UnitOfWork()) { var value = dgvHeader.CurrentRow.Cells["clnId"].Value; if (value != null) { db.VoucherHeaderRepository.Delete((int)value); db.Save(); } } } DocumentListPage_Load(null, null); } else { using (var db = new UnitOfWork()) { if (db.VoucherLineRepository != null) { if (dgvHeader.CurrentRow != null) { var headerId = (int)dgvHeader.CurrentRow.Cells["clnId"].Value; dgvLine.AutoGenerateColumns = false; var result = db.VoucherLineRepositoryFilter.Get(person => person.VoucherHeaderId == headerId); dgvLine.DataSource = result; foreach (DataGridViewRow row in dgvLine.Rows) { var code = (int)row.Cells["clnCode"].Value; var entityCapital = db.AccountCapitalRepository.GetById(code); if (entityCapital != null) { row.Cells["clnEntity"].Value = entityCapital.Name; } var entityBank = db.BankAccountRepository.GetById(code); if (entityBank != null) { row.Cells["clnEntity"].Value = entityBank.Name; } var entityCash = db.CashDeskRepository.GetById(code); if (entityCash != null) { row.Cells["clnEntity"].Value = entityCash.Name; } var entityCoins = db.CoinsRepository.GetById(code); if (entityCoins != null) { row.Cells["clnEntity"].Value = entityCoins.Name; } var entityCost = db.CostRepository.GetById(code); if (entityCost != null) { row.Cells["clnEntity"].Value = entityCost.Name; } var entityIncome = db.IncomeRepository.GetById(code); if (entityIncome != null) { row.Cells["clnEntity"].Value = entityIncome.Name; } var entityPeople = db.PeopleRepository.GetById(code); if (entityPeople != null) { row.Cells["clnEntity"].Value = entityPeople.FirstName + " " + entityPeople.LastName; } var value = (int)row.Cells["clnCurrency"].Value; var resultCurrency = db.CurrencyRepository.GetById(value); if (resultCurrency != null) { row.Cells["clnCur"].Value = resultCurrency.Name; } } } } } } }