コード例 #1
0
 public AdminDashboardModel()
 {
     using (var db = new SMUCEUPCtx())
     {
         MemberCount = db.Members.Count();
     }
 }
コード例 #2
0
 private void ClearDB(object sender, System.Windows.RoutedEventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to clear the database? THIS WILL DELETE ALL MEMBERS ADDED ON THIS COMPUTER!",
                         "Delete Confirmation", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
     {
         using (var db = new SMUCEUPCtx())
         {
             db.Database.Delete();
         }
     }
 }
コード例 #3
0
        public void Export(string filename)
        {
            var res = Application.GetResourceStream(new Uri("MembershipTemplate.xlsx", UriKind.Relative));
            using (var db = new SMUCEUPCtx())
            {
                var engine = new ExcelEngine();
                var app = engine.Excel;
                var wb = app.Workbooks.Open(res.Stream, ExcelOpenType.SpreadsheetML2010, ExcelVersion.Excel2010);
                var sheet = wb.Worksheets[0];

                var rowN = 4;

                foreach (var member in db.Members)
                {
                    sheet.Range[rowN, 1].Value = member.Name;
                    sheet.Range[rowN, 2].Value = member.StudentNumber;
                    sheet.Range[rowN, 3].Value = member.Authcate;
                    sheet.Range[rowN, 4].Value = member.PhoneNumber;
                    sheet.Range[rowN, 5].Value = member.HasMSACard ? "Yes" : "No";
                    sheet.Range[rowN, 6].Value = member.IsClaytonStudent ? "Yes" : "No";
                    sheet.Range[rowN, 7].Value = member.IsInternationalStudent ? "Yes" : "No";
                    if (member.IsStudyingEngineering)
                    {
                        sheet.Range[rowN, 8].Value = member.EngineeringDegree.Name;
                        sheet.Range[rowN, 10].Value = member.EngineeringSpecialty.Name;
                        if (member.IsStudyingDoubleDegree)
                        {
                            sheet.Range[rowN, 9].Value = member.OtherDegree.Name;
                            if (member.OtherMajor1 != null)
                                sheet.Range[rowN, 11].Value = member.OtherMajor1.Name;
                            if (member.OtherMajor2 != null)
                                sheet.Range[rowN, 12].Value = member.OtherMajor2.Name;
                        }
                    }

                    rowN++;
                }

                wb.SaveAs(filename);
            }
        }
コード例 #4
0
        public void Save()
        {
            using (var db = new SMUCEUPCtx())
            {
                var newMember = new Member()
                {
                    Id = Guid.NewGuid(),
                    Name = Name,
                    StudentNumber = StudentNumber,
                    Authcate = AuthcateUsername,
                    PhoneNumber = PhoneNumber,
                    Address = Address,
                    IsClaytonStudent = ClaytonStudent,
                    HasMSACard = MSACard,
                    IsInternationalStudent = IsInternationalStudent,
                    IsStudyingDoubleDegree = IsStudyingDoubleDegree,
                    IsStudyingEngineering = IsStudyingEngineering,
                    EngineeringDegree = EngineeringDegree == 0 ? null : db.EngineeringDegrees.Where(d => d.Id == EngineeringDegree).Single(),
                    EngineeringSpecialty = EngineeringSpecialty == 0 ? null : db.EngineeringSpecialties.Where(s => s.Id == EngineeringSpecialty).Single(),
                    OtherDegree = OtherDegree == 0 ? null : db.NonEngineeringDegrees.Where(d => d.Id == OtherDegree).Single(),
                    OtherMajor1 = OtherMajor1 == 0 ? null : db.NonEngineeringMajors.Where(m => m.Id == OtherMajor1).Single(),
                    OtherMajor2 = OtherMajor2 == 0 ? null : db.NonEngineeringMajors.Where(m => m.Id == OtherMajor2).Single(),
                };

                db.Members.Add(newMember);
                db.SaveChanges();
            }
        }