Example #1
0
 public static string Get相关人(IRepository rep, 车辆产值 产值, 任务 任务, 合同费用项 htfyx)
 {
     车队合同费用项 cdhtfyx = htfyx as 车队合同费用项;
     switch (cdhtfyx.费用归属)
     {
         case 费用归属.委托人:
             return 任务.委托人编号;
         case 费用归属.车主:
             return 产值.承运人编号;
         case 费用归属.驾驶员:
             return 产值.驾驶员编号;
         case 费用归属.对外:
             {
                 object entity;
                 if (任务 != null)
                 {
                     entity = 任务;
                 }
                 else
                 {
                     entity = 产值;
                 }
                 string ret = null;
                 object r = EntityScript.CalculateExpression(cdhtfyx.默认相关人, entity);
                 ret = string.IsNullOrEmpty(cdhtfyx.默认相关人) || r == null ? null : r.ToString().Replace("\"", "");
                 if (string.IsNullOrEmpty(ret))
                 {
                     ret = null;
                 }
                 return ret;
             }
         default:
             throw new ArgumentException("Invalid 费用归属!");
     }
 }
Example #2
0
        public static void 自动生成出车(GeneratedArchiveOperationForm masterForm)
        {
            if (MessageForm.ShowYesNo("是否自动生成出车?","提示"))
            {
                using (IRepository rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository<车辆>())
                {
                    IList<车辆> cl_List = (rep as Feng.NH.INHibernateRepository).List<车辆>(NHibernate.Criterion.DetachedCriteria.For<车辆>()
                    .Add(NHibernate.Criterion.Expression.Eq("默认出车", true)));

                    if (cl_List.Count == 0)
                    {
                        throw new InvalidUserOperationException("您还没有安排默认车!");
                    }

                    foreach (车辆 cl in cl_List)
                    {
                        车辆产值 clcz = new 车辆产值();
                        clcz = masterForm.ControlManager.AddNew() as 车辆产值;
                        clcz.日期 = DateTime.Now.AddDays(1);
                        clcz.车辆编号 = cl.ID;
                        clcz.承运人编号 = cl.车主编号;
                        clcz.驾驶员编号 = cl.默认驾驶员编号;
                        masterForm.DisplayManager.DisplayCurrent();
                        masterForm.ControlManager.EndEdit(true);
                    }
                }
            }
        }
Example #3
0
        private static decimal?Get理论值(IRepository rep, 车辆产值 产值, 任务 任务, 合同费用项 htfyx)
        {
            decimal?d = null;

            d = (任务 != null) ? Get理论值金额(rep, htfyx, 任务) : Get理论值金额(rep, htfyx, 产值);
            return(d);
        }
Example #4
0
        public static void 自动生成全部费用(ArchiveOperationForm masterForm)
        {
            if (!ServiceProvider.GetService <IMessageBox>().ShowYesNo("是否要自动全部生成费用?", "确认"))
            {
                return;
            }
            ProgressForm progressForm = new ProgressForm();

            progressForm.Start(masterForm, "生成");

            Feng.Async.AsyncHelper asyncHelper = new Feng.Async.AsyncHelper(
                new Feng.Async.AsyncHelper.DoWork(delegate()
            {
                费用实体 entity = masterForm.DisplayManager.CurrentItem as 费用实体;
                if (entity == null)
                {
                    throw new ArgumentException("请选择要生成费用的产值!");
                }
                using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <车辆产值>())
                {
                    车辆产值 piao = rep.Get <车辆产值>(entity.ID);
                    rep.Initialize(piao.任务, piao);
                    process_fy_yw.批量生成费用(rep, piao, piao.任务, null, null);
                }

                return(null);
            }),
                new Feng.Async.AsyncHelper.WorkDone(delegate(object result)
            {
                masterForm.ControlManager.OnCurrentItemChanged();
                progressForm.Stop();
            }));
        }
