コード例 #1
0
        //DeleteOB
        public bool _DeleteOb(Ob_DH_TrangThai ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From DH_TrangThai Where ID_TrangThai=@ID_TrangThai"
            };

            command.Parameters.Add(new SqlParameter("ID_TrangThai", ob.ID_TRANGTHAI));
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Không thể xóa dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            command.Dispose();
            command = null;
            conn.Close();
            return(true);
        }
コード例 #2
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_DH_TrangThai ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update DH_TrangThai Set TenTrangThai=@TenTrangThai Where ID_TrangThai=@ID_TrangThai"
            };

            command.Parameters.Add("ID_TrangThai", SqlDbType.Int).Value = ob.ID_TRANGTHAI;
            if (ob.TENTRANGTHAI.Trim() == "")
            {
                command.Parameters.Add("TenTrangThai", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("TenTrangThai", SqlDbType.NVarChar).Value = ob.TENTRANGTHAI;
            }
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Không thể cập nhật dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            if (command.ExecuteNonQuery() == 0)
            {
                MessageBox.Show("Không thể cập nhật dữ liệu. \r\n", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                command.Dispose();
                command = null;
                conn.Close();
                return(false);
            }
            command.Dispose();
            command = null;
            conn.Close();
            return(true);
        }
コード例 #3
0
        //GetObWhere
        public Ob_DH_TrangThai _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_DH_TrangThai ob      = new Ob_DH_TrangThai();
            SqlCommand      command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_TrangThai, TenTrangThai From DH_TrangThai Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_TRANGTHAI = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.TENTRANGTHAI = Convert.ToString(reader[1]);
                }
            }
            if (num == 0)
            {
                command.Dispose();
                command = null;
                reader.Dispose();
                reader = null;
                conn.Close();
                return(null);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(ob);
        }
コード例 #4
0
        //InsertobGetId
        public int _InsertObGetId(Ob_DH_TrangThai ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into DH_TrangThai (ID_TrangThai, TenTrangThai) Values(@ID_TrangThai, @TenTrangThai)Select @@IDENTITY"
                };
                command.Parameters.Add("ID_TrangThai", SqlDbType.Int).Value = ob.ID_TRANGTHAI;
                if (ob.TENTRANGTHAI.Trim() == "")
                {
                    command.Parameters.Add("TenTrangThai", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("TenTrangThai", SqlDbType.NVarChar).Value = ob.TENTRANGTHAI;
                }
                try
                {
                    num = Convert.ToInt32(command.ExecuteScalar());
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Không thể thêm dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    command.Dispose();
                    command = null;
                    conn.Close();
                    return(num);
                }
                command.Dispose();
                command = null;
                conn.Close();
            }
            return(num);
        }
コード例 #5
0
        //ListWhere_sp
        public List <Ob_DH_TrangThai> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DH_TrangThai> list    = new List <Ob_DH_TrangThai>();
            SqlCommand             command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };

            command.Parameters.AddRange(ArrayParameter);
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DH_TrangThai ob = new Ob_DH_TrangThai();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_TRANGTHAI = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.TENTRANGTHAI = Convert.ToString(reader[1]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
コード例 #6
0
        //ListAll
        public List <Ob_DH_TrangThai> _ListAll(SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DH_TrangThai> list    = new List <Ob_DH_TrangThai>();
            SqlCommand             command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_TrangThai, TenTrangThai From DH_TrangThai"
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DH_TrangThai ob = new Ob_DH_TrangThai();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_TRANGTHAI = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.TENTRANGTHAI = Convert.ToString(reader[1]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
コード例 #7
0
 public Ob_DH_TrangThai(Ob_DH_TrangThai newOb)
 {
     id_trangthai = newOb.ID_TRANGTHAI;
     tentrangthai = newOb.TENTRANGTHAI;
 }