Exemplo n.º 1
0
        protected async Task toDelete()
        {
            using (var transaction = PinhuaContext.Database.BeginTransaction())
            {
                var tb_main = await PinhuaContext.tb_IO.FindAsync(RecordId);

                if (tb_main != null)
                {
                    var tb_details = PinhuaContext.tb_IOD.Where(p => p.RecordId == tb_main.RecordId);
                    var affected   = tb_details.Select(d => d.子单号).ToList();
                    PinhuaContext.tb_IO.Remove(tb_main);
                    PinhuaContext.tb_IOD.RemoveRange(tb_details);
                    await PinhuaContext.SaveChangesAsync();

                    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 items1    = PinhuaContext.tb_订单表D.Where(d => childIds1.Contains(d.子单号));
                    var items2    = PinhuaContext.tb_订单表D.Where(d => childIds2.Contains(d.子单号));

                    foreach (var item in items1)
                    {
                        item.状态 = "已入库";
                    }
                    ;
                    foreach (var item in items2)
                    {
                        item.状态 = "";
                    }
                    ;

                    await PinhuaContext.SaveChangesAsync();

                    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;
                        }
                    }
                    ;

                    await PinhuaContext.SaveChangesAsync();

                    transaction.Commit();
                }
            }

            Navigation.NavigateTo(routeA);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
        protected void ValidSubmit(EditContext context)
        {
            using (var transaction = PinhuaContext.Database.BeginTransaction())
            {
                var affected = new List <string>();
                var bAdd     = PinhuaContext.TryRecordAdd <dto销售出库, tb_IO>(main, adding =>
                {
                    adding.类型 = base.category;
                    adding.单号 = PinhuaContext.funcAutoCode("订单号");
                    adding.往来 = PinhuaContext.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == adding.往来号)?.简称;
                });
                if (bAdd)
                {
                    var bAdd2 = PinhuaContext.TryRecordDetailsAdd <dto销售出库, dto销售出库D, tb_IO, tb_IOD>(main, detailsTableDataSource, adding =>
                    {
                        if (string.IsNullOrWhiteSpace(adding.子单号))
                        {
                            adding.子单号 = PinhuaContext.funcAutoCode("子单号");
                        }
                        else
                        {
                            affected.Add(adding.子单号);
                            //var item = PinhuaContext.tb_订单表D.FirstOrDefault(d => d.子单号 == adding.子单号);
                            //if (item != null)
                            //    item.状态 = "已出库";
                        }
                    }
                                                                                                     );

                    if (bAdd2)
                    {
                        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 items1    = PinhuaContext.tb_订单表D.Where(d => childIds1.Contains(d.子单号));
                        var items2    = PinhuaContext.tb_订单表D.Where(d => childIds2.Contains(d.子单号));
                        foreach (var item in items1)
                        {
                            item.状态 = "已出库";
                        }
                        ;
                        foreach (var item in items2)
                        {
                            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);
            }
        }
        protected override void OnInitialized()
        {
            currentDataSource = PinhuaContext.View订单数量收发().Where(item => item.待收 > 0 && item.业务类型.StartsWith("采购")).ToList();

            base.OnInitialized();
        }