Grid View Comparison - asp.net

I want to compare rows of two grid views.GW1 and GW2.
When I click a Search Button ,I want to check the Values in the GW2,and if GW1 and GW2 have same PayID ,EmpID,then that specific row of GW1 must be disabled
Thanks

int i = 0;
while(i < GridView1.Rows.Count && i < GridView2.Rows.Count)
{
if(
GridView1.Rows[i].Cells[column for pay ID].Text == GridView2.Rows[i].Cells[column for pay ID].Text &&
GridView1.Rows[i].Cells[column for emp ID].Text == GridView2.Rows[i].Cells[column for emp ID].Text))
{
GridView1.Rows[i].Enabled = false;
}
i++;
}

Only way I can think of is to loop through table one and search for similar rows in table two. This is how you can do this:
Loop through the Table 1.
Use DataTable.Select to find if there are rows with same PayID and EmpID in Table 2.
If the method returns more than 0 rows, then disable the rows.
Apart from this, you can also think about writing/searching a method which can give you intersection of two tables. If these two columns are priamry keys, then this will work. If not, then you will need to tweak the code as per your need.

do something like this, its not the actual code, but you will have the idea.
for i=0 to gw1rowscount-1
for j=0 to gw2rowscount-1
if gw1(i)(column1)=gw2(j)(column1) and gw1(i)(column2)=gw2(j)(column2) then
end if
next
next

Related

How to solve this error of conditional statements and Loops in R?

You can suggest me any sort of answers, not necessarily need using conditional statements and Loops.
I have the data set with several ids and and three alert or groups.
here is the image for the concept:
and here is the actual Data set for one ID: Click me
Concept is:
I have three alert: Relearn - Rebuild - Replace.
and after relearn: rebuild or replace can come but relearn cannot come
and after rebuild: replace can come but relearn cannot come
after replace: relearn and rebuild cannot come. if there is any replace only that can come
I have attached the image and Dataset for better clear understanding and Here is my try:
temp1 = NULL
temp2 = NULL
sql50 = NULL
for(i in 1:nrow(BrokenPins)) #First Loop
{
sql50 = sqldf(paste("select * from rule_data where key = '",BrokenPins[i,1],"'",sep = ""))
for(j in 1:nrow(sql50))
{ #Second Loop
while (head(sql50$Flag,1) == sql50$Flag[j] )
{
temp1 = sql50[j,]
temp2 = rbind(temp2,temp1)
print("Send")
if(j == 1 || sql50$Flag[j] == sql50$Flag[j-1])
{
j = j+1
}
else(sql50$Flag[j] > sql50$Flag[j-1])
{
break
}
}
}
}
First loop will go through each id and second loop will give me all the alert for that id.
so in the image i have added send and dont send. it wont be in actual table. that basically means send means copy it to new dataframe like i am doing above rbind in the code and dont send means dont copy it. This Above piece of code will run but only take the first and end it.
Finally, Based On above Data set Click me: that is for one ID (key), Flag (1 - Relearn, 2-Rebuild,3-replace). so based on this dataset. my output should have Row 1, 2 and 7 because First Relearn[Flag 1] came then Rebuild[Flag 2] then again relearn[Flag 1]cannot come, only rebuild [Flag 2] and replace[Flag 2] can.
can you help me solve this concept?
One thing I notice is that you use else and also provided a condition; you should only use else when you want every case that is not included in the condition of your if statement. Basically, instead of using else(sql50$Flag[j] > sql50$Flag[j-1]) you should be using else if(sql50$Flag[j] > sql50$Flag[j-1]).

SQLite3 - how to know if the current row is the last row

This is trivial in mysql thanks to mysql_num_rows but no such equivalent is present in sqlite3. Hence the question is how to know if the current row is the last row.
Rearranging like following doesn't help as any previous binding after sqlite3_step is not valid.
sqlite3_prepare_v2()
int fetched = 0;
int last = 0;
while (sqlite3_step(statement) == SQLITE_ROW) {
// this is the previous row
if(fetched) {
process(data, last);
}
fetched = 1;
data = sqlite3_column_text();
}
last = 1;
if(fetched)
process(data, last);
Executing query twice (one with count) is a trivial solution but that's not what I am looking for.
Any ideas? thanks in advance.
SQLite computes the next output row only when needed.
So it is not possible to find out if you can get another row without actually trying to step to that row.
If your code really needs to know whether the current row is the last, you have to make a copy of all the data in the row.

