|
|
Hi i have 3 dropdowns the primary one is filled via jquery ajax request and it fills 2nd dropdown based on seletion and 3rd one is filled after 2nd's selection.
It was previously used Dropdown selected change event which AutoPostBack and gets data from server and page get refresh again and again. Instead of doing this i replace selection change events with jquery ajax calls and its seems fine but now when i click on my search button to fetch data based on selection it loses all dropdown's previous state and reset to default as on fresh page load. Whereas, my repeater remains the data which i had bound on button click. Any help regarding this issue???
|
|
|
|
|
Please use the ASP.NET forum for ASP.NET questions.
|
|
|
|
|
dear friends,
I'm new in Json, I need some help
here's the data:
{
"CardCode": "C001",
"PostingDate": "2017-05-17",
"DocDueDate": "2017-05-17",
"TaxDate": "2017-05-17",
"SalesPersonCode": "-1",
"DocumentNumberingPOS":"2",
"PrimaryNumberingPOS":"A002",
"lines": [{
"ItemCode": "ITEM0001",
"WarehouseCode": "PST-000",
"Quantity": "1",
"Price": "50000"
}, {
"ItemCode": "ITEM0002",
"WarehouseCode": "PST-000",
"Quantity": "1",
"Price": "10000"
}
]
}
and this is the result
{
"errorCode": "0",
"message": "Data has beed added",
"value": "23"
}
I've try to create the code in C#, but still nothing happen, and I don't know how to show the result in text box, and for the login to url, there's username: username and password: password,
here's my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net;
using Newtonsoft.Json;
namespace JsonTest
{
public partial class Form1 : Form
{
private string respon;
private static void PostJson(string url, template postParameters)
{
string postData = JsonConvert.SerializeObject(postParameters);
byte[] bytes = Encoding.UTF8.GetBytes(postData);
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.ContentType = "application/json";
string autorization = "username" + ":" + "password";
byte[] binaryAuthorization = System.Text.Encoding.UTF8.GetBytes(autorization);
autorization = Convert.ToBase64String(binaryAuthorization);
autorization = "Basic " + autorization;
httpWebRequest.Headers.Add("AUTHORIZATION", autorization);
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Count());
}
var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
if (httpWebResponse.StatusCode != HttpStatusCode.OK)
{
string message = String.Format("POST failed. Received HTTP {0}", httpWebResponse.StatusCode);
throw new ApplicationException(message);
}
}
private static void Result(string url, template postParameters)
{
//string respon;
string postData = JsonConvert.SerializeObject(postParameters);
byte[] bytes = Encoding.UTF8.GetBytes(postData);
System.Net.WebRequest request = System.Net.HttpWebRequest.Create("http:xxxxxxxx/api/CustomerSalesOrder"); // This only for your testing
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "GET";
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.ContentType = "application/json";
string autorization = "admin" + ":" + "admin";
byte[] binaryAuthorization = System.Text.Encoding.UTF8.GetBytes(autorization);
autorization = Convert.ToBase64String(binaryAuthorization);
autorization = "Basic " + autorization;
httpWebRequest.Headers.Add("AUTHORIZATION", autorization); //System.Net.WebRequest request = System.Net.HttpWebRequest.Create("(ServerLocal)/WSLokalRest/Peserta/peserta/" + txtNoKartu.Text); Get This from your Client (live)
try
{
System.Net.WebResponse response1 = request.GetResponse();
System.IO.Stream stream = response1.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(stream);
string contents = reader.ReadToEnd();
respon = contents;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
PostJson("http:xxxxxxx/api/CustomerSalesOrder", new template{ });
var template = new template
{
CardCode = "C001",
PostingDate = "2017-05-17",
DocDueDate = "2017-05-17",
TaxDate = "2017-05-17",
SalesPersonCode = "-1",
DocumentNumberingPOS = "2",
PrimaryNumberingPOS = "A002",
};
template.Lines.Add(new template_item
{
ItemCode = "ITEM0001",
WarehouseCode = "PST-000",
Quantity = "1",
Price = "50000",
});
template.Lines.Add(new template_item
{
ItemCode = "ITEM0002",
WarehouseCode = "PST-000",
Quantity = "1",
Price = "10000"
});
txtRespon.Text = respon;
}
}
public class template
{
public string CardCode { get; set; }
public string PostingDate { get; set; }
public string DocDueDate { get; set; }
public string TaxDate { get; set; }
public string SalesPersonCode { get; set; }
public string DocumentNumberingPOS { get; set; }
public string PrimaryNumberingPOS { get; set; }
public static List<template_item> Lines = new List<template_item>();
}
public class template_item
{
public string ItemCode { get; set; }
public string WarehouseCode { get; set; }
public string Quantity { get; set; }
public string Price { get; set; }
}
}
Does anyone could help me ?
Thank you for your help
Regards,
Steve Henry
|
|
|
|
|
|
That is lousy advice, as a newbie he may want a discussion on how to achieve his requirements.
Redirecting his inquiry from c# to web forum or quick answers may be valid because of the context of the question but to redirect everything to quick answers for a "speedy" response is not valid.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
This is the first post for him in Codeproject, may be he is not aware of quick answers section thats why gave a headsup.
since the question is related to json, he might get quick response in QA.
|
|
|
|
|
I agree with Mycroft, there is nothing wrong with the OP's question being here. And no guarantee that he will get a faster answer in QA.
|
|
|
|
|
You have not explained what is wrong with the result, or where you think your code is going wrong. Also, it would really help if you use proper indentation of your code, and the code button to add <pre></pre> tags around your code to make it readable, thus:
public class template_item
{
public string ItemCode { get; set; }
public string WarehouseCode { get; set; }
public string Quantity { get; set; }
public string Price { get; set; }
}
|
|
|
|
|
Hello everyone, I kindly ask for an orientation in my code, which is done in C # with Android Debug Bridge (ADB) commands that run at a DOS prompt.
The command basically reads the serial number from my tablet and transfers it to a textBox. Until then, no problem. However I need to copy this serial number from this textBox and transfer it to a new ADB command in DOS to read the battery data. Below is the code for better understanding, the first block is to get the serial number and transfer it to textBox1:
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = "adb.exe";
startInfo.Arguments = "get-serialno";
process.StartInfo = startInfo;
process.Start();
string output1 = process.StandardOutput.ReadToEnd();
textBox1.Text = output1;
process.WaitForExit();
}
And the second block is the code that will direct the commands to the serial number:
startInfo.FileName = "adb.exe";
startInfo.Arguments = "-s " + textBox1.Text + " shell dumpsys battery";
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
richTextBox1.Text = output;
process.WaitForExit();
But I can not get it to recognize the variable in the argument line. I've tried to concatenate, without success ... where am I going wrong? What I've already tried, in the searches I've done:
startInfo.Arguments = String.Format(@"/c adb -s ""{0}"" shell dumpsys battery", output1);
startInfo.Arguments = "/c adb -s \"" + output1 + "\" shell dumpsys battery";
startInfo.Arguments = $@"/c adb -s ""{output1}"" shell dumpsys battery";
Thanks a lot!
|
|
|
|
|
What is the actual value of the startinfo string when you call Process.Start?
|
|
|
|
|
The value is
e16025f4
If I store this value like this:
startInfo.Arguments = "-s e16025f4 shell dumpsys battery";
It works perfectly!
|
|
|
|
|
No, I mean what is the value of the startInfo.Arguments string when you call process.Start()? Use your debugger to see the exact values when you run the code, not what you think it will be.
|
|
|
|
|
Open a command line, and type in the command. Does it work? Try it until that works. Then tell us what you typed in the command line, and we might be able to figure out how to create that command from C#.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Hi, the command I type in command line thats works is this:
-s e16025f4 shell dumpsys battery
I am trying to figure out a way to use a string or anything to copy the text (the serial number text e16025f4) from the textbox and use it in the command line, because this value is dynamic and changes everytime I connect a different tablet or cellphone in the computer.
|
|
|
|
|
Then it is e.g.
startInfo.Arguments = $"-s {output} shell dumpsys battery";
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Hello
I need help to create a simple editor with intellisense in c# (should be used to format SSML files).
I imagine some kind of textbox where the user can write text and when pressing < a dropdown list is shown containing different elements. When an element is selectet the options for the elements is shown when typing (or something like that) and when < is press again the closing element should be shown as the first element in the dropdown list.
I would be nice if new element and options could be added to the editor in a simple way (list or xml file).
I do not know it it makes sense, if - can anyone tell me where to find samples or / opensource for it.
|
|
|
|
|
This site actually contains multiple articles on that topic. I'm using Scintilla.NET, as it also works nicely under Ubuntu. Ask Google for details.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have this method:
private async Task<QualificationTestResult> RunTest(Location bay, IBayQualificationTest test, CancellationTokenSource token, string baySerialNumber)
{
var _logger = new BayQualificationTestLogger(bay, baySerialNumber);
IEnumerable<string> details = null;
var testResult = new QualificationTestResult
{
Name = test.Name,
Version = test.Version,
};
testResult.Result = test.PerformTest(_logger,
((InstrumentService)_instrumentService).GetBayCommunicationService(bay),
token.Token,
out details);
return testResult;
}
I want to run it for a number of different tests, then get all QualificationTestResults back into a list.
So far I have this:
qualificationResult.TestResults.Clear();
IEnumerable<IBayQualificationTest> tests = GetQualificationTests().OrderBy(x => x.Priority).ToList();
List<Task> tasks = new List<Task>();
Task<QualificationTestResult> thermalTask = null;
Task<QualificationTestResult> eSensingTask = null;
var thermal = tests.Where(t => t.Name.ToLower().Contains("therm")).FirstOrDefault();
if (thermal != null)
{
thermalTask = Task.Factory.StartNew(() =>
RunTest(bay, thermal, token, baySerialNumber));
tasks.Add(thermalTask);
}
.
.
.
Task completionTask = Task.WhenAll(tasks);
foreach (var t in tasks)
{
qualificationResult.TestResults.Add(t);
}
This won't compile. On the Factory line I get
Cannot implicitly convert type 'System.Threading.Tasks.Task<System.Threading.Tasks.Task<...Core.Models.QualificationTestResult>>' to 'System.Threading.Tasks.Task<...Core.Models.QualificationTestResult>'
And on the FOR EACH at the bottom, the t.Result errors with "Task does not contain a definition for Result"
This is driving me nuts. What am I doing wrong here???
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
At a first pass, drop the async from your test method. It's not neccessary because you aren't awaiting anything in that method. Then, you can remove the Task part of it so you're only returning the QualificationTestResult. As you are creating your own external Task for this using the TaskFactory methods, you don't need to make that method return a Task.
This space for rent
|
|
|
|
|
OK, that fixed the Task.Factory problem..
Now, how do I get the results from all the tasks. here's what I have so far
qualificationResult.TestResults.Clear();
IEnumerable<IBayQualificationTest> tests = GetQualificationTests().OrderBy(x => x.Priority).ToList();
List<Task> tasks = new List<Task>();
Task<QualificationTestResult> thermalTask = null;
Task<QualificationTestResult> eSensingTask = null;
var thermal = tests.Where(t => t.Name.ToLower().Contains("therm")).FirstOrDefault();
if (thermal != null)
{
thermalTask = Task.Factory.StartNew(() =>
RunTest(bay, thermal, token, baySerialNumber));
tasks.Add(thermalTask);
};
Task completionTask = Task.WhenAll(tasks);
foreach (var t in tasks)
{
qualificationResult.TestResults.Add(t.Result);
}
The last part won't compile. Tells me there is no "Result" on the task.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
If the calling method is async :
QualificationTestResult[] results = await Task.WhenAll(tasks);
If it's not:
QualificationTestResult[] results = Task.WhenAll(tasks).GetAwaiter().GetResult();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: QualificationTestResult[] results = Task.WhenAll(tasks).GetAwaiter().GetResult();
This fails to compile with "Cannot implicitly convert type 'void' to QualificationTestResult[]"
[UPDATE]
This works
try
{
Task.WaitAll(tasks.ToArray());
}
catch (Exception e)
{
}
foreach (var task in tasks)
{
var result = ((Task<QualificationTestResult>)task).Result;
qualificationResult.TestResults.Add(result);
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 3-Oct-17 11:56am.
|
|
|
|
|
Ah, sorry - one more change to make it work:
List<Task<QualificationTestResult>> tasks = new List<Task<QualificationTestResult>>();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Just gonna throw a simple TPL Dataflow answer out there, since I've been having such a blast with it. Of course it loses a lot of it's utility since it's not part of a pipeline.
var xform = new TransformBlock<IBayQualificationTest,QualificationTestResult>(
thermal => {
try {
qualificationResult.TestResults.Add(RunTest(bay, thermal, token, baySerialNumber));
}catch{}
});
tests.Where(t => t.Name.ToLower().Contains("therm"))Select(x => xform.Post(x));
xform.Complete();
xform.Completion().Wait();
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|