ASP.Net table data link - sql-server

public string GetMemberMessages(string ClubId, string acctno)
{
var data = "";
List<Hashtable> StartList = new List<Hashtable>();
string Conn = GetClubConnectionstring(ClubId);
if (Conn != "Invalid Connection")
{
Sconn = new SqlConnection(Conn);
string lsql ="select * from table where acctno='" + no + "' and datecompl is null order by entrydate desc";
Getdataset(lsql, "tblnotes", ds, ref da, Sconn);
if (ds.Tables["tblnotes"] != null && ds.Tables["tblnotes"].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables["tblnotes"].Rows.Count; i++)
{
Hashtable hashtable = new Hashtable();
for (int j = 0; j < ds.Tables["tblnotes"].Columns.Count; j++)
{
hashtable[ds.Tables["tblnotes"].Columns[j].ToString()] = ds.Tables["tblnotes"].Rows[i][j].ToString();
}
StartList.Add(hashtable);
}
return js.Serialize(StartList);
}
else
{
data = null;
}
}
return js.Serialize(data);
}
<div data-bind="foreach: $root.dataSource">
<table > <tr>
<td>
<span data-bind=" text:notes"</span>>
</td>
</tr>
</table>
</div>
I have MSSQL table, in a field i had insert my messages (ex:Have a good day) with external website linkGoogle.
while i bind the data in my html table like this (have a good day www.google.com) values are shows into view, it working fine. but while i click on that external web linkGoogle. it doesn't navigate google page.
I had tried in SQL server with Html different type to link tags, what are that tag i had put into database, those tag also get visible alone with message and link.

Related

Count Of Hidden Rows in WebTable By Using Selenium

I have a hide button in the application that hides duplicate data entries on web table. I have been trying to capture the number of hidden rows. See html and my approaches below. Every attempt I have tried ended up with 0. However, the result should be 2.
HTML CODE:
<tbody>
<tr role = "row" class="odd">...<tr/>
<tr role = "row" class="even">...<tr/>
<tr role = "row" class="odd">...<tr/>
<tr role = "row" class="even">...<tr/>
<tr role = "row" class="odd">...<tr/>
<tr role = "row" class="odd duplicate" style="display: none;" >...<tr/>
<tr role = "row" class="even duplicate" style="display: none;" >...<tr/>
</tbody>
def getInvisibleTableRowCount()
{
WebDriver driver = DriverFactory.getWebDriver()
WebElement table = driver.findElement(By.xpath("//*[#id='DataTables_Table_0']/tbody"))
List<WebElement> rows_table= table.findElements(By.cssSelector("[display=none]"));
int rowSize = rows_table.size();
return rowSize;
}
Here is my other attempt:
def getInvisibleTableRowCount()
{
WebDriver driver = DriverFactory.getWebDriver()
WebElement table = driver.findElement(By.xpath("//*[#id='DataTables_Table_0']/tbody"))
List<WebElement> rows_table= table.findElements(By.tagName("tr[not(contains(#style,'display: none;'))]"));
int rowSize = rows_table.size();
return rowSize;
}
If I ran the xpath as //*[#id='DataTables_Table_0']/tbody/tr[not(contains(#style,'display: none;'))] , I can find the hidden rows on the browser.
I have also tried this:
def getInvisibleTableRowCount()
{
WebDriver driver = DriverFactory.getWebDriver()
WebElement table = driver.findElement(By.xpath("//*[#id='DataTables_Table_0']/tbody"))
List<WebElement> rows_table= table.findElements(By.tagName("tr"));
int rowSize = rows_table.size();
for(WebElement row: rows_table)
{
if(row.isDisplayed()==false)
{
rowSize = rowSize -1;
}
}
return rowSize;
}
After #Hac's comment, I tried JQuery. I ran the jQuery on browser, it works with no problem. But I get a "NULL" value returned in my function. I double checked the jQuery string that prompts correct in the comment line.
#Keyword
def getTableRowCountAfterHiding()
{
def jQuery='$'+'("#DataTables_Table_0 tbody tr:visible").length'
WebUI.comment(jQuery);
def visibleRowCounts = new utils.ExecuteJavaScript().executeJavaScript(jQuery);
return visibleRowCounts;
}
I defined utils to run JS as it is in below:
public class ExecuteJavaScript {
//This keyword is designed to execute JS.
#Keyword
def executeJavaScript(String javascript) {
((JavascriptExecutor) DriverFactory.getWebDriver()).executeScript(javascript)
}
}
This worked:
def getTableRowCountAfterHiding()
{
WebDriver driver = DriverFactory.getWebDriver()
List<WebElement> table = driver.findElements(By.xpath("//*[#id='DataTables_Table_0']/tbody/tr[not(contains(#style,'display: none;'))]"))
int rowSize = table.size();
return rowSize;
}

