Пример #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                using (var context = new LorikeetAppEntities())
                {
                    decimal number;

                    if (textBoxDebit.Text == "" && decimal.TryParse(textBoxCredit.Text, out number))
                    {
                        var creditToAdd = new DebitSystem();
                        creditToAdd.StaffID  = this.staffID;
                        creditToAdd.MemberID = this.memberID;
                        creditToAdd.Credit   = number;
                        creditToAdd.Debit    = 0;
                        creditToAdd.Details  = textBoxDetails.Text;
                        creditToAdd.Date     = DateTime.Now;

                        decimal?runTotal = 0m;

                        var runningTotal = (from dc in context.DebitSystems
                                            where dc.MemberID == this.memberID
                                            select dc).ToList();

                        if (runningTotal.Any())
                        {
                            runTotal = runningTotal.Last().RunningTotal + number;
                        }
                        else
                        {
                            runTotal = number;
                        }

                        creditToAdd.RunningTotal = runTotal;

                        context.DebitSystems.Add(creditToAdd);
                        context.SaveChanges();

                        Logging.AddLogEntry(staffID, Logging.ErrorCodes.Broadcast, Logging.RefreshCodes.DebitCredit, "Credit for member - " + MiscStuff.GetMemberName(memberID) + " of $" + number + " Added", false);
                    }
                    else if (textBoxCredit.Text == "" && decimal.TryParse(textBoxDebit.Text, out number))
                    {
                        var debitToAdd = new DebitSystem();
                        debitToAdd.StaffID  = this.staffID;
                        debitToAdd.MemberID = this.memberID;
                        debitToAdd.Credit   = 0;
                        debitToAdd.Debit    = number;
                        debitToAdd.Details  = textBoxDetails.Text;
                        debitToAdd.Date     = DateTime.Now;

                        decimal?runTotal = 0m;

                        var runningTotal = (from dc in context.DebitSystems
                                            where dc.MemberID == this.memberID
                                            select dc).ToList();

                        if (runningTotal.Any())
                        {
                            runTotal = runningTotal.Last().RunningTotal - number;
                        }
                        else
                        {
                            runTotal = 0 - number;
                        }

                        debitToAdd.RunningTotal = runTotal;

                        context.DebitSystems.Add(debitToAdd);
                        context.SaveChanges();

                        Logging.AddLogEntry(staffID, Logging.ErrorCodes.Broadcast, Logging.RefreshCodes.DebitCredit, "Debit for member - " + MiscStuff.GetMemberName(memberID) + " of $" + number + " Added", false);
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.AddLogEntry(staffID, Logging.ErrorCodes.Error, Logging.RefreshCodes.None, "Debit / Credit not added - " + ex.Message, false);
                MessageBox.Show(MiscStuff.GetAllMessages(ex));
            }

            textBoxCredit.Text  = "";
            textBoxDebit.Text   = "";
            textBoxDetails.Text = "";

            this.debitSystemTableAdapter.FillByMemberID(this.lorikeetAppDataSet.DebitSystem, memberID);
        }
Пример #2
0
        private void bbiSaveAndClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                using (var context = new LorikeetAppEntities())
                {
                    var diagnosisToRemove = (from dtr in context.Diagnosis
                                             where dtr.MemberID == memberID
                                             select dtr).ToList();

                    if (diagnosisToRemove.Count > 0)
                    {
                        foreach (var dtr in diagnosisToRemove)
                        {
                            context.Diagnosis.Remove(dtr);
                            context.SaveChanges();
                        }
                    }

                    foreach (var dta in diagnosisToAdd)
                    {
                        Diagnosi diagnosisToAdd = new Diagnosi();
                        diagnosisToAdd.MemberID        = memberID;
                        diagnosisToAdd.DiagnosisNameID = dta.DiagnosisNameID;

                        context.Diagnosis.Add(diagnosisToAdd);
                        context.SaveChanges();
                    }

                    Logging.AddLogEntry(staffID, Logging.ErrorCodes.Broadcast, Logging.RefreshCodes.Diagnosis, MiscStuff.GetMemberName(memberID) + " Diagnosis has been edited", false);
                }
            }
            catch (Exception ex)
            {
                Logging.AddLogEntry(staffID, Logging.ErrorCodes.Error, Logging.RefreshCodes.None, MiscStuff.GetMemberName(memberID) + " had a problem when editing Diagnosis - Error - " + ex.Message, false);
                MessageBox.Show(ex.Message);
            }

            this.Close();
        }
