Example #1
0
        protected override void bgw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            try
            {
                using (DamWCFContext dam6Entities = new DamWCFContext(false))
                {
                    ResetConnectionString(dam6Entities);

                    using (EF5x.Models.DamDBContext dam5Entities = new EF5x.Models.DamDBContext())
                    {
                        ResetConnectionString(dam5Entities);
                        _allRowCnt = dam5Entities.MessureParams.Count();
                        DateTime minDate = new DateTime(1970, 1, 1);
                        var      newItem = new MessureValue();

                        foreach (var paramItem in dam5Entities.MessureParams.AsNoTracking())
                        {
                            //寻找已有数据中的最大date
                            DateTimeOffset maxDate = (from i in dam6Entities.MessureValues
                                                      where i.ParamId == paramItem.MessureParamID
                                                      select i.Date).DefaultIfEmpty(minDate).Max();
                            //get all mes values which >maxDate
                            var query = from i in dam5Entities.MessureValues.AsNoTracking()
                                        where i.messureParamID == paramItem.MessureParamID && i.Date > maxDate
                                        select i;
                            foreach (var item in query)
                            {
                                newItem.Id      = Guid.NewGuid();
                                newItem.ParamId = item.messureParamID;
                                newItem.Date    = item.Date;
                                newItem.Val     = item.Val;

                                dam6Entities.MessureValues.Add(newItem);


                                dam6Entities.SaveChanges();
                                dam6Entities.Entry(newItem).State = System.Data.Entity.EntityState.Detached;;
                            }

                            handledCnt++;
                            reportProgress();
                        }
                    }
                }
                reportProgress();

                bgwResult = "导入成功!";
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    bgwResult = ex.InnerException.Message;
                }
                else
                {
                    bgwResult = ex.Message;
                }
            }
        }
Example #2
0
        // POST odata/MessureValues
        public async Task <IHttpActionResult> Post(MessureValue messurevalue)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.MessureValues.Add(messurevalue);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (MessureValueExists(messurevalue.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Created(messurevalue));
        }
Example #3
0
        // PUT odata/MessureValues(5)
        public async Task <IHttpActionResult> Put([FromODataUri] Guid key, MessureValue messurevalue)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (key != messurevalue.Id)
            {
                return(BadRequest());
            }

            db.Entry(messurevalue).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessureValueExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(messurevalue));
        }
Example #4
0
        public async Task <IHttpActionResult> Patch([FromODataUri] Guid key, Delta <MessureValue> patch)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            MessureValue messurevalue = await db.MessureValues.FindAsync(key);

            if (messurevalue == null)
            {
                return(NotFound());
            }

            patch.Patch(messurevalue);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessureValueExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(messurevalue));
        }
Example #5
0
        private void saveData(AppIntegratedInfo appInfo, DataTable table)
        {
            DateTimeOffset maxDate = DateTimeOffset.MinValue;

            if (appInfo.CalcValues.Count > 0)
            {
                //最后一次数据
                maxDate = appInfo.CalcValues[0].Date;
            }

            foreach (DataRow row in table.Rows)
            {
                DateTimeOffset date = (DateTimeOffset)row[PubConstant.timeColumnName];
                if (date > maxDate)
                {
                    foreach (MessureParam item in appInfo.MesParams)
                    {
                        MessureValue mv = new MessureValue();
                        mv.Date    = date;
                        mv.Id      = Guid.NewGuid();
                        mv.ParamId = item.Id;
                        mv.Val     = row[item.ParamName] as double?;

                        appInfo.DbContext.AddToMessureValues(mv);
                    }

                    foreach (CalculateParam item in appInfo.CalcParams)
                    {
                        CalculateValue mv = new CalculateValue();
                        mv.Date    = date;
                        mv.Id      = Guid.NewGuid();
                        mv.ParamId = item.Id;
                        mv.Val     = row[item.ParamName] as double?;


                        appInfo.DbContext.AddToCalculateValues(mv);
                    }

                    object remarkVal = row[PubConstant.remarkColumnName];
                    if (remarkVal != null && remarkVal.ToString().Trim().Length != 0)
                    {
                        Remark remark = new Remark();
                        remark.Id         = Guid.NewGuid();
                        remark.AppId      = appInfo.CurrentApp.Id;
                        remark.Date       = date;
                        remark.RemarkText = remarkVal.ToString().Trim();

                        appInfo.DbContext.AddToRemarks(remark);
                    }
                }
            }
            appInfo.Update();
        }
