Esempio n. 1
0
        protected override void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(EditId))
            {
                MainForm.Db.Persons.Add(new Persons
                {
                    FirstName     = tbFirstName.Text,
                    LastName      = tbLastName.Text,
                    MiddleName    = tbMName.Text,
                    Comments      = tbComments.Text,
                    BirthDate     = dtBirthDate.Value,
                    CreateDate    = DateTime.Now,
                    ModifiedDate  = DateTime.Now,
                    Email         = tbEmail.Text,
                    IsActive      = cbIsActive.Checked,
                    Phone         = tbPhone.Text,
                    Sex           = rbMail.Checked ? 'M' : 'F',
                    SecondaryDate = dtSecondaryDate.Value,
                    GroupId       = (IsDetails ? DetailsId : Convert.ToString(cmbStudenGroup.SelectedValue)),
                    PersonType    = (char)PersonType
                });
            }
            else
            {
                var customer = MainForm.Db.Persons.FirstOrDefault(c => c.Id == EditId);
                if (customer != null)
                {
                    customer.FirstName     = tbFirstName.Text;
                    customer.LastName      = tbLastName.Text;
                    customer.MiddleName    = tbMName.Text;
                    customer.Comments      = tbComments.Text;
                    customer.BirthDate     = dtBirthDate.Value;
                    customer.ModifiedDate  = DateTime.Now;
                    customer.Email         = tbEmail.Text;
                    customer.IsActive      = cbIsActive.Checked;
                    customer.Phone         = tbPhone.Text;
                    customer.Sex           = rbMail.Checked ? 'M' : 'F';
                    customer.SecondaryDate = dtSecondaryDate.Value;
                    customer.GroupId       = (IsDetails ? DetailsId : Convert.ToString(cmbStudenGroup.SelectedValue));
                }
            }

            MainForm.Db.SubmitChanges();
            this.Hide();
            EditGrid.RefreshGrid();
        }
Esempio n. 2
0
        protected override void btnSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(EditId))
            {
                var newEvent = new Events
                {
                    EventName = tbEventName.Text,
                    MasterId  = Convert.ToString(cmbCheff.SelectedValue),
                    StartDate =
                        dtEventDate.Value.Date.AddHours(dtTimeFrom.Value.Hour).AddMinutes(dtTimeFrom.Value.Minute),
                    EndDate      = dtEventDate.Value.Date.AddHours(dtTimeTo.Value.Hour).AddMinutes(dtTimeTo.Value.Minute),
                    Costs        = Convert.ToDecimal(tbCosts.Text),
                    Menu         = tbMenu.Text,
                    CreateDate   = DateTime.Now,
                    ModifiedDate = DateTime.Now,
                    Comments     = tbComments.Text,
                    IsActive     = cbIsActive.Checked,
                    EventType    = (char)EventType
                };
                MainForm.Db.Events.Add(newEvent);
                MainForm.Db.SubmitChanges();
                EditId = newEvent.Id;
            }
            else
            {
                var eventEdit = MainForm.Db.Events.FirstOrDefault(c => c.Id == EditId);
                if (eventEdit != null)
                {
                    eventEdit.EventName = tbEventName.Text;
                    eventEdit.MasterId  = Convert.ToString(cmbCheff.SelectedValue);
                    eventEdit.StartDate =
                        dtEventDate.Value.Date.AddHours(dtTimeFrom.Value.Hour).AddMinutes(dtTimeFrom.Value.Minute);
                    eventEdit.EndDate =
                        dtEventDate.Value.Date.AddHours(dtTimeTo.Value.Hour).AddMinutes(dtTimeTo.Value.Minute);
                    eventEdit.Costs        = Convert.ToDecimal(tbCosts.Text);
                    eventEdit.Menu         = tbMenu.Text;
                    eventEdit.CreateDate   = DateTime.Now;
                    eventEdit.ModifiedDate = DateTime.Now;
                    eventEdit.Comments     = tbComments.Text;
                    eventEdit.IsActive     = cbIsActive.Checked;
                }
            }

            var selectedList  = (clbPartisipents.CheckedItems.Cast <Persons>().ToList()).Select(c => c.Id);
            var tmpDeleteList =
                MainForm.Db.EventsParticipants.Where(
                    c => c.EventId == EditId && !selectedList.Contains(c.ParticipantsId)).ToList();

            foreach (var item in tmpDeleteList)
            {
                MainForm.Db.EventsParticipants.Remove(item);
            }

            var tmpAddList =
                (clbPartisipents.CheckedItems.Cast <Persons>().ToList()).Where(i => !MainForm.Db.EventsParticipants.Where(
                                                                                   c => c.EventId == EditId).Select(c => c.ParticipantsId).Contains(i.Id)).Select(c => c.Id);

            foreach (var item in tmpAddList)
            {
                MainForm.Db.EventsParticipants.Add(new EventsParticipants
                {
                    EventId        = EditId,
                    ParticipantsId = item
                });
            }

            MainForm.Db.SubmitChanges();

            this.Hide();
            EditGrid.RefreshGrid();
        }
