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 tmpBlock GetBlockBytes(ProjectBlockInfo blkInfo) { if (subblkDBF != null) //ZipHelper.FileExists(((Step7ProjectV5)Project)._zipfile, Folder + "SUBBLK.DBF")) { tmpBlock myTmpBlk = new tmpBlock(); var bstTbl = bausteinDBF; DataRow[] bstRows = bstTbl.Select("ID = " + blkInfo.id); if (bstRows != null && bstRows.Length > 0 && !(bstRows[0]["UDA"] is DBNull)) myTmpBlk.uda = (byte[]) bstRows[0]["UDA"]; var dbfTbl = subblkDBF; DataRow[] rows = dbfTbl.Select("OBJECTID = " + blkInfo.id); foreach (DataRow row in rows) { int subblktype = Convert.ToInt32(row["SUBBLKTYP"]); int objid = (int)row["OBJECTID"]; if (objid == blkInfo.id) { byte[] mc5code = null; byte[] ssbpart = null; byte[] addinfo = null; if (row["MC5CODE"] != DBNull.Value) mc5code = (byte[])row["MC5CODE"]; if (row["SSBPART"] != DBNull.Value) ssbpart = (byte[])row["SSBPART"]; if (row["ADDINFO"] != DBNull.Value) addinfo = (byte[])row["ADDINFO"]; int mc5codelen = (int)row["MC5LEN"]; int ssbpartlen = (int)row["SSBLEN"]; int addinfolen = (int)row["ADDLEN"]; if (mc5code != null && mc5code.Length > mc5codelen) Array.Resize<byte>(ref mc5code, mc5codelen); if (ssbpart != null && ssbpart.Length > ssbpartlen) Array.Resize<byte>(ref ssbpart, ssbpartlen); if (addinfo != null && addinfo.Length > addinfolen) Array.Resize<byte>(ref addinfo, addinfolen); if (subblktype == 12 || subblktype == 8 || subblktype == 14 || subblktype == 13 || subblktype == 15) //FC, OB, FB, SFC, SFB { if (row["PASSWORD"] != DBNull.Value && (int)row["PASSWORD"] == 3) myTmpBlk.knowHowProtection = true; //MC7 Code in mc5code myTmpBlk.mc7code = mc5code; myTmpBlk.username = ((string)row["USERNAME"]).Replace("\0", "").Trim(); int ver = ((int)row["VERSION"]); myTmpBlk.version = (ver / 15).ToString() + "." + (ver % 15).ToString(); //Network Information in addinfo myTmpBlk.nwinfo = addinfo; //This line contains Network Information, and after it the Position of the JumpMarks myTmpBlk.LastCodeChange = GetTimeStamp((string)row["TIMESTAMP1"]); myTmpBlk.LastInterfaceChange = GetTimeStamp((string)row["TIMESTAMP2"]); } else if (subblktype == 5 || subblktype == 3 || subblktype == 4 || subblktype == 7 || subblktype == 9) //FC, OB, FB, SFC, SFB { //Interface in mc5code if (mc5code != null) myTmpBlk.blkinterface = Project.ProjectEncoding.GetString(mc5code); } else if (subblktype == 19 || subblktype == 17 || subblktype == 18 || subblktype == 22 || subblktype == 21) //FC, OB, FB, SFC, SFB { myTmpBlk.comments = mc5code; //Comments of the Block myTmpBlk.blockdescription = ssbpart; //Description of the Block myTmpBlk.jumpmarks = addinfo; //The Text of the Jump Marks, Before the Jumpmarks there is some Network Information, but don't know what! } else if (subblktype == 6 || subblktype == 1) //DB, UDT { //DB Structure in Plain Text (Structure and StartValues!) if (mc5code != null) myTmpBlk.blkinterface = Project.ProjectEncoding.GetString(mc5code); //Maybe compiled DB Structure? myTmpBlk.addinfo = addinfo; } else if (subblktype == 10) //DB { //Need to check wich Information is stored here myTmpBlk.mc7code = mc5code; myTmpBlk.blkinterfaceInMC5 = ssbpart; myTmpBlk.LastCodeChange = GetTimeStamp((string)row["TIMESTAMP1"]); myTmpBlk.LastInterfaceChange = GetTimeStamp((string)row["TIMESTAMP2"]); if (ssbpart != null && ssbpartlen > 2 && (ssbpart[0] == 0x0a || ssbpart[0] == 0x0b)) { // if ssbpart[0] == 5 this DB is normal // if ssbpart[0] == 10 this DB is instance for FB, // I do not know what value for SFB myTmpBlk.IsInstanceDB = true; myTmpBlk.FBNumber = (int)ssbpart[1] + 256 * (int)ssbpart[2]; } } else if (subblktype == 0x14) //DB { //Need to check wich Information is stored here } else if (subblktype == 0x42) //DB { //Need to check wich Information is stored here } else if (subblktype == 27) //VAT { myTmpBlk.LastCodeChange = GetTimeStamp((string)row["TIMESTAMP1"]); myTmpBlk.LastInterfaceChange = GetTimeStamp((string)row["TIMESTAMP2"]); //VAT in MC5Code (Absolut adressed) myTmpBlk.mc7code = mc5code; //VAT in ADDINFO (Symbolic adressed) myTmpBlk.nwinfo = addinfo; } else if (subblktype == 38) //VAT { //VAT Comments in MC5Code myTmpBlk.comments = mc5code; } } } return myTmpBlk; } return 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); } } } }