public void ChangeKnowHowProtection(S7ProjectBlockInfo blkInfo, bool KnowHowProtection) { tmpBlock myTmpBlk = new tmpBlock(); if (subblkDBF != null) { var dbfTbl = subblkDBF; foreach (DataRow row in dbfTbl.Rows) { int subblktype = Convert.ToInt32(row["SUBBLKTYP"]); int objid = (int)row["OBJECTID"]; if (objid == blkInfo.id && (subblktype == 12 || subblktype == 8 || subblktype == 14)) { _bausteinDbf = null; _subblkDbf = null; _intBlockList = null; ((Step7ProjectV5)Project).hasChanges = true; if (KnowHowProtection) { DBF.ParseDBF.WriteValue(Folder + "SUBBLK.DBF", "PASSWORD", dbfTbl.Rows.IndexOf(row), 3, ((Step7ProjectV5)Project)._ziphelper, ((Step7ProjectV5)Project)._DirSeperator); } else { DBF.ParseDBF.WriteValue(Folder + "SUBBLK.DBF", "PASSWORD", dbfTbl.Rows.IndexOf(row), 0, ((Step7ProjectV5)Project)._ziphelper, ((Step7ProjectV5)Project)._DirSeperator); } break; } } } }
private void myDataGrid_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && !IsDragging) { Point position = e.GetPosition(null); if (Math.Abs(position.X - _startPoint.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(position.Y - _startPoint.Y) > SystemParameters.MinimumVerticalDragDistance) { //Start DragDrop Action! { var row = UIHelpers.TryFindFromPoint <DataGridRow>((UIElement)sender, e.GetPosition(myDataGrid)); if (row != null) { DataObject dragData = new DataObject("dataRow", row); dragData.SetData("ProjectBlockInfo", myDataGrid.SelectedItem); if (myDataGrid.SelectedItem is S7ProjectBlockInfo) { S7ProjectBlockInfo blkInfo = (S7ProjectBlockInfo)myDataGrid.SelectedItem; string awlblk = blkInfo.GetSourceBlock(); dragData.SetData(FileDragDropHelper.CFSTR_FILEDESCRIPTORW, FileDragDropHelper.GetFileDescriptor(blkInfo.BlockName + ".awl", awlblk)); dragData.SetData(FileDragDropHelper.CFSTR_FILECONTENTS, FileDragDropHelper.GetFileContents(awlblk)); byte[] unicodeText = Encoding.Unicode.GetBytes(awlblk); // UTF-16 byte[] utf8Text = Encoding.UTF8.GetBytes(awlblk); byte[] utf32Text = Encoding.UTF32.GetBytes(awlblk); dragData.SetData(DataFormats.Text, awlblk); dragData.SetData(DataFormats.UnicodeText, unicodeText); dragData.SetData("UTF-8", utf8Text); dragData.SetData("UTF-32", utf32Text); } //dragData = new DataObject(DataFormats.Text,row.ToString()); Mouse.OverrideCursor = dragDropCursor = new GhostCursor(row).Cursor; DragDrop.DoDragDrop((DependencyObject)sender, dragData, DragDropEffects.Copy); Mouse.OverrideCursor = null; } } } } }
public void UndeleteBlock(S7ProjectBlockInfo blkInfo, int newBlockNumber) { tmpBlock myTmpBlk = new tmpBlock(); if (((Step7ProjectV5)Project)._ziphelper.FileExists(Folder + "BAUSTEIN.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(Folder + "BAUSTEIN.DBF", ((Step7ProjectV5)Project)._ziphelper, ((Step7ProjectV5)Project)._DirSeperator); foreach (DataRow row in dbfTbl.Rows) { int objid = (int)row["ID"]; if (objid == blkInfo.id) { ((Step7ProjectV5)Project).hasChanges = true; DBF.ParseDBF.WriteValue(Folder + "BAUSTEIN.DBF", "DELETED_FLAG", dbfTbl.Rows.IndexOf(row), false, ((Step7ProjectV5)Project)._ziphelper, ((Step7ProjectV5)Project)._DirSeperator); DBF.ParseDBF.WriteValue(Folder + "BAUSTEIN.DBF", "NUMMER", dbfTbl.Rows.IndexOf(row), newBlockNumber, ((Step7ProjectV5)Project)._ziphelper, ((Step7ProjectV5)Project)._DirSeperator); } } } if (((Step7ProjectV5)Project)._ziphelper.FileExists(Folder + "SUBBLK.DBF")) { var dbfTbl = DBF.ParseDBF.ReadDBF(Folder + "SUBBLK.DBF", ((Step7ProjectV5)Project)._ziphelper, ((Step7ProjectV5)Project)._DirSeperator); foreach (DataRow row in dbfTbl.Rows) { int objid = (int)row["OBJECTID"]; if (objid == blkInfo.id) { ((Step7ProjectV5)Project).hasChanges = true; DBF.ParseDBF.WriteValue(Folder + "SUBBLK.DBF", "DELETED_FLAG", dbfTbl.Rows.IndexOf(row), false, ((Step7ProjectV5)Project)._ziphelper, ((Step7ProjectV5)Project)._DirSeperator); DBF.ParseDBF.WriteValue(Folder + "SUBBLK.DBF", "BLKNUMBER", dbfTbl.Rows.IndexOf(row), newBlockNumber, ((Step7ProjectV5)Project)._ziphelper, ((Step7ProjectV5)Project)._DirSeperator); } } } }
private void cmdOk_Click(object sender, EventArgs e) { if (SelectPart == SelectPartType.BlocksOfflineFolder) { if (treeStep7Project.SelectedNode != null) { var tmp = (myTreeNode)treeStep7Project.SelectedNode; if (tmp.myObject.GetType() == typeof(BlocksOfflineFolder)) { retVal = (BlocksOfflineFolder)tmp.myObject; } else { retVal = null; } } } else if (SelectPart == SelectPartType.S7ProgrammFolder) { if (treeStep7Project.SelectedNode != null) { var tmp = (myTreeNode)treeStep7Project.SelectedNode; if (tmp.myObject.GetType() == typeof(S7ProgrammFolder)) { retVal = (S7ProgrammFolder)tmp.myObject; } else { retVal = null; } } } else if (SelectPart == SelectPartType.VariableTable) { if (lstProjectFolder.SelectedItem != null) { this.Hide(); S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem; if (tmp.BlockType == PLCBlockType.VAT) { retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp); ((Block)retVal).ParentFolder = tmp.ParentFolder; } } } else if (SelectPart == SelectPartType.VariableTableOrSymbolTable) { if (lstProjectFolder.SelectedItem != null) { this.Hide(); S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem; if (tmp.BlockType == PLCBlockType.VAT) { retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp); ((Block)retVal).ParentFolder = tmp.ParentFolder; } } else if (treeStep7Project.SelectedNode != null) { var tmp = (myTreeNode)treeStep7Project.SelectedNode; if (tmp.myObject is ISymbolTable) { retVal = tmp.myObject as ISymbolTable; } } } else if (SelectPart == SelectPartType.DataBlock) { if (lstProjectFolder.SelectedItem != null) { this.Hide(); S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem; if (tmp.BlockType == PLCBlockType.DB) { retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp); ((Block)retVal).ParentFolder = tmp.ParentFolder; } } } else if (SelectPart == SelectPartType.DataBlocks) { if (lstProjectFolder.SelectedItems.Count > 0) { this.Hide(); var blocks = new List <S7DataBlock>(); foreach (S7ProjectBlockInfo s7ProjectBlockInfo in lstProjectFolder.SelectedItems) { if (s7ProjectBlockInfo.BlockType == PLCBlockType.DB) { var block = ((IBlocksFolder)s7ProjectBlockInfo.ParentFolder).GetBlock(s7ProjectBlockInfo); block.ParentFolder = s7ProjectBlockInfo.ParentFolder; blocks.Add((S7DataBlock)block); } } retVal = blocks.Count > 0 ? blocks : null; } } else if (SelectPart == SelectPartType.FunctionBlock) { if (lstProjectFolder.SelectedItem != null) { this.Hide(); S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem; if (tmp.BlockType == PLCBlockType.FC || tmp.BlockType == PLCBlockType.FB || tmp.BlockType == PLCBlockType.OB) { retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp); ((Block)retVal).ParentFolder = tmp.ParentFolder; } } } else if (SelectPart == SelectPartType.DataType) { if (lstProjectFolder.SelectedItem != null) { this.Hide(); S7ProjectBlockInfo tmp = (S7ProjectBlockInfo)lstProjectFolder.SelectedItem; if (tmp.BlockType == PLCBlockType.UDT) { retVal = ((IBlocksFolder)tmp.ParentFolder).GetBlock(tmp); ((Block)retVal).ParentFolder = tmp.ParentFolder; } } } else if (SelectPart == SelectPartType.SymbolTable) { if (treeStep7Project.SelectedNode != null) { var tmp = (myTreeNode)treeStep7Project.SelectedNode; if (tmp.myObject is ISymbolTable) { retVal = tmp.myObject as ISymbolTable; } else { retVal = null; } } } else if (SelectPart == SelectPartType.Tag) { if (lstProjectFolder.SelectedItem != null) { this.Hide(); DBRowValue tmp = (DBRowValue)lstProjectFolder.SelectedItem; retVal = tmp.myRow.PlcTag; } } if (retVal != null) { this.Close(); } else { MessageBox.Show("Please select the right Project Part, or press cancel to close this window."); } }
/// <summary> /// Read all blocks from the S7 Project and cache them into the 'tmpBlocks' field. /// </summary> /// <returns></returns> private List <ProjectBlockInfo> intReadPlcBlocksList() { bool showDeleted = ((Step7ProjectV5)this.Project)._showDeleted; List <ProjectBlockInfo> tmpBlocks = new List <ProjectBlockInfo>(); if (bausteinDBF != null) { var dbfTbl = bausteinDBF; foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || showDeleted) { int id = (int)row["ID"]; int blocknumber = Convert.ToInt32(row["NUMMER"]); int blocktype = Convert.ToInt32(row["TYP"]); S7ProjectBlockInfo tmp = new S7ProjectBlockInfo(); tmp.ParentFolder = this; tmp.Deleted = (bool)row["DELETED_FLAG"]; tmp.BlockNumber = blocknumber; tmp.id = id; if (blocktype == 0x00) { tmp.BlockType = PLCBlockType.UDT; } else { tmp.BlockType = (PLCBlockType)blocktype; } if (tmp.BlockType == PLCBlockType.SFB || tmp.BlockType == PLCBlockType.SFC || tmp.BlockType == PLCBlockType.SDB || tmp.BlockType == PLCBlockType.DB || tmp.BlockType == PLCBlockType.VAT || tmp.BlockType == PLCBlockType.FB || tmp.BlockType == PLCBlockType.FC || tmp.BlockType == PLCBlockType.OB || tmp.BlockType == PLCBlockType.UDT) { tmpBlocks.Add(tmp); } } } } if (subblkDBF != null) { var dbfTbl = subblkDBF; foreach (S7ProjectBlockInfo step7ProjectBlockInfo in tmpBlocks) { var rows = dbfTbl.Select("OBJECTID = " + step7ProjectBlockInfo.id.ToString()); foreach (DataRow row in rows) { int subblktyp = Convert.ToInt32(row["SUBBLKTYP"]); if ((int)row["OBJECTID"] == step7ProjectBlockInfo.id && (subblktyp == 12 || subblktyp == 8 || subblktyp == 14)) { if ((int)row["PASSWORD"] == 3) { step7ProjectBlockInfo.KnowHowProtection = true; } } } } } NumericComparer <ProjectBlockInfo> nc = new NumericComparer <ProjectBlockInfo>(); tmpBlocks.Sort(nc); return(tmpBlocks); }
private List <ProjectBlockInfo> intReadPlcBlocksList() { bool showDeleted = ((Step7ProjectV5)this.Project)._showDeleted; List <ProjectBlockInfo> tmpBlocks = new List <ProjectBlockInfo>(); if (bausteinDBF != null) //ZipHelper.FileExists(((Step7ProjectV5)Project)._zipfile, Folder + "BAUSTEIN.DBF")) { var dbfTbl = bausteinDBF; //DBF.ParseDBF.ReadDBF(Folder + "BAUSTEIN.DBF", ((Step7ProjectV5)Project)._zipfile, ((Step7ProjectV5)Project)._DirSeperator); //if (Parent is S7ProgrammFolder && ((S7ProgrammFolder)Parent).SymbolTable != null) //{ // SymbolTable symtab = (SymbolTable)((S7ProgrammFolder)Parent).SymbolTable; //} foreach (DataRow row in dbfTbl.Rows) { if (!(bool)row["DELETED_FLAG"] || showDeleted) { int id = (int)row["ID"]; int blocknumber = Convert.ToInt32(row["NUMMER"]); int blocktype = Convert.ToInt32(row["TYP"]); S7ProjectBlockInfo tmp = new S7ProjectBlockInfo(); tmp.ParentFolder = this; tmp.Deleted = (bool)row["DELETED_FLAG"]; tmp.BlockNumber = blocknumber; tmp.id = id; if (blocktype == 0x00) { tmp.BlockType = PLCBlockType.UDT; } else { tmp.BlockType = (PLCBlockType)blocktype; } /* * if (symtab != null) * { * SymbolTableEntry sym = symtab.GetEntryFromOperand(tmp.ToString()); * if (sym != null) * tmp.Symbol = sym.Symbol; * } */ if (tmp.BlockType == PLCBlockType.SFB || tmp.BlockType == PLCBlockType.SFC || tmp.BlockType == PLCBlockType.SDB || tmp.BlockType == PLCBlockType.DB || tmp.BlockType == PLCBlockType.VAT || tmp.BlockType == PLCBlockType.FB || tmp.BlockType == PLCBlockType.FC || tmp.BlockType == PLCBlockType.OB || tmp.BlockType == PLCBlockType.UDT) { tmpBlocks.Add(tmp); } } } } if (subblkDBF != null) //ZipHelper.FileExists(((Step7ProjectV5)Project)._zipfile, Folder + "SUBBLK.DBF")) { var dbfTbl = subblkDBF; // DBF.ParseDBF.ReadDBF(Folder + "SUBBLK.DBF", ((Step7ProjectV5)Project)._zipfile, ((Step7ProjectV5)Project)._DirSeperator); foreach (S7ProjectBlockInfo step7ProjectBlockInfo in tmpBlocks) { var rows = dbfTbl.Select("OBJECTID = " + step7ProjectBlockInfo.id.ToString()); foreach (DataRow row in rows) { int subblktyp = Convert.ToInt32(row["SUBBLKTYP"]); if ((int)row["OBJECTID"] == step7ProjectBlockInfo.id && (subblktyp == 12 || subblktyp == 8 || subblktyp == 14)) { if ((int)row["PASSWORD"] == 3) { step7ProjectBlockInfo.KnowHowProtection = true; } } } } } NumericComparer <ProjectBlockInfo> nc = new NumericComparer <ProjectBlockInfo>(); tmpBlocks.Sort(nc); return(tmpBlocks); }