From bc880ed2ed5cafe60ddf75665d796fb870fc2853 Mon Sep 17 00:00:00 2001 From: tfoman Date: Wed, 14 Jan 2015 16:13:12 +0100 Subject: [PATCH] Synch move-fields to cvs-file editable in excell... --- CobXmlSupport/CobRow.cs | 6 +- CobXmlSupport/GenCobCode.Designer.cs | 44 +++++--- CobXmlSupport/GenCobCode.cs | 55 +++++++++- CobXmlSupport/GenCobCode.resx | 3 + CobXmlSupport/ShowCode.Designer.cs | 14 +++ CobXmlSupport/ShowCode.cs | 153 +++++++++++++++++++++++++-- 6 files changed, 247 insertions(+), 28 deletions(-) diff --git a/CobXmlSupport/CobRow.cs b/CobXmlSupport/CobRow.cs index b6df273..de6c147 100644 --- a/CobXmlSupport/CobRow.cs +++ b/CobXmlSupport/CobRow.cs @@ -43,8 +43,10 @@ namespace CobXmlSupport public string LocalKey { get; set; } public string SampleStr { get; set; } - - + public string MoveCode { get; set; } + //Holding code-parts used when generating moves, to and from structure + //Could be a Variable, simple or qualified, could be retreival code. + //Will replace "MOVE " when generating move sequences public string FieldName { diff --git a/CobXmlSupport/GenCobCode.Designer.cs b/CobXmlSupport/GenCobCode.Designer.cs index 12ff59c..499fe36 100644 --- a/CobXmlSupport/GenCobCode.Designer.cs +++ b/CobXmlSupport/GenCobCode.Designer.cs @@ -64,6 +64,7 @@ this.chkAttribs = new System.Windows.Forms.CheckBox(); this.btnTestThings = new System.Windows.Forms.Button(); this.btnFrXMLTo = new System.Windows.Forms.Button(); + this.btnCrossref = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 @@ -85,7 +86,7 @@ this.outText.Multiline = true; this.outText.Name = "outText"; this.outText.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.outText.Size = new System.Drawing.Size(380, 496); + this.outText.Size = new System.Drawing.Size(380, 480); this.outText.TabIndex = 1; this.outText.WordWrap = false; // @@ -99,7 +100,7 @@ this.outCob.Multiline = true; this.outCob.Name = "outCob"; this.outCob.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.outCob.Size = new System.Drawing.Size(533, 496); + this.outCob.Size = new System.Drawing.Size(533, 480); this.outCob.TabIndex = 2; this.outCob.WordWrap = false; this.outCob.KeyDown += new System.Windows.Forms.KeyEventHandler(this.outCob_KeyDown); @@ -127,7 +128,7 @@ // btnClose // this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnClose.Location = new System.Drawing.Point(864, 632); + this.btnClose.Location = new System.Drawing.Point(864, 639); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(75, 23); this.btnClose.TabIndex = 6; @@ -190,7 +191,7 @@ // this.btnGenICode.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnGenICode.Enabled = false; - this.btnGenICode.Location = new System.Drawing.Point(411, 632); + this.btnGenICode.Location = new System.Drawing.Point(410, 616); this.btnGenICode.Margin = new System.Windows.Forms.Padding(2); this.btnGenICode.Name = "btnGenICode"; this.btnGenICode.Size = new System.Drawing.Size(81, 23); @@ -215,7 +216,7 @@ // this.btnMoves.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnMoves.Enabled = false; - this.btnMoves.Location = new System.Drawing.Point(496, 632); + this.btnMoves.Location = new System.Drawing.Point(495, 616); this.btnMoves.Margin = new System.Windows.Forms.Padding(2); this.btnMoves.Name = "btnMoves"; this.btnMoves.Size = new System.Drawing.Size(93, 23); @@ -242,7 +243,7 @@ // this.btnMoveFrom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnMoveFrom.Enabled = false; - this.btnMoveFrom.Location = new System.Drawing.Point(673, 632); + this.btnMoveFrom.Location = new System.Drawing.Point(672, 616); this.btnMoveFrom.Name = "btnMoveFrom"; this.btnMoveFrom.Size = new System.Drawing.Size(92, 23); this.btnMoveFrom.TabIndex = 16; @@ -296,7 +297,7 @@ this.chkDisplays.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.chkDisplays.AutoSize = true; this.chkDisplays.Enabled = false; - this.chkDisplays.Location = new System.Drawing.Point(771, 644); + this.chkDisplays.Location = new System.Drawing.Point(770, 628); this.chkDisplays.Name = "chkDisplays"; this.chkDisplays.Size = new System.Drawing.Size(71, 17); this.chkDisplays.TabIndex = 21; @@ -347,7 +348,7 @@ // btnSettings // this.btnSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.btnSettings.Location = new System.Drawing.Point(20, 655); + this.btnSettings.Location = new System.Drawing.Point(20, 616); this.btnSettings.Margin = new System.Windows.Forms.Padding(2); this.btnSettings.Name = "btnSettings"; this.btnSettings.Size = new System.Drawing.Size(81, 23); @@ -360,7 +361,7 @@ // this.chkPerform.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.chkPerform.AutoSize = true; - this.chkPerform.Location = new System.Drawing.Point(594, 627); + this.chkPerform.Location = new System.Drawing.Point(593, 611); this.chkPerform.Name = "chkPerform"; this.chkPerform.Size = new System.Drawing.Size(62, 17); this.chkPerform.TabIndex = 27; @@ -371,7 +372,7 @@ // this.chkMvToDisp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.chkMvToDisp.AutoSize = true; - this.chkMvToDisp.Location = new System.Drawing.Point(594, 644); + this.chkMvToDisp.Location = new System.Drawing.Point(593, 628); this.chkMvToDisp.Name = "chkMvToDisp"; this.chkMvToDisp.Size = new System.Drawing.Size(71, 17); this.chkMvToDisp.TabIndex = 28; @@ -382,7 +383,7 @@ // this.chkNewArea.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.chkNewArea.AutoSize = true; - this.chkNewArea.Location = new System.Drawing.Point(771, 627); + this.chkNewArea.Location = new System.Drawing.Point(770, 611); this.chkNewArea.Name = "chkNewArea"; this.chkNewArea.Size = new System.Drawing.Size(64, 17); this.chkNewArea.TabIndex = 29; @@ -412,7 +413,7 @@ // this.chkAttribs.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.chkAttribs.AutoSize = true; - this.chkAttribs.Location = new System.Drawing.Point(771, 660); + this.chkAttribs.Location = new System.Drawing.Point(770, 644); this.chkAttribs.Name = "chkAttribs"; this.chkAttribs.Size = new System.Drawing.Size(85, 17); this.chkAttribs.TabIndex = 32; @@ -423,7 +424,7 @@ // btnTestThings // this.btnTestThings.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.btnTestThings.Location = new System.Drawing.Point(20, 632); + this.btnTestThings.Location = new System.Drawing.Point(21, 639); this.btnTestThings.Name = "btnTestThings"; this.btnTestThings.Size = new System.Drawing.Size(81, 23); this.btnTestThings.TabIndex = 33; @@ -434,7 +435,7 @@ // btnFrXMLTo // this.btnFrXMLTo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnFrXMLTo.Location = new System.Drawing.Point(673, 655); + this.btnFrXMLTo.Location = new System.Drawing.Point(672, 639); this.btnFrXMLTo.Name = "btnFrXMLTo"; this.btnFrXMLTo.Size = new System.Drawing.Size(92, 22); this.btnFrXMLTo.TabIndex = 34; @@ -442,11 +443,23 @@ this.btnFrXMLTo.UseVisualStyleBackColor = true; this.btnFrXMLTo.Click += new System.EventHandler(this.btnFrXMLTo_Click); // + // btnCrossref + // + this.btnCrossref.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnCrossref.Location = new System.Drawing.Point(21, 662); + this.btnCrossref.Name = "btnCrossref"; + this.btnCrossref.Size = new System.Drawing.Size(81, 23); + this.btnCrossref.TabIndex = 35; + this.btnCrossref.Text = "CrossRef"; + this.btnCrossref.UseVisualStyleBackColor = true; + this.btnCrossref.Click += new System.EventHandler(this.btnCrossref_Click); + // // GenCobCode // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(951, 686); + this.ClientSize = new System.Drawing.Size(951, 693); + this.Controls.Add(this.btnCrossref); this.Controls.Add(this.btnFrXMLTo); this.Controls.Add(this.btnTestThings); this.Controls.Add(this.chkAttribs); @@ -528,6 +541,7 @@ private System.Windows.Forms.CheckBox chkAttribs; private System.Windows.Forms.Button btnTestThings; private System.Windows.Forms.Button btnFrXMLTo; + private System.Windows.Forms.Button btnCrossref; } } diff --git a/CobXmlSupport/GenCobCode.cs b/CobXmlSupport/GenCobCode.cs index c4b73a7..cc62c81 100644 --- a/CobXmlSupport/GenCobCode.cs +++ b/CobXmlSupport/GenCobCode.cs @@ -48,9 +48,19 @@ namespace CobXmlSupport //private string SettingLogSectName; ////------------------------- - private readonly string NOMOVE = "NoMove"; + public readonly string NOMOVE = "NoMove"; private readonly bool MOVEFROM = true; + public List RowList + { + get { return rowList; } + } + + public System.Windows.Forms.ComboBox CmbLastFile + { + get { return cmbLastFile; } + } + public GenCobCode() { InitializeComponent(); @@ -670,7 +680,7 @@ namespace CobXmlSupport btnTestThings.Visible = S.ettingSpecials; formLoading = false; - // cmbLastFile.Text = cmbLastFile.Items[0].ToString(); + // cmbLastFile.Text = cmbLastFile.Items[0].ToString(); if (cmbLastFile.Items.Count > 0) { cmbLastFile.Text = cmbLastFile.Items[0].ToString(); @@ -841,7 +851,7 @@ namespace CobXmlSupport /// /// /// - private void CreateComment(TextBox outView, string typeComm, string Author, string Firm, string sourceFile = "") + public void CreateComment(TextBox outView, string typeComm, string Author, string Firm, string sourceFile = "") { outView.Text = " *----------------------------------------------------------------*"; centeredComment(outView, typeComm.ToUpper()); @@ -1342,7 +1352,7 @@ namespace CobXmlSupport fromMoves.CodeShower.Text += "\r\n IF " + cr.CountIn; if (occParRows.Length > 0) { - fromMoves.CodeShower.Text += "( "+ occParRows + " )"; + fromMoves.CodeShower.Text += "( " + occParRows + " )"; } fromMoves.CodeShower.Text += "\r\n > 0"; @@ -1852,5 +1862,42 @@ namespace CobXmlSupport } } + private void btnCrossref_Click(object sender, EventArgs e) + { + //Create showing window + fromToMoves = new ShowCode(); + fromToMoves.Parent = this; + fromToMoves.Labeltext = "Cobol \"CrossRef\" List"; + + foreach (CobRow cr in rowList) + { + if (cr.CobLevel < 2) + { + string inFile = cmbLastFile.Text.Substring(cmbLastFile.Text.LastIndexOf("\\") + 1); + CreateComment(fromToMoves.CodeShower, "Moves reference (with loop) " + cr.FieldName, S.ettingUserName, S.ettingCompany, inFile); + } + // Header square created + + if (!cr.isAttribute && !cr.SampleStr.Equals(NOMOVE)) + { + if (fromToMoves.CodeShower.Text == "") { } + else fromToMoves.CodeShower.Text += "\r\n"; + if (cr.MoveCode == null) + { + fromToMoves.CodeShower.Text += "".PadRight(30) + " " + cr.FieldName.PadRight(30); + + } + else + { + fromToMoves.CodeShower.Text += cr.MoveCode.PadRight(30) + " " + cr.FieldName.PadRight(30); + } + } + + } + + fromToMoves.Show(); + + } + } } diff --git a/CobXmlSupport/GenCobCode.resx b/CobXmlSupport/GenCobCode.resx index 476cfd8..b85e23d 100644 --- a/CobXmlSupport/GenCobCode.resx +++ b/CobXmlSupport/GenCobCode.resx @@ -120,6 +120,9 @@ 17, 17 + + 78 + diff --git a/CobXmlSupport/ShowCode.Designer.cs b/CobXmlSupport/ShowCode.Designer.cs index a061766..95dec67 100644 --- a/CobXmlSupport/ShowCode.Designer.cs +++ b/CobXmlSupport/ShowCode.Designer.cs @@ -32,6 +32,7 @@ this.btnClose = new System.Windows.Forms.Button(); this.txtCode = new System.Windows.Forms.TextBox(); this.lblCodeType = new System.Windows.Forms.Label(); + this.btnSynch = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnClose @@ -73,11 +74,23 @@ this.lblCodeType.TabIndex = 2; this.lblCodeType.Text = ""; // + // btnSynch + // + this.btnSynch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSynch.Location = new System.Drawing.Point(504, 642); + this.btnSynch.Name = "btnSynch"; + this.btnSynch.Size = new System.Drawing.Size(95, 23); + this.btnSynch.TabIndex = 3; + this.btnSynch.Text = "Synch Moves"; + this.btnSynch.UseVisualStyleBackColor = true; + this.btnSynch.Click += new System.EventHandler(this.btnSynch_Click); + // // ShowCode // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(670, 674); + this.Controls.Add(this.btnSynch); this.Controls.Add(this.lblCodeType); this.Controls.Add(this.txtCode); this.Controls.Add(this.btnClose); @@ -95,5 +108,6 @@ private System.Windows.Forms.Button btnClose; private System.Windows.Forms.TextBox txtCode; private System.Windows.Forms.Label lblCodeType; + private System.Windows.Forms.Button btnSynch; } } \ No newline at end of file diff --git a/CobXmlSupport/ShowCode.cs b/CobXmlSupport/ShowCode.cs index 8c96ecf..0765f06 100644 --- a/CobXmlSupport/ShowCode.cs +++ b/CobXmlSupport/ShowCode.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Diagnostics; +using System.IO; namespace CobXmlSupport @@ -20,7 +21,7 @@ namespace CobXmlSupport InitializeComponent(); oldTxt = ""; } - + public TextBox CodeShower { get { return txtCode; } @@ -33,7 +34,7 @@ namespace CobXmlSupport set { lblCodeType.Text = value; } } - private GenCobCode parentWindow; + private GenCobCode parentWindow; public GenCobCode Parent { @@ -60,15 +61,153 @@ namespace CobXmlSupport { string tmpNewText = txtCode.Text.Substring(oldTxt.Length); - // Debug.Write(tmpNewText); - // Tag bort denna kommentering för att testa på vad som precis skrivs på log-fönster. + // Debug.Write(tmpNewText); + // Tag bort denna kommentering för att testa på vad som precis skrivs på log-fönster. oldTxt = txtCode.Text; } } - + private void btnSynch_Click(object sender, EventArgs e) + { + Dictionary wrkDic = null; + string codeComplement = "", fieldCompl = "", codeComplInit = ""; + + string inFile = parentWindow.CmbLastFile.Text.Substring(parentWindow.CmbLastFile.Text.LastIndexOf("\\") + 1); + string inPath = parentWindow.CmbLastFile.Text.Substring(0, parentWindow.CmbLastFile.Text.LastIndexOf("\\") + 1); + string codeFile = inFile.Substring(0, inFile.LastIndexOf(".")) + ".cvs"; + this.CodeShower.Text = " InPath = " + inPath + "\r\n InFile = " + inFile + "\r\n codeFile = " + codeFile + "\r\n codePath = " +inPath+ codeFile + "\r\n -------------- \r\n" + this.CodeShower.Text; + + if (File.Exists(inPath + codeFile)) + { + codeComplement = File.ReadAllText(inPath + codeFile); + } + if (codeComplement.Length > 0) + { + wrkDic = moveFieldDictionary(codeComplement); + } + foreach (CobRow cr in parentWindow.RowList) + { + + if (!cr.isAttribute && !cr.SampleStr.Equals(parentWindow.NOMOVE)) + { + + + if (wrkDic != null && wrkDic.Count > 0) + { + + if (wrkDic.TryGetValue(cr.FieldName, out fieldCompl)) + { + cr.MoveCode = deQuote( fieldCompl); + } + } + if (cr.MoveCode == null) + codeComplInit += cr.FieldName + "\t" + " \r\n"; + else + codeComplInit += cr.FieldName + "\t" + enQuote( cr.MoveCode.Replace("\r\n", "\n")) + "\r\n"; + } + } + string backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + "." + + (DateTime.Now.Year-2000).ToString("00") + + DateTime.Now.Month.ToString("00") + + DateTime.Now.Day.ToString("00") + "T"+ + DateTime.Now.Hour.ToString("00") + + DateTime.Now.Minute.ToString("00") + + DateTime.Now.Second.ToString("00") + ".cvs"; + File.Move(inPath + codeFile, backupfile );//+ DateTime.Now.ToString()); + File.WriteAllText(inPath + codeFile, codeComplInit); + + refreshWindow(); + this.CodeShower.Text = " InPath = " + inPath + "\r\n InFile = " + inFile + "\r\n codeFile = " + codeFile + "\r\n codePath = " + inPath + codeFile + "\r\n -------------- \r\n" + this.CodeShower.Text; + + } + + private string deQuote(string inString) + { + string tmpStr = ""; + char[] x = inString.ToArray(); + for (int i = 0; i < x.Length; i++) + { + if (x[i] == '\"') + { + if (i < x.Length - 1) + { + if (x[i + 1] == '\"') + { + i++; + tmpStr += "\""; + } + } + } + else tmpStr += x[i]; + } + return tmpStr; + } + + private string enQuote(string inString) + { + string tmpStr = ""; + char[] x = inString.ToArray(); + for (int i = 0; i < x.Length; i++) + { + if (x[i] == '\"') + { + { + tmpStr += "\"\""; + } + } + else tmpStr += x[i]; + } + return "\""+tmpStr+"\""; + } + + + private Dictionary moveFieldDictionary(string inFil) + { + Dictionary tmpDic = new Dictionary(); + string[] splits = { "\r\n" }; + string[] itemPairs = inFil.Split(splits, StringSplitOptions.RemoveEmptyEntries); + char[] newSplits = { '\t' }; + foreach (string itemPair in itemPairs) + { + string[] items = itemPair.Split(newSplits); + tmpDic.Add(items[0], items[1].Replace("\n", "\r\n")); + } + + return tmpDic; + } + + private void refreshWindow() + { + this.CodeShower.Text = ""; + foreach (CobRow cr in parentWindow.RowList) + { + if (cr.CobLevel < 2) + { + string inFile = parentWindow.CmbLastFile.Text.Substring(parentWindow.CmbLastFile.Text.LastIndexOf("\\") + 1); + parentWindow.CreateComment(this.CodeShower, "Moves reference (with loop) " + cr.FieldName, S.ettingUserName, S.ettingCompany, inFile); + } + // Header square created + + if (!cr.isAttribute && !cr.SampleStr.Equals(parentWindow.NOMOVE)) + { + if (this.CodeShower.Text == "") { } + else this.CodeShower.Text += "\r\n"; + if (cr.MoveCode == null) + { + this.CodeShower.Text += "".PadRight(30) + " " + cr.FieldName.PadRight(30); + + } + else + { + this.CodeShower.Text += cr.MoveCode.PadRight(30) + " " + cr.FieldName.PadRight(30); + } + } + + } + + } + + - - } }