Пример #3
0
        private void bbiDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (editable && noteID != -1)
            {
                try
                {
                    using (var context = new LorikeetAppEntities())
                    {
                        var noteToDelete = (from n in context.Notes
                                            where n.NotesID == noteID
                                            orderby n.Date
                                            select n).DefaultIfEmpty().First();

                        if (noteToDelete != null)
                        {
                            context.Notes.Remove(noteToDelete);
                            context.SaveChanges();
                        }
                    }
                    Logging.AddLogEntry(staffID, Logging.ErrorCodes.Broadcast, Logging.RefreshCodes.Notes, "Notes on " + MiscStuff.GetMemberName(memberID) + " have been deleted", false);
                }
                catch (Exception ex)
                {
                    Logging.AddLogEntry(staffID, Logging.ErrorCodes.Error, Logging.RefreshCodes.None, "Notes on " + MiscStuff.GetMemberName(memberID) + " has not been deleted - Error - " + ex.Message, false);
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Note is not directly Editable");
            }

            RefreshNotesGrid();

            bbiAdd.Enabled    = false;
            bbiEdit.Enabled   = false;
            bbiDelete.Enabled = false;
        }
Пример #4
0
        private void bbiEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (textBoxAddNote.Text != "")
            {
                try
                {
                    using (var context = new LorikeetAppEntities())
                    {
                        var noteToEdit = (from n in context.Notes
                                          where n.NotesID == noteID
                                          select n).DefaultIfEmpty().First();

                        if (noteToEdit != null)
                        {
                            noteToEdit.Notes = textBoxAddNote.Text;
                            noteToEdit.Date  = dateEditNote.DateTime;
                            context.SaveChanges();
                        }
                    }

                    Logging.AddLogEntry(staffID, Logging.ErrorCodes.Broadcast, Logging.RefreshCodes.Notes, "Notes on " + MiscStuff.GetMemberName(memberID) + " has been edited", false);
                }
                catch (Exception ex)
                {
                    Logging.AddLogEntry(staffID, Logging.ErrorCodes.Error, Logging.RefreshCodes.None, "Notes on " + MiscStuff.GetMemberName(memberID) + " has not been edited - Error - " + ex.Message, false);
                    MessageBox.Show(ex.Message);
                }

                RefreshNotesGrid();

                textBoxAddNote.Text = "";

                bbiAdd.Enabled    = false;
                bbiEdit.Enabled   = false;
                bbiDelete.Enabled = false;
            }
        }
Пример #5
0
        private void bbiAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (textBoxAddNote.Text != "")
            {
                try
                {
                    using (var context = new LorikeetAppEntities())
                    {
                        var noteToAdd = new Note();
                        noteToAdd.Date     = dateEditNote.DateTime;
                        noteToAdd.Editable = true;
                        noteToAdd.MemberID = memberID;
                        noteToAdd.Notes    = textBoxAddNote.Text;
                        noteToAdd.StaffID  = this.staffID;

                        context.Notes.Add(noteToAdd);
                        context.SaveChanges();
                    }

                    Logging.AddLogEntry(staffID, Logging.ErrorCodes.Broadcast, Logging.RefreshCodes.Notes, "Notes on " + MiscStuff.GetMemberName(memberID) + " has been added", false);
                }
                catch (Exception ex)
                {
                    Logging.AddLogEntry(staffID, Logging.ErrorCodes.Error, Logging.RefreshCodes.None, "Notes on " + MiscStuff.GetMemberName(memberID) + " has not been added - Error - " + ex.Message, false);
                    MessageBox.Show(ex.Message);
                }

                RefreshNotesGrid();

                textBoxAddNote.Text = "";
                bbiAdd.Enabled      = false;
                bbiEdit.Enabled     = false;
                bbiDelete.Enabled   = false;
            }
        }
Пример #6
0
        private void bbiSaveAndClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                using (var context = new LorikeetAppEntities())
                {
                    var medicationToRemove = (from dtr in context.Medications
                                              where dtr.MemberID == memberID
                                              select dtr).ToList();

                    if (medicationToRemove.Count > 0)
                    {
                        foreach (var dtr in medicationToRemove)
                        {
                            context.Medications.Remove(dtr);
                            context.SaveChanges();
                        }
                    }

                    foreach (var dta in medicationToAdd)
                    {
                        Medication medicationToAdd = new Medication();
                        medicationToAdd.MemberID         = memberID;
                        medicationToAdd.MedicationNameID = dta.MedicationNameID;

                        context.Medications.Add(medicationToAdd);
                        context.SaveChanges();
                    }

                    Logging.AddLogEntry(staffID, Logging.ErrorCodes.Broadcast, Logging.RefreshCodes.Medication, MiscStuff.GetMemberName(memberID) + " Medications have been changed", false);
                }
            }
            catch (Exception ex)
            {
                Logging.AddLogEntry(staffID, Logging.ErrorCodes.Error, Logging.RefreshCodes.None, MiscStuff.GetMemberName(memberID) + " Medications have not been changed - Error - " + ex.Message, false);
                MessageBox.Show(ex.Message);
            }

            this.Close();
        }