Пример #1
0
 public void Save(AccountSubject aso)
 {
     Execute(new AccountSubjectSaveRequest {
         Content = aso
     });
     DataFactory.Instance.GetCacheHashtable().Remove(CacheHashkey.AccountSubjectList);
 }
Пример #2
0
        void UpdateFullName(AccountSubject aso, dynamic tran)
        {
            var dt  = DBHelper.GetInstance(mContext).ExecuteDt(tran, "select * from _accountsubject order by _no");
            var lst = EntityConvertor <AccountSubject> .ToList(dt);

            aso.fullName = CalcFullName(lst, aso);
            DBHelper.GetInstance(mContext).ExecuteSql(tran, string.Format("update _accountsubject set _fullName = '{0}' where _id = {1}", aso.fullName, aso.id));
        }
        private void btn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var txt = (sender as Button).Name;
                switch (txt)
                {
                case "savenew":
                    if (NeedSave())
                    {
                        Save();
                    }
                    else
                    {
                        Console.WriteLine("don't change,no need save.");
                    }
                    ItemSource = new AccountSubject {
                        direction = 1
                    };
                    break;

                case "save":
                    if (NeedSave())
                    {
                        Save();
                    }
                    else
                    {
                        Console.WriteLine("don't change,no need save.");
                    }
                    FinanceMessageBox.Info("保存成功");
                    Close();
                    break;

                case "close":
                case "exit":
                    if (NeedSave())
                    {
                        MessageBoxResult ret = FinanceMessageBox.Quest("修改了科目,需要进行保存吗?");
                        if (ret == MessageBoxResult.Yes)
                        {
                            Save();
                        }
                        else if (ret == MessageBoxResult.Cancel)
                        {
                            break;
                        }
                    }
                    Close();
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                FinanceMessageBox.Error(ex.Message);
            }
        }
Пример #4
0
        public async Task <AccountSubject> AssigneSubject(AssignRequest assignRequest)
        {
            var accountSubject = new AccountSubject
            {
                AccountId = assignRequest.AccountId,
                SubjectId = assignRequest.SubjectId
            };

            _context.Set <AccountSubject>().Add(accountSubject);
            await _context.SaveChangesAsync();

            return(accountSubject);
        }
Пример #5
0
        public AccountSubject FindByNo(string no)
        {
            AccountSubject filter = new AccountSubject();

            filter.no = no;
            var lst = DataManager.GetInstance(mContext).Query(filter);

            if (lst.Count == 0)
            {
                return(null);
            }
            return(lst.First());
        }
Пример #6
0
        string CalcFullName(List <AccountSubject> lst, AccountSubject at)
        {
            var result = at.name;

            while (at.parentId != 0)
            {
                at = lst.FirstOrDefault(s => s.id == at.parentId);
                if (at == null)
                {
                    break;
                }
                result = at.name + "/" + result;
            }
            return(result);
        }
Пример #7
0
        bool GenerateAccoutSubject(string taskId, List <string> lstAccountSubjectNo)
        {
            var sb = new StringBuilder();
            var lstAccountSubject = AccountSubjectService.GetInstance(mContext).List();
            var lstExists         = lstAccountSubject.Select(a => a.no).ToList();
            var lstNotExist       = new List <string>();

            foreach (var aso in lstAccountSubjectNo)
            {
                if (!(lstExists.Exists(a => aso == a)))
                {
                    if (!aso.Contains("."))
                    {
                        sb.AppendLine(string.Format("不能生成一级科目[{0}];", aso));
                        continue;
                    }

                    var parentNo = aso.Substring(0, aso.LastIndexOf("."));
                    if (!lstExists.Exists(a => a == parentNo))
                    {
                        sb.AppendLine(string.Format("科目[{0}]的上级科目[{1}]不存在,请在科目中新增后重试;", aso, parentNo));
                        continue;
                    }

                    var prams   = new SqlParameter[] { new SqlParameter("accountSubjectNo", aso) };
                    var asoName = mBDBHelper.RunProcScalar("sp_getaccountsubjectname", prams);
                    if (asoName == null || string.IsNullOrEmpty(asoName.ToString()))
                    {
                        sb.AppendLine(string.Format("自动创建科目[{0}]获取科目名称失败;", aso));
                        continue;
                    }

                    var parentAso = lstAccountSubject.FirstOrDefault(a => a.no == parentNo);
                    var newAso    = new AccountSubject();
                    newAso.level     = parentAso.level + 1;
                    newAso.name      = asoName.ToString();
                    newAso.no        = aso;
                    newAso.parentId  = parentAso.id;
                    newAso.rootId    = parentAso.rootId == 0? parentAso.id: parentAso.rootId;
                    newAso.groupId   = parentAso.groupId;
                    newAso.direction = parentAso.direction;
                    AccountSubjectService.GetInstance(mContext).Save(newAso);
                    sb.AppendLine(string.Format("自动创建科目[{0} - {1}]成功;", aso, asoName.ToString()));
                }
            }
            RefreshTaskResult(taskId, ExecTaskType.CreateVoucher.ToString(), 20, "", sb.ToString());
            return(true);
        }
