条形码到窗口wpf应用程序中
本文关键字:应用程序 wpf 窗口 条形码 | 更新日期: 2023-09-27 18:22:13
我正在使用条形码进入窗口wpf应用程序,当项目不存在于数据库中时,它不会显示弹出窗口"MessageBox.Show("Item not Found");"
我已经实现了日志,根据日志它将进入else循环,但不显示消息框。
请让我知道你对同一的想法
我正在使用以下代码:
private void txtBarcode_TextChanged(object sender, TextChangedEventArgs e)
{
string urlLogPath = @"C:'11VideoWorking'Log'CashDrawerLog.txt";
try
{
if (txtBarcode.Text.Length == 13)
{
File.AppendAllText(urlLogPath, "Befor Get Product 'n");
objProductList = ObjGasLogic.GetSearchedProduct();
File.AppendAllText(urlLogPath, "Befor Product Check 'n");
if (objProductList != null)
{
File.AppendAllText(urlLogPath, "Before Condition 'n");
if (objProductList.Any(CheckProduct => CheckProduct.Barcode == txtBarcode.Text.Trim()))
{
File.AppendAllText(urlLogPath, "Item Found 'n");
objProductDetails = objProductList.Where(Product => Product.Barcode == txtBarcode.Text.Trim()).SingleOrDefault();
objProductDetails.Quantity = 0;
BindCurrentlySelectedProduct();
}
else
{
File.AppendAllText(urlLogPath, "Item Not Found ,'n");
MessageBox.Show("Item Not Found");
File.AppendAllText(urlLogPath, "After Item Not Found 'n");
}
//ClearCurrentSelectedProductDetails();
}
else
{
File.AppendAllText(urlLogPath, "6 'n");
MessageBox.Show("Item Not Found");
ClearCurrentSelectedProductDetails();
}
}
File.AppendAllText(urlLogPath, "End of Try 'n");
}
catch (Exception ex)
{
ObjExceptionLogic.LogException(ex.Message, Convert.ToInt32(User.Instance.User_ID));
File.AppendAllText(urlLogPath, "In catch'n" + ex.Message);
}
}
好的,我试着稍微清理一下你的代码,以降低的圈复杂度
private void txtBarcode_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (txtBarcode.Text.Length == 13)
{
var product = ObjGasLogic.GetProduct(txtBarcode.Text.Trim());
if (product != null)
{
objProductDetails = product;
objProductDetails.Quantity = 0;
BindCurrentlySelectedProduct();
}
else
{
MessageBox.Show("Item Not Found");
ClearCurrentSelectedProductDetails();
}
}
}
catch (Exception ex)
{
ObjExceptionLogic.LogException(ex.Message, Convert.ToInt32(User.Instance.User_ID));
}
}
这将要求您在objGasLogic类中创建一个新方法
ObjGasLogic.GetProduct(txtBarcode.Text.Trim())
获取条形码,但应降低此方法的复杂性。
有了这个实现,你应该对问题所在有了更好的了解,我认为在这里写入日志文件有点不必要,一个断点就足够了。