Jquery compelete function not working - jquery-ui

I m very much new to the jQuery and AJAX technology. I am trying to create a form which will insert the values in the database without refresh the page. Most of the code are working as expected. But among there are two case which is not working as expected.
I am fetching values through checkbox. When I select only one checkbox it works but when I select multiple checkbox, the value stored in the database as Array.
I want to display a message once the form data submitted succesfully but its not working.
Please find the below respective code for the same.
Jquery:
$('#add').click(function(){
var domain_type = $('#domain').val();
var domain_zone = $('#domain_zone').val();
var client_name = $('#client_name').val();
//var language[] = "";
var lang = new Array();
if(language==1){
//alert("You select one language");
valid = true;
lang = "English";
}else{
//alert("You select multiple language");
var i =0;
$.each($('input[name=lang]:checked'), function(){
lang.push($(this).val());
});
var count = lang.length;
if(count ==1){
alert("You need to select two languages");
var valid = false;
}else if(count>2){
alert("You can select only two languages");
var valid = false;
}else{
valid = true;
}
}
var formMsge = $('#formStatus');
$('#formStatus').html('<img src="./img/loader.gif"> Please wait while adding the data in database.');
$.ajax({
type: "POST",
url: "./test/test.php",
data: {domain_type:domain_type, domain_zone:domain_zone, client_name:client_name, 'lang[]':lang},
success:function(conf){
$('#formStatus').ajaxComplete(
function(event,request){
if(conf=="OK"){
$('#formSuccess').show();
$('#addClient').hide();
}else{
$('#formError').show();
$('#forError').text("Please try again");
}
}
);
}
});
return false;
});
test.php:
include('../../classes/access_user/all.class.inc.php');
echo $workstream->addClient()
;
php class file:
public function addClient(){
$domain_type = isset($_POST['domain_type'])?$_POST['domain_type']:'';
$domain_zone = isset($_POST['domain_zone'])?$_POST['domain_zone']:'';
$client_name = isset($_POST['client_name'])?$_POST['client_name']:'';
$lang = isset($_POST['lang'])?$_POST['lang']:'';
$add_by = 'Robindra Singha';
$add_on = date("Y-m-d");
if(isset($domain_type) || isset($domain_zone) || isset($client_name) || isset($lang)){
$sql = "INSERT INTO client_list (domain_type_id, client_name, domain_zone, language, add_on, add_by, last_update_on, last_update_by) VALUES('$domain_type','$client_name','$domain_zone','$lang','$add_on','$add_by','$add_on','$add_by')";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_inserted_id() != 0){
$msg = "OK";
}else{
$msg = "System face an issue while adding client details!";
}
}else{
$msg = "System face an issue while adding client details, please try again!";
}
return $msg;
}
In above code, my issue is checkbox value are not able to pass when I select the multiple checkbox, second I am not able to display any text once the form is successfully submit. Except this two issues, my code able to insert the information successfully. I would be glad if any one guide me in completing the work properly. Thank you in advance for your kind support.
Note: I am not able to add the HTML file as i paste here, it display as normal text. please suggest.

Related

How to get the ID of an inserted record in HANA back to SAPUI5 application?

I got an SAPUI5-application in which I create entries and save them via OData-service. That works, the code for the create operation can be found below. What I have to do now is, I need the ID of the inserted record in HANA back in my application. So what I did I implemented a success handler and thought I would get back this ID in the response from my OData-service. But that is not the case, I get back the same value I provided, in this case 0 since this just a dummy value for the OData-service. I did some research on how to tackle this problem, but none of the approaches worked. So I hope someone of you can help me out or got a hint how to do this. Below the code for create-operation, odata-service and the create.xsjs:
Create-operation in SAPUI5:
this.getOwnerComponent().getModel("Mitarbeiter").create("/ARB", oEntry, {
success: function(oData, response){
console.log(response);
}
});
OData-service:
service {
"MITARBEITERABTEILUNG"."ABTEILUNG" as "ABT" navigates ("Mitarbeiter" as "ARB");
"MITARBEITERABTEILUNG"."Mitarbeiter" as "ARB" create using "public.MitarbeiterAbteilung:mitarbeiterMethods.xsjslib::mitarbeiterCreate";
association "Mitarbeiter"
principal "ABT"("ID")
multiplicity "1"
dependent "ARB"("Abteilung")
multiplicity "*";
}
Create.xsjs:
function mitarbeiterCreate(param) {
let aAfterTableName = param.afterTableName;
var oEntry = {};
try {
var statement = param.connection.prepareStatement("SELECT * FROM\"" + aAfterTableName + "\"");
var rs = statement.executeQuery();
var statement2 = param.connection.prepareStatement('SELECT "MITARBEITERABTEILUNG"."MASEQUENCE".NEXTVAL from dummy');
var rs2 = statement2.executeQuery();
while (rs2.next()) {
oEntry.ID = rs2.getInteger(1);
}
statement2.close();
while (rs.next()) {
oEntry.Name = rs.getString(2);
oEntry.Adresse = rs.getString(3);
oEntry.bz = rs.getString(4);
oEntry.Abteilung = rs.getInteger(5);
}
statement = param.connection.prepareStatement('INSERT INTO "MITARBEITERABTEILUNG"."Mitarbeiter" VALUES (?,?,?,?,?)');
statement.setInteger(1, oEntry.ID);
statement.setString(2, oEntry.Name);
statement.setString(3, oEntry.Adresse);
statement.setString(4, oEntry.bz);
statement.setInteger(5, oEntry.Abteilung);
statement.execute();
statement.close();
} catch (e) {
statement.close();
}
}
Answered in the SAP Community here: https://answers.sap.com/questions/566957/how-to-get-the-id-of-an-inserted-record-in-hana-ba.html
The only thing you need to do, is to update the ID value in the "afterTableName" table provided by the function parameter. Something like that:
let statement = param.connection.prepareStatement('update "' + param.afterTableName + '" set ID = ' + oEntry.ID);
statement.executeUpdate();
Of course that needs to be done after you have determined your new ID. In case your column name is not "ID", please replace it with the real column name.

