예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string tagname = txtTagname.Text;

            Tag tag = new Tag
            {
                Name = tagname
            };

            if (String.IsNullOrEmpty(tagname))
            {
                MessageBox.Show("Inputs are not valid.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (db.Tags.FirstOrDefault(t => t.Name == tagname) != null)
            {
                MessageBox.Show("Tag with this name is already exists.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            db.Tags.Add(tag);
            db.SaveChanges();
            txtTagname.Clear();
            MessageBox.Show($"New tag {tagname} added successfully", "Success",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #2
0
        private void btnFinishHim_Click(object sender, EventArgs e)
        {
            foreach (OrderedMedicine ordMed in orderedMedicines)
            {
                _db.Orders.Add(new Order
                {
                    MedicineID = ordMed.Medicine.ID,
                    Count      = ordMed.OrderCount,
                    OrderDate  = DateTime.Now,
                    Price      = ordMed.Medicine.Price
                });

                _db.Medicines.Find(ordMed.Medicine.ID).Count -= ordMed.OrderCount;
            }
            _db.SaveChanges();

            UpdateMedicineDataGrid();

            MessageBox.Show("All ordered added successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private async void btnAddMedicine_Click(object sender, EventArgs e)
        {
            string medicine = txtName.Text.Trim();
            string barcode  = txtBarcode.Text.Trim();

            decimal   price      = nmPrice.Value;
            int       count      = (int)nmCount.Value;
            bool      HasReceipt = chReceipt.Checked;
            int       volume     = (int)nmVolume.Value;
            Comboitem unit       = cmbUnit.SelectedItem as Comboitem;

            Medicine med = new Medicine
            {
                Name       = medicine,
                Barcode    = barcode,
                Price      = price,
                Count      = count,
                HasReceipt = HasReceipt,
                Volume     = volume,
                UnitID     = unit.Value
            };

            if (!CheckMedInput(med))
            {
                MessageBox.Show("Inputs are not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtBarcode.Enabled && CheckMedBarcode(txtBarcode.Text))
            {
                MessageBox.Show("This barcode was used by another medicine", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtBarcode.Enabled)
            {
                //add new medicine

                Medicine addedMedicine = null;

                Task newTask = Task.Run(() =>
                {
                    addedMedicine = _db.Medicines.Add(med);
                    _db.SaveChanges();
                });

                await newTask;

                foreach (var tag in _medicineTags)
                {
                    _db.MedicineToTags.Add(new MedicineToTag
                    {
                        MedicineID = addedMedicine.ID,
                        TagID      = tag.ID
                    });
                }
                _db.SaveChanges();

                MessageBox.Show("New product was successfully added", "Success",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                //update count of existing medicine
                _db.Medicines.First(m => m.Barcode == txtBarcode.Text).Count += count;
                _db.SaveChanges();

                MessageBox.Show("Product count was successfully updated", "Success",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            UpdateMedicineDataGrid();
            ClearInputs();
        }