private void postbtn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         //Using ADO.Net Entities for insertion operation
         WPFLIBDATABASEEntities entities = new WPFLIBDATABASEEntities();
         Question question = new Question();
         question.Question1      = qstntxt.Text;
         question.PostDate       = expdt.SelectedDate.Value;
         question.Mark_Available = Convert.ToInt32(mrkalottxt.Text);
         if (MyImage.Source != null)
         {
             //Begin Convert Image from Source to Byte
             FileStream   stream  = new FileStream(filename, FileMode.Open, FileAccess.Read);
             StreamReader reader  = new StreamReader(stream);
             Byte[]       ImgData = new Byte[stream.Length - 1];
             stream.Read(ImgData, 0, (int)stream.Length - 1);
             //End
             question.Picture = ImgData;
         }
         entities.Questions.Add(question);
         entities.SaveChanges();
         //cleaning up components after insertion
         qstntxt.Clear();
         mrkalottxt.Clear();
         MyImage.Source     = null;
         expdt.SelectedDate = null;
     }
     catch (Exception)
     {
         MessageBox.Show("Please Check All Fields", "Error");
     }
 }
Example #2
0
 private void Loginbtn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         WPFLIBDATABASEEntities dbe = new WPFLIBDATABASEEntities();
         if (Admin.Text != string.Empty || AdminPassword.Password != string.Empty)
         {
             var Admins = dbe.AdminLogins.FirstOrDefault(a => a.AdminID.Equals(Admin.Text));
             if (Admins != null)
             {
                 if (Admins.Password.Equals(AdminPassword.Password))
                 {
                     AdminPanel adpa = new AdminPanel();
                     Application.Current.Windows[0].Close();
                     adpa.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("Password Incorrect");
                 }
             }
             else
             {
                 MessageBox.Show("Admin Invalid");
             }
         }
     }catch (Exception ex)
     {
         MessageBox.Show("" + ex.Message);
     }
 }
 private void Signup_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         WPFLIBDATABASEEntities dbe = new WPFLIBDATABASEEntities();
         if (signidtxt.Text != string.Empty || signpasstxt.Password != string.Empty || signconpasstxt.Password != string.Empty)
         {
             var studentsid = dbe.StudentModelLogins.FirstOrDefault(a => a.Roll_No.Equals(signidtxt.Text));
             if (studentsid != null)
             {
                 if (studentsid.Password == null)
                 {
                     if (signpasstxt.Password != "")
                     {
                         if (signpasstxt.Password == signconpasstxt.Password)
                         {
                             using (dbe)
                             {
                                 var query = (from StudentModelLogin in dbe.StudentModelLogins
                                              where StudentModelLogin.Roll_No == signidtxt.Text
                                              select StudentModelLogin).First();
                                 query.Password         = signpasstxt.Password;
                                 dbe.Entry(query).State = EntityState.Modified;
                                 dbe.SaveChanges();
                                 signidtxt.Clear();
                                 signpasstxt.Clear();
                                 signconpasstxt.Clear();
                                 MessageBox.Show("Account Created.");
                             }
                         }
                         else
                         {
                             MessageBox.Show("Password fields does not match.");
                         }
                     }
                     else
                     {
                         MessageBox.Show("Don't leave a field blank.");
                     }
                 }
                 else
                 {
                     MessageBox.Show("You already have a account.");
                 }
             }
             else
             {
                 MessageBox.Show("Invalid ID");
             }
         }
         else
         {
             MessageBox.Show("Don't leave a field blank.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void loadgrid()
        {
            WPFLIBDATABASEEntities context = new WPFLIBDATABASEEntities();
            var data = from c in context.StudentAnswers
                       select c; /*new { c.SAno, c.Roll_No, c.Answer, c.Qno , c.Mark_Obtained };*/

            studentAnswerDataGrid.ItemsSource = data.ToList();
        }
Example #5
0
        private void loadgrid()
        {
            WPFLIBDATABASEEntities context = new WPFLIBDATABASEEntities();
            var data = from c in context.StudentModelLogins
                       select new { c.Roll_No, c.Name, c.Gender, c.Total_Mark };

            studgrid.ItemsSource = data.ToList();
        }
        private void loadgrid()
        {
            WPFLIBDATABASEEntities context = new WPFLIBDATABASEEntities();
            var data = from c in context.Questions
                       select new { c.Qno, c.Question1, c.Mark_Available, c.Picture, c.PostDate };

            questionDataGrid.ItemsSource = data.ToList();
        }
 private void login_Click(object sender, RoutedEventArgs e)
 {
     if (logidtxt.Text != "" && logpasstxt.Password != "")
     {
         try
         {
             WPFLIBDATABASEEntities dbs = new WPFLIBDATABASEEntities();
             if (logidtxt.Text != string.Empty || logpasstxt.Password != string.Empty)
             {
                 var studs = dbs.StudentModelLogins.FirstOrDefault(a => a.Roll_No.Equals(logidtxt.Text));
                 if (studs != null)
                 {
                     if (studs.Password.Equals(logpasstxt.Password))
                     {
                         roll = studs.Roll_No;
                         nam  = studs.Name;
                         StudentPanel stpa = new StudentPanel(roll, nam);
                         Application.Current.Windows[0].Close();
                         stpa.ShowDialog();
                     }
                     else
                     {
                         MessageBox.Show("Password Incorrect!");
                     }
                 }
                 else
                 {
                     MessageBox.Show("Account not found.");
                 }
             }
             else
             {
                 MessageBox.Show("Fill both fields.");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("" + ex.Message);
         }
     }
     else
     {
         MessageBox.Show("Don't leave a blank field.");
     }
 }