예제 #1
0
        public EventCreationForm(MultipleOutput mo)
        {
            currentevent = mo.newEvent;
            InitializeComponent();
            //add text
            var eventname = mo.newEvent.Name + Environment.NewLine + mo.newEvent.Cost;

            lblEventAdded.Text = eventname;

            // Fill grids with added and not added members
            DataTable dt = new DataTable();

            dt.Columns.Add("First Name");
            dt.Columns.Add("Sur Name");
            foreach (var item in mo.notAdded)
            {
                int charlocation = item.IndexOf(",", StringComparison.Ordinal);
                dt.Rows.Add(item.Substring(0, charlocation), item.Substring(charlocation + 1, (item.Length - charlocation - 1)));
            }
            EventParticipantsNotAdded.DataSource          = dt;
            EventParticipantsNotAdded.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            var neweventmembers = mo.newEvent.eventAmounts.ToList().Select(x => x.thisMember).Select(x => new { x.firstName, x.surName }).ToList();

            EventParticipantsAdded.DataSource          = neweventmembers;
            EventParticipantsAdded.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            // Fill last grid with Members database
            EventMembers = db.eventAmountReductions.Include("thisMember").Where(x => x.ThisEvent.Id == currentevent.Id).ToList();
            EventMemberList.DataSource = hc.Search("", EventMembers);

            EventMemberList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.StartPosition   = new FormStartPosition();
        }
예제 #2
0
        public void toeventcreationform(Form thisform, MultipleOutput mo)
        {
            EventCreationForm ecf = new EventCreationForm(mo);

            ecf.MdiParent = thisform;
            ecf.Show();
        }
예제 #3
0
        private void ImportEvent_Click(object sender, EventArgs e)
        {
            hideinactive();
            MultipleOutput mo = ec.openImportEvent();

            toeventcreationform(this, mo);
        }
예제 #4
0
        public MultipleOutput openImportEvent()
        {
            Stream         myStream = null;
            MultipleOutput mo       = new MultipleOutput();
            OpenFileDialog ofd      = new OpenFileDialog
            {
                InitialDirectory = "C:\\Users\\Matthijs\\Downloads",
                Filter           = "CSV Files (*.csv)|*.csv"
            };

            EventsController ec = new EventsController();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (myStream = ofd.OpenFile())
                {
                    mo = ImportEvent(myStream);
                }
            }
            return(mo);
        }
예제 #5
0
        private void btnImportEvent_Click(object sender, EventArgs e)
        {
            Stream         myStream = null;
            MultipleOutput mo       = new MultipleOutput();
            OpenFileDialog ofd      = new OpenFileDialog
            {
                InitialDirectory = "C:\\Users\\Matthijs\\Downloads",
                Filter           = "CSV Files (*.csv)|*.csv"
            };

            EventsController ec = new EventsController();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (myStream = ofd.OpenFile())
                {
                    mo = ec.ImportEvent(myStream);
                }
                EventCreationForm ecf = new EventCreationForm(mo);
                this.Hide();
                ecf.Show();
            }
        }
예제 #6
0
        public MultipleOutput ImportEvent(Stream stream)
        {
            var counter = 0;

            List <string> notadded      = new List <string>();
            Event         newevent      = new Event();
            List <Event>  currentevents = new List <Event>();

            currentevents = db.Events.ToList();

            using (StreamReader sr = new StreamReader(stream))
            {
                string[] x;
                var      addcounter      = 0;
                var      notaddedcounter = 0;
                while (sr.EndOfStream == false)
                {
                    x = sr.ReadLineAsync().Result.Split(';');
                    counter++;
                    if (counter == 2)
                    {
                        newevent.Cost = decimal.Parse(x[1]);
                        newevent.Name = x[0];
                        if (currentevents.Exists(e => e.Name == x[0]))
                        {
                            var existingevent = currentevents.Find(y => y.Name == x[0]);
                            var eventears     = db.eventAmountReductions.Include("thisMember").Include("thisEvent").Where(z => z.ThisEvent.Id == existingevent.Id).ToList();
                            foreach (var ear in eventears)
                            {
                                db.eventAmountReductions.Remove(ear);
                            }
                            db.Events.Remove(existingevent);
                            db.SaveChanges();
                        }
                    }
                    if (counter > 3)
                    {
                        var memberfinder = db.bareMembers.ToList().Find(y => y.firstName.ToLower() == x[0].ToLower() && y.surName.ToLower() == x[1].ToLower());
                        if (memberfinder != null)
                        {
                            EventAmountReduction ear = new EventAmountReduction();

                            if (int.TryParse(x[2], out int num))
                            {
                                ear.Amount = num;
                            }
                            if (decimal.TryParse(x[3], out decimal num2))
                            {
                                ear.Reduction = num2;
                            }
                            ear.thisMember = memberfinder;
                            db.eventAmountReductions.Add(ear);
                            newevent.eventAmounts.Add(ear);
                            addcounter++;
                            db.SaveChanges();
                        }
                        else
                        {
                            notaddedcounter++;
                            notadded.Add($"{x[0]},{x[1]}");
                        }
                    }
                }
                db.Events.Add(newevent);
                db.SaveChanges();
                StringBuilder sb = new StringBuilder();
                foreach (var member in notadded)
                {
                    sb.Append(member + " ");
                }
            }
            MultipleOutput mo = new MultipleOutput();

            mo.newEvent = newevent;
            mo.notAdded = notadded;
            return(mo);
        }