Re: My First C# (warning - long post)



On Feb 1, 4:29 am, LX-i <lxi0...@xxxxxxxxxxxx> wrote:
andrewmcdonagh wrote:
Ok, so I downloaded and installed vs2005 express, loaded your class
and started using the 'refactoring -> extract method' right click menu
option....

Here's what I've got so far....(if you paste it into your
vs2005...you'll need to spend a few minutes sorting out the line wraps
that posting it to here causes...)

Very cool. I'll be going from this (probably shortening some of those
method names), but I like it. :)


snipped...

Hi,

So here's the next instalment - not a big change (haven't had the time
over the weekend).

So the conversation about the keywords drew my attention to it
properly for the first time...as I was looking at the large methods
before. Once saw what the array was being used for and the
'isCobolKeyword()' method, I saw that here was one of our first
Responsabilities that needs to be pulled out into its own class. As
you had already created the private method 'isCobolKeyword()' this was
even easier for me than other refactrings. It also shows that you are
already looking at the design with a view to creating discrete logical
parts.

So the refactoring I did was....

1) Create a new Interface called 'KeywordDictionary'
with a single method 'isKeyword(String keyword)

2) Create a new Class called CobolKeywordDictionary
2.1) Copied the large keyword array into this new class.
2.2) Copied the 'isCobolKeyword(String ictText) method into this new
class.
2.3) Changed the copied method's name to match the Interface's
method (i.e 'isKeyword(String ictText)' )
2.4) Renamed the method parameter to be more self commenting:
'ictText' became 'keyword'

Note: At this point, I haven't changed a single line of the
CodeStatistics class, and so it STILL compiles and works!

3) Create a new member variable within CodeStatistics class, like so:

private KeywordDictionary keywordDictionary = new
CobolKeywordDictionary();

4) Searched through CodeStatistics class for all usages of its own
'isCobolKeyword(xyz)' and replaced it with
'keywordDictionary.isKeyword(xyz) '

5) Now the CodeStatistics own keyword array and its 'isCobolKeyword'
methods are unused, and so we delete them.

All along, through out this refactoring, the code continued to build
and work. And making the switch from old to new was the last step.

So, you might ask 'why the interface?' good question!

There is no current need for it, but my OO and Unit testing sense
tends to say create an interface more often than not - it will pay for
itself sooner rather than later.
Besides, Interfaces do not incur any runtime performance costs (that
are worth caring about).

What i mean about OO sense, is that now we have separated the
Responsibility of specifying what a KeywordDictionary 'is', compared
to its implementation - CobolKeywordDictionary in our case, or later,
HtmlKeywordDictionary, JavaKeywordDictionary, etc....

From a unit testing sense, it means I can write a unit test for my
CobolKeywordDictionary, by using the class directly, I dont need to
test it, by creating an instance of something that just happens to use
it (CodeStatistics in our case).

HTH

Andrew

---------------------------------------------------------------------------------

The latest code:


using System;
using System.Collections.Generic;
using System.Text;

namespace CodeStats
{

interface KeywordDictionary
{
bool isKeyword(String keyword);
}
}


----------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;

namespace CodeStats
{
class CobolKeywordDictionary : KeywordDictionary
{

private String[] cobolKeywords =
{"ACCEPT",........snipped...to save space

"ZEROS","+","-","*","/","**",">","<","=",">=","<="};

public bool isKeyword(String keyword)
{
Int32 i = 0;
while ((i < cobolKeywords.Length) && (keyword !=
cobolKeywords[i]))
{
i++;
}
if (i < cobolKeywords.Length)
{
return (true);
}
else
{
return (false);
}
}
}
}




----------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Text;

