private void HandleDeleteConstParam(ConstantParam a) { var delmodel = _selectedConstantParam; var msg = new DialogMessage(string.Format("确定要删除参数:{0}吗?", delmodel.ParamName), result => { if (result == System.Windows.MessageBoxResult.Yes) { try { _constantParams.Remove(delmodel); _allParams.Remove(delmodel); } catch (Exception ex) { Messenger.Default.Send <Exception>(ex); } } }); msg.Caption = "确定要删除吗?"; msg.Button = MessageBoxButton.YesNo; msg.Icon = MessageBoxImage.Question; Messenger.Default.Send <DialogMessage>(msg); }
private void HandleAddConstParam(ConstantParam a) { int num = _constantParams.Count(); ConstantParam cp = new ConstantParam(); cp.Id = Guid.NewGuid(); cp.ParamName = "常量参数" + num.ToString(); cp.PrecisionNum = 5; cp.ParamSymbol = "cn" + num.ToString(); cp.Order = (byte)num; cp.UnitSymbol = "no symbol"; cp.Val = 1; cp.AppId = App.Id; _constantParams.Add(cp); _allParams.Add(cp); }
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); } }
private void HandleCreateApp(object param) { List <object> addedList = new List <object>(); try { // int childrenCnt = (from i in DbContext.ProjectParts where i.ParentPart == Part.Id select i).Count(); if (childrenCnt > 0) { throw new Exception("只能在没有子结点的部位创建测点"); } int appCnt = (from s in DbContext.Apps where s.AppName == NewApp.AppName || s.CalculateName == NewApp.CalculateName select s).Count(); if (appCnt > 0) { throw new Exception("新测点的名称或计算名称已存在,无法创建"); } App needAddApp = new App(); needAddApp.Id = Guid.NewGuid(); needAddApp.ProjectPartID = Part.Id; needAddApp.AppName = NewApp.AppName; needAddApp.CalculateName = NewApp.CalculateName; needAddApp.BuriedTime = NewApp.BuriedTime; needAddApp.X = NewApp.X; needAddApp.Y = NewApp.Y; needAddApp.Z = NewApp.Z; needAddApp.OtherInfo = NewApp.OtherInfo; DbContext.AddToApps(needAddApp); addedList.Add(needAddApp); DbContext.SaveChanges(); _currentApps.Add(needAddApp); if (AllowClone) { //clone app params if (CloneAppName.Trim().Length == 0) { throw new Exception("当选择克隆时,模板测点不能为空"); } if (cloneApp == null) { cloneApp = (from s in DbContext.Apps where s.AppName == CloneAppName select s).FirstOrDefault(); if (cloneApp == null) { throw new Exception(string.Format("找不到测点编号为{0}的测点", CloneAppName)); } } DbContext.LoadProperty(cloneApp, "AppParams"); var paramsList = new List <AppParam>(); var formulaList = new List <Formula>(); foreach (var item in cloneApp.AppParams) { AppParam newParam = null; if (item is ConstantParam) { newParam = new ConstantParam(); (newParam as ConstantParam).Val = (item as ConstantParam).Val; } else if (item is MessureParam) { newParam = new MessureParam(); } else if (item is CalculateParam) { newParam = new CalculateParam(); } //set values newParam.Id = Guid.NewGuid(); newParam.AppId = needAddApp.Id; newParam.ParamName = item.ParamName; newParam.ParamSymbol = item.ParamSymbol; newParam.PrecisionNum = item.PrecisionNum; newParam.UnitSymbol = item.UnitSymbol; newParam.Order = item.Order; newParam.Description = item.Description; paramsList.Add(newParam); //DbContext.AddToAppParams(newParam); //addedList.Add(newParam); //clone formules if (item is CalculateParam) { CalculateParam cp = item as CalculateParam; var formulae = (from i in DbContext.Formulae where i.ParamId == cp.Id select i).ToList(); foreach (var fl in formulae) { Formula newfl = new Formula(); newfl.Id = Guid.NewGuid(); newfl.ParamId = newParam.Id; newfl.FormulaExpression = fl.FormulaExpression; newfl.StartDate = fl.StartDate; newfl.EndDate = fl.EndDate; newfl.CalculateOrder = fl.CalculateOrder; formulaList.Add(newfl); //DbContext.AddToFormulae(newfl); //addedList.Add(newfl); } } } ParamsDTO dto = new ParamsDTO(); dto.AddedParams = paramsList; dto.AddedFormulae = formulaList; DbContext.UpdateAppParams(dto); } var msg = new DialogMessage("测点创建成功并已添加到相关的工程部位中。", result => { }); msg.Caption = "创建成功"; msg.Button = MessageBoxButton.OK; msg.Icon = MessageBoxImage.Information; Messenger.Default.Send <DialogMessage>(msg); } catch (Exception ex) { Messenger.Default.Send <Exception>(ex); //reject the changes foreach (object item in addedList) { DbContext.Detach(item); } } finally { // DbContext.Detach(NewApp); } }
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.ConstantParams.Count(); foreach (var item in dam5Entities.ConstantParams.AsNoTracking()) { var id = (from i in dam6Entities.Apps.AsNoTracking() where i.AppName == item.appName select i).First().Id; if (dam6Entities.ConstantParams.FirstOrDefault(i => i.Id == item.ConstantParamID) == null) { var newItem = new ConstantParam(); newItem.AppId = id; newItem.Id = item.ConstantParamID; newItem.Description = item.Description; newItem.Order = item.Order == null?(byte)0:item.Order.Value; newItem.ParamName = item.ParamName; newItem.ParamSymbol = item.ParamSymbol; newItem.PrecisionNum = item.PrecisionNum == null ? (byte)0 : item.PrecisionNum.Value; newItem.UnitSymbol = item.UnitSymbol; newItem.Val = item.Val.Value; dam6Entities.ConstantParams.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; } } }
public async Task T_params_Composite() { using (var client = new HttpClient()) { //get app Uri uri = new Uri(TestConfig.serviceUrl); var context = new DamServiceRef.Container(uri); context.Format.UseJson(); var appItem = context.Apps.Where(s => s.AppName == "第二支仪器").SingleOrDefault(); var conParam1 = new ConstantParam() { Id = Guid.NewGuid(), AppId = appItem.Id, ParamName = "sc1", ParamSymbol = "sc1", PrecisionNum = 2, UnitSymbol = "no", Val = 1, Order = 1, Description = "no description", }; var mesParam1 = new MessureParam() { Id = Guid.NewGuid(), AppId = appItem.Id, ParamName = "sm1", ParamSymbol = "sm1", PrecisionNum = 2, UnitSymbol = "no", Order = 1, Description = "no description", }; var calParam1 = new CalculateParam() { Id = Guid.NewGuid(), AppId = appItem.Id, ParamName = "scal1", ParamSymbol = "scal1", PrecisionNum = 2, UnitSymbol = "no", Order = 1, Description = "no description", }; var formula1 = new Formula() { Id = Guid.NewGuid(), ParamId = calParam1.Id, StartDate = DateTimeOffset.MinValue, EndDate = DateTimeOffset.MaxValue, CalculateOrder = 1, FormulaExpression = "sc1+sm1" }; ParamsDTO dto = new ParamsDTO() { Id = appItem.Id, }; dto.AddedParams = new List <AppParam>() { conParam1, mesParam1, calParam1 }; dto.AddedFormulae = new List <Formula>() { formula1 }; // New code: client.BaseAddress = new Uri(TestConfig.baseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.PostAsJsonAsync("api/ParamsDTOs", dto); Assert.IsTrue(response.IsSuccessStatusCode, " insert param fail"); //add updated ,delete var mesParam2 = new MessureParam() { Id = Guid.NewGuid(), AppId = appItem.Id, ParamName = "sm2", ParamSymbol = "sm2", PrecisionNum = 2, UnitSymbol = "no", Order = 1, Description = "no description", }; var calParam2 = new CalculateParam() { Id = Guid.NewGuid(), AppId = appItem.Id, ParamName = "scal2", ParamSymbol = "scal2", PrecisionNum = 2, UnitSymbol = "no", Order = 1, Description = "no description", }; var formula2 = new Formula() { Id = Guid.NewGuid(), ParamId = calParam2.Id, StartDate = DateTimeOffset.MinValue, EndDate = DateTimeOffset.MaxValue, CalculateOrder = 1, FormulaExpression = "sm2+sc1" }; dto = new ParamsDTO() { Id = appItem.Id, }; dto.AddedParams = new List <AppParam>() { calParam2 }; dto.AddedFormulae = new List <Formula>() { formula2 }; // fail because no corresponding mesparam response = await client.PostAsJsonAsync("api/ParamsDTOs", dto); Assert.IsFalse(response.IsSuccessStatusCode, "constraint fail"); //fail because delete mes1 which cal param1 use dto = new ParamsDTO() { Id = appItem.Id, }; dto.AddedParams = new List <AppParam>() { mesParam2, calParam2 }; dto.AddedFormulae = new List <Formula>() { formula2 }; dto.DeletedParams = new List <AppParam>() { mesParam1 }; response = await client.PostAsJsonAsync("api/ParamsDTOs", dto); Assert.IsFalse(response.IsSuccessStatusCode, "constraint fail"); //delete mes1 and calc1 dto = new ParamsDTO() { Id = appItem.Id, }; conParam1.Val = 2; dto.AddedParams = new List <AppParam>() { mesParam2, calParam2 }; dto.AddedFormulae = new List <Formula>() { formula2 }; dto.UpdatedParams = new List <AppParam>() { conParam1 }; dto.DeletedParams = new List <AppParam>() { mesParam1, calParam1 }; dto.DeletedFormulae = new List <Formula>() { formula1 }; response = await client.PostAsJsonAsync("api/ParamsDTOs", dto); Assert.IsTrue(response.IsSuccessStatusCode, "constraint fail"); //delete all params dto = new ParamsDTO() { Id = appItem.Id, }; dto.DeletedParams = new List <AppParam>() { conParam1, mesParam2, calParam2 }; dto.DeletedFormulae = new List <Formula>() { formula2 }; response = await client.PostAsJsonAsync("api/ParamsDTOs", dto); Assert.IsTrue(response.IsSuccessStatusCode, "delete formulae fail"); //reload mesparam context = new DamServiceRef.Container(uri); var cnt = context.AppParams.Where(s => s.Id == mesParam1.Id).Count(); Assert.AreEqual(0, cnt, "delete test fail"); } }
public async Task T_paramsConst() { using (var client = new HttpClient()) { //get app Uri uri = new Uri(TestConfig.serviceUrl); var context = new DamServiceRef.Container(uri); context.Format.UseJson(); var appItem = context.Apps.Where(s => s.AppName == "第一支仪器").SingleOrDefault(); // New code: client.BaseAddress = new Uri(TestConfig.baseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); ParamsDTO dto = new ParamsDTO() { Id = appItem.Id, }; var conParam1 = new ConstantParam() { Id = Guid.NewGuid(), AppId = appItem.Id, ParamName = "c2", ParamSymbol = "c2", PrecisionNum = 2, UnitSymbol = "no", Val = 1, Order = 1, Description = "no description", }; dto.AddedParams = new List <AppParam>() { conParam1 }; HttpResponseMessage response = await client.PostAsJsonAsync("api/ParamsDTOs", dto); Assert.IsTrue(response.IsSuccessStatusCode, "add param fail"); //modify dto = new ParamsDTO() { Id = appItem.Id, }; conParam1.Order += 1; dto.UpdatedParams = new List <AppParam>() { conParam1 }; response = await client.PostAsJsonAsync("api/ParamsDTOs", dto); Assert.IsTrue(response.IsSuccessStatusCode, "delete param fail"); //now deleted added param dto = new ParamsDTO() { Id = appItem.Id, }; dto.DeletedParams = new List <AppParam>() { conParam1 }; response = await client.PostAsJsonAsync("api/ParamsDTOs", dto); Assert.IsTrue(response.IsSuccessStatusCode, "delete param fail"); } }
public async Task T_paramsConst2() { //get app Uri uri = new Uri(TestConfig.serviceUrl); var context = new DamServiceRef.Container(uri); context.Format.UseJson(); var appItem = context.Apps.Where(s => s.AppName == "第一支仪器").SingleOrDefault(); // New code: ParamsDTO dto = new ParamsDTO() { Id = appItem.Id, }; var conParam1 = new ConstantParam() { Id = Guid.NewGuid(), AppId = appItem.Id, ParamName = "c2", ParamSymbol = "c2", PrecisionNum = 2, UnitSymbol = "no", Val = 1, Order = 1, Description = "no description", }; dto.AddedParams = new List <AppParam>() { conParam1 }; Assert.IsTrue(context.UpdateAppParams(dto), "add param fail"); //modify dto = new ParamsDTO() { Id = appItem.Id, }; conParam1.Order += 1; dto.UpdatedParams = new List <AppParam>() { conParam1 }; Assert.IsTrue(context.UpdateAppParams(dto), "delete param fail"); //now deleted added param dto = new ParamsDTO() { Id = appItem.Id, }; dto.DeletedParams = new List <AppParam>() { conParam1 }; Assert.IsTrue(context.UpdateAppParams(dto), "delete param fail"); }
private void HandleSelectedItemChangedConst(ConstantParam a) { _selectedConstantParam = a; }