Example #5
0
        public static void 自动生成出车(GeneratedArchiveOperationForm masterForm)
        {
            if (MessageForm.ShowYesNo("是否自动生成出车?", "提示"))
            {
                using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <车辆>())
                {
                    IList <车辆> cl_List = (rep as Feng.NH.INHibernateRepository).List <车辆>(NHibernate.Criterion.DetachedCriteria.For <车辆>()
                                                                                          .Add(NHibernate.Criterion.Expression.Eq("默认出车", true)));

                    if (cl_List.Count == 0)
                    {
                        throw new InvalidUserOperationException("您还没有安排默认车!");
                    }

                    foreach (车辆 cl in cl_List)
                    {
                        车辆产值 clcz = new 车辆产值();
                        clcz       = masterForm.ControlManager.AddNew() as 车辆产值;
                        clcz.日期    = DateTime.Now.AddDays(1);
                        clcz.车辆编号  = cl.ID;
                        clcz.承运人编号 = cl.车主编号;
                        clcz.驾驶员编号 = cl.默认驾驶员编号;
                        masterForm.DisplayManager.DisplayCurrent();
                        masterForm.ControlManager.EndEdit(true);
                    }
                }
            }
        }
Example #6
0
        private static void 批量生成费用(IRepository rep, 车辆产值 产值, IEnumerable 任务s, 车队合同费用项 htfyx, IList <业务费用理论值> llzs, bool mustGenerateFy)
        {
            费用项 fyx = EntityBufferCollection.Instance.Get <费用项>(htfyx.费用项编号);

            if (fyx.箱)
            {
                foreach (任务 箱 in 任务s)
                {
                    GenerateFy(rep, 产值, 箱, htfyx, llzs, mustGenerateFy);
                }
            }
            else if (fyx.票)
            {
                GenerateFy(rep, 产值, null, htfyx, llzs, mustGenerateFy);
            }
        }
Example #7
0
        public static void 批量生成费用(IRepository rep, 车辆产值 产值, IEnumerable 任务s, string 费用项编号, 收付标志? 收付标志, IList<业务费用理论值> llzs)
        {
            车队合同 wtrht = CdDataBuffer.Instance.Get车队合同(rep);
            if (wtrht != null)
            {
                foreach (车队合同费用项 htfyx in wtrht.合同费用项)
                {
                    // 如果指定费用项,则只生成此费用项下的费用
                    if (!string.IsNullOrEmpty(费用项编号)
                        && htfyx.费用项编号 != 费用项编号)
                    {
                        continue;
                    }

                    批量生成费用(rep, 产值, 任务s, htfyx, llzs, !string.IsNullOrEmpty(费用项编号));
                }
            }
        }
Example #8
0
        public static void 自动生成费用(ArchiveOperationForm masterForm)
        {
            Dictionary <string, object> setData = masterForm.Tag as Dictionary <string, object>;
            费用实体 entity;

            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <业务费用>())
            {
                entity = rep.Get <费用实体>(setData["费用实体"]);
            }
            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <车辆产值>())
            {
                车辆产值 piao = rep.Get <车辆产值>(setData["费用实体"]);
                rep.Initialize(piao.任务, piao);
                process_fy_yw.批量生成费用(rep, piao, piao.任务, (string)setData["费用项"], !setData.ContainsKey("收付标志") ? null : (收付标志?)setData["收付标志"]);
            }

            (masterForm.MasterGrid as IBoundGrid).ReloadData();
        }
Example #9
0
        public static void 批量生成费用(IRepository rep, 车辆产值 产值, IEnumerable 任务s, string 费用项编号, 收付标志?收付标志, IList <业务费用理论值> llzs)
        {
            车队合同 wtrht = CdDataBuffer.Instance.Get车队合同(rep);

            if (wtrht != null)
            {
                foreach (车队合同费用项 htfyx in wtrht.合同费用项)
                {
                    // 如果指定费用项,则只生成此费用项下的费用
                    if (!string.IsNullOrEmpty(费用项编号) &&
                        htfyx.费用项编号 != 费用项编号)
                    {
                        continue;
                    }

                    批量生成费用(rep, 产值, 任务s, htfyx, llzs, !string.IsNullOrEmpty(费用项编号));
                }
            }
        }
Example #10
0
        public static string Get相关人(IRepository rep, 车辆产值 产值, 任务 任务, 合同费用项 htfyx)
        {
            车队合同费用项 cdhtfyx = htfyx as 车队合同费用项;

            switch (cdhtfyx.费用归属)
            {
            case 费用归属.委托人:
                return(任务.委托人编号);

            case 费用归属.车主:
                return(产值.承运人编号);

            case 费用归属.驾驶员:
                return(产值.驾驶员编号);

            case 费用归属.对外:
            {
                object entity;
                if (任务 != null)
                {
                    entity = 任务;
                }
                else
                {
                    entity = 产值;
                }
                string ret = null;
                object r   = EntityScript.CalculateExpression(cdhtfyx.默认相关人, entity);
                ret = string.IsNullOrEmpty(cdhtfyx.默认相关人) || r == null ? null : r.ToString().Replace("\"", "");
                if (string.IsNullOrEmpty(ret))
                {
                    ret = null;
                }
                return(ret);
            }

            default:
                throw new ArgumentException("Invalid 费用归属!");
            }
        }
Example #11
0
        public static int 批量生成费用(IRepository rep, 车辆产值 票, IEnumerable 箱, string 费用项编号, 收付标志?收付标志)
        {
            int cnt = 0;

            // 需按照委托人合同和付款合同生成相应费用和费用理论值
            // 如果总体来生成,则按照:
            // 如果费用已经打了完全标志,则不生成。如果相应理论值已经生成过,也不生成。
            // 如果单个费用项来生成,则不管理论值是否已经生成过
            // Todo: 理论值可能显示生成票的,后来信息完全了再生成箱的,此时要删除票的
            //using (IRepository rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository(票.GetType()))
            {
                try
                {
                    rep.BeginTransaction();

                    IList <业务费用理论值> llzs = (rep as Feng.NH.INHibernateRepository).List <业务费用理论值>(NHibernate.Criterion.DetachedCriteria.For <业务费用理论值>()
                                                                                                 .Add(NHibernate.Criterion.Expression.Eq("费用实体.ID", 票.ID)));

                    rep.Initialize(票.费用, 票);

                    process_fy_generate.批量生成费用(rep, 票, 箱, 费用项编号, 收付标志, llzs);


                    ////  有几项(发票税,贴息费)要看收款费用
                    // 不行,会多生成
                    //批量生成费用付款(rep, 费用实体类型, 票, 箱, 费用项编号, 收付标志, llzs);

                    rep.CommitTransaction();
                }
                catch (Exception ex)
                {
                    rep.RollbackTransaction();
                    ServiceProvider.GetService <IExceptionProcess>().ProcessWithNotify(ex);
                }
            }
            return(cnt);
        }
Example #12
0
 private static void 批量生成费用(IRepository rep, 车辆产值 产值, IEnumerable 任务s, 车队合同费用项 htfyx, IList<业务费用理论值> llzs, bool mustGenerateFy)
 {
     费用项 fyx = EntityBufferCollection.Instance.Get<费用项>(htfyx.费用项编号);
     if (fyx.箱)
     {
         foreach (任务 箱 in 任务s)
         {
             GenerateFy(rep, 产值, 箱, htfyx, llzs, mustGenerateFy);
         }
     }
     else if (fyx.票)
     {
         GenerateFy(rep, 产值, null, htfyx, llzs, mustGenerateFy);
     }
 }
Example #13
0
 private static decimal? Get理论值(IRepository rep, 车辆产值 产值, 任务 任务, 合同费用项 htfyx)
 {
     decimal? d = null;
     d = (任务 != null) ? Get理论值金额(rep, htfyx, 任务) : Get理论值金额(rep, htfyx, 产值);
     return d;
 }
Example #14
0
        private static void GenerateFy(IRepository rep, 车辆产值 产值, 任务 任务, 车队合同费用项 htfyx, IList<业务费用理论值> llzs, bool mustGenerateFy)
        {
            string 相关人 = Get相关人(rep, 产值, 任务, htfyx);
            decimal? 金额 = Get理论值(rep, 产值, 任务, htfyx);
            if (金额.HasValue && 金额.Value == decimal.MinValue)
            {
                return;
            }

            bool llrHaveGenerated = false;
            foreach (业务费用理论值 i in llzs)
            {
                bool b = i.费用项编号 == htfyx.费用项编号
                    && i.相关人编号 == 相关人;
                if (b && 任务 != null)
                {
                    b &= i.任务ID == 任务.ID;
                }
                if (b)
                {
                    llrHaveGenerated = true;
                    break;
                }
            }

            业务费用理论值 ywfylrz = null;
            if (!llrHaveGenerated)
            {
                if (金额.HasValue)
                {
                    ywfylrz = new 业务费用理论值();
                    ywfylrz.费用实体 = 产值;
                    ywfylrz.费用项编号 = htfyx.费用项编号;
                    ywfylrz.票 = 产值;
                    ywfylrz.收付标志 = htfyx.收付标志;
                    ywfylrz.相关人编号 = Get相关人(rep, 产值, 任务, htfyx);
                    ywfylrz.车辆编号 = 产值.车辆编号;
                    ywfylrz.费用归属 = (htfyx as 车队合同费用项).费用归属;
                    //ywfylrz.金额 = 金额.Value;
                    ProcessFywithSl(ywfylrz, 金额.Value);

                    if (任务 != null)
                    {
                        ywfylrz.任务 = 任务;
                        ywfylrz.任务ID = 任务.ID;
                    }

                    (new HdBaseDao<业务费用理论值>()).Save(rep, ywfylrz);
                    llzs.Add(ywfylrz);
                }
            }

            if (htfyx.是否生成实际费用)
            {
                bool generateFy = false;
                // 在外层,判断理论值是否生成过
                if (!mustGenerateFy)
                {
                    if (htfyx.是否空值全部生成)
                    {
                        // 金额为Null的时候判断时候生成过,没生成过也要生成
                        if (!金额.HasValue)
                        {
                            bool fyHaveGenerated = false;
                            foreach (业务费用 i in 产值.费用)
                            {
                                bool b = i.费用项编号 == htfyx.费用项编号
                                   && i.费用归属 == htfyx.费用归属;
                                if (b && 任务 != null)
                                {
                                    b &= i.任务.ID == 任务.ID;
                                }
                                if (b)
                                {
                                    fyHaveGenerated = true;
                                    break;
                                }
                            }
                            generateFy = !fyHaveGenerated;
                        }
                    }

                    if (!generateFy)
                    {
                        // 只有理论值未生成过,且有理论值的情况下,准备生成费用
                        if (!llrHaveGenerated && ywfylrz != null)
                        {
                            // 如果理论值未生成过,要检查是否要生成费用
                            bool fyHaveGenerated = false;
                            foreach (业务费用 i in 产值.费用)
                            {
                                bool b = i.费用项编号 == htfyx.费用项编号
                                   && i.费用归属 == htfyx.费用归属;
                                if (b && 任务 != null)
                                {
                                    b &= i.任务.ID == 任务.ID;
                                }
                                if (b)
                                {
                                    fyHaveGenerated = true;
                                    break;
                                }
                            }
                            generateFy = !fyHaveGenerated;
                        }
                        else
                        {
                            generateFy = false;
                        }
                    }
                }
                else
                {
                    generateFy = true;
                }

                if (generateFy)
                {
                    bool fylbSubmitted = false;

                    IList<费用信息> list = (rep as Feng.NH.INHibernateRepository).List<费用信息>(NHibernate.Criterion.DetachedCriteria.For<费用信息>()
                        .Add(NHibernate.Criterion.Expression.Eq("费用项编号", htfyx.费用项编号))
                        .Add(NHibernate.Criterion.Expression.Eq("车辆产值.ID", 产值.ID)));
                    System.Diagnostics.Debug.Assert(list.Count <= 1);
                    if (list.Count == 1)
                    {
                        if (htfyx.收付标志 == 收付标志.收)
                        {
                            fylbSubmitted = list[0].Submitted;
                        }
                        else
                        {
                            fylbSubmitted = list[0].完全标志付;
                        }
                    }

                    // 完全标志还未打
                    if (!fylbSubmitted)
                    {
                        // 不生成理论值为0的
                        if (!金额.HasValue || (金额.HasValue && 金额.Value != 0))
                        {
                            业务费用 item = new 业务费用();
                            item.费用实体 = 产值;
                            item.车辆产值 = 产值;
                            item.费用项编号 = htfyx.费用项编号;

                            item.收付标志 = htfyx.收付标志;
                            item.相关人编号 = 相关人;
                            item.车辆编号 = 产值.车辆编号;
                            item.费用归属 = (htfyx as 车队合同费用项).费用归属;
                            //item.金额 = 金额;
                            if (金额 != null)
                            {
                                ProcessFywithSl(item, 金额.Value);
                            }
                            else
                            {
                                item.金额 = 金额;
                            }
                            if (任务 != null)
                            {
                                item.任务 = 任务;
                            }

                            (new 业务费用Dao()).Save(rep, item);

                            产值.费用.Add(item);
                        }
                    }
                }
            }
        }