namespace CodeStats
{
public class CodeStatistics
{
// Properties (public instance variables)
bool updatedStats = false;
String elementId = "";
int locTotal = 0;
int locExecutable = 0;
int locCommented = 0;

// Private instance variables
protected SqlConnection dbConn;
protected SqlConnection dbHelp;
protected char elementType = ' ';
protected String elementSubType = "";
protected String fileName = "";
protected bool inComment = false;
protected List<String> programID = new List<String>();

private KeywordDictionary keywordDictionary = new
CobolKeywordDictionary();

// Constuctor for no parameter
public CodeStatistics(String csServerName)
{
openSqlConnection(csServerName);
}

// Constructor for passed Element ID
public CodeStatistics(String csServerName, String csElementId)
{
openSqlConnection(csServerName);
retrieveElementInfo(csElementId);
}

// Establish the element for this class instance
public void retrieveElementInfo(String reiElementId)
{
// Retrieve the information about the passed program
SqlCommand cmd = new SqlCommand("SELECT element_id,
element_type, element_subtype, server_name "
+ "FROM active_elements "
+ "WHERE element_id = '" + reiElementId.Trim() + "'",
dbConn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
elementType =
Convert.ToChar(dr["element_type"].ToString().Trim().Substring(0, 1));
elementSubType =
dr["element_subtype"].ToString().Trim();
fileName = dr["server_name"].ToString().Trim();
elementId = reiElementId;
}
dr.Close();
dr.Dispose();
}

// Update the statistics for the element ID
public void updateStatistics(String usPath, String
usProcessName)
{
if (File.Exists(usPath + fileName))
{
String textLine = "";

clearOutCrossReferenceTables();

textLine = parseFile(usPath, usProcessName, textLine);


deleteAnyReferencesToCallsIfTheTargetIsDefinedInTheProgram();

updateLocInTheCscsDatabase();
}
}

private void updateLocInTheCscsDatabase()
{
// Update LOC in the CSCS database
SqlCommand sc = new SqlCommand("UPDATE Active_Elements "
+ "SET Commented_Lines = " +
locCommented.ToString()
+ ", Executable_Lines = " +
locExecutable.ToString()
+ ", Total_Lines = " + locTotal.ToString()
+ "WHERE Element_ID = '" + elementId + "'", dbConn);
sc.ExecuteNonQuery();
sc.Dispose();
}

private void
deleteAnyReferencesToCallsIfTheTargetIsDefinedInTheProgram()
{
if (programID.Count > 0)
{ // Delete any references to calls if the target is
defined in the program (i.e., nested subprograms)
SqlCommand scDelete = new SqlCommand();

scDelete.CommandText = "DELETE FROM sdp_CSCI_CALL_Xref
"
+ "WHERE Element_ID = '" + elementId + "' "
+ "AND Call_Name IN ('";
for (int i = 0; i < programID.Count; i++)
{
scDelete.CommandText += programID[i] + "'";
if (i < (programID.Count - 1))
{
scDelete.CommandText += ",'";
}
}
scDelete.CommandText += ")";
scDelete.Connection = dbConn;
scDelete.ExecuteNonQuery();
scDelete.Dispose();
}
}

private String parseFile(String usPath, String usProcessName,
String textLine)
{
StreamReader file = File.OpenText(usPath + fileName);

while (!file.EndOfStream)
{
textLine = file.ReadLine().ToUpper();

if ((elementType != 'P') && (elementType != 'L'))
{
textLine = textLine.Trim();
}

countLine(textLine); // Count this line as a "line of
code"

switch (elementType)
{
case 'P':
case 'L':
textLine = textLine.Replace(",", "
").Replace(".", " ").Trim();
updateProcXref(textLine);
updateRejectXref(textLine, usProcessName);
updateCallXref(textLine);
//updateCull(textLine);
break;
}

}

file.Close();
file.Dispose();
return textLine;
}

private void clearOutCrossReferenceTables()
{
// Depending on the type, clear out the cross-reference
tables
switch (elementType)
{
case 'P':
case 'L':
SqlCommand scDel = new SqlCommand();
scDel.Connection = dbConn;

// Delete item/proc xref
scDel.CommandText = "DELETE FROM Proc_Prog_Xref
WHERE ProgName = '" + elementId + "'";
scDel.ExecuteNonQuery();

// Delete item/reject xref
scDel.CommandText = "DELETE FROM RejectsXref WHERE
program = '" + elementId + "'";
scDel.ExecuteNonQuery();

// Delete item/call xref
scDel.CommandText = "DELETE FROM
sdp_CSCI_Call_Xref WHERE Element_ID = '" + elementId + "'";
scDel.ExecuteNonQuery();

// Delete cull information
scDel.CommandText = "DELETE FROM sdp_Dbe_Csci_Xref
WHERE CSCI = '" + elementId + "'";
scDel.ExecuteNonQuery();
scDel.CommandText = "DELETE FROM sdp_Dbr_Csci_Xref
WHERE CSCI = '" + elementId + "'";
scDel.ExecuteNonQuery();

scDel.Dispose();
break;
}
}

protected void countLine(String clLine)
{
String commentStart = "";
String commentEnd = "";
String commentSingle = "";

// A line is a line...
locTotal++;

if (clLine != "")
{
switch (elementType)
{
case 'P':
case 'L':
lineOfCobolCode(clLine);
break;

case 'G':
linesOfGuiCode(clLine, ref commentStart, ref
commentEnd, ref commentSingle);
break;

case 'R':
linesOfRunstreamsCode(clLine);
break;

case 'Q':
linesOfIquRunstreamsCode(clLine);
break;

default:
// Anything else, a non-blank line is
executable
locExecutable++;
break;
}
}
}

private void linesOfIquRunstreamsCode(String clLine)
{
// IQ/U Runstreams
if (clLine.Substring(0, 1) == ".")
{
locCommented++;
}
else
{
locExecutable++;
}
}

private void linesOfRunstreamsCode(String clLine)
{
// Runstreams
if ((elementSubType == "IPF") && (clLine.Substring(0, 1)
== "@"))
{ // IPF comment character
locCommented++;
}
else
{
if ((elementSubType == "QLP") && (clLine.Substring(0,
1) == "*"))
{ // QLP comment character
locCommented++;
}
else
{ // Apply ECL comment rules
if ((clLine.Length > 2) && ((clLine.Substring(0,
3) == "@ .") || (clLine.Substring(0, 3) == "@. ")))
{ // ECL comment character
locCommented++;
}
else
{
locExecutable++;
}
}
}
}

private void linesOfGuiCode(String clLine, ref String
commentStart, ref String commentEnd, ref String commentSingle)
{
determineLanguageCommentTags(ref commentStart, ref
commentEnd, ref commentSingle);

if ((commentStart == "") && (commentEnd == "") &&
(commentSingle == ""))
{ // We don't look for comments - if it's not blank,
it's executable
locExecutable++;
}
else
{
if (inComment)
{ // We're in a multi-line comment
locCommented++;
if (clLine.IndexOf(commentEnd) >= 0)
{ // This is the last line of the multi-line
comment
inComment = false;
}
}
else
{
if (clLine.IndexOf(commentStart) >= 0)
{
countNewMultiLineComment(clLine, commentStart,
commentEnd);
}
else
{
countSingleLineComments(clLine,
commentSingle);
}
}
}
}

private void countNewMultiLineComment(String clLine, String
commentStart, String commentEnd)
{
if (clLine.IndexOf(commentEnd) == -1)
{ // Start of a multi-line comment
inComment = true;
}
if ((clLine.IndexOf(commentStart) == 0))
{ // Nothing before the comment - the entire line is
commented
locCommented++;
}
else
{ // Something before the comment - count the line as
executable
locExecutable++;
}
}

private void countSingleLineComments(String clLine, String
commentSingle)
{
if ((commentSingle != "") &&
(clLine.IndexOf(commentSingle) >= 0))
{
if (clLine.IndexOf(commentSingle) == 0)
{ // The entire line is a comment
locCommented++;
}
else
{ // Only the end of the line is commented
locExecutable++;
}
}
else
{
locExecutable++;
}
}

private void determineLanguageCommentTags(ref String
commentStart, ref String commentEnd, ref String commentSingle)
{
// GUI
if ((elementSubType == "HTML") || (elementSubType ==
"CSS") || (elementSubType == "XML"))
{
commentStart = "<!--";
commentEnd = "-->";
}
else
{
if (elementSubType == "XSLT")
{
commentStart = "<xsl:comment>";
commentEnd = "</xsl:comment>";
}
else
{
if (elementSubType == "JS")
{
commentStart = "/*";
commentEnd = "*/";
commentSingle = "//";
}
}
}
}

private void lineOfCobolCode(String clLine)
{
// COBOL
if ((clLine.Length > 6) && (clLine.Substring(6, 1) ==
"*"))
{
locCommented++;
}
else
{
locExecutable++;
}
}

protected void updateProcXref(String upxLine)
{
// For this to work right, we need all items separated by
only one space
upxLine = normalizeSpace(upxLine);

switch (elementType)
{
case 'P':

establishTheCrossReferenceBasedOnCopyStatement(upxLine);
break;

case 'L':

establishTheCrossReferenceBasedOnPerformStatement(upxLine);
break;
}
}

private void
establishTheCrossReferenceBasedOnPerformStatement(String upxLine)
{
// Establish the cross-reference based on perform
statement
if ((upxLine.Length > 9) && (upxLine.Substring(0, 8) ==
"PERFORM "))
{
String[] words = upxLine.Split(' ');
String[] pieces = words[1].Split('-');

// Don't count performs of the proc itself
if ((pieces[0] != elementId) &&
(isElement(pieces[0])))
{ // See if this is already in the xref
SqlCommand scCheck = new SqlCommand("SELECT
ProgName FROM Proc_Prog_Xref "
+ "WHERE ProgName = '" + elementId + "' "
+ "AND ProcName = '" + pieces[0] + "'",
dbConn);
SqlDataReader drCheck = scCheck.ExecuteReader();
if (!drCheck.HasRows)
{
executeSQL("INSERT INTO Proc_Prog_Xref "
+ "(ProgName, ProcName, Passive,
EntryPoint) "
+ "VALUES ('" + elementId + "','"
+ pieces[0] + "',1,NULL)");
}
drCheck.Close();
drCheck.Dispose();
scCheck.Dispose();
}
}
}

private void
establishTheCrossReferenceBasedOnCopyStatement(String upxLine)
{
// Establish the cross-reference based on copy statement
if ((upxLine.Length > 6) && (upxLine.Substring(0, 5) ==
"COPY "))
{
String[] words = upxLine.Split(' ');
String[] pieces = words[1].Split('-');

if (isElement(pieces[0]))
{ // See if this is already in the cross-reference
SqlCommand scCheck = new SqlCommand("SELECT
ProgName FROM Proc_Prog_Xref "
+ "WHERE ProgName = '" + elementId + "' "
+ "AND ProcName = '" + pieces[0] + "' "
+ "AND EntryPoint = '" + words[1] + "'",
dbConn);
SqlDataReader drCheck = scCheck.ExecuteReader();
if (!drCheck.HasRows)
{ // Add this program/proc to the table
executeSQL("INSERT INTO Proc_Prog_Xref "
+ "(ProgName, ProcName, Passive,
EntryPoint) "
+ "VALUES ('" + elementId + "','" +
pieces[0] + "',0,'" + words[1] + "')");
}
drCheck.Close();
drCheck.Dispose();
scCheck.Dispose();
}
}
}

protected void updateRejectXref(String urxLine, String
urxProcessName)
{
Int32 rejectCode;

// Get rid of extra spaces
urxLine = normalizeSpace(urxLine);

if ((urxLine.IndexOf("REJCDE") >= 0) &&
(urxLine.IndexOf("MOVE ") >= 0))
{ // Line is "MOVE [something] TO REJCDE"
String[] words = urxLine.Split(' ');
if (Int32.TryParse(words[1], out rejectCode))
{
// Mask off narratives to get the lowest 4 digits
rejectCode = rejectCode % 10000;

if (rejectCode > 0)
{ // Is this reject already in the xref?
SqlCommand scCheck = new SqlCommand("SELECT
program FROM RejectsXref "
+ "WHERE program = '" + elementId + "' "
+ "AND reject_num = " +
rejectCode.ToString(), dbConn);
SqlDataReader drCheck =
scCheck.ExecuteReader();
if (!drCheck.HasRows)
{ // Insert it
executeSQL("INSERT INTO RejectsXref "
+ "(program, reject_num, last_updated,
last_updated_by) "
+ "VALUES ('" + elementId + "'," +
rejectCode.ToString()
+ ",current_timestamp,'" +
urxProcessName + "')");
}
drCheck.Close();
drCheck.Dispose();
scCheck.Dispose();
}
}
}
}

protected void updateCallXref(String ucxLine)
{
String[] words = normalizeSpace(ucxLine).Split(' ');

// Check for "PROGRAM-ID"
if (words[0] == "PROGRAM-ID")
{ // Save these off - we'll delete them at the end
programID.Add(words[1]);
}

if ((words.Length > 1) && (words[0] == "CALL"))
{
if ((words[1].Substring(0, 1) == "\"") ||
(words[1].Substring(0, 1) == "'"))
{ // Calling a literal - this is one we'll store
String callName = words[1].Substring(1,
words[1].Length - 2);

SqlCommand scCheck = new SqlCommand("SELECT
Element_ID FROM sdp_CSCI_CALL_Xref "
+ "WHERE Element_ID = '" + elementId + "' "
+ "AND Call_Name = '" + callName + "'",
dbConn);
SqlDataReader drCheck = scCheck.ExecuteReader();
if (!drCheck.HasRows)
{ // It's not there - insert it
executeSQL("INSERT INTO sdp_CSCI_CALL_Xref "
+ "(Element_ID, Call_Name) "
+ "VALUES ('" + elementId + "','" +
callName + "')");
}
drCheck.Close();
drCheck.Dispose();
scCheck.Dispose();
}
}
}

protected void updateCull(String ucLine)
{
ucLine = normalizeSpace(ucLine);

if ((ucLine.IndexOf("FETCH ") >= 0) ||
(ucLine.IndexOf("FIND ") >= 0)
|| (ucLine.IndexOf("MODIFY ") >= 0) ||
(ucLine.IndexOf("STORE ") >= 0)
|| (ucLine.IndexOf("DELETE ") >= 0) ||
(ucLine.IndexOf("INSERT ") >= 0)
|| (ucLine.IndexOf("REMOVE ") >= 0))
{
updateCullRecord(ucLine);
}
else
{

splitUpTheWordsAndCheckForDmsFieldNameOrRprocDataName(ucLine);
}
}

private void
splitUpTheWordsAndCheckForDmsFieldNameOrRprocDataName(String ucLine)
{
// Split up the words, and check for a DMS field name or R-
proc data name
String[] words = ucLine.Split(' ');
for (int i = 0; i < words.Length; i++)
{
if ((! keywordDictionary.isKeyword(words[i])) && (!
hasSymbols(words[i])))
{
updateCullItem(words[i], ucLine);
}
}
}

// Update DML records in cull
protected void updateCullRecord(String ucrLine)
{
String[] words = ucrLine.Split(' ');
Int32 word = 0;
String column = "";

// --- CHECK #1 --- record name //

checkRecordName(words, ref word, ref column);

// --- CHECK #2 --- set name //

checkSetname(ucrLine, words, ref word, ref column);
}

private void checkSetname(String ucrLine, String[] words, ref
Int32 word, ref String column)
{
if ((ucrLine.IndexOf(" SET") >= 0) ||
(ucrLine.IndexOf("VIA ") >= 0))
{
String setName = "";

// Find the word "via" or "set"
word = 0;
while ((words[word] != "VIA") && (words[word] !=
"SET"))
{
word++;
}

if ((words[word] == "SET") && (word > 0))
{ // "FETCH xxx WITHIN xxxx SET", "REMOVE xxxx FROM
xxxxx SET", etc.
setName = words[--word];
}
else
{
if ((words[word] == "VIA") && (word <
(words.Length - 1)))
{ // "FETCH xxx VIA xxxx USING xxxx" format
statement
setName = words[++word];
}
}

if (setName != "")
{
// Is this a valid set name?
SqlCommand scSetChk = new SqlCommand("SELECT
set_name FROM dms_sets "
+ "WHERE set_name = '" + setName + "'",
dbHelp);
SqlDataReader drSetChk = scSetChk.ExecuteReader();

if (drSetChk.HasRows)
{
// What column name do we update?
column = "";

if ((ucrLine.IndexOf("FETCH ") >= 0) ||
(ucrLine.IndexOf("FIND ") >= 0))
{
column = "Fetches";
}
else
{
if (ucrLine.IndexOf("INSERT") >= 0)
{
column = "Inserts";
}
else
{
if (ucrLine.IndexOf("REMOVE") >= 0)
{
column = "Removes";
}
}
}

if (column != "")
{ // Does it already exist in the cross-
reference?
SqlCommand scCheck = new
SqlCommand("SELECT Dbr FROM sdp_Dbr_Csci_Xref "
+ "WHERE Dbr = '" + setName + "'",
dbConn);
SqlDataReader drCheck =
scCheck.ExecuteReader();

if (!drCheck.HasRows)
{ // Insert a new blank row
SqlCommand scInsert = new
SqlCommand("INSERT INTO sdp_Dbr_Csci_Xref "
+ "(Dbr, Csci, Fetches, Modifies,
Inserts, Stores, Removes, Deletes) "
+ "VALUES ('" + setName + "','" +
elementId + "',0,0,0,0,0,0)", dbConn);
scInsert.ExecuteNonQuery();
scInsert.Dispose();
}

drCheck.Close();
drCheck.Dispose();
scCheck.Dispose();

SqlCommand scUpdate = new
SqlCommand("UPDATE sdp_Dbr_Csci_Xref "
+ "SET " + column + " = " + column + "
+ 1 "
+ "WHERE Dbr = '" + setName + "' "
+ "AND Csci = '" + elementId +
"'", dbConn);
scUpdate.ExecuteNonQuery();
scUpdate.Dispose();
}
}

drSetChk.Close();
drSetChk.Dispose();
scSetChk.Dispose();
}
}
}