Esempio n. 3
0
        protected override void btnSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(EditId))
            {
                var newGroup = new Groups
                {
                    Name           = tbGroupName.Text,
                    TeacherId      = Convert.ToString(cmbTeacher.SelectedValue),
                    StartEducation = dtGroupStartDate.Value,
                    Level          = cbLevel.Text,
                    CreateDate     = DateTime.Now,
                    ModifiedDate   = DateTime.Now,
                    IsActive       = cbGroupIsActive.Checked,
                    Comments       = tbGroupComments.Text,
                    GroupType      = (char)GroupType
                };
                MainForm.Db.Groups.Add(newGroup);
                MainForm.Db.SubmitChanges();
                EditId = newGroup.Id;
            }
            else
            {
                var customer = MainForm.Db.Groups.FirstOrDefault(c => c.Id == EditId);
                if (customer != null)
                {
                    customer.Name           = tbGroupName.Text;
                    customer.TeacherId      = Convert.ToString(cmbTeacher.SelectedValue);
                    customer.StartEducation = dtGroupStartDate.Value;
                    customer.Comments       = tbGroupComments.Text;
                    customer.Level          = cbLevel.Text;
                    customer.ModifiedDate   = DateTime.Now;
                    customer.IsActive       = cbGroupIsActive.Checked;
                    customer.GroupType      = (char)GroupType;
                }
            }

            MainForm.Db.GroupsDays.RemoveAll((c => c.GroupId == EditId));
            MainForm.Db.SubmitChanges();

            var defaultDate = new DateTime(2015, 1, 1, 0, 0, 0, 0);

            var panel = (Controls["schedulerPanel"] as GroupBox);

            for (var i = 1; i <= 7; i++)
            {
                if ((panel.Controls["cbDay" + i] as CheckBox).Checked)
                {
                    MainForm.Db.GroupsDays.Add(new GroupsDays
                    {
                        GroupId   = EditId,
                        Day       = i,
                        StartTime = defaultDate + (panel.Controls["dtFrom" + i] as DateTimePicker).Value.TimeOfDay,
                        EndTime   = defaultDate + (panel.Controls["dtTo" + i] as DateTimePicker).Value.TimeOfDay
                    });
                }
            }


            /* var deleteList = _schedulerForm.GroupScheduler.Items.Select(c => (int)c.Tag);
             * var tmpDeleteList =
             *  MainForm.Db.GroupsDays.Where(c => c.GroupId == EditId && !deleteList.Contains(c.Id)).ToList();
             *
             * foreach (var item in tmpDeleteList)
             * {
             *  MainForm.Db.GroupsDays.DeleteOnSubmit(item);
             * }
             *
             *
             * foreach (var item in _schedulerForm.GroupScheduler.Items.Where(c => (int)c.Tag != -1))
             * {
             *  var edit = MainForm.Db.GroupsDays.FirstOrDefault(c => c.Id == (int)item.Tag);
             *  if (edit != null)
             *  {
             *      edit.StartDate = item.StartDate;
             *      edit.EndDate = item.EndDate;
             *  }
             * }
             *
             * foreach (var item in _schedulerForm.GroupScheduler.Items.Where(c => (int)c.Tag == -1))
             * {
             *  MainForm.Db.GroupsDays.Add(new GroupsDays
             *  {
             *      GroupId = EditId,
             *      StartDate = item.StartDate,
             *      EndDate = item.EndDate
             *  });
             * }
             */
            MainForm.Db.SubmitChanges();
            this.Hide();
            EditGrid.RefreshGrid();
        }