コード例 #1
0
        public Entity.Graphics CreateNewGraphicDS(App selApp)
        {
            string appName = selApp.AppName;

            AppIntegratedInfo appInfo = new AppIntegratedInfo(selApp, 0, null, null);
            var graDS = new Entity.Graphics();

            // appInfo.CalcParams默认已排序
            for (int i = 0; i < appInfo.CalcParams.Count; i++)
            {
                CalculateParam cp   = appInfo.CalcParams[i];
                var            line = graDS.Lines.NewLinesRow();
                line.AppName    = appName;
                line.UnitSymbol = cp.UnitSymbol;
                line.AppId      = cp.AppId;
                line.ParamName  = cp.ParamName;
                line.LegendName = cp.ParamName;
                line.IsShow     = true;
                line.ParamId    = cp.Id;
                line.EndEdit();
                graDS.Lines.AddLinesRow(line);
            }
            graDS.AcceptChanges();

            return(graDS);
        }
コード例 #2
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            string         recid   = dataGridView1.Rows[e.RowIndex].Cells["Recid"].Value.ToString();;
            string         xmbh    = dataGridView1.Rows[e.RowIndex].Cells["SYXMBH"].Value.ToString();;
            string         jcxm    = dataGridView1.Rows[e.RowIndex].Cells["JCXM"].Value.ToString();;
            string         localT  = dataGridView1.Rows[e.RowIndex].Cells["LocalTableName"].Value.ToString();;
            string         localF  = dataGridView1.Rows[e.RowIndex].Cells["LocalZdName"].Value.ToString();;
            string         remoteT = dataGridView1.Rows[e.RowIndex].Cells["RemoteTableName"].Value.ToString();;
            string         remoteF = dataGridView1.Rows[e.RowIndex].Cells["RemoteZdName"].Value.ToString();;
            CalculateParam param   = new CalculateParam();

            param.Recid           = recid;
            param.SYXMBH          = xmbh;
            param.JCXM            = jcxm;
            param.LocalTableName  = localT;
            param.LocalZdName     = localF;
            param.RemoteTableName = remoteT;
            param.RemoteZdName    = remoteF;

            int ret = _fieldManage.UpdateParam(param);

            if (ret == -1)
            {
                MessageBox.Show("修改失败");
            }
        }
コード例 #3
0
ファイル: FieldManage.cs プロジェクト: yangwenjie-u/cal
        public int UpdateParam(CalculateParam info)
        {
            if (info == null)
            {
                return(-1);
            }
            string sqlStr = "";

            sqlStr = string.Format($"select * from H_Calculate_Param where recid ='{info.Recid}' ");

            var ds = _sqlBase.ExecuteDataset(sqlStr);

            if (ds != null && ds.Tables[0].Rows.Count != 0)
            {
                var fieldName = ds.Tables[0].Rows[0]["RemoteZdName"];

                sqlStr = $"update H_Calculate_Param set SYXMBH = '{info.SYXMBH}', JCXM = '{info.JCXM}', LocalTableName = '{info.LocalTableName}'," +
                         $" LocalZdName = '{info.LocalZdName}', RemoteTableName = '{info.RemoteTableName}', RemoteZdName = '{info.RemoteZdName}' where recid = '{info.Recid}';";
                _sqlBase.ExecuteNonQuery(sqlStr);

                sqlStr = $"update ZDZD_{info.SYXMBH}  set ZDMC = '{info.RemoteZdName}' where SJBMC = '{info.RemoteTableName}' and ZDMC = '{fieldName}'";

                return(_sqlBase.ExecuteNonQuery(sqlStr));
            }
            return(-1);
        }
