Exemplo n.º 1
0
 public DataBlockControl(decimal percentage, DataBlockModel dataBlockModel, bool onlyShow)
 {
     InitializeComponent();
     this.onlyShow     = onlyShow;
     this.Percentage   = percentage;
     this.CurrentModel = dataBlockModel;
 }
Exemplo n.º 2
0
        public void AddDataControls(DataBlockTemplateModel templateModel)
        {
            ResetArea();
            int width = this.pn_Area.Width / templateModel.ColumnNum;

            for (int i = 0; i < templateModel.ColumnNum; i++)
            {
                DataBlockModel newDataBlockModel = PrintDatas.dataBlockMList.Find(m => m.TemplateModelID == templateModel.ModelID &&
                                                                                  m.Index == i);
                DataBlockControl dc = new DataBlockControl(1, newDataBlockModel, true);
                dc.Dock = DockStyle.Left;
                dc.DataSelectedEvent += Dc_DataSelectedEvent;
                dc.DataKeyDownEvent  += Dc_DataKeyDownEvent;
                currentDBList.Add(dc);
                this.pn_Area.Controls.Add(dc);
                dc.BringToFront();
            }
            currentDBList[currentDBList.Count - 1].Dock = DockStyle.Fill;
            foreach (var dc in currentDBList)
            {
                dc.FontFamilyName = templateModel.FontFamilyName;
                dc.FontSize       = templateModel.FontSize;
                dc.Distance       = templateModel.Distance;
                dc.LineWidth      = templateModel.LineWidth;
            }
        }
Exemplo n.º 3
0
        private void DataModelProperty_Load(object sender, EventArgs e)
        {
            CurrentDataModel = DataBlockModel.CreateNewInstance();
            DataTable dt = new DataTable();

            dt.Columns.Add("value", typeof(int));
            dt.Columns.Add("display", typeof(string));
            foreach (var item in PrintDatas.PrintFieldBM)
            {
                dt.Rows.Add(item.ID, item.PrintName);
            }
            cb_DataName.DataSource    = dt;
            cb_DataName.DisplayMember = "display";
            cb_DataName.ValueMember   = "value";
        }
