Exemplo n.º 1
0
        /// <summary>
        /// 学员登录
        /// </summary>
        private void traineeLogin()
        {
            if (traineeJobNumberTextBox.Text.Trim().Length > 0 && traineePwdTextBox.Text.Trim().Length > 0)
            {
                string jobNumber = traineeJobNumberTextBox.Text.Trim();
                string pwd       = Tool.getMd5Str(traineePwdTextBox.Text.Trim());

                string        conStr = "server=localhost;database=training;integrated security=SSPI";
                SqlConnection con    = new SqlConnection(conStr);
                con.Open();
                string         sql     = "select * from trainees where jobNumber='" + jobNumber + "' and pwd='" + pwd + "'";
                SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
                DataSet        ds      = new DataSet();
                adapter.Fill(ds, "trainees");
                int rows = ds.Tables["trainees"].Rows.Count;

                if (rows > 0)
                {
                    Trainee     trainee   = new Trainee(ds);
                    TraineeForm traineeFm = new TraineeForm(trainee);
                    traineeFm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("员工编号或密码错误");
                }
            }
            else
            {
                MessageBox.Show("请正确输入员工编号和密码");
            }
        }
        public void UpdateTrainee(TraineeForm t)
        {
            if (t.txtTraineeName.Text == "")
            {
                MessageBox.Show("Please,Enter Name");
            }
            else if (!IsAllLetters(t.txtTraineeName.Text))
            {
                MessageBox.Show("Please, Enter Letters Only");
            }
            else
            {
                string gen;
                if (t.rbtnTraineeFemale.IsChecked == true)
                {
                    gen = "Female";
                }
                else
                {
                    gen = "Male";
                }

                int Id = int.Parse(t.txtTraineeID.Text.ToString());
                var tr = (from tre in context.Trainee
                          where tre.ID == Id
                          select tre).FirstOrDefault();
                tr.Name           = t.txtTraineeName.Text;
                tr.Qualification  = t.txtTraineeQualification.Text;
                tr.Gender         = gen;
                tr.MilitaryStatus = t.txtTraineeMilitaryStatus.Text;
                context.SaveChanges();
                MessageBox.Show("Sucsesfuly updated");
            }
        }
        public ActionResult Add(TraineeForm form)
        {
            if (ModelState.IsValid)
            {
                using (UserContext db = new UserContext())
                {
                    TraineeForm currentForm = new TraineeForm()
                    {
                        Name                = form.Name,
                        Surname             = form.Surname,
                        MiddleName          = form.MiddleName,
                        NameOfTheUniversity = form.NameOfTheUniversity,
                        UniversityCourse    = form.UniversityCourse,
                        Faculty             = form.Faculty,
                        Phone               = form.Phone,
                        Email               = form.Email,
                        Info                = form.Info,
                    };

                    currentForm.CreateDate         = DateTime.Now;
                    currentForm.ChangeDate         = DateTime.Now;
                    currentForm.FormCreater        = User.Identity.Name;
                    currentForm.AuthorOfLastChange = User.Identity.Name;

                    User user = db.Users.FirstOrDefault(u => u.Email == User.Identity.Name);

                    db.TraineeForms.Add(currentForm);
                    user.TraineeForms.Add(currentForm);

                    db.SaveChanges();
                    return(RedirectToAction("Home", "Form"));
                }
            }
            return(View(form));
        }
        public void AddTrainee(TraineeForm t, int LabID)
        {
            if (t.txtTraineeName.Text == "")
            {
                MessageBox.Show("Please,Enter Name");
            }
            else
            {
                string gen;
                if (t.rbtnTraineeFemale.IsChecked == true)
                {
                    gen = "Female";
                }
                else
                {
                    gen = "Male";
                }
                Trainee trainee = new Trainee()
                {
                    Name           = t.txtTraineeName.Text,
                    Qualification  = t.txtTraineeQualification.Text,
                    MilitaryStatus = t.txtTraineeMilitaryStatus.Text,
                    Gender         = gen,
                    LabID          = LabID
                };

                context.Trainee.Add(trainee);
                context.SaveChanges();
                MessageBox.Show("Trainee inserted");
            }
        }
 public void FillTraineeList(TraineeForm tr)
 {
     // TraineeList t = new TraineeList();
     // t.lstTrainee.DisplayMemberPath = "Name";
     // t.lstTrainee.SelectedValuePath = "ID";
     //t.lstTrainee.ItemsSource = context.Trainee.ToList();
 }
 public ActionResult Edit(TraineeForm form)
 {
     using (UserContext db = new UserContext())
     {
         db.Entry(form).State    = EntityState.Modified;
         form.AuthorOfLastChange = User.Identity.Name;
         form.ChangeDate         = DateTime.Now;
         db.SaveChanges();
         return(RedirectToAction("Home", "Form"));
     }
 }
 public ActionResult Delete(int?id)
 {
     if (id == null)
     {
         return(HttpNotFound());
     }
     using (UserContext db = new UserContext())
     {
         TraineeForm form = db.TraineeForms.Find(id);
         if (form == null)
         {
             return(HttpNotFound());
         }
         return(View(form));
     }
 }
 public ActionResult DeleteConfirmed(int?id)
 {
     if (id == null)
     {
         return(HttpNotFound());
     }
     using (UserContext db = new UserContext())
     {
         TraineeForm form = db.TraineeForms.Find(id);
         if (form == null)
         {
             return(HttpNotFound());
         }
         db.TraineeForms.Remove(form);
         db.SaveChanges();
         return(RedirectToAction("Home", "Form"));
     }
 }