private void saveTicket_Click(object sender, EventArgs e)
        {
            try
            {
                using (var context = new Cabinet_MedicalEntities())
                {
                    var af = (from afect in context.Diseases
                              where afect.Denumire.Equals(diseaseBox.SelectedItem.ToString().Trim())
                              select afect.ID).ToList().First();
                    History_Patients hist = new History_Patients
                    {
                        ID_Afectiune = af,
                        ID_Pacient   = pacient.ID,
                        ID_Medic     = medic.ID,
                        Data         = DateTime.Now
                    };
                    context.History_Patients.Add(hist);
                    context.SaveChanges();

                    Internment_Tickets bilet = new Internment_Tickets
                    {
                        ID_Istoric = hist.ID,
                        Descriere  = diseaseBox.Text.ToString().Trim()
                    };
                    context.Internment_Tickets.Add(bilet);
                    context.SaveChanges();
                    MessageBox.Show("Biletul de trimitere a fost inregistrat!", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Eroare!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (var context = new Cabinet_MedicalEntities())
                {
                    string medic     = textBoxMedic.Text;
                    string afectiune = textBoxAfectiune.Text;
                    int    zile      = Int32.Parse(textBoxZile.Text);
                    if (textBoxMedic.Text.Length == 0)
                    {
                        throw new Exception("Nu ati introdus numele medicului/asistentului!");
                    }
                    else if (textBoxAfectiune.Text.Length == 0)
                    {
                        throw new Exception("Nu ati introdus denumirea afectiunii!");
                    }
                    else if (textBoxZile.Text.Length == 0)
                    {
                        throw new Exception("Nu ati introdus numarul de zile!");
                    }
                    else if (textBoxTipScutire.Text.Length == 0)
                    {
                        throw new Exception("Nu ati introdus tipul scutirii!");
                    }
                    else
                    {
                        var query = (from m in context.Employees
                                     where m.Nume.Equals(medic)
                                     select m).FirstOrDefault();

                        var query2 = (from a in context.Diseases

                                      where a.Denumire.Equals(afectiune)
                                      select a).FirstOrDefault();
                        if (query2 == null)
                        {
                            throw new Exception("Denumirea afectiunii este incorecta!");
                        }
                        else if (query == null)
                        {
                            throw new Exception("Numele medicului introdus esti incorect!");
                        }

                        else
                        {
                            var addnew = new History_Patients
                            {
                                ID_Medic = query.ID,

                                Data         = DateTime.Now,
                                ID_Pacient   = Pacient.ID,
                                ID_Afectiune = query2.ID
                            };
                            context.History_Patients.Add(addnew);
                            context.SaveChanges();

                            var addsc = new Exemption
                            {
                                ID_Istoric  = addnew.ID,
                                Zile_Repaus = zile,
                                Tip         = textBoxTipScutire.Text
                            };



                            context.Exemptions.Add(addsc);
                            context.SaveChanges();

                            MessageBox.Show("Scutirea a fost inregistrata cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            textBoxAfectiune.Text  = "";
                            textBoxMedic.Text      = "";
                            textBoxTipScutire.Text = "";
                            textBoxZile.Text       = "";
                        }
                    }
                }
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            using (var context = new Cabinet_MedicalEntities())
            {
                try
                {
                    if (textBoxAf.Text.Length == 0)
                    {
                        throw new Exception("Nu ati introdus denumirea afectiunii!");
                    }
                    else if (textBoxMed.Text.Length == 0)
                    {
                        throw new Exception("Nu ati introdus denumirea medicamentului!");
                    }
                    else if (textBoxNrF.Text.Length == 0)
                    {
                        throw new Exception("Nu ati introdus numarul de flacoane!");
                    }

                    else
                    {
                        var res = (from p in context.Drugs
                                   where p.Denumire.Equals(textBoxMed.Text)
                                   select p).FirstOrDefault();
                        int numar = Int32.Parse(textBoxNrF.Text);



                        var query2 = (from a in context.Diseases

                                      where a.Denumire.Equals(textBoxAf.Text)
                                      select a).FirstOrDefault();



                        if (query2 == null)
                        {
                            throw new Exception("Denumirea afectiunii este incorecta!");
                        }
                        string den = res.Denumire;

                        if (res.Stoc > numar)
                        {
                            var addnew = new History_Patients
                            {
                                ID_Medic = m.ID,

                                Data         = DateTime.Now,
                                ID_Pacient   = Pacient.ID,
                                ID_Afectiune = query2.ID
                            };
                            context.History_Patients.Add(addnew);
                            context.SaveChanges();

                            var addret = new Recipe
                            {
                                ID_Istoric     = addnew.ID,
                                ID_Medicament  = res.ID,
                                Numar_Flacoane = numar
                            };


                            context.Recipes.Add(addret);
                            context.SaveChanges();

                            using (var dbContextTransaction = context.Database.BeginTransaction())
                            {
                                try
                                {
                                    var pp = from dr in context.Drugs
                                             where dr.Denumire.Equals(den)
                                             select dr;
                                    foreach (var pastile in pp)
                                    {
                                        pastile.Stoc = pastile.Stoc - numar;
                                    }
                                    context.SaveChanges();
                                    dbContextTransaction.Commit();
                                }
                                catch (Exception)
                                {
                                    dbContextTransaction.Rollback();
                                }
                            }
                            MessageBox.Show("Reteta a fost inregistrata cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            textBoxAf.Text  = "";
                            textBoxMed.Text = "";
                            textBoxNrF.Text = "";
                        }
                        else
                        {
                            MessageBox.Show("Stoc insuficient!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Message",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }