/// <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(); } }
public void Save(AccountSubject aso) { if (string.IsNullOrEmpty(aso.no) || string.IsNullOrEmpty(aso.name)) { throw new FinanceException(FinanceResult.IMPERFECT_DATA, "科目代码或名称不能为空"); } if (aso.direction != 1 && aso.direction != -1) { throw new FinanceException(FinanceResult.IMPERFECT_DATA, "科目余额方向无效"); } var bRet = DBHelper.GetInstance(mContext).Exist(string.Format("select 1 from _Auxiliary where _type ={0} and _id = {1}", (int)AuxiliaryType.AccountGroup, aso.groupId)); if (!bRet) { throw new FinanceException(FinanceResult.IMPERFECT_DATA, "科目类别无效"); } dynamic tran = DBHelper.GetInstance(mContext).BeginTransaction(); try { bRet = DBHelper.GetInstance(mContext).Exist(tran, string.Format("select 1 from _accountsubject where _no ='{0}' and _id <> {1}", aso.no, aso.id)); if (bRet) { throw new FinanceException(FinanceResult.IMPERFECT_DATA, "代码已存在"); } if (aso.id == 0) { var pos = aso.no.LastIndexOf('.'); if (pos != -1) { var pre = aso.no.Substring(0, pos); var filter = new AccountSubject { no = pre }; List <AccountSubject> lst = DataManager.GetInstance(mContext).Query(tran, filter); if (lst.Count == 0) { throw new FinanceException(FinanceResult.IMPERFECT_DATA, "父级科目不存在:" + pre); } var parentItem = lst.FirstOrDefault(); aso.parentId = parentItem.id; aso.rootId = parentItem.rootId; aso.level = parentItem.level + 1; parentItem.isHasChild = true; DataManager.GetInstance(mContext).Update(tran, parentItem); } SerialNoService serial = new SerialNoService(mContext, tran) { SerialKey = SerialNoKey.System }; aso.id = serial.GetIncrease(); aso.level = aso.level == 0 ? 1 : aso.level; DataManager.GetInstance(mContext).Insert(tran, aso); } else { DataManager.GetInstance(mContext).Update(tran, aso); } UpdateFullName(aso, tran); UserService.GetInstance(mContext).UpdateTimeStampArticle(TimeStampArticleEnum.AccountSubject, tran); DBHelper.GetInstance(mContext).CommitTransaction(tran); } catch (Exception ex) { DBHelper.GetInstance(mContext).RollbackTransaction(tran); throw ex; } }