Exemplo n.º 4
0
        public DataBlockModel getDBbyName(string DBsymbolName)
        {
            var resultDB = new DataBlockModel();

            foreach (var db in DBs)
            {
                if (db.Title.Equals(DBsymbolName))
                {
                    resultDB = db;
                }
            }


            return(resultDB);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Генерация текста исходного кода в синтаксисе STL
        /// для последующего создания Instance DB на базе FB1 программе ПЛК
        /// </summary>
        /// <returns></returns>
        private List <String> GenerateStlInstanceDb(DataBlockModel db)
        {
            var list = new List <string>();

            list.Add("DATA_BLOCK " + db.FullName);
            list.Add("TITLE =" + db.Title);
            list.Add("{ S7_techparam := 'S7WRSAPX.Application' }");
            list.Add("AUTHOR:  Kratovi4");
            list.Add("FAMILY : STDCONT");
            list.Add("VERSION : 1.0");
            list.Add("FB 1");
            list.Add("BEGIN");
            list.Add("END_DATA_BLOCK");
            list.Add("\r\n");

            return(list);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Генерация текста исходного кода в синтаксисе STL
        /// для последующего создания Data Block в программе ПЛК
        /// </summary>
        /// <returns></returns>
        private List <String> GenerateStlDb(DataBlockModel db)
        {
            var list = new List <string>();

            list.Add("DATA_BLOCK " + db.FullName);
            list.Add("TITLE =" + db.Title);
            list.Add("AUTHOR:  Kratovi4");
            list.Add("VERSION : 2.0");
            list.Add("STRUCT");
            list.Add(db.ArrayName + ": ARRAY  [1 .. " + db.ArrayIndex + "] OF ");
            list.Add("\"" + db.UdtName + "\"; // Array");
            list.Add("END_STRUCT ;");
            list.Add("BEGIN");
            list.Add("END_DATA_BLOCK");
            list.Add("\r\n");

            return(list);
        }
Exemplo n.º 7
0
        private string GenerateSclLogicCode(DataBlockModel db)
        {
            var s = "";

            // we need something like this: Logic_SNS(SENSOR:="11A".SNS[i]); // 20
            s  = "Logic_";
            s += db.ArrayName + "(" + db.ArrayName + ":=";
            s += "\"" + db.SymbolName + "\"";
            s += "." + db.ArrayName + "[i]";

            if (db.ArrayName.Equals("SNS") | db.ArrayName.Equals("SNC"))
            {
                s += ");  // " + db.ArrayIndex.ToString();
            }
            else
            {
                s += ",Clock:=clk); // " + db.ArrayIndex.ToString();
            }

            return(s);
        }
        public void GivenDataBlock_WhenSerialized_ShouldRoundTrip()
        {
            var block1 = new DataBlock <TextBlock>(DateTime.Now, "blockTypeV1", "blockIdV1", new TextBlock("name", "type", "author", "dataV1"));

            DataBlockModel <TextBlockModel> dataBlockModel = block1.ConvertTo <TextBlock, TextBlockModel>();
            string json = JsonSerializer.Serialize(dataBlockModel);

            json.Should().NotBeNullOrWhiteSpace();

            DataBlockModel <TextBlockModel> resultModel = JsonSerializer.Deserialize <DataBlockModel <TextBlockModel> >(json);

            resultModel.Should().NotBeNull();

            DataBlock <TextBlock> result = resultModel.ConvertTo <TextBlockModel, TextBlock>();

            result.Should().NotBeNull();

            block1.TimeStamp.Should().Be(result.TimeStamp);
            block1.BlockType.Should().Be(result.BlockType);
            block1.BlockId.Should().Be(result.BlockId);
            (block1.Data == result.Data).Should().BeTrue();
        }
Exemplo n.º 9
0
        public void AddDataControls(DataBlockTemplateModel templateModel)
        {
            CurrentTemplateModel = templateModel;
            RemoveAllDataBlockControls();
            PaddingLeft   = templateModel.PaddingLeft;
            PaddingTop    = templateModel.PaddingTop;
            PaddingRight  = templateModel.PaddingRight;
            PaddingBottom = templateModel.PaddingBottom;
            ColumnNum     = templateModel.ColumnNum;
            PageWidth     = templateModel.PageWidth;
            int width = this.pn_Area.Width / ColumnNum;

            for (int i = 0; i < ColumnNum; i++)
            {
                DataBlockModel newDataBlockModel = PrintDatas.dataBlockMList.Find(m => m.TemplateModelID == templateModel.ModelID &&
                                                                                  m.Index == i);
                if (newDataBlockModel == null)
                {
                    newDataBlockModel = DataBlockModel.CreateNewInstance();
                    PrintDatas.dataBlockMList.Add(newDataBlockModel);
                    newDataBlockModel.ColumnWidth     = (int)(width / Percentage);
                    newDataBlockModel.Index           = i;
                    newDataBlockModel.TemplateModelID = templateModel.ModelID;
                }
                DataBlockControl dc = new DataBlockControl(Percentage, newDataBlockModel, false);
                dc.Dock = DockStyle.Left;
                dc.DataSelectedEvent += Dc_DataSelectedEvent;
                dataControls.Add(dc);
                this.pn_Area.Controls.Add(dc);
                dc.BringToFront();
            }
            dataControls[dataControls.Count - 1].Dock = DockStyle.Fill;
            FontFamilyName = templateModel.FontFamilyName;
            FontSize       = templateModel.FontSize;
            Distance       = templateModel.Distance;
            LineWidth      = templateModel.LineWidth;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Создание списка элементов с неповторяющимся номеров блока данных
        /// </summary>
        /// <returns></returns>
        private bool GenerateUniqDbList()
        {
            var isGenerated = false;

            if (IsEmptyCategories())
            {
                return(false);
            }

            var sysNumList      = new List <string>();
            var uniqSymbolsList = new List <SymbolTableItemModel>();

            foreach (var cat in this.Categories.OrderBy(k => k.Id))
            {
                foreach (var el in cat.S7Items.OrderByDescending(key => key.DbArrayIndex))
                {
                    if (!sysNumList.Contains(el.DbFullName))
                    {
                        sysNumList.Add(el.DbFullName);
                        uniqSymbolsList.Add(el);
                        isGenerated = true;
                    }
                }
                sysNumList.Clear();

                foreach (var el in uniqSymbolsList.OrderBy(k => k.SystemNumber))
                {
                    var db = new DataBlockModel();
                    // 11Y
                    if (el.DbArrayName.Equals("PID"))
                    {
                        continue; // WARNING: no PIDS in the DB list !!!
                        //db.SymbolName = "PID" + el.Codename;
                        // db.Title = el.SignalComment;
                    }
                    else
                    {
                        db.SymbolName = el.SystemNumber + cat.Db.Symbol;
                        // Sensors 4-20
                        db.Title = cat.Description;
                    }

                    // DB111
                    db.FullName = el.DbFullName;

                    // SNS_UDT
                    db.UdtName = cat.Db.UdtName;

                    // Rounded size of DB Array[]
                    db.ArrayIndex = RoundToFive(el.DbArrayIndex);

                    // SNS
                    db.ArrayName = cat.Db.ArrayName;

                    UniqDBlist.Add(db);

                    isGenerated = true;
                }

                uniqSymbolsList.Clear();
            }
            return(isGenerated);
        }