Пример #1
0
        private void Dialog_Closing(object sender, MaterialDesignThemes.Wpf.DialogClosingEventArgs eventArgs)
        {
            var confirmed = (bool)eventArgs.Parameter;

            if (confirmed)
            {
                if (!string.IsNullOrEmpty(txtFirstName.Text) && !string.IsNullOrEmpty(txtLastName.Text) &&
                    !string.IsNullOrEmpty(txtMobile.Text))
                {
                    int?id;
                    if (Member.Id == 0)
                    {
                        Member              = new MemberVM();
                        Member.Firstname    = txtFirstName.Text;
                        Member.Lastname     = txtLastName.Text;
                        Member.Mobile       = txtMobile.Text;
                        Member.NationalCode = txtNationalCode.Text;
                        Member.IsRegular    = false;
                        id = Member.Insert();
                        db = new Data.GymContextDataContext();
                    }
                    else
                    {
                        id = Member.Id;
                    }
                    if (id.HasValue)
                    {
                        Member.Id = id.Value;
                        Data.Passage enter = new Data.Passage {
                            IsEntrance = true, MemberId = id.Value, Time = DateTime.Now
                        };

                        byte method = (byte)(rdCash.IsChecked == true ? 0 : (rdPos.IsChecked == true ? 1 : (rdCard.IsChecked == true ? 2 : 3)));

                        Data.Transaction pay = new Data.Transaction
                        {
                            Amount   = txtPayable.Value,
                            Datetime = DateTime.Now,
                            Info     = "تک جلسه" + (txtFacilityCost.Value > 0 ? " + امکانات" : ""),
                            MemberId = id.Value,
                            Method   = method,
                            UserId   = Main.CurrentUser.Id,
                            Type     = (byte)TransactionType.SingleSession
                        };

                        db.Passages.InsertOnSubmit(enter);
                        db.Transactions.InsertOnSubmit(pay);
                        db.SubmitChanges();

                        Member.UseCloset(db);

                        var main = Application.Current.Windows.Cast <Window>().ToList().Find(w => w.GetType().Name == "Main") as Main;
                        main.TransitList.UpdatePassages();

                        Main.Home.Closets.LoadClosets();
                    }
                }
            }
            this.Close();
        }
Пример #2
0
        private void Time_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var id = ((int)((Label)sender).Tag);

            Data.Passage exit = new Data.Passage {
                IsEntrance = false, MemberId = id, Time = DateTime.Now
            };

            db.Passages.InsertOnSubmit(exit);
            db.SubmitChanges();

            var member = db.Members.Where(m => m.Id == id).FirstOrDefault();
            var Member = new MemberCard(member.Id);

            Member.Member.FreeUpCloset(db);
            //member.FreeUpCloset(db);

            Main.Home.TransitList.UpdatePassages();
            Main.Home.Closets.LoadClosets();
            LoadIrregularEnters();
        }
Пример #3
0
        void ProcessTransit(MaterialDesignThemes.Wpf.DialogClosingEventArgs eventArgs)
        {
            if (Type == MemberSelectionCategory.PersonnelTransit)
            {
                Data.Passage pass = new Data.Passage();
                pass.MemberId   = SelectedMember.Id;
                pass.IsEntrance = prdIn.IsChecked == true;
                pass.Time       = DateTime.Now;
                db.Passages.InsertOnSubmit(pass);

                db.SubmitChanges();
                Main.Home.TransitList.UpdatePassages();

                if (SelectedMember != null)
                {
                    this.Close();
                }
            }
            else if (Type == MemberSelectionCategory.MembersTransit)
            {
                if (rdIn.IsChecked == true)
                {
                    var usedCoursesCount = CoursesBox.Children.Cast <CheckBox>().Where(c => c.IsChecked == true).Count();
                    if (usedCoursesCount == 0)
                    {
                        Alert.Content            = $"هیچ دوره ای انتخاب نشده بنابراین ورود ثبت نشد، مجددا تلاش فرمایید";
                        MessageSnackBar.IsActive = true;
                        eventArgs.Cancel();
                        return;
                    }

                    CoursesBox.Children.Cast <CheckBox>().Where(c => c.IsChecked == true).ToList().ForEach(check =>
                    {
                        //if (!needsSave) needsSave = true;
                        var item = check.Tag as MemberCourse;

                        var courseUsage = db.EnrollCourses.Where(ec =>
                                                                 ec.CourseId == item.CId &&
                                                                 ec.EnrollId == item.EId
                                                                 ).FirstOrDefault();

                        if (courseUsage.Enroll.Frequency == 2) //2 = جلسه ای
                        {
                            courseUsage.SessionsLeft -= 1;
                        }
                    });
                }

                //bool needsSave = false;

                //if (needsSave) db.SubmitChanges();

                Data.Passage pass = new Data.Passage();
                pass.MemberId   = SelectedMember.Id;
                pass.IsEntrance = Type == MemberSelectionCategory.MembersTransit ? rdIn.IsChecked == true : prdIn.IsChecked == true;
                pass.Time       = DateTime.Now;
                db.Passages.InsertOnSubmit(pass);


                if (rdOut.IsChecked == true)
                {
                    var mmbr  = db.Members.Where(m => m.Id == SelectedMember.Id).FirstOrDefault();
                    var nrols = mmbr.Enrolls.Where(e => e.StartDate <= DateTime.Today &&
                                                   (e.ExpireDate == null || e.ExpireDate >= DateTime.Today)).ToList();
                    var nc = nrols.SelectMany(n => n.EnrollCourses).ToList();


                    if (!nc.Any(c => c.SessionsLeft > 0))
                    {
                        nrols.SelectMany(n => n.EnrollFacilities).ToList().ForEach(f => f.SessionsLeft = 0);
                        nrols.ForEach(n => n.IsActive = false);
                    }
                    else
                    {
                        FacilitiesBox.Children.Cast <CheckBox>().Where(c => c.IsChecked == true).ToList().ForEach(check =>
                        {
                            var item = check.Tag as MemberFacility;

                            var facilityUsage = db.EnrollFacilities.Where(ef =>
                                                                          ef.FacilityId == item.FId &&
                                                                          ef.EnrollId == item.EId
                                                                          ).FirstOrDefault();

                            facilityUsage.SessionsLeft -= 1;
                        });
                    }
                }

                db.SubmitChanges();
                Info.SetMember(SelectedMember.Id, pass.IsEntrance ? "ورود" : "خروج", PayedFacilities.Select(f => f.Name).ToList());
                Info.Show();
                Info.Focus();
                Close();

                if (pass.IsEntrance)
                {
                    SelectedMember.UseCloset(db);
                }
                else
                {
                    SelectedMember.FreeUpCloset(db);
                }

                Main.Home.Closets.LoadClosets();
                Main.Home.TransitList.UpdatePassages();

                //Reduce one Session from Course Sessions & Facility Sessions

                //bool needsSave = false;
                //FacilitiesBox.Children.Cast<CheckBox>().Where(c => c.IsChecked == true).ToList().ForEach(check =>
                //  {
                //      if (!needsSave) needsSave = true;
                //      var item = check.Tag as MemberFacility;

                //      var facilityUsage = db.EnrollFacilities.Where(ef =>
                //          ef.FacilityId == item.FId &&
                //          ef.EnrollId == item.EId
                //      ).FirstOrDefault();

                //      facilityUsage.SessionsLeft -= 1;
                //  });
                //if (needsSave) db.SubmitChanges();


                //if (SelectedMember != null)
                //{
                //    this.Close();
                //}
            }
            else if (Type == MemberSelectionCategory.DeleteMembers)
            {
                db = new Data.GymContextDataContext();
                db.Members.Where(m => m.Id == SelectedMember.Id).FirstOrDefault().IsDeleted = true;

                if (tglGetCardBack.IsChecked == true)
                {
                    ;//Make Card Clear to be used by other members
                }
                db.SubmitChanges();

                ListMembers(txtSearchBox.Text);
            }
        }