End Google Ads 201810 - BS.net 01 --> Hi,

I have created one program in c# console. But I am not getting all the values. Can anybody please look into the code where it is not working. The code actually generates one text file after reading from other two files. If somebody is interested I can send the two files to the email address. Code is listed as below:

using System;

using System.Collections;

using System.Reflection;

using System.Data;

using System.IO;



namespace sam
{

class Program
{

private static string path1;

private static string path2;

private static string target;

private static string s_strApplicationPath;



[STAThreadAttribute()]

private static void Main(string[] args)
{

try
{

s_strApplicationPath = Environment.CurrentDirectory;

path1 = String.Concat(s_strApplicationPath, "\\Security.txt");

path2 = String.Concat(s_strApplicationPath, "\\Position.txt");

target = String.Concat(s_strApplicationPath, "\\Price.txt");

DataTable dataTable1 = new DataTable("Security");

DataTable dataTable2 = new DataTable("Position");



if (File.Exists(path1))
{

dataTable1 = ReadFromFile(path1, 0);

}

else
{

Console.WriteLine("The Security file is not available in the Application Directory");

Console.WriteLine("OPERATION INCOMPLETE !");

}

if (File.Exists(path2))
{

dataTable2 = ReadFromFile(path2, 1);

}

else
{

Console.WriteLine("The Position file is not available in the Application Directory");

Console.WriteLine("OPERATION INCOMPLETE !");

}

if (File.Exists(target))
{

File.Delete(target);

}

WriteToFile(target, dataTable1, dataTable2);

Console.WriteLine("PRICE FILE GENERATED SUCESSFULLY !");

}

catch (FileNotFoundException e1)
{

string str1 = e1.Message.ToString();

if (str1 == "File or assembly, or one of its dependencies, was not found.")
{

str1 = "File or assembly is not available in the Application Directory.";

}

Console.WriteLine(str1);

}

catch (Exception e2)
{

Console.WriteLine(e2.Message.ToString());

}

}

public static DataTable ReadFromFile(string FilePath, int intType)
{

DataTable dataTable;



dataTable = new DataTable("Security");

int i = 0;

if (intType == 0)
{

DataColumn dataColumn = new DataColumn("securitytype", Type.GetType("System.String"));

dataTable.Columns.Add(dataColumn);

dataColumn = new DataColumn("SecurityCode", Type.GetType("System.String"));

dataTable.Columns.Add(dataColumn);

dataColumn = new DataColumn("SecurityDesc", Type.GetType("System.String"));

dataTable.Columns.Add(dataColumn);

i = 24;

}

else
{

DataColumn dataColumn = new DataColumn("SecurityCode", Type.GetType("System.String"));

dataTable.Columns.Add(dataColumn);

dataColumn = new DataColumn("Date", Type.GetType("System.String"));

dataTable.Columns.Add(dataColumn);

dataColumn = new DataColumn("Units", Type.GetType("System.Double"));

dataTable.Columns.Add(dataColumn);

dataColumn = new DataColumn("MarketValue", Type.GetType("System.Double"));

dataTable.Columns.Add(dataColumn);

i = 15;

}

char[] chs = "\t".ToCharArray();

try
{

TextReader textReader = new StreamReader(FilePath);

string str = textReader.ReadLine();

if (str.IndexOf("\t") > 0)
{

chs = "\t".ToCharArray();

}

else
{

chs= " ".ToCharArray();

}

if (chs[0].ToString() == " ")
{

bool flag1 = true;

while (flag1)
{

if (str.IndexOf(" ") > 0)
{

str = str.Replace(" ", " ");

}

else
{

flag1 = false;

}

}

}

while (str != null)
{

DataRow dataRow = dataTable.NewRow();

string[] strs = str.Split(chs, i);

if (intType == 0)
{

dataRow["securitytype"] = strs[0];

dataRow["SecurityCode"] = strs[1];

dataRow["SecurityDesc"] = strs[2];

}

else
{
dataRow["SecurityCode"] = strs[4];
dataRow["Date"] = strs[5];
dataRow["Units"] = strs[6];
dataRow["MarketValue"] = strs[10];
}

dataTable.Rows.Add(dataRow);

str = textReader.ReadLine();

if (chs[0].ToString() == " " && str!= null)
{

bool flag2 = true;

while (flag2)
{

if (str.IndexOf(" ") > 0)
{

str = str.Replace(" ", " ");

}

else
{

flag2 = false;

}

}

}

}

return dataTable;

}

catch (Exception e)
{

throw e;

}

}

public static void WriteToFile(string FilePath, DataTable dtSecurity, DataTable dtPosition)
{

try
{

TextWriter textWriter = new StreamWriter(target, false);

IEnumerator iEnumerator1 = dtSecurity.Rows.GetEnumerator();

try
{

while (iEnumerator1.MoveNext())
{

string str4;

DataRow dataRow1 = (DataRow)iEnumerator1.Current;

string str1 = dataRow1["SecurityCode"].ToString();

string str2 = dataRow1["securitytype"].ToString();

string str8 = dataRow1["securityDesc"].ToString();

double d1 = 0.0;

double d2 = 0.0;

double d3 = 0.0;

IEnumerator iEnumerator2 = dtPosition.Rows.GetEnumerator();

try
{

DataRow dataRow2;

while (iEnumerator2.MoveNext())
{

dataRow2 = (DataRow)iEnumerator2.Current;

if (str8 == dataRow2["Securitycode"].ToString())
{

d1 += (double)dataRow2["MarketValue"];

d2 += (double)dataRow2["Units"];

//break;

}

if (str1 == dataRow2["SecurityCode"].ToString())
{

d1 += (double)dataRow2["MarketValue"];

d2 += (double)dataRow2["Units"];

break;

}

}

}

finally
{

IDisposable iDisposable = iEnumerator2 as IDisposable;

if (iDisposable != null)
{

iDisposable.Dispose();

}

}
if ((str4 = str2.ToUpper()) == null)
//if ((str4 = str8.ToUpper()) == null)
{
goto IL_01d5;

}

str4 = String.IsInterned(str4);

if (str4 == "CBUS")
{

goto IL_0163;

}

if (str4 == "GBUS")
{

goto IL_0176;

}

if (str4 == "MBUS")
{

goto IL_0189;

}

if (str4 == "BMUS")
{

goto IL_019c;

}

if (str4 == "GMUS")
{

goto IL_01af;

}

if (str4 != "FMUS")
{

goto IL_01d5;

}

else
{

d3 = 100.0 * (d1 / d2);

}

goto IL_01dc;



IL_01d5:

d3 = d1 / d2;

goto IL_01dc;

IL_0163:

d3 = 100.0 * (d1 / d2);

goto IL_01dc;

IL_0176:

d3 = 100.0 * (d1 / d2);

goto IL_01dc;
IL_0189:

d3 = 100.0 * (d1 / d2);

goto IL_01dc;

IL_019c:

d3 = 100.0 * (d1 / d2);

goto IL_01dc;

IL_01af:

d3 = 100.0 * (d1 / d2);

IL_01dc:

if (d3 > 0.0)
{

string str3 = String.Concat(new string[] { dataRow1["securitytype"].ToString(), "\t", dataRow1["Securitycode"].ToString(), "\t", d3.ToString(), "\t\t2" });

textWriter.WriteLine(str3);

textWriter.Flush();

}

}

}

finally
{

IDisposable iDisposable = iEnumerator1 as IDisposable;

if (iDisposable != null)
{

iDisposable.Dispose();

}

}

textWriter.Close();

textWriter = null;

return;

}

catch (Exception e)
{

throw e;

}

}



}

}

Regards,
Samrat