private void checkRecordName(String[] words, ref Int32 word,
ref String column)
{
// Find the word where we're doing the DML
while ((words[word] != "FETCH") && (words[word] != "FIND")
&& (words[word] != "MODIFY") && (words[word] !=
"STORE")
&& (words[word] != "DELETE") && (words[word] !=
"INSERT")
&& (words[word] != "REMOVE") && (word < words.Length))
{
word++;
}

if ((word < (words.Length - 2))
&& ((words[word + 1] == "FIRST") || (words[word + 1]
== "NEXT")
|| (words[word + 1] == "PRIOR") || (words[word +
1] == "LAST")))
{ // "FETCH FIRST xxx", etc.
word++;
}

if ((word < (words.Length - 2)) && (words[word + 1] !=
"RECORD"))
{
// Determine the proper column name
if ((words[word] == "FETCH") || (words[word] ==
"FIND"))
{
column = "Fetches";
}
else
{
if (words[word] == "MODIFY")
{
column = "Modifies";
}
else
{
column = words[word].ToLower() + "s";
}
}

// The next word may be a record name
String recordName = words[++word];

// Is this name a valid record?
SqlCommand scRecChk = new SqlCommand("SELECT
record_name FROM dms_records "
+ "WHERE record_name = '" + recordName + "'",
dbHelp);
SqlDataReader drRecChk = scRecChk.ExecuteReader();

if (drRecChk.HasRows)
{ // Does the record already exist in the cross-
reference?
SqlCommand scCheck = new SqlCommand("SELECT CSCI
FROM sdp_Dbr_Csci_Xref "
+ "WHERE Dbr = '" + recordName + "' "
+ "AND Csci = '" + elementId + "'",
dbConn);
SqlDataReader drCheck = scCheck.ExecuteReader();

if (!drCheck.HasRows)
{ // Add a new zeroed-out row
SqlCommand scInsert = new SqlCommand("INSERT
INTO sdp_Dbr_Csci_Xref "
+ "(Dbr, Csci, Fetches, Modifies, Inserts,
Stores, Removes, Deletes) "
+ "VALUES ('" + recordName + "','" +
elementId + "',0,0,0,0,0,0)", dbConn);
scInsert.ExecuteNonQuery();
scInsert.Dispose();
}

drCheck.Close();
drCheck.Dispose();
scCheck.Dispose();

// Update this count
SqlCommand scUpdate = new SqlCommand("UPDATE
sdp_Dbr_Csci_Xref "
+ "SET " + column + " = " + column + " + 1 "
+ "WHERE Dbr = '" + recordName + "' "
+ "AND Csci = '" + elementId + "'",
dbConn);
scUpdate.ExecuteNonQuery();
scUpdate.Dispose();
}

drRecChk.Close();
drRecChk.Dispose();
scRecChk.Dispose();
}
}

