I have been making an app for a friend, but recently got stuck. For some reason, when I try to test "itemSubtotalAddRq" I get the following error:
Request[3]: ItemSubtotalAddRq ItemSubtotalAdd
Name: required fiels is missing
End of ItemSubtotalAdd
Im not sure what it is, but I know its one of the ItemSubtotalAddRq lines, or im using iItemSubtotalAdd wrong.
public void SalesInfoAdd(IMsgSetRequest requestMsgSet)
{
ISalesReceiptAdd salesReceiptAddRq = requestMsgSet.AppendSalesReceiptAddRq();
//IItemSubtotalAdd itemSubtotalAddRq = requestMsgSet.AppendItemSubtotalAddRq();
salesReceiptAddNew = new List<ISalesReceiptLineAdd>();
salesReceiptAddRq.CustomerRef.FullName.SetValue(Form.phoneNumber.Text);
salesReceiptAddRq.IsPending.SetValue(true);
salesReceiptAddRq.IsTaxIncluded.SetValue(false);
salesReceiptAddRq.FOB.SetValue(Form.orderID.Text);
salesReceiptAddNew.Clear();
int cnt = 0;
//while (i < Form.productID.Count)
for (int j = 0; j < Form.productID.Count; j++)
{
salesReceiptAddNew.Add(salesReceiptAddRq.ORSalesReceiptLineAddList.Append().SalesReceiptLineAdd);
salesReceiptAddNew[j].ItemRef.FullName.SetValue(Form.productID[j].ToString());
salesReceiptAddNew[j].ORRatePriceLevel.Rate.SetValue(Convert.ToDouble(Form.pricesList.Items[j]));
salesReceiptAddNew[j].Quantity.SetValue(Form.QBqt[j]);
salesReceiptAddNew[j].Desc.SetValue(Form.productsList.Items[j].ToString().ToUpper() + " -" + " " +
Form.QBsku[j].ToString().ToUpper());
cnt = j;
}
if (Form.DiscountType.Text != "None" || Form.DiscountType.Text != " ")
{
if (Form.productID.Count >= 2)
{
cnt++;
salesReceiptAddNew.Add(salesReceiptAddRq.ORSalesReceiptLineAddList.Append().SalesReceiptLineAdd);
salesReceiptAddNew[cnt].ItemRef.FullName.SetValue("SUBTOTAL");
salesReceiptAddNew[cnt].ORRatePriceLevel.Rate.SetValue(Form.totalOfAllItems);
//itemSubtotalAddRq.Name.SetValue("SUBTOTAL");
//itemSubtotalAddRq.IsActive.SetValue(true);
}
else
itemSubtotalAddRq.IsActive.SetValue(false);
cnt++;
salesReceiptAddNew.Add(salesReceiptAddRq.ORSalesReceiptLineAddList.Append().SalesReceiptLineAdd);
salesReceiptAddNew[cnt].ItemRef.FullName.SetValue(Form.DiscountType.Text);
}
if(Form.freeShipping.Checked == false)
{
cnt++;
salesReceiptAddNew.Add(salesReceiptAddRq.ORSalesReceiptLineAddList.Append().SalesReceiptLineAdd);
salesReceiptAddNew[cnt].ItemRef.FullName.SetValue("SHIPPING");
salesReceiptAddNew[cnt].ORRatePriceLevel.Rate.SetValue(Convert.ToDouble(Form.shipping.Text));
}
IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
}
this is the only solution i could think of, and it still doesn't work. any thoughts?
I think you are referring to 'ItemType' which is under 'Line' tag
Ref - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0500_quickbooks_windows/0600_object_reference/salesreceipt
XML
<Add RequestId="ca435123492c41b891f7841cf4d0e81d" xmlns="http://www.intuit.com/sb/cdm/v2">
<OfferingId>ipp</OfferingId>
<ExternalRealmId>65123456</ExternalRealmId>
<SalesReceipt>
<Header>
---
</Header>
<Line>
<Id idDomain="QB">66</Id>
<Desc>Description</Desc>
<ItemId idDomain="QB">4</ItemId>
<ItemName>Dusting</ItemName>
<ItemType>Subtotal</ItemType>
<UnitPrice>1231</UnitPrice>
</Line>
</SalesReceipt>
</Add>
Using Java, I had coded like this. I think, there should be some similar enums/classes in .Net too. Can you take a look at the .Net docs
Link - http://developer-static.intuit.com/SDKDocs/QBV2Doc/IntuitDataServicesSDK/
Instead of 'SUBTOTAL', you should use 'Subtotal'. In the service background, allowed values are [Assembly, Fixed Asset, Group, Inventory, Other Charge, Payment, Product, Service, Subtotal].
You can try this use case in the ApiExplorer.
Link - https://developer.intuit.com/apiexplorer?apiname=V2QBD#SalesReceipt
Java Code
QBSalesReceipt entityPojo = QBObjectFactory.getQBObject(context, QBSalesReceipt.class);
SalesReceiptLine receiptLine = QBObjectFactory.getQBObject(context, SalesReceiptLine.class);
receiptLine.setItemType(ItemTypeEnum.SUBTOTAL);
ArrayList receiptLines = new ArrayList();
receiptLines.add(receiptLine);
entityPojo.setLine(receiptLines);
QBSalesReceiptService service = QBServiceFactory.getService(context, QBSalesReceiptService.class);
service.addSalesReceipt(context, entityPojo);
Plz let me know how it goes.
Thanks
Related
So, I am trying to upload a certain files with names like '2018-2-10 10-23-34' // February 10, 2018 10:23:34, this is not a one file only, I have like multiple files with names like these. That's why I use HttpFileCollection.
Now, for example that I selected files with file names like these, I want to check if it has the right file name, else it will just SaveAs as it is.
As you can see below, I added a fake code, its fake since its not working or it has a wrong syntax in it.
I saw a code like this, but I don't know how to apply this on my current code with HttpFileCollection, please help.
bool contains = Directory.EnumerateFiles(path).Any(f => f.Contains("three"));
My Code
protected void UploadButton_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
try
{
string date = DateTime.Now.ToString("yyyy-M-d");
DateTime DateValue;
DateValue = DateTime.Parse(date, CultureInfo.InvariantCulture);
string dayoftheweek = "(" + DateValue.ToString("dddd") + ")";
Response.Write(dayoftheweek);
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
foreach (hfc[i].FileName.Contains(date))// What I am trying to do, but wrong syntax or wrong code
{
hfc[i].SaveAs(#path+"\\" + hfc[i].FileName + dayoftheweek);
}// What I am trying to do, but wrong syntax or wrong code
Response.Write(hfc[i].FileName);
hfc[i].SaveAs(#path+"\\" + hfc[i].FileName);
}
}
catch (Exception) { }
}
Your foreach loop is wrong as you mentioned.
//This will make you iterate trough the file collection
for (int i = 0; i < hfc.Count; i++)
{
if(hfc[i].FileName.Contains(date))
{
hfc[i].SaveAs(#path+"\\" + hfc[i].FileName + dayoftheweek);
}
}
The foreach loop is not needed anymore so you can remove
foreach (hfc[i].FileName.Contains(date))
{
}
The problem is your for each loop doesnt have a declaration
foreach(var variable in Enumerable){
//other code
}
so in your case it would be
foreach( var file in hfc)
{
//other code
}
and it should work just fine
I have a button to Export my Gridview1 data to Excel, but when i tried the code below(which i used in C#), it gives me a compiling error. Can you help me..
Error 1: Cannot apply indexing with [] to an expression of type 'System.Web.UI.WebControls.GridView'
Error 2: The name 'MessageBox' does not exist in the current context
try
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Visible = true;
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Add(System.Reflection.Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1];
int StartCol = 1;
int StartRow = 1;
int j = 0, i = 0;
//Write Headers
for (j = 0; j < GridView1.Columns.Count; j++)
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow, StartCol + j];
myRange.Value2 = GridView1.Columns[j].HeaderText;
}
StartRow++;
//Write datagridview content
for (i = 0; i < GridView1.Rows.Count; i++)
{
for (j = 0; j < GridView1.Columns.Count; j++)
{
try
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow + i, StartCol + j];
myRange.Value2 = GridView1[j, i].Value == null ? "" : GridView1[j, i].Value;
}
catch
{
;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Firstly, full disclosure: I'm not an expert on asp.net WebForms, so I'm reading this on a syntax basis only (not examining whether or not your actual framework usage is correct).
Error 1
To my eye, the error occurs here:
myRange.Value2 = GridView1[j, i].Value == null ? "" : GridView1[j, i].Value;
It looks like you are trying to reference GridView1 with array notation, inside a loop using variables i and j. However, look at your loops:
for (i = 0; i < GridView1.Rows.Count; i++)
for (j = 0; j < GridView1.Columns.Count; j++)
Your loops are accessing GridView1 via collections, specifically .Rows and .Columns respectively. So my assumption would be that you might need something like:
myRange.Value2 = GridView1.Rows[i].Columns[j].Value == null ? "" : GridView1.Rows[i].Columns[j].Value;
Remember, this is just a syntactic guess based on your earlier code (GridView1.Columns[j].HeaderText).
Error 2
The issue here is that the name (static class or variable) you are using, MessageBox, doesn't seem to exist at this point in the code. So I would ask:
Is the variable in scope? I.e., is it declared earlier in the try block, and has now gone out of scope in the catch?
If it's a static class, is the assembly referenced correctly? Intellisense should pick this up for you in Visual Studio, with refactor options to include a reference as a using statement above, or fully qualify the name for you.
From memory MessageBox is a static class in the WPF assemblies somewhere to do with windows forms, not as a part of ASP.NET - it is used to show a window in a desktop program. If you wish to show a message in a browser, that would be a javascript statement like:
alert("Your exception message here");
However, you will need some means of catching that Exception (ex), grabbing the text from it (ex.ToString()) and transmitting that into the page to be shown via javascript.
Last thought on that: if you are wanting to show that error, and it's as a result of a button clicked on the page, you may be intending to invoke the Export to Excel function as an AJAX call to the server. If this is the case, try returning a HTTP error code (like a 500 or something) back to the browser, and using the .fail() binder to display an appropriate client-side error. Just a suggestion :)
I am using C# with Microsoft.Web.Administration to remove all of the apps inside of a site. I do not want to remove the site app itself (path = "/").
Here's the code:
ServerManager manager = new ServerManager();
for (int i = 0; i < manager.Sites[siteName].Applications.Count; i++)
{
if (manager.Sites[siteName].Applications[i].Path != "/")
{
manager.Sites[siteName].Applications.RemoveAt(i);
}
}
manager.CommitChanges();
What happens with this code is that some apps get removed and others don't, and which apps get removed and which don't are different each run.
manager.Sites[sitename].Applications.Clear();
will work, but it will also remove the application with path = "/", which I don't want.
I tried doing something like this, too:
Application baseApp = null;
for (int i = 0; i < manager.Sites[siteName].Applications.Count; i++)
{
if (manager.Sites[siteName].Applications[i].Path == "/")
{
baseApp = manager.Sites[siteName].Applications[i];
}
}
manager.Sites[siteName].Applications.Clear();
if (baseApp != null)
{
manager.Sites[siteName].Applications.Add(baseApp);
}
manager.CommitChanges();
But that didn't work either. The app with path = "/" was never re-added, or wasn't added properly.
Is there anyone with more experience with Microsoft.Web.Automation who has some insights on removing more than one app at a time that can help me out with this?
As it turns out, I was making the classic stupid mistake of altering the collection while enumerating through it. The first app would be removed and the count would go down. Some apps were never getting looked at. The randomness of the removal was simply due to the unordered nature of the collection. Silly me!
This works:
List<Application> appsToRemove = new List<Application>();
for (int i = 0; i < manager.Sites[siteName].Applications.Count; i++)
{
if (manager.Sites[siteName].Applications[i].Path != "/")
{
Console.WriteLine("Removing {0}", manager.Sites[siteName].Applications[i].Path);
appsToRemove.Add(manager.Sites[siteName].Applications[i]);
}
}
foreach (Application a in appsToRemove)
{
manager.Sites[siteName].Applications.Remove(a);
}
manager.CommitChanges();
I am using Google Navigation charts in a project.
Everything works fine when I run the javascript code in the client side (.aspx page), but when I put it in the code behind and echo/write it out (via Response.Write()) it throws an error, specifically at the point where the javascript code trys to call the indexOf() method on an array.
I have tried to examine the cause of the error, but the only info I get is that this is a problem in IE8 and earlier with the indexOf() method- this cannot be my problem, because as I said it works fine when I call it directly from the client - it is only giving a problem form the code-behind.
This is the specific error I receive:
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'indexOf'
This will work fine (in client):
for (var i = 0; i < data.getNumberOfColumns() ; i++) {
if (i == 0 || defaultSeries.indexOf(i) > -1) {
// if the column is the domain column or in the default list, display the series
columns.push(i);
}
....
but this will throw an error (in code-behind):
htmlJS += "for (var i = 0; i < data.getNumberOfColumns() ; i++) {";
htmlJS += "if (i == 0 || defaultSeries.indexOf(i) > -1) {";
// if the column is the domain column or in the default li";st, display the series
htmlJS += "columns.push(i);";
htmlJS += "}";
....
Response.Write(htmlJS);
Does anyone know why this error only occurs from the code-behind?
Assuming defaultSeries is an array, you will need to polyfill Array.prototype.indexOf for IE<9, which only supports indexOf on strings.
Here's a polyfill from MDN:
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
if ( this === undefined || this === null ) {
throw new TypeError( '"this" is null or not defined' );
}
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
fromIndex = +fromIndex || 0;
if (Math.abs(fromIndex) === Infinity) {
fromIndex = 0;
}
if (fromIndex < 0) {
fromIndex += length;
if (fromIndex < 0) {
fromIndex = 0;
}
}
for (;fromIndex < length; fromIndex++) {
if (this[fromIndex] === searchElement) {
return fromIndex;
}
}
return -1;
};
}
Two things:
Based on your code, you might have a white-space issue with the javascript - you are concatenating the string, and so, for example, you will have a section that looks like "{if" - however, this is not likely causing your issue.
What IS likely causing your issue is the timing of the javascript hitting the page. Does the object EXIST when the response.write gets flushed to the client? In order to make sure that all the required bits of the page exist when you need them, you normally will want to use the scripting object methods to add the script, and then CALL the code on once the page is loaded. Check out this page on adding script dynamically to a page: http://msdn.microsoft.com/en-us/library/ms178207(v=vs.100).aspx
Thank you everyone - I have found a soltuion that works:
If I create the same string which contains the javascript indexOf() method and then either assign it as output to a literal element on the aspx page, or if I "echo" it out via the <% %> special tags then the javascript code will run fine.
So the following runs:
Code-Behind:
public string jsHtml ="";
jsHtml +="<script type='text/javascript'>";
jsHtml+="var defaultSeries = [1,2,3];";
jsHtml+="alert(defaultSeries.indexOf(2));";
jsHtml+="</script>";
txtValueA.Text = jsHtml;
Client/aspx page:
<asp:Literal ID="txtValueA" runat="server></asp:Literal>
//OR
<%=jsHtml %>
Strange but True..... thanks for the input
Am trying to display unread chats from skype to my c# application. I used int msgCount=skype.MissedMessages.Count to get number of unread messages and tried given functions skype.MissedChats.ToString() and skype.get_Message(msgCount).ToString(). But they display " System._ComObject". Any suggestions???
The answer is so simple and I got it as follows..
for (int i = 0; i < skype.MissedMessages.Count; i++)
{
if (skype.MissedMessages[i + 1].Type == TChatMessageType.cmeSaid)
{
string unreadMessage = skype.MissedMessages[i + 1].Body;
}
}
It's possible to read other details such as name of sender by skype.MissedMessages[i + 1].Sender
I would guess that it would require you to use an indexer to actually display the content of one particular chat message. Right now you're converting a ChatCollection to a string, and I would guess that they haven't implemented that, so it just returns this.GetType().Name.
I would guess that the indexer would work like this:
List<string> messages = new List<string>();
foreach (Char c in skype.MissedChats)
{
try
{
messages.Add(c.Name);
}
catch (COMException) { } // Invalid chat
}