Exemple #1
0
        protected void HandleValidSubmit(EditContext context)
        {
            using (var transaction = PinhuaContext.Database.BeginTransaction())
            {
                var affected = new List <string>();
                var bEdit    = PinhuaContext.TryRecordEdit <dto采购订单, tb_订单表>(main, adding =>
                {
                    adding.业务类型 = base.category;
                    adding.往来   = PinhuaContext.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == adding.往来号)?.简称;
                });
                if (bEdit)
                {
                    Action <dto采购订单D> Adding = item =>
                    {
                        if (string.IsNullOrWhiteSpace(item.子单号)) // 子单号为空的,表示新插入
                        {
                            item.子单号 = PinhuaContext.funcAutoCode("子单号");
                        }
                        else // 子单号不为空,表示从报价单引入,插入
                        {
                            affected.Add(item.子单号);
                            var baojiaD = PinhuaContext.Set <tb_报价表D>().FirstOrDefault(d => d.子单号 == item.子单号);
                            if (baojiaD != null)
                            {
                                baojiaD.状态 = "已下单";
                            }
                        }
                    };
                    Action <dto采购订单D> Updating = item =>
                    {
                        affected.Add(item.子单号);
                        var baojiaD = PinhuaContext.Set <tb_报价表D>().FirstOrDefault(d => d.子单号 == item.子单号);
                        if (baojiaD != null)
                        {
                            baojiaD.状态 = "已下单";
                        }
                    };
                    Action <tb_订单表D> Deleting = item =>
                    {
                        affected.Add(item.子单号);
                        var tb_报价D = PinhuaContext.Set <tb_报价表D>().FirstOrDefault(d => d.子单号 == item.子单号);
                        if (tb_报价D != null)
                        {
                            tb_报价D.状态 = "";
                        }
                    };

                    var bEdit2 = PinhuaContext.TryRecordDetailsEdit <dto采购订单, dto采购订单D, tb_订单表, tb_订单表D>(main, detailsTableDataSource,
                                                                                                         Adding, Updating, Deleting);

                    if (bEdit2)
                    {
                        var mains = from m in PinhuaContext.tb_报价表
                                    join d in PinhuaContext.tb_报价表D on m.RecordId equals d.RecordId
                                    where affected.Contains(d.子单号)
                                    select m;

                        foreach (var m in mains)
                        {
                            var bRet = PinhuaContext.tb_报价表D.Where(d => d.RecordId == m.RecordId).Any(d => d.状态.Contains("已"));
                            if (bRet)
                            {
                                m.LockStatus = 1;
                            }
                            else
                            {
                                m.LockStatus = 0;
                            }
                        }
                        ;
                        PinhuaContext.SaveChanges();

                        transaction.Commit();
                    }
                }

                Navigation.NavigateTo(routeA);
            }
        }
Exemple #2
0
        protected void ValidSubmit(EditContext context)
        {
            using (var transaction = PinhuaContext.Database.BeginTransaction())
            {
                var affected = new List <string>();
                var bEdit    = PinhuaContext.TryRecordEdit <dto销售出库, tb_IO>(main, adding =>
                {
                    adding.类型 = base.category;
                    adding.往来 = PinhuaContext.Set <tb_往来表>().FirstOrDefault(p => p.往来号 == adding.往来号)?.简称;
                });

                if (bEdit)
                {
                    Action <dto销售出库D> Adding = item =>
                    {
                        if (string.IsNullOrEmpty(item.子单号)) // 子单号为空的,表示新插入
                        {
                            item.子单号 = PinhuaContext.funcAutoCode("子单号");
                        }
                        else // 子单号不为空,表示从报价单引入,插入
                        {
                            affected.Add(item.子单号);
                        }
                    };

                    Action <dto销售出库D> Updating = item => affected.Add(item.子单号);
                    Action <tb_IOD>   Deleting = item => affected.Add(item.子单号);

                    var bEdit2 = PinhuaContext.TryRecordDetailsEdit <dto销售出库, dto销售出库D, tb_IO, tb_IOD>(main, detailsTableDataSource, Adding, Updating, Deleting);

                    if (bEdit2)
                    {
                        var childIds1 = PinhuaContext.View订单数量收发().Where(d => (d.已发 ?? 0) > 0 && affected.Contains(d.子单号)).Select(d => d.子单号);
                        var childIds2 = PinhuaContext.View订单数量收发().Where(d => (d.已发 ?? 0) == 0 && affected.Contains(d.子单号)).Select(d => d.子单号);
                        var result1   = PinhuaContext.tb_订单表D.Where(d => childIds1.Contains(d.子单号));
                        var result2   = PinhuaContext.tb_订单表D.Where(d => childIds2.Contains(d.子单号));
                        foreach (var item in result1)
                        {
                            item.状态 = "已出库";
                        }
                        ;
                        foreach (var item in result2)
                        {
                            item.状态 = "";
                        }
                        ;
                        PinhuaContext.SaveChanges();

                        var mains = from m in PinhuaContext.tb_订单表
                                    join d in PinhuaContext.tb_订单表D on m.RecordId equals d.RecordId
                                    where affected.Contains(d.子单号)
                                    select m;

                        foreach (var m in mains)
                        {
                            var bRet = PinhuaContext.tb_订单表D.Where(d => d.RecordId == m.RecordId).Any(d => d.状态.Contains("已"));
                            if (bRet)
                            {
                                m.LockStatus = 1;
                            }
                            else
                            {
                                m.LockStatus = 0;
                            }
                        }
                        ;
                        PinhuaContext.SaveChanges();

                        transaction.Commit();
                    }
                }

                Navigation.NavigateTo(routeA);
            }
        }