protected void updateCullItem(String uciWord, String uciLine)
{
bool used = false;
bool updated = false;

// Check to see if the word starts with "R" and has a
dash, and is not this proc
if ((uciWord.Substring(0, 1) == "R")
&& (uciWord.Substring(3, 1) == "-")
&& (uciWord.Substring(0, 4) != elementId))
{
if (uciLine.IndexOf("PERFORM") >= 0)
{ // We've got a paragraph name performed
SqlCommand scTables = new SqlCommand("SELECT
DISTINCT table_name rt "
+ "FROM rdms_tables rt, rdms_table_columns rtc
"
+ "WHERE rt.table_name = rtc.table_name "
+ "AND rtc.r_proc_element_name LIKE '"
+ uciWord.Substring(0, 4) + "%'", dbHelp);
SqlDataReader drTables = scTables.ExecuteReader();

while (drTables.HasRows)
{ // See if this table already exists in the
cull look-up
int i = 0; // !WORK this is crap
}
}
else
{
if (uciLine.IndexOf("MOVE") >= 0)
{
if (uciLine.IndexOf("TO") >
uciLine.IndexOf(uciWord))
{
used = true;
}
else
{
updated = true;
}
}
else
{
updated = true;
}
}
}
else
{ // See if the word is a valid DMS field
}
}

