コード例 #1
0
        private void ButtonRefresh_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("select * from Std");

            DataGridView1.ReadOnly = true; //nạp lại dữ liệu trên dgv
            DataGridViewImageColumn picCol = new DataGridViewImageColumn();

            DataGridView1.RowTemplate.Height = 90;
            DataGridView1.DataSource         = student.getStudents(cmd);
            picCol             = (DataGridViewImageColumn)DataGridView1.Columns[7];
            picCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
            DataGridView1.AllowUserToAddRows = false;
        }
コード例 #2
0
        private void studentsListForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the '_DESKTOP_RRRHOP4DataSet1.SinhVien' table. You can move, or remove it, as needed.
            this.sinhVienTableAdapter.Fill(this._DESKTOP_RRRHOP4DataSet1.SinhVien);
            SqlCommand cmd = new SqlCommand("select * from Std");

            DataGridView1.ReadOnly = true;
            //xử lí hình ảnh, code có tham khảo msdn
            DataGridViewImageColumn picCol = new DataGridViewImageColumn();

            DataGridView1.RowTemplate.Height = 90; //chỉnh pic đẹp
            DataGridView1.DataSource         = student.getStudents(cmd);
            picCol             = (DataGridViewImageColumn)DataGridView1.Columns[7];
            picCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
            DataGridView1.AllowUserToAddRows = false;
        }
コード例 #3
0
        private void Print_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the '_DESKTOP_RRRHOP4DataSet3.Std' table. You can move, or remove it, as needed.
            this.stdTableAdapter.Fill(this._DESKTOP_RRRHOP4DataSet3.Std);
            DateTimePic3.CustomFormat  = "yyyy-dd-MM";
            DateTimePic3.Format        = DateTimePickerFormat.Custom;
            DateTimePick4.CustomFormat = "yyyy-dd-MM";
            DateTimePick4.Format       = DateTimePickerFormat.Custom;
            // TODO: This line of code loads data into the '_DESKTOP_RRRHOP4DataSet1.SinhVien' table. You can move, or remove it, as needed.

            SqlCommand cmd = new SqlCommand("select * from Std");

            DataGridView2.ReadOnly = true;
            //xử lí hình ảnh, code có tham khảo msdn
            DataGridViewImageColumn picCol = new DataGridViewImageColumn();

            DataGridView2.RowTemplate.Height = 90; //chỉnh pic đẹp
            DataGridView2.Width      = 4500;
            DataGridView2.DataSource = student.getStudents(cmd);
            picCol             = (DataGridViewImageColumn)DataGridView2.Columns[7];
            picCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
            DataGridView2.AllowUserToAddRows = false;
        }
コード例 #4
0
ファイル: UpdateDeleteStudentForm.cs プロジェクト: ysnna/QLXe
        private void buttonFind_Click(object sender, EventArgs e)
        {
            #region Tìm kiếm theo ID của Thầy

            /*
             * if (IsNumber(txtSearch.Text) == true)
             * {
             *  int id = int.Parse(txtSearch.Text);
             *  SqlCommand cmd = new SqlCommand("select id, fname, lname, bdate, gender, phone, address, picture from Std where id = " + id);
             *  DataTable table = student.getStudents(cmd);
             *  if (table.Rows.Count >= 0)
             *  {
             *      TextBoxID.Text = table.Rows[0]["id"].ToString();
             *      TextBoxFname.Text = table.Rows[0]["fname"].ToString();
             *      TextBoxLname.Text = table.Rows[0]["lname"].ToString();
             *      DateTimePicker1.Value = (DateTime)table.Rows[0]["bdate"];
             *      if (table.Rows[0]["gender"].ToString() == "Female")
             *      {
             *          RadioButtonFemale.Checked = true;
             *      }
             *      else RadioButtonMale.Checked = true;
             *      TextBoxPhone.Text = table.Rows[0]["phone"].ToString();
             *      TextBoxAddress.Text = table.Rows[0]["address"].ToString();
             *      byte[] pic = (byte[])table.Rows[0]["picture"];
             *      MemoryStream picture = new MemoryStream(pic);
             *      PictureBoxStudentImage.Image = Image.FromStream(picture);
             *      MessageBox.Show("Not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *  }
             *  else MessageBox.Show("Not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *
             * }
             * else
             * {
             *  studentsListForm up = new studentsListForm();
             *  up.ShowDialog();
             *
             * }
             */
            #endregion
            MY_DB mydb = new MY_DB();
            if (IsNumber(TextBoxSearch.Text))   //tìm kiếm theo ID
            {
                int        id      = int.Parse(TextBoxSearch.Text);
                SqlCommand command = new SqlCommand("SELECT id, fname, lname, bdate, gender, phone, address, picture from Std where id = " + id + "or phone = " + id, mydb.getConnection);
                //SqlCommand comand = new SqlCommand(query + id, db.GetConnection);
                DataTable      table   = new DataTable();
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                adapter.Fill(table);
                if (table.Rows.Count > 0)
                {
                    TextBoxID.Text        = table.Rows[0]["id"].ToString();
                    TextBoxFname.Text     = table.Rows[0]["fname"].ToString();
                    TextBoxLname.Text     = table.Rows[0]["lname"].ToString();
                    DateTimePicker1.Value = (DateTime)table.Rows[0]["bdate"];
                    if (table.Rows[0]["gender"].ToString() == "Female")
                    {
                        RadioButtonFemale.Checked = true;
                    }
                    else
                    {
                        RadioButtonMale.Checked = true;
                    }
                    TextBoxPhone.Text   = table.Rows[0]["phone"].ToString();
                    TextBoxAddress.Text = table.Rows[0]["address"].ToString();
                    byte[]       pic     = (byte[])table.Rows[0]["picture"];
                    MemoryStream picture = new MemoryStream(pic);
                    PictureBoxStudentImage.Image = Image.FromStream(picture);
                }
                else
                {
                    MessageBox.Show("Not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else  //Tìm theo tên
            {
                SqlCommand command = new SqlCommand("SELECT * FROM Std WHERE fname = @name", mydb.getConnection);
                command.Parameters.Add("@name", SqlDbType.VarChar).Value = TextBoxSearch.Text;
                SqlDataAdapter da = new SqlDataAdapter(command);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    AdvancedSearch find = new AdvancedSearch();
                    find.DataGridView1.DataSource = student.getStudents(command);
                    find.DataGridView1.ReadOnly   = true;
                    DataGridViewImageColumn picCol = new DataGridViewImageColumn();
                    find.DataGridView1.RowTemplate.Height = 90;
                    picCol             = (DataGridViewImageColumn)find.DataGridView1.Columns[7];
                    picCol.ImageLayout = DataGridViewImageCellLayout.Zoom;
                    find.DataGridView1.AllowUserToAddRows = false;
                    find.Show();
                }
                else
                {
                    MessageBox.Show("Not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }