Exemple #1
0
        public override bool LoadTabPage()
        {
            bool ret = false;

            try
            {
                tblController tblcontroller = Global.EWS.m_tblSolution.GetControllerFromID(ID);
                foreach (tblPou tblpou in tblcontroller.m_tblPouCollection)
                {
                    foreach (tblVariable tblvariable in tblpou.m_tblVariableCollection)
                    {
                        if ((!Common.IsFunctionType(tblvariable.Type)) && (tblvariable.Class & (int)VarClass.FunctionInstanse) == 0)
                        {
                            object[] newrow = new object[] { tblvariable.VarName,
                                                             tblvariable.Description,
                                                             tblpou.pouName,
                                                             Global.EWS.m_tblSolution.VarTypeStringList[tblvariable.Type],
                                                             tblvariable.InitialVal,
                                                             Global.EWS.m_tblSolution.AreaStringList[tblvariable.PlantStructureID] };
                            _dataTable.Rows.Add(newrow);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(ret);
        }
        public MessageReport DeleteById(string id, ref tblController obj)
        {
            var re = new MessageReport();

            re.Message   = "Error";
            re.isSuccess = false;

            try
            {
                obj = GetById(Guid.Parse(id));
                if (obj != null)
                {
                    _tblControllerRepository.Delete(n => n.ControllerID.ToString() == id);

                    Save();

                    re.Message   = FunctionHelper.GetLocalizeDictionary("Home", "notification")["DeleteSuccess"];
                    re.isSuccess = true;
                }
                else
                {
                    re.Message   = FunctionHelper.GetLocalizeDictionary("Home", "notification")["record_does_not_exist"];
                    re.isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                re.Message   = ex.Message;
                re.isSuccess = false;
            }

            return(re);
        }
Exemple #3
0
        private void FillPOUCombo(long _domainid, long _controllerid, long _pouid)
        {
            try
            {
                BindingList <tblPou> _combo        = new BindingList <tblPou>();
                tblController        tblcontroller = tblSolution.m_tblSolution().GetControllerFromID(_controllerid);

                comboBoxPOU.DataSource    = _combo;
                comboBoxPOU.DisplayMember = "pouName";
                comboBoxPOU.ValueMember   = "pouID";
                foreach (tblPou tblpou in tblcontroller.m_tblPouCollection)
                {
                    if (tblpou.pouName == "GLOBAL")
                    {
                        _combo.Add(tblpou);
                        comboBoxPOU.SelectedValue = tblpou.pouID;
                    }
                    if (tblpou.pouID == _pouid)
                    {
                        _combo.Add(tblpou);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #4
0
 private void toolStripComboBoxDomain_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (tbldomain != null)
     {
         tbldomain.m_tblControllerCollection.ControllerChanged -= new ControllerChangedEventHandler(updateControllerComboventhandler);
     }
     tbldomain  = (tblDomain)toolStripComboBoxDomain.SelectedItem;
     domainname = tbldomain.DomainName;
     domainid   = tbldomain.DomainID;
     tbldomain.m_tblControllerCollection.ControllerChanged += new ControllerChangedEventHandler(updateControllerComboventhandler);
     if (tbldomain.m_tblControllerCollection.Count > 0)
     {
         updateControllerCombo();
         toolStripComboBoxController.Enabled = true;
     }
     else
     {
         toolStripComboBoxController.Items.Clear();
         toolStripComboBoxProgram.Items.Clear();
         toolStripComboBoxController.Enabled = false;
         toolStripComboBoxProgram.Enabled    = false;
         tblcontroller = null;
         tblpou        = null;
         SelectVariable();
     }
 }
Exemple #5
0
        private void advancedDataGridView_main_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex == -1)
                {
                }
                else
                {
                    tblController tblcontroller = Global.EWS.m_tblSolution.GetControllerFromID(ID);

                    string str = (string)this.advancedDataGridView_main.Rows[e.RowIndex].Cells[2].Value;
                    str = str.ToLower();
                    string str1 = (string)this.advancedDataGridView_main.Rows[e.RowIndex].Cells[0].Value;
                    str1 = str1.ToLower();
                    foreach (tblPou tblpou in tblcontroller.m_tblPouCollection)
                    {
                        if (str == tblpou.pouName.ToLower())
                        {
                            foreach (tblVariable tblvariable in tblpou.m_tblVariableCollection)
                            {
                                if (tblvariable.VarName.ToLower() == str1)
                                {
                                    EXParent.mainEWSForm.propertyWindowControl.propertyGridComponemt.SelectedObject = tblvariable;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #6
0
        private void comboBoxSelect1_SelectedValueChanged(object sender, EventArgs e)
        {
            string str  = (string)comboBoxseletedTable.SelectedItem;
            string str1 = (string)comboBoxSelect1.SelectedItem;

            comboBoxSelect2.Items.Clear();
            switch (str)
            {
            case "Channel":
            {
                tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromName(str1);
                foreach (tblBoard tblboard in tblcontroller.m_tblBoardCollection)
                {
                    comboBoxSelect2.Items.Add(tblboard.BoardNo);
                }
                comboBoxSelect2.SelectedIndex = 0;
            }
            break;

            case "Variable":
            {
                tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromName(str1);
                foreach (tblPou tblpou in tblcontroller.m_tblPouCollection)
                {
                    comboBoxSelect2.Items.Add(tblpou.pouName);
                }
                comboBoxSelect2.SelectedIndex = 0;
                break;
            }

            case "BOOL":
            {
                tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromName(str1);
                foreach (tblPou tblpou in tblcontroller.m_tblPouCollection)
                {
                    comboBoxSelect2.Items.Add(tblpou.pouName);
                }
                comboBoxSelect2.SelectedIndex = 0;
                break;
            }

            case "REAL":
            {
                tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromName(str1);
                foreach (tblPou tblpou in tblcontroller.m_tblPouCollection)
                {
                    comboBoxSelect2.Items.Add(tblpou.pouName);
                }
                comboBoxSelect2.SelectedIndex = 0;
                break;
            }

            case "HMI":
                break;

            case "Alarm":
                break;
            }
        }
Exemple #7
0
 public TabSTPageControl(EXTabControl _parent, long id)
     : base(_parent, id)
 {
     InitializeComponent();
     TabPageType = TABPAGETYPE.ST;
     //_drawarea = new DrawArea(this);
     tblpou        = Global.EWS.m_tblSolution.GetPouFromID(ID);
     tblcontroller = Global.EWS.m_tblSolution.GetControllerobjectofPOUID(ID);
 }
Exemple #8
0
 public AddPouForm(tblController _controller, POUTYPE _poutype)
 {
     controller = _controller;
     poutype    = _poutype;
     //ControllerID = _controller.ControllerID;
     InitializeComponent();
     LoadPouTypes();
     LoadVarProgrammingLanguage();
 }
Exemple #9
0
        private void toolStripComboBoxController_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tblcontroller != null)
            {
                tblcontroller.m_tblPOUCollection.POUChanged -= new POUChangedEventHandler(updatePOUComboventhandler);
            }
            tblcontroller = (tblController)toolStripComboBoxController.SelectedItem;
            tblcontroller.m_tblPOUCollection.POUChanged += new POUChangedEventHandler(updatePOUComboventhandler);

            updatePOUCombo();
            toolStripComboBoxProgram.Enabled = true;
        }
        public ActionResult Create(tblController obj, string key, string pc, string group = "", bool SaveAndCountinue = false)
        {
            ViewBag.PCs = GetPCList();

            ViewBag.keyValue   = key;
            ViewBag.pcValue    = pc;
            ViewBag.groupValue = group;

            ViewBag.CommunicationType = FunctionHelper.Communication1();
            ViewBag.LineType          = FunctionHelper.LineTypes1();
            ViewBag.Read = FunctionHelper.ReaderTypes1();

            if (!ModelState.IsValid)
            {
                return(View(obj));
            }

            if (string.IsNullOrWhiteSpace(obj.ControllerName))
            {
                ModelState.AddModelError("ControllerName", FunctionHelper.GetLocalizeDictionary("Home", "notification")["Controller_Name"]);
                return(View(obj));
            }

            var existed = _tblControllerService.GetByName(obj.ControllerName);

            if (existed != null)
            {
                ModelState.AddModelError("ControllerName", FunctionHelper.GetLocalizeDictionary("Home", "notification")["Controller_Name_already_exists"]);
                return(View(obj));
            }

            obj.ControllerID = Guid.NewGuid();

            //Thực hiện thêm mới
            var result = _tblControllerService.Create(obj);

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.ControllerID.ToString(), obj.ControllerName, "tblController", ConstField.ParkingCode, ActionConfigO.Create);

                if (SaveAndCountinue)
                {
                    TempData["Success"] = result.Message;
                    return(RedirectToAction("Create", new { group = group, key = key, pc = pc, selectedId = obj.ControllerID }));
                }

                return(RedirectToAction("Index", new { group = group, key = key, pc = pc, selectedId = obj.ControllerID }));
            }
            else
            {
                return(View(obj));
            }
        }
Exemple #11
0
        public void AddControllers(string filename)
        {
            if (MainForm.Instance().CurrentUser.SystemExplorer != (int)EXPLORER_ACCESS.Full)
            {
                System.Windows.Forms.MessageBox.Show("current user cannot add any Contrller");
            }
            if (!File.Exists(filename))
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("File " + filename + " does not exist");
                return;
            }
            int           ret = 0;
            string        str;
            string        _log          = "";
            bool          headerline    = true;
            tblController tblcontroller = new tblController();

            using (StreamReader reader = new StreamReader(filename))
            {
                while ((str = reader.ReadLine()) != null)
                {
                    str.Replace(",,", ", ,");
                    if (str.StartsWith("!"))
                    {
                        continue;
                    }
                    if (headerline)
                    {
                        tblcontroller.headerString = str;
                        headerline = false;
                    }
                    else
                    {
                        string[] _strs = str.Split(new Char[] { ',' });
                        tblcontroller = new tblController();
                        tblcontroller.AddFromString(_strs, "", ref _log);

                        if ((ret = tblcontroller.Insert()) != 0)
                        {
                            if (ret == 19)
                            {
                                DCS.Forms.MainForm.Instance().WriteToOutputWindows(_log + " Already exist in database");
                            }
                        }
                        else
                        {
                            tblSolution.m_tblSolution().m_tblControllerCollection.Add(tblcontroller);
                        }
                    }
                }
                reader.Close();
            }
        }
        public JsonResult Delete(string id)
        {
            var obj = new tblController();

            var result = _tblControllerService.DeleteById(id, ref obj);

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.ControllerID.ToString(), obj.ControllerName, "tblController", ConstField.ParkingCode, ActionConfigO.Delete);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemple #13
0
        public TabSTPageControl(long id)
            : base(id)
        {
            InitializeComponent();

            TabPageType = TABPAGETYPE.ST;
            //_drawarea = new DrawArea(this);
            tblpou = tblSolution.m_tblSolution().GetPouFromID(ID);
#if EWSAPP
            _pouobject = new POUObject(_tblpou);
#endif
            tblcontroller = tblSolution.m_tblSolution().GetControllerobjectofPOUID(ID);
        }
Exemple #14
0
        //private long _DomainID;
        //public long DomainID
        //{
        //    get
        //    {
        //        return _DomainID;
        //    }
        //    set
        //    {
        //        _DomainID = value;
        //    }
        //}



        public TabSFCPageControl(EXTabControl _parent, long id)
            : base(_parent, id)
        {
            InitializeComponent();
            //_drawarea = new DrawArea(this);
            TabPageType         = TABPAGETYPE.SFC;
            tblpou              = Global.EWS.m_tblSolution.GetPouFromID(ID);
            tblcontroller       = Global.EWS.m_tblSolution.GetControllerobjectofPOUID(ID);
            drawarea.Size       = new System.Drawing.Size(1280, 830);
            drawarea.SnapX      = 8;
            drawarea.SnapY      = 8;
            drawarea.SnapEnable = true;
            UpdateToolstripNavigation();
        }
        public override bool LoadTabPage()
        {
            bool ret = false;

            try
            {
                VariableGrid  variablegrid;
                tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromID(ID);
                foreach (tblPou tblpou in tblcontroller.m_tblPouCollection)
                {
                    foreach (tblVariable tblvariable in tblpou.m_tblVariableCollection)
                    {
                        if ((!Common.IsFunctionType(tblvariable.Type)) && (tblvariable.Class & (int)VarClass.FunctionInstanse) == 0)
                        {
                            switch ((VarType)tblvariable.Type)
                            {
                            case VarType.BOOL:
                                variablegrid = new BoolVariableGrid(tblvariable);
                                break;

                            case VarType.REAL:
                                variablegrid = new RealVariableGrid(tblvariable);
                                break;

                            default:
                                variablegrid = new VariableGrid(tblvariable);
                                break;
                            }
                            tempList.Add(variablegrid);
                        }
                    }
                }
                foreach (VariableGrid _variablegrid in tempList)
                {
                    object[] newrow = new object[] { _variablegrid.VarName,
                                                     _variablegrid.Description,
                                                     _variablegrid.pouName,
                                                     _variablegrid.TypeName,
                                                     _variablegrid.InitialVal,
                                                     _variablegrid.PlantStructureName };
                    _dataTable.Rows.Add(newrow);
                }
                advancedDataGridView_main.ClearSelection();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(ret);
        }
        //private long _DomainID;
        //public long DomainID
        //{
        //    get
        //    {
        //        return _DomainID;
        //    }
        //    set
        //    {
        //        _DomainID = value;
        //    }
        //}



        public TabSFCPageControl(long id)
            : base(id)
        {
            InitializeComponent();
            //_drawarea = new DrawArea(this);
            TabPageType = TABPAGETYPE.SFC;
            _tblpou     = tblSolution.m_tblSolution().GetPouFromID(ID);
#if EWSAPP
            _pouobject = new POUObject(_tblpou);
#endif
            tblcontroller       = tblSolution.m_tblSolution().GetControllerobjectofPOUID(ID);
            drawarea.Size       = new System.Drawing.Size(1280, 830);
            drawarea.SnapX      = 8;
            drawarea.SnapY      = 8;
            drawarea.SnapEnable = true;
            UpdateToolstripNavigation();
        }
Exemple #17
0
 private void updateControllerCombo()
 {
     toolStripComboBoxController.Items.Clear();
     for (int i = 0; i < tbldomain.m_tblControllerCollection.Count; i++)
     {
         toolStripComboBoxController.Items.Add(tbldomain.m_tblControllerCollection[i]);
     }
     toolStripComboBoxController.ComboBox.DisplayMember = "ControllerName";
     if (tblcontroller != null)
     {
         tblcontroller.m_tblPOUCollection.POUChanged -= new POUChangedEventHandler(updatePOUComboventhandler);
     }
     if (toolStripComboBoxController.Items.Count > 0)
     {
         if (toolStripComboBoxController.SelectedIndex == -1)
         {
             toolStripComboBoxController.SelectedIndex = 0;
         }
         tblcontroller = tbldomain.m_tblControllerCollection[toolStripComboBoxController.SelectedIndex];
         tblcontroller.m_tblPOUCollection.POUChanged += new POUChangedEventHandler(updatePOUComboventhandler);
         updatePOUCombo();
     }
 }
        public MessageReport Create(tblController obj)
        {
            var re = new MessageReport();

            re.Message   = "Error";
            re.isSuccess = false;

            try
            {
                _tblControllerRepository.Add(obj);

                Save();

                re.Message   = FunctionHelper.GetLocalizeDictionary("Home", "notification")["addSuccess"];
                re.isSuccess = true;
            }
            catch (Exception ex)
            {
                re.Message   = ex.Message;
                re.isSuccess = false;
            }

            return(re);
        }
Exemple #19
0
        private void FillDataset()
        {
            tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromID(ControllerID);


            foreach (tblPou tblpou in tblcontroller.m_tblPouCollection)
            {
                if (tblpou.pouID == (long)comboBoxPOU.SelectedValue)
                {
                    foreach (tblVariable tblvariable in tblpou.m_tblVariableCollection)
                    {
                        object[] newrow = new object[] {
                            tblvariable.VarName,
                            tblvariable.Description,
                            tblSolution.m_tblSolution().VarTypeStringList[tblvariable.Type],
                            ((VarClass)tblvariable.Class).ToString(),
                            ((long)tblvariable.VarNameID).ToString()
                        };
                        _dataTable.Rows.Add(newrow);
                    }
                    break;
                }
            }
        }
        public ActionResult Update(tblController obj, int page = 1, string key = "", string pc = "", string group = "")
        {
            //
            ViewBag.PCs = GetPCList();

            //
            ViewBag.keyValue   = key;
            ViewBag.pcValue    = pc;
            ViewBag.PN         = page;
            ViewBag.groupValue = group;

            //
            ViewBag.CommunicationType = FunctionHelper.Communication1();
            ViewBag.LineType          = FunctionHelper.LineTypes1();
            ViewBag.Read = FunctionHelper.ReaderTypes1();

            //
            var oldObj = _tblControllerService.GetById(obj.ControllerID);

            if (oldObj == null)
            {
                ViewBag.Error = FunctionHelper.GetLocalizeDictionary("Home", "notification")["record_does_not_exist"];
                return(View(obj));
            }

            //
            if (string.IsNullOrWhiteSpace(obj.ControllerName))
            {
                ModelState.AddModelError("ControllerName", FunctionHelper.GetLocalizeDictionary("Home", "notification")["Controller_Name"]);
                return(View(oldObj));
            }

            //
            var existed = _tblControllerService.GetByName_Id(obj.ControllerName, obj.ControllerID);

            if (existed != null)
            {
                ModelState.AddModelError("ControllerName", FunctionHelper.GetLocalizeDictionary("Home", "notification")["Controller_Name_already_exists"]);
                return(View(oldObj));
            }

            if (!ModelState.IsValid)
            {
                return(View(oldObj));
            }

            //Gán giá trị
            oldObj.ControllerName    = obj.ControllerName;
            oldObj.Baudrate          = obj.Baudrate;
            oldObj.CommunicationType = obj.CommunicationType;
            oldObj.Comport           = obj.Comport;
            oldObj.Inactive          = obj.Inactive;
            oldObj.LineTypeID        = obj.LineTypeID;
            oldObj.PCID        = obj.PCID;
            oldObj.Reader1Type = obj.Reader1Type;
            oldObj.Reader2Type = obj.Reader2Type;
            oldObj.Address     = obj.Address;
            //oldObj.SortOrder = obj.SortOrder;

            //Thực hiện cập nhật
            var result = _tblControllerService.Update(oldObj);

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.ControllerID.ToString(), obj.ControllerName, "tblController", ConstField.ParkingCode, ActionConfigO.Update);

                return(RedirectToAction("Index", new { group = group, page = page, key = key, pc = pc, selectedId = obj.ControllerID }));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(oldObj));
            }
        }
 public tbltaskCollection(tblController parent)
 {
     m_ControllerID_tblController = parent;
 }
        private void addUD(bool _isfunction, POUTYPE _poutype, POUEXECUTIONTYPE _pouexecutiontype, string _nodetreename)
        {
            AddUDPouForm addudpouform = new AddUDPouForm();

            if (DialogResult.OK == addudpouform.ShowDialog())
            {
                int _type = 0;
                if (_isfunction)
                {
                    _type = 0;
                }
                else
                {
                    _type = (int)VarType.USERDEFUNED;
                }
                foreach (tblFunction tblfunction in tblSolution.m_tblSolution().m_tblFunctionCollection)
                {
                    if (tblfunction.IsFunction == _isfunction)
                    {
                        if (tblfunction.Type > _type)
                        {
                            _type = tblfunction.Type;
                        }
                    }
                }

                if (CheckUDNameIsValid(addudpouform.pouname))
                {
                    tblPou tblpou = new tblPou();
                    tblpou.pouName       = addudpouform.pouname;
                    tblpou.Description   = addudpouform.poudescription;
                    tblpou.Type          = _poutype;
                    tblpou.Language      = addudpouform.pouLanguageType;
                    tblpou.executiontype = _pouexecutiontype;
                    tblpou.ControllerID  = tblSolution.m_tblSolution().Dummytblcontroller.ControllerID;
                    tblpou.Insert();
                    tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromID(tblpou.ControllerID);
                    tblcontroller.m_tblPouCollection.Add(tblpou);
                    tblcontroller.SavePouDB();
                    tblFunction _tblfunction = new tblFunction();
                    _tblfunction.FunctionName  = addudpouform.pouname;
                    _tblfunction.Description   = addudpouform.poudescription;
                    _tblfunction.Language      = (int)addudpouform.pouLanguageType;
                    _tblfunction.SolutionID    = tblSolution.m_tblSolution().SolutionID;
                    _tblfunction.FunctionGroup = (int)FunctionGroup.USER_DEFINED;
                    _tblfunction.IsFunction    = _isfunction;
                    _tblfunction.IsStandard    = false;
                    _tblfunction.Extensible    = false;
                    _tblfunction.Overloaded    = false;
                    _tblfunction.Width         = 4;
                    _tblfunction.Mode          = 3;
                    _tblfunction.Type          = _type + 1;
                    int ret = _tblfunction.Insert();
                    if (ret == 0)
                    {
                        //tblSolution.m_tblSolution().functionbyType.Add(_tblfunction.Type, _tblfunction);
                        //tblSolution.m_tblSolution().functionbyName.Add(_tblfunction.FunctionName, _tblfunction);
                        //EWSTreeNode _node;
                        foreach (TreeNode rootnode in treeViewControl.Nodes)
                        {
                            foreach (TreeNode _node in rootnode.Nodes)
                            {
                                //_node = (EWSTreeNode)node;
                                //while (_node.NextNode != null)
                                {
                                    if (_node.Text == _nodetreename)
                                    {
                                        EWSTreeNode node4 = new EWSTreeNode(tblpou.pouName);
                                        node4.NodeID = tblpou.pouID;
                                        if (_isfunction)
                                        {
                                            node4.Nodetype         = TREE_NODE_TYPE.FUNCTION;
                                            node4.ContextMenuStrip = contextMenuStripUDF;
                                        }
                                        else
                                        {
                                            node4.Nodetype         = TREE_NODE_TYPE.FUNCTIONBLOCK;
                                            node4.ContextMenuStrip = contextMenuStripUDFB;
                                        }
                                        switch ((PROGRAM_LANGUAGE)tblpou.Language)
                                        {
                                        case PROGRAM_LANGUAGE.ENUM_PROGRAM_LANGUAGE_FBD:
                                            node4.ImageIndex         = 4;
                                            node4.SelectedImageIndex = 5;
                                            break;

                                        case PROGRAM_LANGUAGE.ENUM_PROGRAM_LANGUAGE_ST:
                                            node4.ImageIndex         = 12;
                                            node4.SelectedImageIndex = 13;
                                            break;
                                        }


                                        _node.Nodes.Add(node4);
                                        return;
                                    }
                                    //   _node = (EWSTreeNode)_node.NextNode;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #23
0
        public void AddPOU(string filename, string controllername)
        {
            if (MainForm.Instance().CurrentUser.LogicExplorer != (int)EXPLORER_ACCESS.Full)
            {
                System.Windows.Forms.MessageBox.Show("current user cannot add any Contrller");
            }
            if (!File.Exists(filename))
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("File " + filename + " does not exist");
                return;
            }
            int           ret = 0;
            string        str;
            string        _log = "";
            int           ControllerNameCol = -1;
            bool          headerline        = true;
            tblPou        tblpou            = new tblPou();
            tblController tblcontroller     = tblSolution.m_tblSolution().GetControllerFromName(controllername);

            if (tblcontroller == null)
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("Import POU Error controller " + controllername + " does not exist in database");
                return;
            }
            using (StreamReader reader = new StreamReader(filename))
            {
                while ((str = reader.ReadLine()) != null)
                {
                    str.Replace(",,", ", ,");
                    if (str.StartsWith("!"))
                    {
                        continue;
                    }
                    if (headerline)
                    {
                        tblpou.headerString = str;
                        headerline          = false;
                        ControllerNameCol   = tblpou.ColumnExistInHeader("ControllerName");
                        if (ControllerNameCol == -1)
                        {
                            DCS.Forms.MainForm.Instance().WriteToOutputWindows("POU add error: ControllerName column does not exist in " + filename);
                            break;
                        }
                    }
                    else
                    {
                        tblpou = new tblPou();
                        string[] _strs = str.Split(new Char[] { ',' });
                        if (_strs[ControllerNameCol].ToLower() == controllername)
                        {
                            tblpou.AddFromString(_strs, _strs[ControllerNameCol], ref _log);
                            tblpou.ControllerID = tblcontroller.ControllerID;
                            if ((ret = tblpou.Insert()) != 0)
                            {
                                if (ret == 19)
                                {
                                    DCS.Forms.MainForm.Instance().WriteToOutputWindows(_log + " Already exist in database");
                                }
                            }
                            else
                            {
                                tblcontroller.m_tblPouCollection.Add(tblpou);
                            }
                        }
                    }
                }
                reader.Close();
            }
        }
Exemple #24
0
        public void AddREAL(string filename, string controllername, string pouname)
        {
            if (MainForm.Instance().CurrentUser.LogicExplorer != (int)EXPLORER_ACCESS.Full)
            {
                System.Windows.Forms.MessageBox.Show("current user cannot add any Contrller");
            }
            if (!File.Exists(filename))
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("File " + filename + " does not exist");
                return;
            }
            int ControllerNameCol = -1;
            int pouNameCol        = -1;
            int VarNameCol        = -1;

            int           ret = 0;
            string        str;
            string        _log          = "";
            bool          headerline    = true;
            tblREAL       tblreal       = new tblREAL();
            tblController tblcontroller = tblSolution.m_tblSolution().GetControllerFromName(controllername);

            if (tblcontroller == null)
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("Import REAL Error: controller " + controllername + " does not exist in database");
                return;
            }
            tblPou tblpou = tblcontroller.GetPouFromName(pouname);

            if (tblpou == null)
            {
                DCS.Forms.MainForm.Instance().WriteToOutputWindows("Import REAL Error: pou " + pouname + " does not exist in " + controllername);
                return;
            }
            //var transaction = Common.Conn.BeginTransaction();
            using (StreamReader reader = new StreamReader(filename))
            {
                while ((str = reader.ReadLine()) != null)
                {
                    str.Replace(",,", ", ,");
                    if (str.StartsWith("!"))
                    {
                        continue;
                    }
                    if (headerline)
                    {
                        tblreal.headerString = str;
                        headerline           = false;
                        ControllerNameCol    = tblreal.ColumnExistInHeader("ControllerName");
                        if (ControllerNameCol == -1)
                        {
                            DCS.Forms.MainForm.Instance().WriteToOutputWindows("REAL add error: ControllerName column does not exist in " + filename);
                            break;
                        }
                        pouNameCol = tblreal.ColumnExistInHeader("pouName");
                        if (pouNameCol == -1)
                        {
                            DCS.Forms.MainForm.Instance().WriteToOutputWindows("REAL add error: pouName column does not exist in " + filename);
                            break;
                        }
                        VarNameCol = tblreal.ColumnExistInHeader("VarName");
                        if (VarNameCol == -1)
                        {
                            DCS.Forms.MainForm.Instance().WriteToOutputWindows("REAL add error: VarName column does not exist in " + filename);
                            break;
                        }
                    }
                    else
                    {
                        tblreal = new tblREAL();
                        string[] _strs = str.Split(new Char[] { ',' });
                        if ((_strs[ControllerNameCol].ToLower() == controllername) && (_strs[pouNameCol].ToLower() == pouname))
                        {
                            if (tblpou.VariablesByName.ContainsKey(_strs[VarNameCol].ToLower()))
                            {
                                tblVariable tblvariable = tblpou.VariablesByName[_strs[VarNameCol].ToLower()];
                                tblreal.AddFromString(_strs, _strs[pouNameCol], ref _log);

                                tblreal.VarNameID = tblvariable.VarNameID;
                                if ((ret = tblreal.Insert()) != 0)
                                {
                                    if (ret == 19)
                                    {
                                        DCS.Forms.MainForm.Instance().WriteToOutputWindows(_log + " Already exist in database");
                                    }
                                }
                            }
                            else
                            {
                                DCS.Forms.MainForm.Instance().WriteToOutputWindows("REAL add Error: Varaible " + _strs[VarNameCol] + " does not exist in database");
                            }
                        }
                    }
                }
                reader.Close();
            }
        }