private void txtProductCode_Leave(object sender, EventArgs e) { //判断编号是否已存在 if (!string.IsNullOrEmpty(this.txtProductCode.Text.Trim()) && !string.IsNullOrEmpty(this.txtUnitCode.Text.Trim())) { BaseProductUnitTable ProductUnitCode = new BaseProductUnitTable(); ProductUnitCode = bProductUnit.GetModel(txtProductCode.Text, txtUnitCode.Text); if (ProductUnitCode != null) { txtProductCode.Text = ""; txtProductName.Text = ""; txtUnitCode.Text = ""; txtUnitName.Text = ""; txtProductCode.Focus(); MessageBox.Show("商品编号与单位编号组合已存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (!string.IsNullOrEmpty(this.txtProductCode.Text.Trim())) { BaseProductTable product = new BaseProductTable(); BProduct bProduct = new BProduct(); product = bProduct.GetModel(this.txtProductCode.Text); if (product == null || "".Equals(product)) { txtProductCode.Focus(); txtProductCode.Text = ""; txtProductName.Text = ""; MessageBox.Show("商品编号不存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { txtProductCode.Text = product.CODE; txtProductName.Text = product.NAME; } } else { txtProductName.Text = ""; } }
/// <summary> /// 获得当前选中的数据 /// </summary> private void GetCurrentSelectedTable() { try { string productcode = dgvData.SelectedRows[0].Cells["PRODUCT_CODE"].Value.ToString(); string unitcode = dgvData.SelectedRows[0].Cells["UNIT_CODE"].Value.ToString(); if (productcode != "") { _currentProductUnitTable = bProductUnit.GetModel(productcode, unitcode); } } catch (Exception ex) { } if (_currentProductUnitTable == null || _currentProductUnitTable.PRODUCT_CODE == null || "".Equals(_currentProductUnitTable.PRODUCT_CODE)) { _currentProductUnitTable = null; } }