Ejemplo n.º 1
0
        public bool sua(QuyDinh_DTO qd)
        {
            string query = string.Empty;

            query += "UPDATE QuyDinh SET [tenQD] = @tenQD, [noidung] = @noidung WHERE [maQD] = @maQD";
            using (SqlConnection _cnn = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = _cnn;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@maQD", qd.maQD);
                    cmd.Parameters.AddWithValue("@tenQD", qd.tenQD);
                    cmd.Parameters.AddWithValue("@noidung", qd.noidung);
                    try
                    {
                        _cnn.Open();
                        cmd.ExecuteNonQuery();
                        _cnn.Close();
                        _cnn.Dispose();
                    }
                    catch (Exception ex)
                    {
                        _cnn.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool them(QuyDinh_DTO qd)
        {
            string query = string.Empty;

            query += "INSERT INTO [QuyDinh] ([maQD], [tenQD], [noidung])";
            query += "VALUES (@maQD, @tenQD, @noidung)";
            using (SqlConnection _cnn = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = _cnn;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@maQD", qd.maQD);
                    cmd.Parameters.AddWithValue("@tenQD", qd.tenQD);
                    cmd.Parameters.AddWithValue("@noidung", qd.noidung);
                    try
                    {
                        _cnn.Open();
                        cmd.ExecuteNonQuery();
                        _cnn.Close();
                        _cnn.Dispose();
                    }
                    catch (Exception ex)
                    {
                        _cnn.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            //1. Map data from GUI
            QuyDinh_DTO qd = new QuyDinh_DTO();

            qd.maQD = txtmaQD.Text;

            //2. Kiểm tra data hợp lệ or not

            //3. Xóa trong DB
            bool kq = qdBus.xoa(qd);

            if (kq == false)
            {
                MessageBox.Show("Xóa thất bại. Vui lòng kiểm tra lại dũ liệu");
            }
            else
            {
                txtmaQD.Text    = "";
                txttenQD.Text   = "";
                txtnoidung.Text = "";
                MessageBox.Show("Xóa thành công");
                this.loadData_Vao_GridView();
            }
        }
Ejemplo n.º 4
0
        private void XóaQuyĐịnhToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // ' Get the current cell location.
            int currentRowIndex = dgvQuyDinh.CurrentCellAddress.Y;// 'current row selected


            //'Verify that indexing OK
            if (-1 < currentRowIndex && currentRowIndex < dgvQuyDinh.RowCount)
            {
                QuyDinh_DTO qd = (QuyDinh_DTO)dgvQuyDinh.Rows[currentRowIndex].DataBoundItem;
                if (qd != null)
                {
                    bool kq = qdBus.xoa(qd);
                    if (kq == false)
                    {
                        MessageBox.Show("Xóa quy định thất bại. Vui lòng kiểm tra lại dữ liệu");
                    }
                    else
                    {
                        MessageBox.Show("Xóa quy định thành công");
                        this.loadData_Vao_GridView();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public List <QuyDinh_DTO> selectByKeyWord(string sKeyword)
        {
            string query = string.Empty;

            query += "SELECT [maQD], [tenQD], [noidung]";
            query += "FROM [QuyDinh]";
            query += " WHERE ([maQD] LIKE CONCAT('%',@sKeyword,'%'))";
            query += " OR ([tenQD] LIKE CONCAT('%',@sKeyword,'%'))";
            query += " OR ([noidung] LIKE CONCAT('%',@sKeyword,'%'))";

            List <QuyDinh_DTO> lsQuyDinh = new List <QuyDinh_DTO>();

            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@sKeyword", sKeyword);
                    try
                    {
                        con.Open();
                        SqlDataReader reader = null;
                        reader = cmd.ExecuteReader();
                        if (reader.HasRows == true)
                        {
                            while (reader.Read())
                            {
                                QuyDinh_DTO qd = new QuyDinh_DTO();
                                qd.maQD    = reader["maQD"].ToString();
                                qd.tenQD   = reader["tenQD"].ToString();
                                qd.noidung = reader["noidung"].ToString();
                                lsQuyDinh.Add(qd);
                            }
                        }

                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(null);
                    }
                }
            }
            return(lsQuyDinh);
        }
Ejemplo n.º 6
0
        public List <QuyDinh_DTO> select()
        {
            string query = string.Empty;

            query += "SELECT [maQD], [tenQD], [noidung]";
            query += "FROM [QuyDinh]";

            List <QuyDinh_DTO> lsQuyDinh = new List <QuyDinh_DTO>();

            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    try
                    {
                        con.Open();
                        SqlDataReader reader = null;
                        reader = cmd.ExecuteReader();
                        if (reader.HasRows == true)
                        {
                            while (reader.Read())
                            {
                                QuyDinh_DTO qd = new QuyDinh_DTO();
                                qd.maQD    = reader["maQD"].ToString();
                                qd.tenQD   = reader["tenQD"].ToString();
                                qd.noidung = reader["noidung"].ToString();
                                lsQuyDinh.Add(qd);
                            }
                        }

                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(null);
                    }
                }
            }
            return(lsQuyDinh);
        }
        public bool sua(QuyDinh_DTO qd)
        {
            bool re = qdDal.sua(qd);

            return(re);
        }
        public bool them(QuyDinh_DTO qd)
        {
            bool re = qdDal.them(qd);

            return(re);
        }