コード例 #4
0
        private void HandleDeleteCalculateParam(CalculateParam a)
        {
            var delmodel = _selectedCalculateParam;
            var msg      = new DialogMessage(string.Format("确定要删除参数:{0}吗?", delmodel.ParamName), result =>
            {
                if (result == System.Windows.MessageBoxResult.Yes)
                {
                    try
                    {
                        _calculateParams.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);
        }
コード例 #5
0
        private void fillDataTable(AppIntegratedInfo appInfo, object[,] allData, Hashtable nameIndexMaps, DataTable table)
        {
            for (int i = 0; i < listDates.Count; i++)
            {
                DataRow row = table.NewRow();

                foreach (string key in nameIndexMaps.Keys)
                {
                    if (key == PubConstant.timeColumnName)
                    {
                        row[key] = new DateTimeOffset(listDates[i]);//转换
                    }
                    else if (key == PubConstant.remarkColumnName)
                    {
                        row[key] = allData[i + 1, (int)nameIndexMaps[key]];//index从1开始
                    }
                    else
                    {
                        object val = allData[i + 1, (int)nameIndexMaps[key]];//

                        double?ret = null;
                        if (val is string)
                        {
                            string temp = val.ToString().Trim();
                            try
                            {
                                ret = double.Parse(temp);
                            }
                            catch (Exception)
                            {
                                throw new Exception(string.Format("Excel文件{0}的表{1}中,第{2}行的'{3}'列数据有误\n ", fullPath, workSheetName, i + 1 + _tableHeaderRowsCnt, key));//i从0开始,所有还原的话要加1,而excel的第一行是表头,所以还要加tableHeaderRowsCnt
                            }
                        }
                        else if (val is double)
                        {
                            ret = (double)val;
                        }

                        if (ret != null)
                        {
                            CalculateParam cp = appInfo.CalcParams.Find(delegate(CalculateParam item) { return(item.ParamName == key); });
                            if (cp != null && cp.PrecisionNum != null)
                            {
                                ret = Hammergo.Utility.Helper.Round(ret.Value, cp.PrecisionNum);
                            }

                            row[key] = ret;
                        }
                    }
                }

                row.EndEdit();
                table.Rows.Add(row);
            }

            table.AcceptChanges();
        }
コード例 #6
0
        private void HandleAddCalculateParam(CalculateParam a)
        {
            int            num = _calculateParams.Count() + 1;
            CalculateParam cp  = new CalculateParam();

            cp.Id           = Guid.NewGuid();
            cp.ParamName    = "计算参数" + num.ToString();
            cp.PrecisionNum = 2;
            cp.ParamSymbol  = "c" + num.ToString();
            cp.Order        = (byte)num;
            cp.UnitSymbol   = "no symbol";
            cp.AppId        = App.Id;

            _calculateParams.Add(cp);
            _allParams.Add(cp);
        }
コード例 #7
0
        private void btn_submit_Click(object sender, EventArgs e)
        {
            try
            {
                string xmbh    = txt_xmbh.Text.Trim();
                string jcxm    = txt_jcxm.Text.Trim();
                string localT  = txt_localT.Text.Trim();
                string localF  = txt_localF.Text.Trim();
                string remoteT = txt_remoteT.Text.Trim();
                string remoteF = txt_remoteF.Text.Trim();

                if (string.IsNullOrEmpty(xmbh) || string.IsNullOrEmpty(jcxm) || string.IsNullOrEmpty(localT) ||
                    string.IsNullOrEmpty(localF) || string.IsNullOrEmpty(remoteT) || string.IsNullOrEmpty(remoteF))
                {
                    MessageBox.Show("err:输入信息不完整");
                    return;
                }
                CalculateParam param = new CalculateParam();
                param.SYXMBH          = xmbh;
                param.JCXM            = jcxm;
                param.LocalTableName  = localT;
                param.LocalZdName     = localF;
                param.RemoteTableName = remoteT;
                param.RemoteZdName    = remoteF;
                var dd = _fieldManage.InsertParam(param);

                if (dd == -2)
                {
                    MessageBox.Show($"已存在配置字段" + remoteF);
                }
                else if (dd == 1)
                {
                    MessageBox.Show($"成功");
                    ReflashViews();
                }
                else
                {
                    MessageBox.Show("err");
                }
            }
            catch
            {
            }
        }
コード例 #8
0
ファイル: FieldManage.cs プロジェクト: yangwenjie-u/cal
        public int InsertParam(CalculateParam param)
        {
            try
            {
                var    cout   = 0;
                string sqlStr = string.Format($"select * from H_Calculate_Param where SYXMBH ='{param.SYXMBH}' and RemoteTableName ='{param.RemoteTableName}' and RemoteZdName='{param.RemoteZdName}'");
                var    ds     = _sqlBase.ExecuteDataset(sqlStr);
                if (ds != null && ds.Tables[0].Rows.Count != 0)
                {
                    //已有字段
                    return(-2);
                }

                sqlStr = $"select 1 from ZDZD_{param.SYXMBH} where ZDMC ='{param.RemoteZdName}' and  SJBMC ='{param.RemoteTableName}'";

                cout = _sqlBase.ExecuteNonQuery(sqlStr);
                if (cout > 0)
                {
                    return(1);
                }
                //sqlStr = $" INSERT INTO [dbo].[ZDZD_{param.SYXMBH}]([SJBMC],[ZDMC],[SFXS],[MUSTIN],[LX],[SY])     VALUES('{param.RemoteTableName}','{param.RemoteZdName}',0,0,'H,I','配置字段')";
                sqlStr = $"insert into ZDZD_{param.SYXMBH} ( SJBMC, ZDMC, SY, ZDLX, ZDCD1, ZDCD2, INPUTZDLX, KJLX, SFBHZD, BHMS,ZDSX, SFXS, XSCD, XSSX, SFGD, MUSTIN, DEFAVAL, HELPLNK, CTRLSTRING, ZDXZ,WXSSX, WSFXS, MSGINFO, EQLFUNC, HELPWHERE, GETBYBH, SSJCX, SFBGZD,VALIDPROC, LX, ZDSXSQL, ENCRYPT, FZYC, FZCS, NOSAVE, location)" +
                         $"VALUES('{param.RemoteTableName}', '{param.RemoteZdName}', '配置字段', 'nvarchar', '200', '0', 'nvarchar', '', 'False', '', 'False', 'False', '0', '367.0000', 'False', 'False', '', '', '', 'S', '367.0000', 'True', '', '', '', 'True', '', 'True', '', 'H,I', NULL, NULL, NULL, NULL, NULL, NULL)  " +
                         $"";
                cout = _sqlDebugTool.ExecuteNonQuery(sqlStr);
                if (cout > 0)
                {
                    sqlStr = $"insert into   H_Calculate_Param  (SYXMBH,JCXM,LocalTableName,LocalZdName,RemoteTableName,RemoteZdName) values('{param.SYXMBH}','{param.JCXM}','{param.LocalTableName}','" +
                             $"{param.LocalZdName}','{param.RemoteTableName}','{param.RemoteZdName}')";

                    return(_sqlBase.ExecuteNonQuery(sqlStr));

                    //sqlStr = $"alter table {param.RemoteTableName} add {param.RemoteZdName} varchar(200) null ";
                    //return _sqlBase.ExecuteNonQuery(sqlStr);
                }

                //zdzd 插入失败
                return(-1);
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
コード例 #9
0
ファイル: Configuration.cs プロジェクト: zfkingth/DamWebAPI
        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);
            }
        }
コード例 #10
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();
                        foreach (var item in dam5Entities.CalculateParams.AsNoTracking())
                        {
                            var id = (from i in dam6Entities.Apps.AsNoTracking()
                                      where i.AppName == item.appName
                                      select i).First().Id;

                            if (dam6Entities.CalculateParams.FirstOrDefault(i => i.Id == item.CalculateParamID) == null)
                            {
                                var newItem = new CalculateParam();

                                newItem.AppId        = id;
                                newItem.Id           = item.CalculateParamID;
                                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;

                                var formula = new Formula();
                                formula.Id                = Guid.NewGuid();
                                formula.ParamId           = item.CalculateParamID;
                                formula.FormulaExpression = item.CalculateExpress;
                                byte calcOrder = 1;
                                if (item.CalculateOrder != null)
                                {
                                    calcOrder = item.CalculateOrder.Value;
                                }
                                formula.CalculateOrder = calcOrder;
                                formula.StartDate      = new DateTime(1970, 1, 1);   //默认公式的时间刻度
                                formula.EndDate        = new DateTime(9999, 12, 31); //默认终止时间

                                dam6Entities.CalculateParams.Add(newItem);
                                dam6Entities.Formulae.Add(formula);

                                dam6Entities.SaveChanges();
                                dam6Entities.Entry(newItem).State = System.Data.Entity.EntityState.Detached;;
                                dam6Entities.Entry(formula).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;
                }
            }
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        /// <summary>
        /// 将实际的值填充到参数列表中,如果参数没有相应的值,将被赋初值0
        /// </summary>
        /// <param name="list">参数列表</param>
        /// <param name="appCalcName">测点的计算名称</param>
        /// <param name="date">日期</param>
        /// <param name="appendDot">是否将计算名称和点加在参数的前面</param>
        /// <param name="simpleInfo">测点数据信息</param>
        internal static void fillListByCalcName_Date(hammergo.caculator.MyList list, DateTimeOffset date, bool appendDot, AppIntegratedInfo simpleInfo)
        {
            string appCalcName = simpleInfo.CurrentApp.CalculateName;

            foreach (ConstantParam cp in simpleInfo.ConstantParams)
            {
                string key = cp.ParamSymbol;
                if (appendDot)
                {
                    key = String.Format("{0}.{1}", appCalcName, key);
                }
                list.add(key, cp.Val);
            }

            //赋初值0

            foreach (MessureParam mp in simpleInfo.MesParams)
            {
                string key = mp.ParamSymbol;
                if (appendDot)
                {
                    key = String.Format("{0}.{1}", appCalcName, key);
                }
                list.add(key, 0);
            }

            //赋初值0
            foreach (CalculateParam cp in simpleInfo.CalcParams)
            {
                string key = cp.ParamSymbol;
                if (appendDot)
                {
                    key = String.Format("{0}.{1}", appCalcName, key);
                }
                list.add(key, 0);
            }

            //加快速度
            foreach (MessureValue mv in simpleInfo.MesValues.Where(s => s.Date == date))
            {
                MessureParam mp = simpleInfo.MesParams.Find(delegate(MessureParam item) { return(item.Id == mv.ParamId); });

                string key = mp.ParamSymbol;
                if (appendDot)
                {
                    key = String.Format("{0}.{1}", appCalcName, key);
                }

                list[key] = mv.Val.Value;
            }

            //加快速度
            foreach (CalculateValue cv in simpleInfo.CalcValues.Where(s => s.Date == date))
            {
                CalculateParam cp  = simpleInfo.CalcParams.Find(delegate(CalculateParam item) { return(item.Id == cv.ParamId); });
                string         key = cp.ParamSymbol;
                if (appendDot)
                {
                    key = String.Format("{0}.{1}", appCalcName, key);
                }

                list[key] = cv.Val.Value;
            }
        }
コード例 #13
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
        }
コード例 #14
0
ファイル: UnitTest1.cs プロジェクト: zfkingth/DamWebAPI
        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");
            }
        }
コード例 #15
0
 private void HandleSelectedItemChangedCalc(CalculateParam a)
 {
     _selectedCalculateParam = a;
 }