save codefile as dif ...

This commit is contained in:
2015-01-20 22:59:42 +01:00
parent ddca2f7929
commit 44cbf368b6

View File

@ -17,6 +17,7 @@ namespace CobXmlSupport
{
public readonly string CSV = ".csv";
public readonly string DIF = ".dif";
string oldTxt;
bool bSynch;
@ -90,11 +91,12 @@ namespace CobXmlSupport
{
Dictionary<string, string> wrkDic = null;
string codeComplement = "", fieldCompl = "", codeComplInit = "";
int actRows = 0;
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(".")) + CSV;
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;
//string codeFile = inFile.Substring(0, inFile.LastIndexOf(".")) + CSV;
string codeFile = inFile.Substring(0, inFile.LastIndexOf(".")) + DIF;
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))
{
@ -102,7 +104,8 @@ namespace CobXmlSupport
}
if (codeComplement.Length > 0)
{
wrkDic = moveFieldDictionary(codeComplement);
// wrkDic = moveFieldDictionary(codeComplement);
wrkDic = moveDifFieldDictionary(codeComplement);
}
foreach (CobRow cr in parentWindow.RowList)
{
@ -119,13 +122,41 @@ namespace CobXmlSupport
cr.MoveCode = deQuote( fieldCompl);
}
}
codeComplInit += "-1,0\r\n";
codeComplInit += "BOT\r\n";
codeComplInit += "1,0\r\n";
if (cr.MoveCode == null)
codeComplInit += cr.FieldName + "\t" + " \r\n";
{
codeComplInit += enQuote(cr.FieldName) + "\r\n";
codeComplInit += "1,0\r\n";
codeComplInit += enQuote(" ") + "\r\n";
}
else
codeComplInit += cr.FieldName + "\t" + enQuote( cr.MoveCode.Replace("\r\n", "\n")) + "\r\n";
{
codeComplInit += enQuote(cr.FieldName) + "\r\n";
codeComplInit += "1,0\r\n";
codeComplInit += enQuote(cr.MoveCode.Replace("\r\n", "\n")) + "\r\n";
}
actRows++;
}
}
codeComplInit = "TABLE\r\n" +
"0,1\r\n" +
"\"EXCEL\"\r\n" +
"VECTORS\r\n" +
"0"+actRows.ToString()+"\r\n" +
"\"\"\r\n" +
"TUPLES\r\n" +
"0,2\r\n" +
"\"\"\r\n" +
"DATA\r\n" +
"0,0\r\n" +
"\"\"\r\n" +
codeComplInit+
"-1,0\r\n"+
"EOD\r\n";
string backupfile;
if (S.ettingUserCodeBcup)
{
@ -135,10 +166,10 @@ namespace CobXmlSupport
DateTime.Now.Day.ToString("00") + "T" +
DateTime.Now.Hour.ToString("00") +
DateTime.Now.Minute.ToString("00") +
DateTime.Now.Second.ToString("00") + CSV;
DateTime.Now.Second.ToString("00") + DIF;
}
else {
backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + ".backup"+CSV;
backupfile = inPath + inFile.Substring(0, inFile.LastIndexOf(".")) + ".backup"+DIF;
File.Delete(backupfile);
}
@ -208,6 +239,68 @@ namespace CobXmlSupport
return tmpDic;
}
private Dictionary<string, string> moveDifFieldDictionary(string inFil)
{
bool TABLE = false, VECTORS = false, TUPLES = false, DATA = false;
int rows = 0, rowCount = 0;
Dictionary<string, string> tmpDic = new Dictionary<string, string>();
string[] splits = { "\r\n" };
char[] csplit = {','};
string[] items = inFil.Split(splits, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < items.Count();i++ )
{
string item = items[i];
switch (item.ToUpper())
{
case "TABLE":
{
TABLE = true;
break;
}
case "VECTORS":
{
VECTORS = true;
string[] nums = items[i + 1].Split(csplit);
rows = int.Parse(nums[1]);
break;
}
case "TUPLES":
{
TUPLES = true;
break;
}
case "DATA":
{
DATA = true;
break;
}
case "BOT":
{
if (TABLE && VECTORS && TUPLES && DATA)
{
if (rowCount < rows)
{
tmpDic.Add(deQuote(items[i + 2]), items[i+4].Replace("\n", "\r\n"));
rowCount++;
i = i + 4;
}
}
break;
}
case "EOD":
{
i= items.Count();
break;
}
}
}
return tmpDic;
}
private void refreshWindow()
{
this.CodeShower.Text = "";