Exemple #1
0
 public void FillContext(WorksheetContext ctx)
 {
     ctx.Context.Entites.ForEach((e) =>
     {
         Attribute attribute = e.Attributes.FirstOrDefault(a => a.IsTypeOf <Table>());
         if (attribute.IsNotNull())
         {
             Table table = attribute.CastToType <Table>();
             if (_dataSet.Tables.Contains(table.TableName))
             {
                 IEntityCollection collection = e.Entities as IEntityCollection;
                 if (collection.IsNotNull())
                 {
                     foreach (DataRow row in _dataSet.Tables[table.TableName].Rows)
                     {
                         Entity entity = collection.CreateInstance(e.EntityType, true, new object[] { row }) as Entity;
                         if (entity.IsNotNull())
                         {
                             collection.Add(entity);
                         }
                     }
                 }
             }
         }
     });
     ctx.AcceptChanges();
 }
        public virtual void RemoveWorkshetRow(long id, string SessionId)
        {
            WorksheetContext ctx = Session.GetSessionData(SessionId, "WorksheetContext").CastToType <WorksheetContext>();
            WorksheetRow     row = ctx.WorksheetRows.FirstOrDefulatEntity(r => r.Id == id);

            if (row.IsNotNull())
            {
                ctx.WorksheetRows.Remove(row);
            }
        }
        public virtual void AcceptChanges(long id, string SessionId)
        {
            WorksheetContext ctx       = Session.GetSessionData(SessionId, "WorksheetContext").CastToType <WorksheetContext>();
            Screening        screening = ctx.Screenings.FirstOrDefulatEntity(s => s.Id == id);

            if (screening.IsNotNull())
            {
                screening.AcceptChanges();
            }
        }
        public virtual void Recalculate(long id, string SessionId)
        {
            WorksheetContext ctx       = Session.GetSessionData(SessionId, "WorksheetContext").CastToType <WorksheetContext>();
            Screening        screening = ctx.Screenings.FirstOrDefulatEntity(s => s.Id == id);

            if (screening.IsNotNull())
            {
                screening.ValueResult = (long.Parse(screening.ValueA) + long.Parse(screening.ValueB)).ToString();
            }
        }
        public virtual object DeleteScreening(long id, string SessionId)
        {
            WorksheetContext ctx       = Session.GetSessionData(SessionId, "WorksheetContext").CastToType <WorksheetContext>();
            Screening        screening = ctx.Screenings.FirstOrDefulatEntity(s => s.Id == id);

            if (screening != null)
            {
                Worksheet w = screening.Worksheet;
                ctx.Screenings.Remove(screening);
                w.Description = "Workshet(" + w.Screenings.CountEntity() + ")";
                return(new { Model = w });
            }
            else
            {
                return(new ErrorView());
            }
        }
        public virtual object Load(string SessionId)
        {
            WorksheetContext ctx     = Session.GetSessionData(SessionId, "WorksheetContext").CastToType <WorksheetContext>();
            DataHandler      handler = Session.GetSessionData(SessionId, "WorksheetDataHandler").CastToType <DataHandler>();

            handler.FillDataSet();
            handler.FillContext(ctx);
            ctx.Context.EntityCreated = handler.EntityCreated;
            if (ctx.Worksheets.Count > 0)
            {
                return(new { Model = ctx.Worksheets.FirstOrDefault(), Probes = ctx.Probes.ToList() });
            }
            else
            {
                return(new ErrorView());
            }
        }
        public virtual object Lock(long id, string SessionId)
        {
            WorksheetContext ctx       = Session.GetSessionData(SessionId, "WorksheetContext").CastToType <WorksheetContext>();
            Screening        screening = ctx.Screenings.FirstOrDefulatEntity(s => s.Id == id);

            if (screening.IsNotNull())
            {
                if (screening.IsFrozen)
                {
                    WorksheetContext.UnFreeze(screening);
                }
                else
                {
                    WorksheetContext.Freeze(screening);
                }
            }
            return(new { Id = id, Frozen = screening.IsFrozen });
        }
        public virtual object AddScreening(long id, long probeid, string SessionId)
        {
            WorksheetContext ctx       = Session.GetSessionData(SessionId, "WorksheetContext").CastToType <WorksheetContext>();
            Worksheet        worksheet = ctx.Worksheets.FirstOrDefulatEntity(w => w.Id == id);

            if (worksheet != null)
            {
                Screening screening = ctx.Screenings.CreateInstance();
                screening.WorksheetId = worksheet.Id;
                screening.ProbeId     = probeid;
                ctx.Screenings.Add(screening);
                worksheet.Description = "Workshet(" + worksheet.Screenings.CountEntity() + ")";
                return(new { Model = screening });
            }
            else
            {
                return(new ErrorView());
            }
        }
        public virtual object ScreeningChanged(long screeningId, string SessionId)
        {
            WorksheetContext ctx = Session.GetSessionData(SessionId, "WorksheetContext").CastToType <WorksheetContext>();

            return(new { Screening = ctx.Screenings.FirstOrDefulatEntity(s => s.Id == screeningId) });
        }
        public virtual object ProbeChenged(long probeId, string SessionId)
        {
            WorksheetContext ctx = Session.GetSessionData(SessionId, "WorksheetContext").CastToType <WorksheetContext>();

            return(new { Screenings = ctx.Screenings.WhereEntity(s => s.ProbeId == probeId).ToList() });
        }