Exemplo n.º 1
0
 protected void view_NeedDataSource(object sender, Telerik.Web.UI.RadListViewNeedDataSourceEventArgs e)
 {
     var sv = ps.SelectedDate.HasValue ? ps.SelectedDate.Value : DateTime.Today;
     var ev = pe.SelectedDate.HasValue ? pe.SelectedDate.Value : DateTime.Today;
     var _s = new DateTime(sv.Year, sv.Month, 1).ToTimeNode();
     var _e = new DateTime(ev.Year, ev.Month, 1).ToTimeNode();
     if (_s > _e)
     {
         var _t = _s;
         _s = _e;
         _e = _t;
     }
     var catalogs = tree.GetAllNodes().Where(o => o.Checked).Select(o => o.Value.GlobalId()).ToList();
     var source = catalogs.Join(db.Value.Store_ST.Where(o => o.Time >= _s && o.Time <= _e), o => o, o => o.CatalogId, (a, b) => b).ToList();
     var list = new List<InMemoryST>();
     var ___objs = catalogs.Join(db.Value.StoreObject.Where(o => o.State < 2), o => o, o => o.CatalogId, (a, b) => b.Id).ToList();
     foreach (var ___id in ___objs)
     {
         if (source.Count(o => o.ObjectId == ___id && o.Time == _s) == 0)
         {
             db.Value.ActionRecord(___id, DateTime.Parse(_s.FromTimeNode()), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
             db.Value.SaveChanges();
         }
     }
     foreach (var g in source.GroupBy(o => o.ObjectId))
     {
         var obj = new InMemoryST();
         var v = g.OrderBy(o => o.Time).ToList();
         obj.CatalogPath = v.First().CatalogPath;
         obj.Name = v.First().Name;
         obj.Single = v.First().Single;
         obj.Consumable = v.First().Consumable;
         obj.Fixed = v.First().Fixed;
         obj.S = g.First().StartAmount;
         obj.SM = g.First().StartMoney;
         obj.SP = obj.S == 0 ? 0M : decimal.Divide(obj.SM, obj.S);
         obj.I = g.Sum(o => o.InAmount);
         obj.IM = g.Sum(o => o.InMoney);
         obj.IP = obj.I == 0 ? 0M : decimal.Divide(obj.IM, obj.I);
         obj.U = g.Sum(o => o.LendAmount + o.ConsumeAmount);
         obj.UM = g.Sum(o => o.LendMoney + o.ConsumeMoney);
         obj.UP = obj.U == 0 ? 0M : decimal.Divide(obj.UM, obj.U);
         obj.R = g.Sum(o => o.RedoAmount);
         obj.RM = g.Sum(o => o.RedoMoney);
         obj.RP = obj.R == 0 ? 0M : decimal.Divide(obj.RM, obj.R);
         obj.O = g.Sum(o => o.OutAmount);
         obj.OM = g.Sum(o => o.OutMoney);
         obj.OP = obj.O == 0 ? 0M : decimal.Divide(obj.OM, obj.O);
         obj.E = g.Last().EndAmount;
         obj.EM = g.Last().EndMoney;
         obj.EP = obj.E == 0 ? 0M : decimal.Divide(obj.EM, obj.E);
         if (obj.S > 0 || obj.SM > 0 || obj.I > 0 || obj.IM > 0 || obj.U > 0 || obj.UM > 0 || obj.R > 0 || obj.RM > 0 || obj.O > 0 || obj.OM > 0 || obj.E > 0 || obj.EM > 0)
             list.Add(obj);
     }
     if (!name.Text.Trim().Null())
     {
         list = list.Where(o => o.Name == name.Text.Trim()).ToList();
     }
     ___total.Value = list.Sum(o => o.S).ToMoney() + "@" + list.Sum(o => o.SM).ToMoney() + "@" + list.Sum(o => o.I).ToMoney() + "@" + list.Sum(o => o.IM).ToMoney() + "@" + list.Sum(o => o.U).ToMoney() + "@" + list.Sum(o => o.UM).ToMoney() + "@" + list.Sum(o => o.R).ToMoney() + "@" + list.Sum(o => o.RM).ToMoney() + "@" + list.Sum(o => o.E).ToMoney() + "@" + list.Sum(o => o.EM).ToMoney();
     view.DataSource = list.OrderBy(o => o.CatalogPath).ThenBy(o => o.Name).ToList();
 }