// Establish connections with the database
protected void openSqlConnection(String oscServerName)
{
String connString = "";

if (oscServerName == "")
{
oscServerName = "[servername]";
}

connString = "server=" + oscServerName +
";database=[database];User ID=[user];Password=[password];";
dbConn = new SqlConnection(connString);
dbConn.Open();

connString = connString.Replace("[database]", "[another-
database]");
dbHelp = new SqlConnection(connString);
dbHelp.Open();
}

public String cscsRegValue(String crvKey)
{
SqlCommand crvCmd = new SqlCommand("SELECT reg_value "
+ "FROM sdp_registry "
+ "WHERE reg_key = '" + crvKey + "'", dbConn);
SqlDataReader crvDR = crvCmd.ExecuteReader();
if (crvDR.Read())
{
return (crvDR["reg_value"].ToString().Trim());
}
else
{
return ("");
}
}

protected void executeSQL(String esText)
{
SqlConnection esConn = new
SqlConnection(dbConn.ConnectionString + "password=[password];");
SqlCommand esCmd = new SqlCommand(esText, esConn);
esConn.Open();
esCmd.ExecuteNonQuery();
esCmd.Dispose();
esConn.Close();
esConn.Dispose();
}

// Eliminates all embedded spaces more than one
protected String normalizeSpace(String nsText)
{
String workText = nsText;

while (workText.IndexOf(" ") >= 0)
{
workText = workText.Replace(" ", " ");
}
return (workText);
}

// Returns "true" if the text passed is an element in CSCS
protected bool isElement(String ieText)
{
Boolean itExists = false;

SqlCommand ieCmd = new SqlCommand("SELECT Actv_Ind FROM
Active_Elements "
+ " WHERE Element_ID = '" + ieText + "'", dbConn);
SqlDataReader ieDR = ieCmd.ExecuteReader();
if (ieDR.HasRows)
{
itExists = true;
}
ieDR.Close();
ieDR.Dispose();
ieCmd.Dispose();

return (itExists);
}



// Returns "true" if the words passed has symbols in it
protected bool hasSymbols(String hsText)
{
if ((hsText.IndexOf("(") >= 0) || (hsText.IndexOf(")") >=
0)
|| (hsText.IndexOf("\"") >= 0) || (hsText.IndexOf("'")
= 0)
|| (hsText.IndexOf("_") >= 0))
{
return (true);
}
else
{
return (false);
}
}

}

}






.



Relevant Pages

  • Re: newbie: string reference
    ... what you hope to do with string references, ... private void MyMethod ...
    (microsoft.public.dotnet.languages.csharp)
  • C# Event Handlers For Dynamically Created DropDownLists
    ... Problem - when the user selection is extracted form the dropdownlists ... private void Page_Load ... private void btnLoadDb_Click(object sender, System.EventArgs e) ... string dbFileDestination = Path.Combine; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# Retain PlaceHolder ViewState
    ... the dropdownlists. ... Object reference not set to an instance of an object. ... sourceControl, String eventArgument) ... private void Page_Load ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how can I get url of page ASPNET C#
    ... public string UrlBaner ... protected HtmlGenericControl DivEuroAdresBaner; ... private void Page_Load ... flashParem += "English*http://www.euroadres.pl/zmienjezyk.aspx*2 |"; ...
    (microsoft.public.dotnet.framework.aspnet)
  • The Source Code without extraneous bits
    ... private void buttonRunProgram_Click ... private void addThreadToThreadWatch(Thread t, string ... TextWriter tmpFileWriter = new ... string strFileName; ...
    (microsoft.public.dotnet.languages.csharp)