Пример #8
0
        void IImportHandler.Deconde(ref DataSet ds)
        {
            DataTable dt = ds.Tables[0];

            DataRow[] dataRows = dt.Select("1=1", "代码 asc");

            long idIndex = SerialNoService.GetInstance(new Dictionary <string, object> {
                { "Tid", mTid }
            }).GetIncrease(dt.Rows.Count, SerialNoKey.System);

            Auxiliary auxiliary = new Auxiliary()
            {
                type = (long)AuxiliaryType.AccountGroup
            };
            var lstAuxiliary = DataManager.GetInstance(new Dictionary <string, object> {
                { "Tid", mTid }
            }).Query <Auxiliary>(auxiliary);

            ///TODO:
            ///     1、列名映射
            ///     2、值转换
            ///     3、计算父子关系
            List <AccountSubject> lst = new List <AccountSubject>();

            foreach (DataRow dr in dataRows)
            {
                AccountSubject at = new AccountSubject();
                at.id = idIndex;
                foreach (DataColumn col in dt.Columns)
                {
                    switch (col.ColumnName)
                    {
                    case "代码":
                        var no = dr[col.ColumnName].ToString();
                        at.no = no;
                        var pointIndex = at.no.LastIndexOf(".");
                        if (pointIndex > -1)
                        {
                            var            parentNo      = no.Substring(0, pointIndex);
                            AccountSubject parentAccount = lst.FirstOrDefault(a => a.no == parentNo);
                            if (parentAccount == null)
                            {
                                throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "找不到父节点科目【" + parentNo + "】.");
                            }
                            at.parentId = parentAccount.id;
                            at.level    = parentAccount.level + 1;
                            at.rootId   = parentAccount.rootId == 0 ? parentAccount.id : parentAccount.rootId;
                            parentAccount.isHasChild = true;
                        }
                        else
                        {
                            at.level = 1;
                        }
                        break;

                    case "名称":
                        at.name     = dr[col.ColumnName].ToString();
                        at.fullName = CalcFullName(lst, at);
                        break;

                    case "类别":
                        string    strAux = dr[col.ColumnName].ToString();
                        Auxiliary aux    = lstAuxiliary.Find(t => t.name == strAux);
                        if (aux == null)
                        {
                            //如果需要,去数据库检索一遍
                            throw new FinanceException(FinanceResult.RECORD_NOT_EXIST, "类别【" + strAux + "】.");
                        }
                        at.groupId = aux.id;
                        break;

                    case "余额方向":
                        at.direction = dr[col.ColumnName].ToString() == "借" ? 1 : -1;
                        break;
                        //case "现金科目":
                        //    at.isCashSubject = dr[col.ColumnName].ToString() == "是";
                        //    break;
                        //case "银行科目":
                        //    at.isBankSubject = dr[col.ColumnName].ToString() == "是";
                        //    break;
                        //case "现金等价物":
                        //    at.isCashEqulvalent = dr[col.ColumnName].ToString() == "是";
                        //    break;
                        //case "主表项目":
                        //    var val = dr[col.ColumnName].ToString();
                        //    if(!string.IsNullOrEmpty(val))
                        //        at.mainProjectId = 0L;
                        //    break;
                    }
                }
                if (!string.IsNullOrEmpty(at.no))
                {
                    lst.Add(at);
                    idIndex++;
                }
            }
            DataTable dtRsp = EntityConvertor <AccountSubject> .ToDataTable(lst);

            dtRsp.TableName = "AccountSubject";
            ds = new DataSet();
            ds.Tables.Add(dtRsp);
        }
Пример #9
0
        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;
            }
        }