Example #15
0
        private static void GenerateFy(IRepository rep, 车辆产值 产值, 任务 任务, 车队合同费用项 htfyx, IList <业务费用理论值> llzs, bool mustGenerateFy)
        {
            string  相关人 = Get相关人(rep, 产值, 任务, htfyx);
            decimal?金额  = Get理论值(rep, 产值, 任务, htfyx);

            if (金额.HasValue && 金额.Value == decimal.MinValue)
            {
                return;
            }

            bool llrHaveGenerated = false;

            foreach (业务费用理论值 i in llzs)
            {
                bool b = i.费用项编号 == htfyx.费用项编号 &&
                         i.相关人编号 == 相关人;
                if (b && 任务 != null)
                {
                    b &= i.任务ID == 任务.ID;
                }
                if (b)
                {
                    llrHaveGenerated = true;
                    break;
                }
            }

            业务费用理论值 ywfylrz = null;

            if (!llrHaveGenerated)
            {
                if (金额.HasValue)
                {
                    ywfylrz       = new 业务费用理论值();
                    ywfylrz.费用实体  = 产值;
                    ywfylrz.费用项编号 = htfyx.费用项编号;
                    ywfylrz.票     = 产值;
                    ywfylrz.收付标志  = htfyx.收付标志;
                    ywfylrz.相关人编号 = Get相关人(rep, 产值, 任务, htfyx);
                    ywfylrz.车辆编号  = 产值.车辆编号;
                    ywfylrz.费用归属  = (htfyx as 车队合同费用项).费用归属;
                    //ywfylrz.金额 = 金额.Value;
                    ProcessFywithSl(ywfylrz, 金额.Value);

                    if (任务 != null)
                    {
                        ywfylrz.任务   = 任务;
                        ywfylrz.任务ID = 任务.ID;
                    }

                    (new HdBaseDao <业务费用理论值>()).Save(rep, ywfylrz);
                    llzs.Add(ywfylrz);
                }
            }

            if (htfyx.是否生成实际费用)
            {
                bool generateFy = false;
                // 在外层,判断理论值是否生成过
                if (!mustGenerateFy)
                {
                    if (htfyx.是否空值全部生成)
                    {
                        // 金额为Null的时候判断时候生成过,没生成过也要生成
                        if (!金额.HasValue)
                        {
                            bool fyHaveGenerated = false;
                            foreach (业务费用 i in 产值.费用)
                            {
                                bool b = i.费用项编号 == htfyx.费用项编号 &&
                                         i.费用归属 == htfyx.费用归属;
                                if (b && 任务 != null)
                                {
                                    b &= i.任务.ID == 任务.ID;
                                }
                                if (b)
                                {
                                    fyHaveGenerated = true;
                                    break;
                                }
                            }
                            generateFy = !fyHaveGenerated;
                        }
                    }

                    if (!generateFy)
                    {
                        // 只有理论值未生成过,且有理论值的情况下,准备生成费用
                        if (!llrHaveGenerated && ywfylrz != null)
                        {
                            // 如果理论值未生成过,要检查是否要生成费用
                            bool fyHaveGenerated = false;
                            foreach (业务费用 i in 产值.费用)
                            {
                                bool b = i.费用项编号 == htfyx.费用项编号 &&
                                         i.费用归属 == htfyx.费用归属;
                                if (b && 任务 != null)
                                {
                                    b &= i.任务.ID == 任务.ID;
                                }
                                if (b)
                                {
                                    fyHaveGenerated = true;
                                    break;
                                }
                            }
                            generateFy = !fyHaveGenerated;
                        }
                        else
                        {
                            generateFy = false;
                        }
                    }
                }
                else
                {
                    generateFy = true;
                }

                if (generateFy)
                {
                    bool fylbSubmitted = false;

                    IList <费用信息> list = (rep as Feng.NH.INHibernateRepository).List <费用信息>(NHibernate.Criterion.DetachedCriteria.For <费用信息>()
                                                                                           .Add(NHibernate.Criterion.Expression.Eq("费用项编号", htfyx.费用项编号))
                                                                                           .Add(NHibernate.Criterion.Expression.Eq("车辆产值.ID", 产值.ID)));
                    System.Diagnostics.Debug.Assert(list.Count <= 1);
                    if (list.Count == 1)
                    {
                        if (htfyx.收付标志 == 收付标志.收)
                        {
                            fylbSubmitted = list[0].Submitted;
                        }
                        else
                        {
                            fylbSubmitted = list[0].完全标志付;
                        }
                    }

                    // 完全标志还未打
                    if (!fylbSubmitted)
                    {
                        // 不生成理论值为0的
                        if (!金额.HasValue || (金额.HasValue && 金额.Value != 0))
                        {
                            业务费用 item = new 业务费用();
                            item.费用实体  = 产值;
                            item.车辆产值  = 产值;
                            item.费用项编号 = htfyx.费用项编号;

                            item.收付标志  = htfyx.收付标志;
                            item.相关人编号 = 相关人;
                            item.车辆编号  = 产值.车辆编号;
                            item.费用归属  = (htfyx as 车队合同费用项).费用归属;
                            //item.金额 = 金额;
                            if (金额 != null)
                            {
                                ProcessFywithSl(item, 金额.Value);
                            }
                            else
                            {
                                item.金额 = 金额;
                            }
                            if (任务 != null)
                            {
                                item.任务 = 任务;
                            }

                            (new 业务费用Dao()).Save(rep, item);

                            产值.费用.Add(item);
                        }
                    }
                }
            }
        }
