private void DoProductFetching(string productCode, bool isAllowed) { if (String.IsNullOrEmpty(productCode)) return; cmbProduct.SelectedIndex = -1; var selectedIndex = cmbProduct.FindStringExact( StringHelper.Right("000000000" + productCode, 9)); //Switch to foreign code if(selectedIndex == -1) { cmbProduct.SelectedIndexChanged -= CmbProductSelectedIndexChanged; cmbProduct.DisplayMember = Product.ConstForeignCode; selectedIndex = cmbProduct.FindStringExact(productCode); //Switch to product code cmbProduct.DisplayMember = Product.ConstProductCode; cmbProduct.SelectedIndex = -1; cmbProduct.SelectedIndexChanged += CmbProductSelectedIndexChanged; } cmbProduct.SelectedIndex = selectedIndex; if ((selectedIndex != -1) || (!isAllowed)) return; var strCriteria = new List<string> { "(ProductCode = '" + StringHelper.Right("000000000" + productCode, 9) + "' OR ForeignCode = '" + productCode + "')", "QtyInStock > 0" }; var productList = _productService.GetObjects(strCriteria); if (productList.Count != 0) { if(productList.Count > 1) { Visible = false; using (var frmProductList = new FrmProductSearch()) { frmProductList.CodeProduct = productCode; if (frmProductList.ShowDialog(this) == DialogResult.OK) { var product = frmProductList.Product; if (product != null) { _productList.Add(product); DoProductFetching(product.ProductCode, true); } } Visible = true; } return; } foreach (Product product in productList) _productList.Add(product); DoProductFetching(productCode, false); } else { txtHidden.Text = string.Empty; const string briefMsg = "អំពីផលិតផល"; var detailMsg = Resources.MsgOperationRequestProductNotFound; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); return; } } }
private void TxtHiddenKeyDown(object sender, KeyEventArgs e) { if (e == null) return; try { switch (e.KeyCode) { case Keys.Escape: CancelSale(); break; case Keys.Delete: if (_saleItemBindingList.Count == 0) return; UpdateSaleItem(Resources.OperationRequestDelete, dgvSaleItem.SelectedRows[0].Index); break; case Keys.Add: if (!btnValid.Enabled) return; if (_saleItemBindingList.Count == 0) return; UpdateSaleItem(Resources.OperationRequestInsert, dgvSaleItem.SelectedRows[0].Index); break; case Keys.Subtract: if (!btnValid.Enabled) return; if (_saleItemBindingList.Count == 0) return; UpdateSaleItem(Resources.OperationRequestUpdate, dgvSaleItem.SelectedRows[0].Index); break; case Keys.Up: if (_saleItemBindingList.Count == 0) return; UpdateSelectedIndex(dgvSaleItem.SelectedRows[0].Index - 1); break; case Keys.Down: if (_saleItemBindingList.Count == 0) return; UpdateSelectedIndex(dgvSaleItem.SelectedRows[0].Index + 1); break; case Keys.Return: DoProductFetching(txtHidden.Text, true); break; case Keys.F1: Visible = false; using (var frmProductList = new FrmProductSearch()) { if(frmProductList.ShowDialog(this) == DialogResult.OK) { var product = frmProductList.Product; if(product != null) { if (product.QtyInStock != 0) { _productList.Add(product); DoProductFetching(product.ProductCode, true); } else { txtHidden.Text = string.Empty; const string briefMsg = "អំពីផលិតផល"; var detailMsg = Resources.MsgOperationRequestProductNotFound; using (var frmMessageBox = new FrmExtendedMessageBox()) { frmMessageBox.BriefMsgStr = briefMsg; frmMessageBox.DetailMsgStr = detailMsg; frmMessageBox.IsCanceledOnly = true; frmMessageBox.ShowDialog(this); } } } } Visible = true; } break; case Keys.F2: if(dgvSaleItem.CurrentRow == null) return; var selectedIndex = dgvSaleItem.SelectedRows[0].Index; var saleItem = _saleItemBindingList[selectedIndex]; if (saleItem == null) return; Visible = false; using (var frmSaleQty = new FrmSaleQty()) { frmSaleQty.SaleItem = saleItem; if (frmSaleQty.ShowDialog(this) == DialogResult.OK) { saleItem = frmSaleQty.SaleItem; _saleItemBindingList[selectedIndex] = saleItem; var product = saleItem.FkProduct; saleItem.Discount = product.DiscountPercentage; var publicUnitPriceOut = product.UnitPriceIn + ((product.UnitPriceIn * product.ExtraPercentage) / 100); publicUnitPriceOut = publicUnitPriceOut - ((publicUnitPriceOut * product.DiscountPercentage) / 100); if (publicUnitPriceOut == product.UnitPriceIn) publicUnitPriceOut = product.UnitPriceOut; publicUnitPriceOut = float.Parse( publicUnitPriceOut.ToString("N", AppContext.CultureInfo), AppContext.CultureInfo); saleItem.PublicUpOut = publicUnitPriceOut; saleItem.UnitPriceOut = product.UnitPriceIn + ((product.UnitPriceIn * product.ExtraPercentage) / 100); saleItem.UnitPriceOut = float.Parse( saleItem.UnitPriceOut.ToString("N", AppContext.CultureInfo), AppContext.CultureInfo); saleItem.SubTotal = saleItem.QtySold * publicUnitPriceOut; dgvSaleItem.Refresh(); CalculateSale(); } Visible = true; } break; default: break; } } catch (Exception exception) { FrmExtendedMessageBox.UnknownErrorMessage( Resources.MsgCaptionUnknownError, exception.Message); } }