How we can show "No Data Available" message in RDLC Reports via Resources files

How we can show "No Data Available" message in RDLC Reports via Resources files if no data is found. Currently we are reflecting message from NoRowsMessage property for a table, matrix, or list
(https://technet.microsoft.com/en-us/library/cc645968.aspx).
But we want to show it via Resource files and C# code rather then setting it from Properties of Table. Can anyone please assist. The code (Page_Load) of our control page (.ascx)is mentioned below:
private void Page_Load(object sender, EventArgs e)
{
var presenter = (ReportPresenter)Model;
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.Visible = true;
var rdlcPath = "~/ReportsRDLC/EmployeeData.rdlc";
if(presenter.ReportFilter.GroupOption == Resources.Date)
{
rdlcPath = "~/ReportsRDLC/EmployeeDatebyDate.rdlc";
}
groupOption.SelectedValue = presenter.ReportFilter.GroupOption;
const string DataSetName = "EmployeeDataSet";
reportViewer.LocalReport.ReportPath = HttpContext.Current.Server.MapPath(rdlcPath);
var dataSource = new ReportDataSource(DataSetName, presenter.EmployeeDetails);
reportViewer.AsyncRendering = false;
reportViewer.SizeToReportContent = true;
reportViewer.ShowPrintButton = false;
reportViewer.ShowRefreshButton = false;
reportViewer.ShowToolBar = true;
reportViewer.Height = 600;
reportViewer.Width = 400;
reportViewer.ShowPageNavigationControls = false;
reportViewer.ShowFindControls = false;
reportViewer.ShowZoomControl = false;
reportViewer.LocalReport.DataSources.Add(dataSource);
}
Perhaps you could send the message as a parameter.
You can tell if the report will be empty depending if presenter.EmployeeDetails is empty.
ReportParameter[] myParameters = new ReportParameter[1];
myParameters[0] = new ReportParameter("pEmptyMessage", presenter.EmployeeDetails.Any() ? "No Data Available" : string.Empty);
reportViewer.LocalReport.SetParameters(myParameters);
On your report you can then display this message as you please, using the parameter. You can even place it in a textbox and decide whether to display it based on the value.
I hope this is of use to you.
Edit: I forgot to mention that you should add the report parameter with the correct name to your reporter:
In the reporter you can then use the parameter as followed : [#pEmptyMessage]
=Parameters!pEmptyMessage.Value

RDLC report direct print without print preview

I need some help regarding rdlc report in mvc 4.
In my project i have a rdlc report when the user clicks on a button. I will show the report in another tab.
When the user clicks on the button how can I send the print request directly to the default printer which is configured in the system environment without showing a print preview dialogue?
ReportingSerivceLib.PrintManager objPrintManager = new PrintManager();
IList<ParameterValue> parameters = new List<ParameterValue>();
parameters.Add(new ParameterValue {
Name = "Sales_Bill_ID",
Value = POS_Sales_Bill_MasterObj.POS_Sales_Bill_Master.Sales_Bill_ID.ToString()
});
var imgname1 = db.POS_Sales_Bill_Master.SingleOrDefault(
a => a.Sales_Bill_ID == POS_Sales_Bill_MasterObj.POS_Sales_Bill_Master.Sales_Bill_ID).ATTRIBUTE1;
parameters.Add(new ParameterValue {
Name = "Barcode_Parameter", Value = path + "/barcode/" + imgname1.ToString()
});
parameters.Add(new ParameterValue {
Name = "Report_Code", Value = "RPT_Sales_Bill_Receipt"
});
parameters.Add(new ParameterValue {
Name = "Logo_Parameter", Value = "abcteskfdk"
});
string Rpt_Folder_Name = System.Configuration.ConfigurationManager.AppSettings["ReportPath"];
objPrintManager.PrintReport(Rpt_Folder_Name + "RPT_Sales_Bill_Receipt", parameters.ToArray(), -1, -1);

Get all tweets with specific hashtag

I've been experimenting with the Twitter API because I want to display a few lists of tweets on a special page.
Among those lists is a list with all tweets containing a specific hashtag (e.g. #test)
However I cannot find how to get that list in either XML or JSON (preferably the latter), does anyone know how? It is also fine if it can be done in TweetSharp
You can simply fetch http://search.twitter.com/search.json?q=%23test to get a list of tweets containing #test in JSON, where %23test is #test URL encoded.
I'm not familiar with TweetSharp, but I guess there must be a search command that you can use to search for #test, and then transform the resulting tweets into JSON yourself.
First install TweetSharp using github
https://github.com/danielcrenna/tweetsharp
Here is the code to do a search
TwitterService service = new TwitterService();
var tweets = service.Search("#Test", 100);
List<TwitterSearchStatus> resultList = new List<TwitterSearchStatus>(tweets.Statuses);
If you have more then one page results you can setup a loop and call each page
service.Search("#Test", i += 1, 100);
It seems like there is a change in the API since last few months. Here is the updated code:
TwitterSearchResult res = twitter.Search(new SearchOptions { Q = "xbox" });
IEnumerable<TwitterStatus> status = res.Statuses;
u access with this url for your tweet searchs. But u have to use OAuth protocols.
https://api.twitter.com/1.1/search/tweets.json?q=%40twitterapi
I struggled with the same problem. Here is my vague solution . Enjoy Programming.
It will get out of the function whenever your required number of tweets are acquired/fetched.
string maxid = "1000000000000"; // dummy value
int tweetcount = 0;
if (maxid != null)
{
var tweets_search = twitterService.Search(new SearchOptions { Q = keyword, Count = Convert.ToInt32(count) });
List<TwitterStatus> resultList = new List<TwitterStatus>(tweets_search.Statuses);
maxid = resultList.Last().IdStr;
foreach (var tweet in tweets_search.Statuses)
{
try
{
ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
tweetcount++;
}
catch { }
}
while (maxid != null && tweetcount < Convert.ToInt32(count))
{
maxid = resultList.Last().IdStr;
tweets_search = twitterService.Search(new SearchOptions { Q = keyword, Count = Convert.ToInt32(count), MaxId = Convert.ToInt64(maxid) });
resultList = new List<TwitterStatus>(tweets_search.Statuses);
foreach (var tweet in tweets_search.Statuses)
{
try
{
ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
tweetcount++;
}
catch { }
}
}

jQuery UI portlets - toggle portlets to save to a cookie (half way there!)

I'm a bit of a jQuery n00b so please excuse me if this seems like a stupid question. I am creating a site using the jQuery UI more specifically the sortable portlets. I have been able store whether or not a portlet is has been open or closed to a cookie. This is done using the following code. The slider ID is currently where the controls are stored to turn each portlet on and off.
var cookie = $.cookie("hidden");
var hidden = cookie ? cookie.split("|").getUnique() : [];
var cookieExpires = 7; // cookie expires in 7 days, or set this as a date object to specify a date
// Remember content that was hidden
$.each( hidden, function(){
var pid = this; //parseInt(this,10);
$('#' + pid).hide();
$("#slider div[name='" + pid + "']").addClass('add');
})
// Add Click functionality
$("#slider div").click(function(){
$(this).toggleClass('add');
var el = $("div#" + $(this).attr('name'));
el.toggle();
updateCookie(el);
});
$('a.toggle').click(function(){
$(this).parents(".portlet").hide();
// *** Below line just needs to select the correct 'id' and insert as selector i.e ('#slider div#block-1') and then update cookie! ***
$('#slider div').addClass('add');
});
// Update the Cookie
function updateCookie(el){
var indx = el.attr('id');
var tmp = hidden.getUnique();
if (el.is(':hidden')) {
// add index of widget to hidden list
tmp.push(indx);
} else {
// remove element id from the list
tmp.splice( tmp.indexOf(indx) , 1);
}
hidden = tmp.getUnique();
$.cookie("hidden", hidden.join('|'), { expires: cookieExpires } );
}
})
// Return a unique array.
Array.prototype.getUnique = function() {
var o = new Object();
var i, e;
for (i = 0; e = this[i]; i++) {o[e] = 1};
var a = new Array();
for (e in o) {a.push (e)};
return a;
}
What I would like to do is also add a [x] into the corner of each portlet to give the user another way of hiding it but I'm unable to currently get this to store within the Cookie using the code above.
Can anyone give me a pointer of how I would do this?
Thanks in advance!
Gareth
Have you tried adding another selector to the click function?
$("#slider div, #slider div > span.ui-icon-x").click(function(){
$(this).toggleClass('add');
var el = $("div#" + $(this).attr('name'));
el.toggle();
updateCookie(el);
});

Resources