Import large amounts of data from Excel file into SQL Server using .NET Core and Angular

I want to import data from Excel files into SQL Server. The size of the file is 22 MB and contains approximately 1 million rows, but I get the error timeout.
This is the code of my controller
[System.Web.Http.Route("UploadExcel")]
[System.Web.Http.HttpPost]
[RequestFormLimits(MultipartBodyLengthLimit = 409715200)]
[RequestSizeLimit(409715200)]
public string ExcelUpload()
{
string message = "";
HttpResponseMessage result = null;
var httpRequest = HttpContext.Current.Request;
using (AngularDBEntities objEntity = new AngularDBEntities())
{
if (httpRequest.Files.Count > 0)
{
HttpPostedFile file = httpRequest.Files[0];
Stream stream = file.InputStream;
IExcelDataReader reader = null;
if (file.FileName.EndsWith(".xls"))
{
reader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else if (file.FileName.EndsWith(".xlsx"))
{
reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}
else
{
message = "This file format is not supported";
}
DataSet excelRecords = reader.AsDataSet();
reader.Close();
var finalRecords = excelRecords.Tables[0];
for (int i = 0; i < finalRecords.Rows.Count; i++)
{
UserDetail objUser = new UserDetail();
objUser.UserName = finalRecords.Rows[i][0].ToString();
objUser.EmailId = finalRecords.Rows[i][1].ToString();
objUser.Gender = finalRecords.Rows[i][2].ToString();
objUser.Address = finalRecords.Rows[i][3].ToString();
objUser.MobileNo = finalRecords.Rows[i][4].ToString();
objUser.PinCode = finalRecords.Rows[i][5].ToString();
objEntity.UserDetails.Add(objUser);
}
int output = objEntity.SaveChanges();
if (output > 0)
{
message = "Excel file has been successfully uploaded";
}
else
{
message = "Excel file uploaded failed";
}
}
else
{
result = Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
return message;
}
I added maxRequestLength="1048576" executionTimeout="999999" to the web.config file in the system.web section, and maxAllowedContentLength="1073741824" to security tag, but I am still facing this problem.
Knowing that when I upload small files, the data is added to the table
you can add all items in a list and finally use bulk insert. use can use Entity Framework Extensions.

How to skip the locator which does not exist in selenium webdriver?

I have around 50 rows in a page. But those items are in sequence.
The problem is when someone entered and deleted that table row. That id would not be there in page..
Example:
User added 1st record: id 101 added.
User added 2nd record: id 102 added
User added 3rd record: id 103 added.
If user deletes 2nd record, then two records would be there on the page but with id 101, 103.
I am trying to write that if that id is present then get the text else leave that in the for loop. I am getting only records till it found if that id is not found getting NoSuchElementException is displayed.
Please correct the code. But i want to the solution that if that id not exist, skip and run the else part.
for (int i = counterstart; i <= counterend; i++) {
if(driver.findElement(By.xpath("//*[#id='" + i + "']/a")).isDisplayed()){
System.out.println(i+" is present");
String Projects = driver.findElement(By.xpath("//*[#id='" + i + "']/a")).getText();
System.out.println(Projects);
} else{
System.out.println(i+" is NOT present");
}
}
The exception that I get:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //*[#id='7593']/a (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 503 milliseconds
Try this method isPresent instead of isDisplayed.
public boolean isPresent(WebElement e) {
boolean flag = true;
try {
e.isDisplayed();
flag = true;
}
catch (Exception e) {
flag = false;
}
return flag;
}
How about this:
for (int i = counterstart; i <= counterend; i++) {
WebElement element;
try{
element = driver.findElement(By.xpath("//*[#id='" + i + "']/a"));
}catch(NoSuchElementException n)
{
element = null;
}
if(element !=null){
System.out.println(i+" is present");
String Projects = driver.findElement(By.xpath("//*[#id='" + i + "']/a")).getText();
System.out.println(Projects);
}else{
System.out.println(i+" is NOT present");
}
}
Find all the parent of all the elements you want to get the text from and use it to drill down, this way you won't get the exception
Assuming the html looks like this
<div id="parent">
<div id="11">
<a>text</a>
</div>
<div id="12">
<a>text</a>
</div>
<div id="13">
<a>text</a>
</div>
</div>
You can do this
// get all the elements with id
List<WebElement> ids = driver.findElements(By.cssSelector("#parent > div"));
// get all the texts using the id elements
for (WebElement id :ids) {
String projects = id.findElement(By.tagName("a")).getText();
System.out.println(projects);
}

How to get all selected Checkbox values into a sql query

I have a multiple filter query like this:
I want to make the checkboxes be selected and then added to the following query:
var db = Database.Open("RMS") ;
var selectCommand = "SELECT * FROM RMS";
var formSSO = "";
var formCase_Status= "";
var fromDate = "";
var toDate = "";
var SQLSELECT = "SELECT * FROM Admins WHERE Email = #0";
var Email = WebSecurity.CurrentUserName;
var data1 = db.QuerySingle(SQLSELECT, Email);
var Name = data1.Name;
formSSO = Request.QueryString["formSSO"];
formCase_Status = Request["formCase_Status[]"];
fromDate = Request.QueryString["fromDate"];
toDate = Request.QueryString["toDate"];
selectCommand = "SELECT * FROM RMS WHERE Assigned_To = #4";
if(!Request.QueryString["formSSO"].IsEmpty() ) {
selectCommand +=" AND SSO LIKE #0";
}
if(!Request.QueryString["formCase_Status"].IsEmpty() ) {
selectCommand +=" AND Case_Status = #1";
}
if(!Request.QueryString["fromDate"].IsEmpty() ) {
selectCommand +=" AND Created >= #2";
}
if(!Request.QueryString["toDate"].IsEmpty() ) {
selectCommand +=" AND Created <= #3";
}
I can get it working if only one checkbox is selected but my main point is to allow multiple checkboxes to be checked. How can I do this either with JS or Jquery I have tried answers on other qts but they don't quite go with what I am doing. I don't want an alert but a way that I can call all checked values in the select statement.
This is the checkbox:
<li class="form-line form-line-column" id="id_20">
<label class="form-label-top" id="label_20" for="input_20"> Status </label>
<div id="cid_20" class="form-input-wide">
<input type="checkbox" checked="#(Request["formCase_Status[]"] == "In Progress")" name="formCase_Status[]" value="In Progress"> In Progress<br>
<input type="checkbox" checked="#(Request["formCase_Status[]"] == "Pending")" name="formCase_Status[]" value="Pending"> Pending<br>
<input type="checkbox" checked="#(Request["formCase_Status[]"] == "Closed")" name="formCase_Status[]" value="Closed"> Closed<br>
</div>
</li>

Salesforce App follow stopped working

My company has an app that they got off of the app exchange(Note: before I started) that allowed you to follow or unfollow large number of cases/accounts/opportunities etc in salesforce.com. Supposedly it worked before and now it isn't working. I need an idea of what is wrong with the code for each button. If I can't fix them, any ideas for a replacement app? The app is no longer on the app exchange any more.
here's the code for the follow button:
{!REQUIRESCRIPT("/soap/ajax/18.0/connection.js")}
//EDIT THE FOLLOWING LINE TO ALTER THE CODE FOR OTHER OBJECTS. USE THE PICKLISTS ABOVE TO SELECT FIELD TYPE = $ObjectType AND THE OBJECT NAME THEN REPLACE "$ObjectType.Case" WITH YOUR NEW OBJECT NAME
var records = {!GETRECORDIDS( $ObjectType.Case)};
function LBox() {
var box = new parent.SimpleDialog("steve"+Math.random(), true);
parent.box = box;`
box.setTitle("Follow Records");
box.createDialog();
box.setWidth(220);
box.setContentInnerHTML("<img src='/img/loading32.gif' alt='' /> Running");
box.setupDefaultButtons();`
box.show();
}
function CBox(){
box.setContentInnerHTML("You are now following "+follow_count+" records<br /><br />Close");
}
if (records[0] == null) {
alert("Please select at least one record.");
}
else {
var follow_count = 0;
LBox();
for (var i = 0; i < records.length; i++){
var fol=new sforce.SObject("EntitySubscription");
fol.ParentId = records[i];
fol.SubscriberId = '{!User.Id}';
try{
sforce.connection.create([fol]);
follow_count++;
}
catch(e){
alert(e);
}
}
CBox();
}
here's the unfollow button:
{!REQUIRESCRIPT("/soap/ajax/18.0/connection.js")}
// EDIT THE FOLLOWING LINE TO ALTER THE CODE FOR OTHER OBJECTS. USE THE PICKLISTS ABOVE TO SELECT FIELD TYPE = $ObjectType AND THE OBJECT NAME THEN REPLACE "$ObjectType.Case" WITH YOUR NEW OBJECT NAME
var records = {!GETRECORDIDS( $ObjectType.Case)};
// display running message popup
function LBox() {
var box = new parent.SimpleDialog("steve"+Math.random(), true);
parent.box = box;`
box.setTitle("Unfollow Records");
box.createDialog();
box.setWidth(220);
box.setContentInnerHTML("<img src='/img/loading32.gif' alt='' /> Running");
box.setupDefaultButtons();
box.show();
}
// display output message
function CBox(){
if (unfollow_count < records.length)
box.setContentInnerHTML("You have now unfollowed "+unfollow_count+" records. You were not following the other selected records. <br /><br />Close");
else
box.setContentInnerHTML("You have now unfollowed "+unfollow_count+" records. <br /><br />Close");
}
if (records[0] == null) {
alert("Please select at least one record.");
}
else {
var unfollow_count = 0;`
LBox();
try {
// find following records
var searchstring = "SELECT Id FROM EntitySubscription WHERE (ParentId IN (";
for (var i = 0; i < records.length - 1; i++) {
searchstring += "'" + records[i] + "',";
}
searchstring += "'" + records[records.length - 1] + "') AND SubscriberId ='{!User.Id}')";
var resultRecords = sforce.connection.query(searchstring).getArray("records");
// delete following records
var recordIds = [];
for (var i = 0; i < resultRecords.length; i++) {
recordIds.push(resultRecords[i].Id);
unfollow_count++;
}
sforce.connection.deleteIds(recordIds);
} catch(e) {
alert(e);
}
CBox();
}
The first error message has to do with permissions, I don't get this error because I have admin rights, the second error is only on the account tab's button. I'm more worried about the permissions problem, is there anything there about permissions. Any help is great!
I think the issue is a throttle in SFDC, you are limited to following only a certain number of records per user. If this app was designed as you described to mass-follow records, it's possible your hitting that throttle, which is kind of the impression I get from the error your co-worker is receiving about at most 1000, also if it worked before, it would make sense that you have maxed out a limit for the org/user
Queries on EntitySubscription by users who aren't system admins must contain a LIMIT. If you change the query code in the button to the following it should work:
// find following records
var searchstring = "SELECT Id FROM EntitySubscription WHERE (ParentId IN (";
for (var i = 0; i < records.length - 1; i++) {
searchstring += "'" + records[i] + "',";
}
searchstring += "'" + records[records.length - 1] + "') AND SubscriberId ='{!User.Id}') LIMIT 1000";

Resources