How to check specific column exist in datarow?

I came across situation,where columnname for datatable is dynamic.While fetching a data I want to check existence of column.
DataTable table = ds.Table["Sample1"]
if(table.Row.Count > 0)
{
foreach(DataRow dr in table.Rows )
{
if(dr.Table.Column.Contain("DateInfo"))
{
// store value in variable
// first approach
}
if(table.Column.Contain("DateInfo"))
{
// store value in variable
// second approach
}
}
}
Which one is best approach?
Will this be enough:
1st Approach: Which will simply check in an entire DataTable.
datatable.Columns.Contains("column")
2nd Approach: which will check for each row collection in DataTable
dr.Table.Columns.Contains("column")
3rd Approach: Which fetch each columns in DataColumnCollection object and then check if it contains the specific field or not.
DataColumnCollection columns = datatable.Columns;
if (columns.Contains(columnName))
So these all approaches are better in their own way. you can use whatever you find it better.
This is best one
dr.Table.Column.Contain("DateInfo")
foreach loop get single row at a time sometimes if any conditional is possible in this method

Remove item from groovy list

I am trying to remove an item from groovy list. I've tried following:
List<User> availableUsers = []
availableUsers = workers
for (int i = 0; i < availableUsers.size(); i++) {
if (availableUsers[i].equals(user)){
availableUsers.drop(i)
break
}
}
I've also tried:
availableUsers.remove(user)
In both cases the list gets emptied. Does anyone have any idea what's going on?
Have you tried
availableUsers - user
?
Docu: http://groovy.codehaus.org/groovy-jdk/java/util/List.html#minus(java.lang.Object)
Haven't got much experience with groovy myself, but that's what I would try.
As mentioned above, the answer depends on whether you wish to remove all occurrences of an item...
myList = ['a','b','c', 'c']
myList -= 'c'
assert myList == ['a','b']
...or just the first instance.
myList = ['a','b','c', 'c']
myList.remove(myList.indexOf('c'))
assert myList == ['a','b','c']
I'm still new to Groovy myself, but one of the underlying principles is that it almost always has a way of making common tasks trivial one-liners. Adding or removing items from a collection would certainly qualify.
Fildor is right, but if you only want ot remove the first occurence of user in your list (minus will remove all occurrences), you will probably need something like:
list = list.indexOf( user ).with { idx ->
if( idx > -1 ) {
new ArrayList( list ).with { a ->
a.remove( idx )
a
}
}
else list
}
I had a related requirement but wanted to remove more than one items knowing their index position. It was not easy to do in a loop as after removing the first item, the index position of the remaining ones changes. It seemed easy to first create a list with items to be removed and then use the collections minus operation to remove them from the target list. Here is an example:
myList=['a','b','c','d']
remove=[0,1,2] //index list of list elements to remove
removeList=myList[remove]
println removeList
assert ['d']== myList.minus(removeList)
LIMITATION:if the value at index is present multiple times in target list, ALL instances are removed.
So, if
myList=['a','b','c','d','a','e']
remove=[0,1,2]
removeList=myList[remove]
assert myList.minus(removeList)== ['d','e']
the result will be d,e

SQLite seek question

I'm using SQLite version 3 to run the following code.
//Run SQL SELCT query
sqlite3_prepare16_v2("SELECT * FROM table_name");
sqlite3_step();
//Need to review results in several iterations
for(int i = 0; i < n; i++)
{
//Seek to beginning
sqlite3_reset();
do
{
//Get values
sqlite3_column_int();
...
sqlite3_column_text16();
}
while(sqlite3_step() == SQLITE_ROW);
}
But for some reason the first batch of data I get is all 0's. What am I not doing correct in the code above?
Assuming what you are showing is pseudocode since you're missing many arguments to the sqlite3 funcitons...
You need a sqlite3_step after sqlite3_reset and before getting the first row of values.
You can change your do {...} while(sqlite3_step() == SQLITE_ROW) to a while(sqlite3_step() == SQLITE_ROW)...} to accomplish that.
This will also eliminate the need to step immediately after the sqlite3_prepare16_v2

Resources