Example #16
0
        public static int 批量生成费用(IRepository rep, 车辆产值 票, IEnumerable 箱, string 费用项编号, 收付标志? 收付标志)
        {
            int cnt = 0;

            // 需按照委托人合同和付款合同生成相应费用和费用理论值
            // 如果总体来生成,则按照:
            // 如果费用已经打了完全标志,则不生成。如果相应理论值已经生成过,也不生成。
            // 如果单个费用项来生成,则不管理论值是否已经生成过
            // Todo: 理论值可能显示生成票的,后来信息完全了再生成箱的,此时要删除票的
            //using (IRepository rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository(票.GetType()))
            {
                try
                {
                    rep.BeginTransaction();

                    IList<业务费用理论值> llzs = (rep as Feng.NH.INHibernateRepository).List<业务费用理论值>(NHibernate.Criterion.DetachedCriteria.For<业务费用理论值>()
                                            .Add(NHibernate.Criterion.Expression.Eq("费用实体.ID", 票.ID)));

                    rep.Initialize(票.费用, 票);

                    process_fy_generate.批量生成费用(rep, 票, 箱, 费用项编号, 收付标志, llzs);

                    ////  有几项(发票税,贴息费)要看收款费用
                    // 不行,会多生成
                    //批量生成费用付款(rep, 费用实体类型, 票, 箱, 费用项编号, 收付标志, llzs);

                    rep.CommitTransaction();
                }
                catch (Exception ex)
                {
                    rep.RollbackTransaction();
                    ServiceProvider.GetService<IExceptionProcess>().ProcessWithNotify(ex);
                }
            }
            return cnt;
        }
