Beispiel #1
0
        // to modify type from THELOAISACH table
        public bool mod(typeDTO type)
        {
            string query = string.Empty;

            query += "UPDATE THELOAISACH SET ";
            query += "TenTheLoai=@ttl WHERE MaTheLoai = @mtl";
            using (SqlConnection con = new SqlConnection(@"server=" + Dns.GetHostName() + ";Trusted_Connection=yes;database=LIBMANAGEMENT;")) //Init connection to host
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@mtl", type.maTheLoai);
                    cmd.Parameters.AddWithValue("@ttl", type.tenTheLoai);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
        private void btnMod_Click(object sender, EventArgs e)
        {
            frmModTypes  frmModTypes = new frmModTypes();
            DialogResult warning     = new DialogResult();

            warning = MessageBox.Show("Bạn có chắc chắn muốn sửa thể loại này?", "Cảnh báo!", MessageBoxButtons.YesNo);
            if (warning == DialogResult.Yes)
            {
                int rowIndex = dgvTypesManage.CurrentCell.RowIndex;

                typeDTO typeDTO = new typeDTO();
                typeDTO.maTheLoai  = dgvTypesManage.Rows[rowIndex].Cells[0].Value.ToString();
                typeDTO.tenTheLoai = dgvTypesManage.Rows[rowIndex].Cells[1].Value.ToString();

                frmModTypes.tbTypeCode.Text     = typeDTO.maTheLoai;
                frmModTypes.tbTypeName.Text     = typeDTO.tenTheLoai;
                frmModTypes.tbTypeCode.ReadOnly = true;

                frmModTypes.ShowDialog();
            }
            else
            {
                return;
            }
            LoadDataInto_DataGridViewOfType();
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int maxType = typeBUS.getMaxNumberofType();
            int temp    = typeBUS.getNumberofType(); // to get present number of type

            if (temp >= maxType && maxType != 0)
            {
                MessageBox.Show("Số lượng thể loại đã lớn hơn số qui định");
                return;
            }
            else
            {
                typeDTO typeDTO = new typeDTO();
                //to map data from gui
                typeDTO.maTheLoai  = tbTypeCode.Text;
                typeDTO.tenTheLoai = tbTypeName.Text;

                bool result = typeBUS.add(typeDTO);
                if (result == true)
                {
                    MessageBox.Show("Thêm thể loại thành công");
                }
                else
                {
                    MessageBox.Show("Thêm thể loại thất bại");
                }
            }
        }
Beispiel #4
0
        //to select list of type from DB
        public List <typeDTO> selectedTypes()
        {
            string query = string.Empty;

            query += "SELECT *";
            query += " FROM THELOAISACH";

            List <typeDTO> lsTypes = new List <typeDTO>();

            using (SqlConnection con = new SqlConnection(@"server=" + Dns.GetHostName() + ";Trusted_Connection=yes;database=LIBMANAGEMENT;"))
            {
                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())
                            {
                                typeDTO types = new typeDTO();
                                types.maTheLoai  = reader["MaTheLoai"].ToString();
                                types.tenTheLoai = reader["TenTheLoai"].ToString();
                                lsTypes.Add(types);
                            }
                        }

                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(null);
                    }
                }
            }
            return(lsTypes);
        }
        private void btnDel_Click(object sender, EventArgs e)
        {
            DialogResult warning = new DialogResult();

            warning = MessageBox.Show("Bạn có chắc chắn muốn xóa thể loại này?", "Cảnh báo!", MessageBoxButtons.YesNo);
            if (warning == DialogResult.Yes)
            {
                int rowIndex = dgvTypesManage.CurrentCell.RowIndex;

                typeDTO typeDTO = new typeDTO();
                typeDTO.maTheLoai = dgvTypesManage.Rows[rowIndex].Cells[0].Value.ToString();
                typeBUS.del(typeDTO);
            }
            else
            {
                return;
            }
            LoadDataInto_DataGridViewOfType();
        }
        private void btnMod_Click(object sender, EventArgs e)
        {
            typeDTO typeDTO = new typeDTO();

            //to map data from gui
            typeDTO.maTheLoai  = tbTypeCode.Text;
            typeDTO.tenTheLoai = tbTypeName.Text;

            bool result = typeBUS.mod(typeDTO);

            if (result == true)
            {
                MessageBox.Show("Sửa thể loại thành công");
            }
            else
            {
                MessageBox.Show("Sửa thể loại thất bại");
            }
        }
Beispiel #7
0
        public bool mod(typeDTO typeDTO)
        {
            bool isMod = typeDAL.mod(typeDTO);

            return(isMod);
        }
Beispiel #8
0
        public bool del(typeDTO typeDTO)
        {
            bool isDel = typeDAL.del(typeDTO);

            return(isDel);
        }
Beispiel #9
0
        public bool add(typeDTO typeDTO)
        {
            bool isAdd = typeDAL.add(typeDTO);

            return(isAdd);
        }