Example #6
0
        public void T_app_CheckExistData2()
        {
            Uri uri     = new Uri(TestConfig.serviceUrl);
            var context = new DamServiceRef.Container(uri);

            context.Format.UseJson();

            var app = context.Apps.Where(s => s.AppName == "第一支仪器").SingleOrDefault();


            context.LoadProperty <AppParam>(app, "AppParams", null);

            //添加测量参数

            DateTimeOffset date = DateTimeOffset.Now;

            List <MessureValue> list = new List <MessureValue>();

            foreach (var param in app.AppParams.OfType <MessureParam>())
            {
                var item = new MessureValue()
                {
                    Id      = Guid.NewGuid(),
                    Date    = date,
                    ParamId = param.Id,
                    Val     = 1
                };
                list.Add(item);
                context.AddToMessureValues(item);
            }


            context.SaveChanges();

            var result = context.CheckExistData(app.Id, date);

            Assert.AreEqual(true, result, "测试失败");

            foreach (var item in list)
            {
                context.DeleteObject(item);
            }



            context.SaveChanges();

            result = context.CheckExistData(app.Id, date);

            Assert.AreEqual(false, result, "测试失败");
        }
Example #7
0
        // DELETE odata/MessureValues(5)
        public async Task <IHttpActionResult> Delete([FromODataUri] Guid key)
        {
            MessureValue messurevalue = await db.MessureValues.FindAsync(key);

            if (messurevalue == null)
            {
                return(NotFound());
            }

            db.MessureValues.Remove(messurevalue);
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #8
0
        protected override void Seed(Hammergo.Data.DamWCFContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            var type1 = new ApparatusType();

            type1.Id       = Guid.NewGuid();
            type1.TypeName = "第一种类型";



            var type2 = new ApparatusType();

            type2.Id       = Guid.NewGuid();
            type2.TypeName = "第二种类型";

            context.ApparatusTypes.AddOrUpdate(type1, type2);

            //添加工程部位
            var root = new ProjectPart()
            {
                Id         = Guid.NewGuid(),
                PartName   = "root",
                ParentPart = null,
            };

            var p1 = new ProjectPart()
            {
                Id         = Guid.NewGuid(),
                PartName   = "p1",
                ParentPart = root.Id,
            };

            var p2 = new ProjectPart()
            {
                Id         = Guid.NewGuid(),
                PartName   = "p2",
                ParentPart = root.Id,
            };


            context.ProjectParts.AddOrUpdate(root, p1, p2);


            //添加仪器
            var app1 = new App();

            app1.Id            = Guid.NewGuid();
            app1.AppName       = "第一支仪器";
            app1.CalculateName = "FirstApp";
            app1.AppTypeID     = type1.Id;
            app1.ProjectPartID = p1.Id;

            var app2 = new App();

            app2.Id            = Guid.NewGuid();
            app2.AppName       = "第二支仪器";
            app2.CalculateName = "SecondApp";
            app2.AppTypeID     = type2.Id;
            app2.ProjectPartID = p2.Id;


            var app3 = new App();

            app3.Id            = Guid.NewGuid();
            app3.AppName       = "第三支仪器";
            app3.CalculateName = "ThirdApp";
            app3.AppTypeID     = type2.Id;
            app3.ProjectPartID = p2.Id;

            context.Apps.AddOrUpdate(app1, app2, app3);



            var remark3 = new Remark()
            {
                Id         = Guid.NewGuid(),
                Date       = DateTime.Now,
                RemarkText = "remark",
                AppId      = app2.Id,
            };

            context.Remarks.AddOrUpdate(remark3);

            var conParam1 = new ConstantParam()
            {
                Id           = Guid.NewGuid(),
                AppId        = app1.Id,
                ParamName    = "c1",
                ParamSymbol  = "c1",
                PrecisionNum = 2,
                UnitSymbol   = "no",
                Val          = 1,
                Order        = 1,
                Description  = "no description",
            };

            var mesParam1 = new MessureParam()
            {
                Id           = Guid.NewGuid(),
                AppId        = app1.Id,
                ParamName    = "m1",
                ParamSymbol  = "m1",
                PrecisionNum = 2,
                UnitSymbol   = "no",
                Order        = 1,
                Description  = "no description",
            };


            var calcParam1 = new CalculateParam()
            {
                Id           = Guid.NewGuid(),
                AppId        = app1.Id,
                ParamName    = "cal1",
                ParamSymbol  = "cal1",
                PrecisionNum = 2,
                UnitSymbol   = "no",
                Order        = 1,
                Description  = "no description",
            };

            context.AppParams.AddOrUpdate(conParam1, mesParam1, calcParam1);
            //添加第一支仪器的数据
            DateTimeOffset date  = DateTimeOffset.Now;
            int            count = 20;

            for (int i = 0; i < count; i++)
            {
                MessureValue mv = new MessureValue()
                {
                    Id      = Guid.NewGuid(),
                    ParamId = mesParam1.Id,
                    Date    = date.AddDays(-i),
                    Val     = i
                };

                CalculateValue cv = new CalculateValue()
                {
                    Id      = Guid.NewGuid(),
                    ParamId = calcParam1.Id,
                    Date    = date.AddDays(-i),
                    Val     = i
                };

                var remark = new Remark()
                {
                    Id         = Guid.NewGuid(),
                    Date       = date.AddDays(-i),
                    RemarkText = "remark" + i,
                    AppId      = app1.Id,
                };


                context.MessureValues.AddOrUpdate(mv);
                context.CalculateValues.AddOrUpdate(cv);
                context.Remarks.AddOrUpdate(remark);
            }

            //添加第三支仪器的参数
            var conParam1_third = new ConstantParam()
            {
                Id           = Guid.NewGuid(),
                AppId        = app3.Id,
                ParamName    = "c1",
                ParamSymbol  = "c1",
                PrecisionNum = 2,
                UnitSymbol   = "no",
                Val          = 1,
                Order        = 1,
                Description  = "no description",
            };

            var mesParam1_third = new MessureParam()
            {
                Id           = Guid.NewGuid(),
                AppId        = app3.Id,
                ParamName    = "m1",
                ParamSymbol  = "m1",
                PrecisionNum = 2,
                UnitSymbol   = "no",
                Order        = 1,
                Description  = "no description",
            };


            var calcParam1_third = new CalculateParam()
            {
                Id           = Guid.NewGuid(),
                AppId        = app3.Id,
                ParamName    = "cal1",
                ParamSymbol  = "cal1",
                PrecisionNum = 2,
                UnitSymbol   = "no",
                Order        = 1,
                Description  = "no description",
            };

            context.AppParams.AddOrUpdate(conParam1_third, mesParam1_third, calcParam1_third);

            ///first app fomula

            var formula = new Formula()
            {
                Id                = Guid.NewGuid(),
                ParamId           = calcParam1.Id,
                StartDate         = DateTimeOffset.MinValue,
                EndDate           = DateTimeOffset.MaxValue,
                CalculateOrder    = 1,
                FormulaExpression = "c1+m1"
            };

            context.Formulae.AddOrUpdate(formula);


            var formula_third = new Formula()
            {
                Id                = Guid.NewGuid(),
                ParamId           = calcParam1_third.Id,
                StartDate         = DateTimeOffset.MinValue,
                EndDate           = DateTimeOffset.MaxValue,
                CalculateOrder    = 1,
                FormulaExpression = "c1+m1+FirstApp.cal1"
            };

            context.Formulae.AddOrUpdate(formula_third);



            //添加第三支仪器的数据
            count = 10;
            for (int i = 0; i < count; i++)
            {
                MessureValue mv = new MessureValue()
                {
                    Id      = Guid.NewGuid(),
                    ParamId = mesParam1_third.Id,
                    Date    = date.AddDays(-i),
                    Val     = i + 1
                };

                CalculateValue cv = new CalculateValue()
                {
                    Id      = Guid.NewGuid(),
                    ParamId = calcParam1_third.Id,
                    Date    = date.AddDays(-i),
                    Val     = i + 2
                };

                var remark = new Remark()
                {
                    Id         = Guid.NewGuid(),
                    Date       = date.AddDays(-i),
                    RemarkText = "remark" + i + 1,
                    AppId      = app3.Id,
                };


                context.MessureValues.AddOrUpdate(mv);
                context.CalculateValues.AddOrUpdate(cv);
                context.Remarks.AddOrUpdate(remark);
            }
        }
Example #9
0
        //重新计算相关值,并反映在gridview中
        public static void redirectToObjects(AppIntegratedInfo appInfo, DataRow row, string feildName)
        {
            DateTimeOffset date = (DateTimeOffset)row[PubConstant.timeColumnName];
            MessureParam   mp   = appInfo.MesParams.FirstOrDefault(s => s.ParamName == feildName);

            if (mp != null)
            {
                MessureValue editedValue = appInfo.MesValues.Find(delegate(MessureValue item)
                {
                    return(item.Date == date && item.ParamId == mp.Id);
                });

                if (editedValue == null)
                {
                    //create new object
                    editedValue         = new MessureValue();
                    editedValue.Date    = date;
                    editedValue.ParamId = mp.Id;
                    appInfo.MesValues.Add(editedValue);

                    appInfo.DbContext.AddToMessureValues(editedValue);
                }


                editedValue.Val = (double)row[feildName];

                appInfo.DbContext.UpdateObject(editedValue);

                //recalculate the calc values
                reCalcValues(appInfo, row, date);
            }
            else
            {
                //直接编辑成果值,所有不用计算本测点的数据,但需要更新引用测点的数据
                CalculateParam cp = appInfo.CalcParams.Find(delegate(CalculateParam item)
                {
                    return(item.ParamName == feildName);
                });

                if (cp != null)
                {
                    CalculateValue calcValue = appInfo.CalcValues.Find(delegate(CalculateValue item)
                    {
                        return(item.Date == date && item.ParamId == cp.Id);
                    });

                    if (calcValue == null)
                    {
                        //create new object
                        calcValue         = new CalculateValue();
                        calcValue.Date    = date;
                        calcValue.ParamId = cp.Id;
                        appInfo.CalcValues.Add(calcValue);

                        appInfo.DbContext.AddToCalculateValues(calcValue);
                    }

                    calcValue.Val = (double)row[feildName];

                    //dbcontext标记要更新
                    appInfo.DbContext.UpdateObject(calcValue);
                }
            }

            //may be need reset the filter to null
        }