Example #17
0
        public static void 批量添加费用(ArchiveOperationForm masterForm)
        {
            IControlManager cm = masterForm.ControlManager;

            ArchiveSelectForm selectForm = new ArchiveSelectForm("批量添加业务费用");

            if (selectForm.ShowDialog() == DialogResult.OK)
            {
                ArchiveCheckForm form = selectForm.SelectedForm as ArchiveCheckForm;

                if (form != null && form.ShowDialog() == DialogResult.OK)
                {
                    foreach (object i in form.SelectedEntites)
                    {
                        业务费用 item = new 业务费用();
                        if (i is 车辆产值)
                        {
                            车辆产值 tang = i as 车辆产值;
                            item.车辆   = (i == null ? null : tang.车辆);
                            item.车辆编号 = i == null ? null : (Guid?)tang.车辆编号;
                            item.费用实体 = tang;
                            item.车辆产值 = tang;
                        }
                        else if (i is 任务)
                        {
                            任务 xiang = i as 任务;

                            // it must have piao
                            //item.车辆产值 = xiang.车辆产值;
                            item.任务   = (i == null ? null : xiang);
                            item.车辆   = (i == null ? null : xiang.车辆产值.车辆);
                            item.车辆编号 = i == null ? null : (Guid?)xiang.车辆产值.车辆编号;
                            item.费用实体 = xiang.车辆产值;// new 车辆产值 { ID = item.车辆产值.ID, Version = item.车辆产值.Version };
                            item.车辆产值 = xiang.车辆产值;
                        }
                        else
                        {
                            System.Diagnostics.Debug.Assert(false, "选中的费用实体类型不是要求类型,而是" + i.GetType().ToString());
                        }

                        object entity = cm.AddNew();
                        if (entity != null)
                        {
                            cm.DisplayManager.Items[cm.DisplayManager.Position] = item;
                            cm.EndEdit();
                        }
                        else
                        {
                            // 出现错误,不再继续。 AddNew的时候,前一个出现错误,没保存。然后提示时候保存,选不继续
                            masterForm.ControlManager.CancelEdit();
                            break;
                        }

                        //bool isPiao = (i is 普通票);
                        //string filter = "现有费用实体类型 LIKE '%" + (int)item.票.费用实体类型;
                        //if (isPiao)
                        //{
                        //    filter += ",%' AND 票 = " + isPiao;
                        //}
                        //else
                        //{
                        //    filter += ",%' AND 箱 = " + !isPiao;
                        //}
                        //masterForm.ActiveGrid.CurrentDataRow.Cells["费用项编号"].CellEditorManager = ControlDataLoad.GetGridComboEditor("费用项_业务", filter);
                    }
                }
            }
        }