示例#1
0
 /// <summary>
 /// 批量修改列
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button17_Click(object sender, EventArgs e)
 {
     try
     {
         var i   = 0;
         var col = dataGridView1.Columns[dataGridView1.SelectedCells[0].ColumnIndex];
         var str = Interaction.InputBox($"是否批量修改选中的{col.HeaderText}列", "批量修改");
         if (!string.IsNullOrEmpty(col.HeaderText))
         {
             foreach (DataGridViewCell item in dataGridView1.SelectedCells)
             {
                 var          stu  = studentManage.GetInfo((string)dataGridView1.Rows[item.RowIndex].Cells[1].Value);
                 PropertyInfo prop = typeof(Student).GetProperty(col.DataPropertyName);
                 prop.SetValue(stu, str);
                 studentManage.Save(stu);
                 ++i;
             }
             MessageBox.Show($"修改成功,共{i}条");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("修改失败!!!! 请联系作者 ex:" + "\n" + ex.Message + ex.StackTrace);
     }
     button1_Click(null, null);
 }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (Int32.TryParse(textBox5.Text.Trim(), out int age) == false)
            {
                MessageBox.Show("年龄 必须为数字");
                return;
            }
            if (Student == null)
            {
                Student = new Student();
            }
            else
            {
                //编辑
            }
            //Student.UserId = userId;
            //Student.UserName = textBox2.Text.Trim();
            //Student.UserPassWord = textBox3.Text.Trim();
            //Student.IsAdmin = checkBox1.Checked;

            Student.Sno    = textBox1.Text.Trim();
            Student.Sname  = textBox2.Text.Trim();
            Student.Stel   = textBox4.Text.Trim();
            Student.Sage   = age;
            Student.Sgrade = textBox6.Text.Trim();
            Student.Ssex   = radioButton1.Checked;
            try
            {
                StudentManange.Save(Student);
                MessageBox.Show("保存成功");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("请检查输入内容。是否超长\n" + ex.Message);
            }
        }