Synch move-fields to cvs-file editable in excell...
This commit is contained in:
@ -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<string, string> 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<char>();
|
||||
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<char>();
|
||||
for (int i = 0; i < x.Length; i++)
|
||||
{
|
||||
if (x[i] == '\"')
|
||||
{
|
||||
{
|
||||
tmpStr += "\"\"";
|
||||
}
|
||||
}
|
||||
else tmpStr += x[i];
|
||||
}
|
||||
return "\""+tmpStr+"\"";
|
||||
}
|
||||
|
||||
|
||||
private Dictionary<string, string> moveFieldDictionary(string inFil)
|
||||
{
|
||||
Dictionary<string, string> tmpDic = new Dictionary<string, string>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user