Exemplo n.º 1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (!superValidator1.Validate())
            {
                return;
            }
            try
            {
                if (UserAction == "edit")
                {
                    MedicineDetail.MedicineName = textBoxMedicineName.Text;
                    MedicineDetail.Quantity     = int.Parse(textBoxQuantity.Text);
                    MedicineDetail.Price        = decimal.Parse(textBoxPrice.Text);
                    DialogResult dialogResult = MessageBox.Show("Xác nhận cập nhập thông tin thuốc", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        if (Medicine.UpdateMedicine(MedicineDetail) > 0)
                        {
                            MessageBox.Show("Cập nhập thông tin thuốc thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    Medicine newMedicine = new Medicine(0, textBoxMedicineName.Text, int.Parse(textBoxQuantity.Text), decimal.Parse(textBoxPrice.Text));
                    if (Medicine.InsertMedicine(newMedicine) > 0)
                    {
                        MessageBox.Show("Thêm thuốc thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Lỗi dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.Close();
        }