I have two DataTables.
distinct:
+-------+-------+
| host | count |
+-------+-------+
| comp1 | 2 |
+-------+-------+
| comp2 | 3 |
+-------+-------+
| comp3 | 2 |
+-------+-------+
t:
+----+-------+
| id | host |
+----+-------+
| 1 | comp1 |
+----+-------+
| 2 | comp2 |
+----+-------+
| 3 | comp1 |
+----+-------+
| 4 | comp3 |
+----+-------+
| 5 | comp1 |
+----+-------+
| 6 | comp3 |
+----+-------+
I want to remove all rows from t which contains the computername having less than 3 in count column in distinct table. The code:
for (int i = 0; i < distinct.Rows.Count; i++)
{
if (Convert.ToInt32(distinct.Rows[i][1]) < 3)
{
foreach (DataRow row in t.Select())
{
if (row[1].ToString() == distinct.Rows[i][0].ToString())
{
row.Delete();
}
}
}
}
But it does nothing. If I compare the content of t before the above code and after, it's just the same. what am I missing here?
Please refer following link
How To Compare and delete datatable row using C#
Related
I am having excel file like following structure:
ColA | ColB | ColC | ColD | ColE | ColF | ColG
1 | a | a | 23 | 12 | asd | 5
2 | s | v | 73 | 14 | qsd | 7
4 | t | b | 52 | 52 | avn |
2 | y | t | 13 | 71 | asx | 2
5 | d | e | 20 | 18 | vss |
1 | f | n | 63 | 72 | ann |
9 | g | a | 27 | 10 | aqz | 15
I want to read and get only those rows which does not have value in ColG.
I can iterate every rows and match each cell value of every row using following code:
for (int i = 0; i < rows.Count(); i++)
{
DataRow dataRow = dataTable.NewRow();
int cellCounter = 0;
foreach (Cell cell in rows.ElementAt(i))
{
dataRow[cellCounter] = GetCellValue(spreadSheetDocument, cell);
cellCounter++;
}
dataTable.Rows.Add(dataRow);
}
But it is very memory and time consuming process.
Can anyone help me out to achieve the same.
Thanks in advance.
For example,
using System;
using System.Collections;
namespace ConsoleApplication
{
class A : IEnumerable
{
B b;
public A()
{
b = new B();
}
public IEnumerator GetEnumerator()
{
yield return b.FunA(0);
yield return b.FunB(1);
yield return b.FunC(2);
yield return b.FunD(3);
yield return b.FunE(4);
}
}
class B
{
public int FunA(int x)
{
return x;
}
public int FunB(int x)
{
return x * 2;
}
public int FunC(int x)
{
return x * 3;
}
public int FunD(int x)
{
return x * 4;
}
public int FunE(int x)
{
return x * 5;
}
}
class Program
{
static void Main(string[] args)
{
var a = new A();
foreach(var number in a)
{
Console.WriteLine(number);
}
Console.ReadLine();
}
}
}
How to describe this program in sequence diagram?
I think it should be something similar to a loop or alt section like below.
+------------+ +------------+ +------------+
| Program | | A | | B |
+-----+------+ +------+-----+ +------+-----+
| | |
| | |
| | |
| | |
+-----+--------------------------------------------------------------+
|loop | | [0] | | |
+-----+ | | | |
| | | | |
| | | | |
| | | | |
+--------------------------------------------------------------------+
| | [1] | | |
| | | | |
| | | | |
| | | | |
| | | | |
+--------------------------------------------------------------------+
| | [2] | | |
| | | | |
| | | | |
| | | | |
| | | | |
+--------------------------------------------------------------------+
| | [3] | | |
| | | | |
| | | | |
| | | | |
| | | | |
+--------------------------------------------------------------------+
| | [4] | | |
| | | | |
| | | | |
| | | | |
| | | | |
+--------------------------------------------------------------------+
| | |
| | |
Edit:
I'm analyzing the source code of a plugin of Unity3D. IEnumerator and yield are used to implement a coroutine model. The coroutine is used as an alternative to the thread. So it IS reasonable to show the part of the logic of coroutine in the sequence diagram.
For sequence diagram you can define the loop(while loop) as far as yield keyword execution is concern please refer the below link
internals of C# interators
I think this link will help you to understand why the yield can be represented as loop.
I have been beating my head on this for awhile, this is in import form, it imports lines from a excel spreadsheet to a datagridview then allows the user to make sure changes if needed, then adds or updates the db lines.
I have included sample rows from the spreadsheet, and the part of the code that checks the lines. My issue is that 4 of the rows do not flag as prev. found no matter how many times you run it.
Any input?
Sample excel file:
+-------+----------+-----------+------------------+-------+------------+--------+------------------------+
| Trans | Eff Date | Policy # | Insured Name | PIF | GWP | Agent% | Agent NB Comm |
+-------+----------+-----------+------------------+-------+------------+--------+------------------------+
| AV | Jul-10 | 186990710 | FLORECE, BOB | 0 | 0.00 | 10.000 | 0.00 |
| AV | Jul-18 | 193214729 | CIRONIDA, JOHN A | 0 | 0.00 | 10.000 | 0.00 |
| CH | Jun-26 | 186990710 | FLORECE, BOB | 0 | 51.97 | 10.000 | 5.20 |
| CH | Jul-10 | 186990710 | FLORECE, BOB | 0 | (64.83) | 10.000 | (6.48) - NOT MATCHED |
| CH | Jul-10 | 186990710 | FLORECE, BOB | 1 | 272.19 | 10.000 | 27.22 |
| CH | Jul-01 | 192182230 | URZ, SUSAN A | 0 | (50.70) | 10.000 | (5.07) - NOT MATCHED |
| CH | Jul-09 | 193089995 | STOMPKINS, JIM | 0 | 45.37 | 10.00 | 4.54 |
| CH | Jul-18 | 193214729 | CIRONIDA, JOHN A | 1 | 125.99 | 10.000 | 12.60 |
| CH | May-15 | 196666151 | STROP, JONA | 0 | 13.40 | 10.000 | 1.34 |
| CH | May-15 | 196666151 | STROP, JONA | 0 | (13.40) | 10.000 | (1.34) |
| CN | Jul-03 | 193435083 | MADDORE, SHARON | -1 | (1,097.81) | 10.000 | (109.78) - NOT MATCHED |
| NB | Jul-01 | 192182230 | URZ, SUSAN A | 3 | 570.10 | 10.000 | 57.01 |
| CH | Jul-10 | 197907782 | LANSKY, WAYNE | 0 | 4.34 | 10.000 | 0.43 |
| NB | Jul-14 | 184221262 | SMITH, DAN | 2 | 419.60 | 10.000 | 41.96 |
| CH | Jul-03 | 184532495 | MULLEN, ROBERT | 0 | (16.41) | 10.000 | (1.64) - NOT MATCHED |
+-------+----------+-----------+------------------+-------+------------+--------+------------------------+
code:
intDGRow = dgvImported.Rows.Count;
for (int i = 0; i < intDGRow; i++)
{
//set var values from the dgv
strPolicyNum = dgvImported.Rows[i].Cells["policynum"].Value.ToString().Replace(" ", string.Empty);
strEDate = DateTime.Parse(dgvImported.Rows[i].Cells["EffDate"].Value.ToString()).ToShortDateString();
strGWP = dgvImported.Rows[i].Cells["gwp"].Value.ToString().Replace(",", string.Empty);
strPIF = dgvImported.Rows[i].Cells["pif"].Value.ToString();
//check if row matches a current transaction in the DB - if so update matched column to value = matched - checks for match by doing a row count in the DB that match the fields - if only 1 row matches then the transaction is a match
if (dbAccess.RowCount("sales", "policynum = '" + strPolicyNum + "' AND effectivedate = #" + strEDate + "# AND pif = " + strPIF + " AND gwp = " + strGWP) == 1)
{
if (dbAccess.RowCount("sales", "policynum = '" + strPolicyNum + "' AND effectivedate = #" + strEDate + "# AND pif = " + strPIF + " AND gwp = " + strGWP + "AND matched = true") == 1)
{
dgvImported.Rows[i].Cells["Matched"].Value = "PrevMatched"; //update the matched column to reflect this item was previously matched
}
else
{
dgvImported.Rows[i].Cells["Matched"].Value = "Matched"; //update the matched column to reflect this item was matched
}//end sub if / else (prev matched)
}//end if
else
{
dgvImported.Rows[i].Cells["Matched"].Value = "UnMatched"; //update the matched column to reflect this item was not matched
}//end else
dgvImported.Rows[i].Cells["producer"].Value = dbAccess.ValueLookup("SELECT producer FROM sales WHERE policynum = '" + strPolicyNum + "'", "producer"); //lookup the producer for the policy number - should pull the last producer attached to the policy
dgvImported.Rows[i].Cells["SalesID"].Value = dbAccess.ValueLookup("SELECT saleskey FROM sales WHERE policynum = '" + strPolicyNum + "' AND effectivedate = #" + strEDate + "# AND gwp = " + strGWP, "saleskey"); //lookup the saleskey from sales table that matches the transaction
}//end for
}//end if file open
}//end file open button
if you need any additional details let me know.
Wanting it to look something like this. I am then planning to put barcodes in each of the tables. Any help is appreciated.
_________ ________ ______
| | | | | |
| | | | | |
| | | | | |
| | | | | |
--------- -------- --------
_________ ________ ______
| | | | | |
| | | | | |
| | | | | |
| | | | | |
--------- -------- --------
Hope the following code helpful...
Document document = new Document(rect, marginLeft, marginRight, marginTop, marginBottom);
int tableColumns = 3;
Table aTable = new Table(tableColumns);
int row = 1;
int col = 0;
foreach (Barcode s in codeslist)
{
// Create new barcode
Image imageCode128 = GetImageCode128(s);
// Create a new cell to host the barcode image
Cell cell = new Cell();
cell.Add(imageCode128);
aTable.AddCell(cell,row,col);
if (col == tableColumns-1)
{
col = 0;
row ++;
}
else col++;
}
// Add the completed table to the Document and close it.
document.Add(aTable);
document.Close();
I've data which looks something like this.
| id | name | depth | itemId |
+-----+----------------------+-------+-------+
| 0 | ELECTRONICS | 0 | NULL |
| 1 | TELEVISIONS | 1 | NULL |
| 400 | Tube | 2 | NULL |
| 432 | LCD | 3 | 1653 |
| 422 | Plasma | 3 | 1633 |
| 416 | Portable electronics | 3 | 1595 |
| 401 | MP3 Player | 3 | 1249 |
| 191 | Flash | 2 | NULL |
| 555 | CD Players | 3 | 2198 |
| 407 | 2 Way Radio | 3 | 1284 |
| 388 | I've a problem with | 3 | 1181 |
| 302 | What is your bill pa | 3 | 543 |
| 203 | Where can I find my | 3 | 299 |
| 201 | I would like to make | 3 | 288 |
| 200 | Do you have any job | 3 | 284 |
| 192 | About Us | 3 | NULL |
| 199 | What can you tell me | 4 | 280 |
| 198 | Do you help pr | 4 | 276 |
| 197 | would someone help co| 4 | 272 |
| 196 | can you help ch | 4 | 268 |
| 195 | What awards has Veri | 4 | 264 |
| 194 | What's the latest ne | 4 | 260 |
| 193 | Can you tell me more | 4 | 256 |
| 180 | Site Help | 2 | NULL |
| 421 | Where are the | 3 | 1629 |
| 311 | How can I access My | 3 | 557 |
| 280 | Why isn't the page a | 3 | 512 |
To convert the above data into unordered list based on depth, I'm using the following code
int lastDepth = -1;
int numUL = 0;
StringBuilder output = new StringBuilder();
foreach (DataRow row in ds.Tables[0].Rows)
{
int currentDepth = Convert.ToInt32(row["Depth"]);
if (lastDepth < currentDepth)
{
if (currentDepth == 0)
{
output.Append("<ul class=\"simpleTree\">");
output.AppendFormat("<li class=\"root\"><span>root</span><ul><li class=\"open\" ><span><a href=\"#\" title={1}>{0}</a></span>", row["name"],row["id"]);
}
else
{
output.Append("<ul>");
if(currentDepth==1)
output.AppendFormat("<li><span>{0}</span>", row["name"]);
else
output.AppendFormat("<li><span class=\"text\"><a href=\"#\" title={1}>{0}</a></span>", row["name"], row["id"]);
}
numUL++;
}
else if (lastDepth > currentDepth)
{
output.Append("</li></ul></li>");
if(currentDepth==1)
output.AppendFormat("<li><span>{0}</span>", row["name"]);
else
output.AppendFormat("<li><span class=\"text\"><a href=\"#\" title={1}>{0}</a></span>", row["name"], row["id"]);
numUL--;
}
else if (lastDepth > -1)
{
output.Append("</li>");
output.AppendFormat("<li><span class=\"text\"><a href=\"#\" title={1}>{0}</a></span>", row["name"],row["id"]);
}
lastDepth = currentDepth;
}
for (int i = 1; i <= numUL+1; i++)
{
output.Append("</li></ul>");
}
myliteral.text=output.ToString();
But the resulting unordered list doesnt seem to be forming properly(using which i am constructing a tree).For example "Site Help" with id '180' is supposed to appear as a direct child of "Televisions" with id '1',is appearing as a direct child of 'Flash' with id '191' using my code.so in addition to considering depth,I've decided to consider itemid as well in order to get the treeview properly.Those rows of the table with itemId not equal to null are not supposed to have a child node(i.e.,they are the leaf nodes in the tree) and all the other nodes can have child nodes.
Please could someone help me in constructing a proper unordered list based on my depth,itemid columns?
Update:
The 'itemid' column refers to the id of an item which is present in another table.This column just helps in identifying if an item has any sub items(i.e., 'name' in my data in this case has any other unordered lists under it).
It looks like the initial code wasn't taking account of the number of levels back up you needed to go from the "Can you tell me more" node to the "Site Help" node.
int lastDepth = -1;
int numUL = 0;
StringBuilder output = new StringBuilder();
foreach (DataRow row in ds.Tables[0].Rows)
{
int currentDepth = Convert.ToInt32(row["Depth"]);
if (lastDepth < currentDepth)
{
if (currentDepth == 0)
{
output.Append("<ul class=\"simpleTree\">");
output.AppendFormat("<li class=\"root\"><span>root</span><ul><li class=\"open\" ><span><a href=\"#\" title={1}>{0}</a></span>", row["name"], row["id"]);
}
else
{
output.Append("<ul>");
if (currentDepth == 1)
output.AppendFormat("<li><span>{0}</span>", row["name"]);
else
output.AppendFormat("<li><span class=\"text\"><a href=\"#\" title={1}>{0}</a></span>", row["name"], row["id"]);
}
numUL++;
}
else if (lastDepth > currentDepth)
{
//output.Append("</li></ul></li>");
output.Append("</li>");
for (int i = lastDepth; i > currentDepth; i--)
{
output.Append("</ul></li>");
}
if (currentDepth == 1)
output.AppendFormat("<li><span>{0}</span>", row["name"]);
else
output.AppendFormat("<li><span class=\"text\"><a href=\"#\" title={1}>{0}</a></span>", row["name"], row["id"]);
numUL--;
}
else if (lastDepth > -1)
{
output.Append("</li>");
output.AppendFormat("<li><span class=\"text\"><a href=\"#\" title={1}>{0}</a></span>", row["name"], row["id"]);
}
lastDepth = currentDepth;
}
for (int i = 1; i <= numUL + 1; i++)
{
output.Append("</li></ul>");
}
myliteral.Text = output.ToString();
Stuart.