C#代码在遇到断点时有效,否则在我禁用所有断点[Winforms]时不起作用

时间:2019-02-19 12:39:13

标签: c# .net winforms

当我尝试调试应用断点时,下面的代码可以完美运行,但是当我禁用断点并再次运行时,它无法完美运行。我在这里创建一个非库存项目,现在当它导航到其他页面时,它不会显示所有插入的行。

我试图使提交调用异步并将SaveNonStockItems()置于等待状态,但这没有用

    private void btnSubmit_Click(object sender, EventArgs e)
    {
        StringBuilder quoteDetailIDs = new StringBuilder();
        foreach (DataGridViewRow dataGridViewRow in grdQuoteDetail.Rows)
        {
            if (dataGridViewRow.Cells["colSelected"].Value != null &&
                dataGridViewRow.Cells["colSelected"].Value != DBNull.Value &&
                (bool)dataGridViewRow.Cells["colSelected"].Value)
            {
                quoteDetailIDs.Append(dataGridViewRow.Cells["colQuoteDetailID"].Value + ", ");
            }
        }
        StringBuilder quoteDetailIDsNonStock = new StringBuilder();
        if(SaveNonStockItems())
        {
            foreach (DataGridViewRow dataGridViewRow in grdNonStocks.Rows)
                {
                    if (dataGridViewRow.Cells["colSelectedNonStock"].Value != null &&
                        dataGridViewRow.Cells["colSelectedNonStock"].Value != DBNull.Value &&
                        (bool)dataGridViewRow.Cells["colSelectedNonStock"].Value)
                    {
                        quoteDetailIDsNonStock.Append(dataGridViewRow.Cells["colQuoteDetailID2"].Value + ", ");
                    }
                }
                //  Remove trailing ', '
                quoteDetailIDs.Append(quoteDetailIDsNonStock.ToString());
                quoteDetailIDs.Remove(quoteDetailIDs.Length - 2, 2);

                Guid orderID = Guid.Empty;
                try
                {
                    BeginInit("Converting " + _quotesModule.QuoteTypeInfo.TypeName + "# " + _quotesModule.QuoteHeader[0].QuoteHeaderID + " To Order..."); 
 _quotesModule.ConvertToOrder(_quotesModule.QuoteHeader[0].QuoteHeaderID, _quotesModule.QuoteHeader[0].CustTreeNodeID,Guid.Empty,_quotesModule.QuoteHeader[0].SupplyChainNodeID, txtPONumber.Text, quoteDetailIDs.ToString(),
                    chkCopyItemNotes.Checked, rdoOpenOrder.Checked ? 1 : 2,
                    rdoOpenOrder.Checked ? 0 : ctrlVendor.SelectedSupplyChainNodeID,
                    ref orderID, SessionModule.Current.User.UnityUserID);  
                    EndInit();
                    Global.AppResume();
                    if (orderID != Guid.Empty)
                    {
                        Navigate.ReOpenOrder(orderID);
                    }
                    DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    ErrorDialog.DisplayModal(ex);
                    EndInit();
                    Global.AppResume();
                    DialogResult = DialogResult.Cancel;
                }
        }

    private bool SaveNonStockItems()
    {
        if (grdNonStocks.Rows.Count > 0)
        {
            foreach (DataGridViewRow dataGridViewRow in grdNonStocks.Rows)
            {
                if (dataGridViewRow.Cells["colSelectedNonStock"].Value != null &&
                    dataGridViewRow.Cells["colSelectedNonStock"].Value != DBNull.Value &&
                    (bool)dataGridViewRow.Cells["colSelectedNonStock"].Value)
                {
                    string xml = CreateXml(dataGridViewRow);
                    if (xml != string.Empty)
                    {
                        try
                        {
                            int _skuID = ProductMaint.CreateNonStockingSku(xml, SessionModule.UserID); //Proc that inserts this
                            /* capture the item number for adding to the order (hack-ish) */
                            dataGridViewRow.Cells["colSkuID"].Value = _skuID;
                        }
                        catch (MercuryException mex)
                        {
                            /* non-stock creation failed */
                            ErrorDialog.DisplayModal("Non-stock creation failed.", mex.Message, true);
                            throw mex;

                        }
                    }
                    else
                    {
                        ErrorDialog.DisplayModal("Failed to generate creation parameters.");
                        return false;
                    }
                }
            }
        }
        return true;
    }

    private string CreateXml(DataGridViewRow dataGridViewRow)
    {
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        System.Xml.XmlNode root = doc.CreateElement("NonStockingSku");
        System.Xml.XmlNode sku = doc.CreateElement("Sku");
        System.Xml.XmlAttribute attr = null;


        doc.AppendChild(root);
        root.AppendChild(sku);
        attr = doc.CreateAttribute("ItemNumber");
        attr.Value = dataGridViewRow.Cells["colItemNumber2"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("Description");
        attr.Value = dataGridViewRow.Cells["colItemDescription2"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("ProductTypeID");
        attr.Value = dataGridViewRow.Cells["colType"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("ProductLineID");
        attr.Value = dataGridViewRow.Cells["colProductLine"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("ProductDepartmentID");
        attr.Value = dataGridViewRow.Cells["colDepartment"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("Landed");
        attr.Value = dataGridViewRow.Cells["colLanded"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("VendorSupplyChainNodeID");
        attr.Value = dataGridViewRow.Cells["colVendor"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("ListPrice");
        attr.Value = dataGridViewRow.Cells["colListPrice"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("Cost");
        attr.Value = dataGridViewRow.Cells["colCost"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("QuoteDetailID");
        attr.Value = dataGridViewRow.Cells["colQuoteDetailID2"].Value.ToString();
        sku.Attributes.Append(attr);

        attr = doc.CreateAttribute("Quantity");
        attr.Value = dataGridViewRow.Cells["colQuantity"].Value.ToString();
        sku.Attributes.Append(attr);



        return doc.OuterXml;

    }
}      
public static int CreateNonStockingSku(string parametersXml, int unityUserID)
    {
        Proc p = new Proc("NonStockingSku_i");
        p["@ParametersXml"] = parametersXml;
        p["@UnityUserID"] = unityUserID;
        p.Exec();

        int skuID;
        string message;

        if (p["@SkuID"] != DBNull.Value)
        {
            skuID = (int)p["@SkuID"];
            return skuID;
        }
        else
        {
            if (p["@Message"] != DBNull.Value)
            {
                message = p["@Message"].ToString();
            }
            else
            {
                message = "Unspecified error.";
            }
            throw new MercuryException(message);
        }
    }

我只想知道共振的表现。我从未在winforms中遇到过这样的问题,是因为我正在循环中保存还是找不到问题,它令人头疼的原因是发现问题是调试,但是当我调试代码时,它工作正常并且结果显示良好

此外,数据已正确存储在数据库中,只是无法以其导航的形式正确加载。

0 个答案:

没有答案