private void btSave_Click(object sender, EventArgs e) { if (!ValidateData()) { return; } string productCode = txtProductCode.Text; string productType = cbBoxProductType.Text; string brand = cbBoxBrand.Text; decimal inputPrice = decimal.Parse(txtInputPrice.Text); decimal price = decimal.Parse(txtPrice.Text); decimal price2 = 0; decimal.TryParse(txtPrice2.Text, out price2); decimal price3 = 0; decimal.TryParse(txtPrice3.Text, out price3); decimal price4 = 0; decimal.TryParse(txtPrice4.Text, out price4); string note = txtNote.Text; int prodId = 0; using (TransactionScope tran = new TransactionScope()) { int.TryParse(prodTableAdapter.InsertProdReturnId(productCode, brand, inputPrice, price, price2, price3, price4, productType, note).ToString(), out prodId); if (prodId != 0) { foreach (object item in chkListBoxSize.CheckedItems) { productTableAdapter.InsertProductReturnId(item.ToString(), price, inputPrice, price2, price3, price4, prodId); } } tran.Complete(); } DialogResult result = MessageBox.Show("Tạo mã hàng thành công, bạn có muốn tạo mã hàng mới?", "Tạo mã hàng thành công", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (result == System.Windows.Forms.DialogResult.OK) { ClearData(); } else { this.Close(); } }
private void InsertProduct() { string productCode = txtProductCode.Text; string productType = cbBoxProductType.Text; string brand = cbBoxBrand.Text; string size = cbBoxSize.Text; decimal productCost = decimal.Parse(txtInputPrice.Text == string.Empty ? "0" : txtInputPrice.Text); decimal price = decimal.Parse(txtPrice.Text); decimal price2 = decimal.Parse(txtPrice2.Text); decimal price3 = decimal.Parse(txtPrice3.Text); decimal price4 = decimal.Parse(txtPrice4.Text); int prodId = int.Parse(lbProdId.Text); if (int.Parse(productTableAdapter.InsertProductReturnId(size, price, productCost, price2, price3, price4, prodId).ToString()) > 0) { MessageBox.Show("Thêm mã hàng thành công"); ClearData(); txtProductCode_TextChanged(new object(), new EventArgs()); } }