private static void UpdateRowWithPurchLine(DataRow row, IPRDocumentLine line)
        {
            // Update columns that are included in IPRDocumentLine
            row[DataAccessConstants.LineReceiptNumber] = line.RecId;
            row[DataAccessConstants.ItemNumber]        = line.ItemId;
            row[DataAccessConstants.ItemName]          = line.ItemName;
            // If the item is a service, qtyOrdered is always 0.
            decimal quantity = line.QtyOrdered == 0 ? line.PurchQty : line.QtyOrdered;

            row[DataAccessConstants.QuantityOrdered]  = PurchaseOrderReceiving.InternalApplication.Services.Rounding.Round(quantity, 3);
            row[DataAccessConstants.QuantityReceived] = PurchaseOrderReceiving.InternalApplication.Services.Rounding.Round(line.PurchReceived, 3);

            if (row.RowState == DataRowState.Added)
            {
                // Always set to zero because only delta will be shown and submitted
                row[DataAccessConstants.QuantityReceivedNow] = PurchaseOrderReceiving.InternalApplication.Services.Rounding.Round(line.PurchReceivedNow, 3);
            }

            row[DataAccessConstants.UnitOfMeasure]  = line.PurchUnit;
            row[DataAccessConstants.ConfigId]       = line.ConfigId;
            row[DataAccessConstants.InventSizeId]   = line.InventSizeId;
            row[DataAccessConstants.InventColorId]  = line.InventColorId;
            row[DataAccessConstants.InventStyleId]  = line.InventStyleId;
            row[DataAccessConstants.DeliveryMethod] = line.DeliveryMethod;

            // Does not assign GUID. GUID cannot be used as PK because it will change every time on AX side
        }
        private void btnCommit_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // Save lines to local database
                SaveReceipt();

                LoadReceiptLinesFromDB();

                // Commit receipt to AX via webservice
                IPRDocument prDoc = PurchaseOrderReceiving.InternalApplication.Services.StoreInventoryServices.CommitOrderReceipt(this.PONumber, this.ReceiptNumber, this.prType);

                // Remove rows that are successfully submitted
                List <DataRow> removeRows = new List <DataRow>();

                if (prDoc != null)
                {
                    foreach (DataRow row in entryTable.Rows)
                    {
                        IPRDocumentLine updatedLine = prDoc.PRDocumentLines.Where(line => string.Equals(line.Guid, row.Field <string>(DataAccessConstants.Guid), StringComparison.OrdinalIgnoreCase) &&
                                                                                  line.UpdatedInAx == true).FirstOrDefault();

                        if (updatedLine != null)
                        {
                            removeRows.Add(row);
                        }
                    }
                }

                if (removeRows.Count > 0)
                {
                    foreach (DataRow row in removeRows)
                    {
                        // Remove line from local DB
                        receiptData.DeleteReceiptLine(row.Field <string>(DataAccessConstants.Guid));

                        // Remove line from form
                        entryTable.Rows.Remove(row);
                        entryTable.AcceptChanges();
                    }

                    if (removeRows.Count == prDoc.PRDocumentLines.Count)
                    {
                        // Delete header if all lines are removed
                        receiptData.DeleteReceipt(prDoc.RecId);

                        // Show commit succeeded message
                        using (frmMessage dialog = new frmMessage(10314011, MessageBoxButtons.OK, MessageBoxIcon.Information))
                        {
                            POSFormsManager.ShowPOSForm(dialog);
                            if (dialog.DialogResult == DialogResult.OK)
                            {
                                this.DialogResult = DialogResult.OK;
                                Close();
                            }
                        }
                    }
                    else
                    {
                        // Show partial commit success message
                        using (frmMessage dialog = new frmMessage(10314012, MessageBoxButtons.OK, MessageBoxIcon.Information))
                        {
                            POSFormsManager.ShowPOSForm(dialog);
                        }

                        grInventory.DataSource = entryTable;
                        entryTable.AcceptChanges();
                    }
                }
                else
                {
                    // Show commit failure message
                    using (frmMessage dialog = new frmMessage(10314013, MessageBoxButtons.OK, MessageBoxIcon.Information))
                    {
                        POSFormsManager.ShowPOSForm(dialog);
                    }

                    grInventory.DataSource = entryTable;
                    entryTable.AcceptChanges();
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }